1 17 18 21 package org.quartz.impl.jdbcjobstore; 22 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 28 35 public class StdRowLockSemaphore extends DBSemaphore { 36 37 44 45 public static final String SELECT_FOR_LOCK = "SELECT * FROM " 46 + TABLE_PREFIX_SUBST + TABLE_LOCKS + " WHERE " + COL_LOCK_NAME 47 + " = ? FOR UPDATE"; 48 49 56 57 61 public StdRowLockSemaphore() { 62 super(DEFAULT_TABLE_PREFIX, null, SELECT_FOR_LOCK); 63 } 64 65 public StdRowLockSemaphore(String tablePrefix, String selectWithLockSQL) { 66 super(tablePrefix, selectWithLockSQL, SELECT_FOR_LOCK); 67 } 68 69 76 77 80 protected void executeSQL(Connection conn, String lockName, String expandedSQL) throws LockException { 81 PreparedStatement ps = null; 82 ResultSet rs = null; 83 try { 84 ps = conn.prepareStatement(expandedSQL); 85 ps.setString(1, lockName); 86 87 if (getLog().isDebugEnabled()) { 88 getLog().debug( 89 "Lock '" + lockName + "' is being obtained: " + 90 Thread.currentThread().getName()); 91 } 92 rs = ps.executeQuery(); 93 if (!rs.next()) { 94 throw new SQLException (Util.rtp( 95 "No row exists in table " + TABLE_PREFIX_SUBST + 96 TABLE_LOCKS + " for lock named: " + lockName, getTablePrefix())); 97 } 98 } catch (SQLException sqle) { 99 106 if (getLog().isDebugEnabled()) { 107 getLog().debug( 108 "Lock '" + lockName + "' was not obtained by: " + 109 Thread.currentThread().getName()); 110 } 111 112 throw new LockException("Failure obtaining db row lock: " 113 + sqle.getMessage(), sqle); 114 } finally { 115 if (rs != null) { 116 try { 117 rs.close(); 118 } catch (Exception ignore) { 119 } 120 } 121 if (ps != null) { 122 try { 123 ps.close(); 124 } catch (Exception ignore) { 125 } 126 } 127 } 128 } 129 130 protected String getSelectWithLockSQL() { 131 return getSQL(); 132 } 133 134 public void setSelectWithLockSQL(String selectWithLockSQL) { 135 setSQL(selectWithLockSQL); 136 } 137 } 138 | Popular Tags |