?? stdjdbcdelegate.java
字號:
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows inserted
*/
public int insertCronTrigger(Connection conn, CronTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_CRON_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setString(3, trigger.getCronExpression());
ps.setString(4, trigger.getTimeZone().getID());
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Insert the blob trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows inserted
*/
public int insertBlobTrigger(Connection conn, Trigger trigger)
throws SQLException, IOException {
PreparedStatement ps = null;
ByteArrayOutputStream os = null;
try {
// update the blob
os = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(trigger);
oos.close();
byte[] buf = os.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(buf);
ps = conn.prepareStatement(rtp(INSERT_BLOB_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setBinaryStream(3, is, buf.length);
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Update the base trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @param state
* the state that the trigger should be stored in
* @return the number of rows updated
*/
public int updateTrigger(Connection conn, Trigger trigger, String state,
JobDetail jobDetail) throws SQLException, IOException {
// save some clock cycles by unnecessarily writing job data blob ...
boolean updateJobData = trigger.getJobDataMap().isDirty();
ByteArrayOutputStream baos = null;
if(updateJobData && trigger.getJobDataMap().size() > 0)
baos = serializeJobData(trigger.getJobDataMap());
PreparedStatement ps = null;
int insertResult = 0;
try {
if(updateJobData)
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
else
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER_SKIP_DATA));
ps.setString(1, trigger.getJobName());
ps.setString(2, trigger.getJobGroup());
ps.setBoolean(3, trigger.isVolatile());
ps.setString(4, trigger.getDescription());
long nextFireTime = -1;
if (trigger.getNextFireTime() != null) {
nextFireTime = trigger.getNextFireTime().getTime();
}
ps.setBigDecimal(5, new BigDecimal(String.valueOf(nextFireTime)));
long prevFireTime = -1;
if (trigger.getPreviousFireTime() != null) {
prevFireTime = trigger.getPreviousFireTime().getTime();
}
ps.setBigDecimal(6, new BigDecimal(String.valueOf(prevFireTime)));
ps.setString(7, state);
if (trigger instanceof SimpleTrigger) {
// updateSimpleTrigger(conn, (SimpleTrigger)trigger);
ps.setString(8, TTYPE_SIMPLE);
} else if (trigger instanceof CronTrigger) {
// updateCronTrigger(conn, (CronTrigger)trigger);
ps.setString(8, TTYPE_CRON);
} else {
// updateBlobTrigger(conn, trigger);
ps.setString(8, TTYPE_BLOB);
}
ps.setBigDecimal(9, new BigDecimal(String.valueOf(trigger
.getStartTime().getTime())));
long endTime = 0;
if (trigger.getEndTime() != null) {
endTime = trigger.getEndTime().getTime();
}
ps.setBigDecimal(10, new BigDecimal(String.valueOf(endTime)));
ps.setString(11, trigger.getCalendarName());
ps.setInt(12, trigger.getMisfireInstruction());
if(updateJobData) {
ps.setBytes(13, baos.toByteArray());
ps.setString(14, trigger.getName());
ps.setString(15, trigger.getGroup());
}
else {
ps.setString(13, trigger.getName());
ps.setString(14, trigger.getGroup());
}
insertResult = ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
if (insertResult > 0) {
deleteTriggerListeners(conn, trigger.getName(), trigger.getGroup());
String[] trigListeners = trigger.getTriggerListenerNames();
for (int i = 0; trigListeners != null && i < trigListeners.length; i++)
insertTriggerListener(conn, trigger, trigListeners[i]);
}
return insertResult;
}
/**
* <p>
* Update the simple trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows updated
*/
public int updateSimpleTrigger(Connection conn, SimpleTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_SIMPLE_TRIGGER));
ps.setInt(1, trigger.getRepeatCount());
ps.setBigDecimal(2, new BigDecimal(String.valueOf(trigger
.getRepeatInterval())));
ps.setInt(3, trigger.getTimesTriggered());
ps.setString(4, trigger.getName());
ps.setString(5, trigger.getGroup());
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Update the cron trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows updated
*/
public int updateCronTrigger(Connection conn, CronTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_CRON_TRIGGER));
ps.setString(1, trigger.getCronExpression());
ps.setString(2, trigger.getName());
ps.setString(3, trigger.getGroup());
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Update the blob trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows updated
*/
public int updateBlobTrigger(Connection conn, Trigger trigger)
throws SQLException, IOException {
PreparedStatement ps = null;
ByteArrayOutputStream os = null;
try {
// update the blob
os = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(trigger);
oos.close();
byte[] buf = os.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(buf);
ps = conn.prepareStatement(rtp(UPDATE_BLOB_TRIGGER));
ps.setBinaryStream(1, is, buf.length);
ps.setString(2, trigger.getName());
ps.setString(3, trigger.getGroup());
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
if (os != null) os.close();
}
}
/**
* <p>
* Check whether or not a trigger exists.
* </p>
*
* @param conn
* the DB Connection
* @param triggerName
* the name of the trigger
* @param groupName
* the group containing the trigger
* @return true if the trigger exists, false otherwise
*/
public boolean triggerExists(Connection conn, String triggerName,
String groupName) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_TRIGGER_EXISTENCE));
ps.setString(1, triggerName);
ps.setString(2, groupName);
rs = ps.executeQuery();
if (rs.next()) {
return true;
} else {
return false;
}
} finally {
if (null != rs) {
try {
rs.close();
} catch (SQLException ignore) {
}
}
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Update the state for a given trigger.
* </p>
*
* @param conn
* the DB Connection
* @param triggerName
* the name of the trigger
* @param groupName
* the group containing the trigger
* @param state
* the new state for the trigger
* @return the number of rows updated
*/
public int updateTriggerState(Connection conn, String triggerName,
String groupName, String state) throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER_STATE));
ps.setString(1, state);
ps.setString(2, triggerName);
ps.setString(3, groupName);
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
/**
* <p>
* Update the given trigger to the given new state, if it is one of the
* given old states.
* </p>
*
* @param conn
* the DB connection
* @param triggerName
* the name of the trigger
* @param groupName
* the group containing the trigger
* @param newState
* the new state for the trigger
* @param oldState1
* one of the old state the trigger must be in
* @param oldState2
* one of the old state the trigger must be in
* @param oldState3
* one of the old state the trigger must be in
* @return int the number of rows updated
* @throws SQLException
*/
public int updateTriggerStateFromOtherStates(Connection conn,
String triggerName, String groupName, String newState,
String oldState1, String oldState2, String oldState3)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER_STATE_FROM_STATES));
ps.setString(1, newState);
ps.setString(2, triggerName);
ps.setString(3, groupName);
ps.setString(4, oldState1);
ps.setString(5, oldState2);
ps.setString(6, oldState3);
return ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
public int updateTriggerStateFromOtherStatesBeforeTime(Connection conn,
String newState, String oldState1, String oldState2, long time)
throws SQLException {
PreparedStatement ps = null;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -