1 16 17 package org.quartz.impl.jdbcjobstore; 18 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 import java.sql.SQLException ; 22 23 34 public class UpdateLockRowSemaphore extends DBSemaphore { 35 36 43 44 public static final String UPDATE_FOR_LOCK = 45 "UPDATE " + TABLE_PREFIX_SUBST + TABLE_LOCKS + 46 " SET " + COL_LOCK_NAME + " = " + COL_LOCK_NAME + 47 " WHERE " + COL_LOCK_NAME + " = ? "; 48 49 50 57 58 public UpdateLockRowSemaphore() { 59 super(DEFAULT_TABLE_PREFIX, null, UPDATE_FOR_LOCK); 60 } 61 62 69 70 73 protected void executeSQL(Connection conn, String lockName, String expandedSQL) throws LockException { 74 PreparedStatement ps = null; 75 76 try { 77 ps = conn.prepareStatement(expandedSQL); 78 ps.setString(1, lockName); 79 80 if (getLog().isDebugEnabled()) { 81 getLog().debug( 82 "Lock '" + lockName + "' is being obtained: " + 83 Thread.currentThread().getName()); 84 } 85 86 int numUpdate = ps.executeUpdate(); 87 88 if (numUpdate < 1) { 89 throw new SQLException (Util.rtp( 90 "No row exists in table " + TABLE_PREFIX_SUBST + TABLE_LOCKS + 91 " for lock named: " + lockName, getTablePrefix())); 92 } 93 } catch (SQLException sqle) { 94 101 if(getLog().isDebugEnabled()) { 102 getLog().debug( 103 "Lock '" + lockName + "' was not obtained by: " + 104 Thread.currentThread().getName()); 105 } 106 107 throw new LockException( 108 "Failure obtaining db row lock: " + sqle.getMessage(), sqle); 109 } finally { 110 if (ps != null) { 111 try { 112 ps.close(); 113 } catch (Exception ignore) { 114 } 115 } 116 } 117 } 118 119 protected String getUpdateLockRowSQL() { 120 return getSQL(); 121 } 122 123 public void setUpdateLockRowSQL(String updateLockRowSQL) { 124 setSQL(updateLockRowSQL); 125 } 126 } 127 | Popular Tags |