📄 stdjdbcdelegate.java
字号:
ps.setString(2, job.getGroup());
ps.setString(3, listener);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
/**
* <p>
* Get all of the listeners for a given job.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the job name whose listeners are wanted
* @param groupName
* the group containing the job
* @return array of <code>String</code> listener names
*/
public String[] selectJobListeners(Connection conn, String jobName,
String groupName) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ArrayList list = new ArrayList();
ps = conn.prepareStatement(rtp(SELECT_JOB_LISTENERS));
ps.setString(1, jobName);
ps.setString(2, groupName);
rs = ps.executeQuery();
while (rs.next()) {
list.add(rs.getString(1));
}
Object[] oArr = list.toArray();
String[] sArr = new String[oArr.length];
System.arraycopy(oArr, 0, sArr, 0, oArr.length);
return sArr;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Select the JobDetail object for a given job name / group name.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the job name whose listeners are wanted
* @param groupName
* the group containing the job
* @return the populated JobDetail object
* @throws ClassNotFoundException
* if a class found during deserialization cannot be found or if
* the job class could not be found
* @throws IOException
* if deserialization causes an error
*/
public JobDetail selectJobDetail(Connection conn, String jobName,
String groupName, ClassLoadHelper loadHelper)
throws ClassNotFoundException, IOException, SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOB_DETAIL));
ps.setString(1, jobName);
ps.setString(2, groupName);
rs = ps.executeQuery();
JobDetail job = null;
if (rs.next()) {
job = new JobDetail();
job.setName(rs.getString(COL_JOB_NAME));
job.setGroup(rs.getString(COL_JOB_GROUP));
job.setDescription(rs.getString(COL_DESCRIPTION));
job.setJobClass(loadHelper.loadClass(rs
.getString(COL_JOB_CLASS)));
job.setDurability(getBoolean(rs, COL_IS_DURABLE));
job.setVolatility(getBoolean(rs, COL_IS_VOLATILE));
job.setRequestsRecovery(getBoolean(rs, COL_REQUESTS_RECOVERY));
Map map = null;
if (canUseProperties()) {
map = getMapFromProperties(rs);
} else {
map = (Map) getObjectFromBlob(rs, COL_JOB_DATAMAP);
}
if (null != map) {
job.setJobDataMap(new JobDataMap(map));
}
}
return job;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* build Map from java.util.Properties encoding.
*/
private Map getMapFromProperties(ResultSet rs)
throws ClassNotFoundException, IOException, SQLException {
Map map;
InputStream is = (InputStream) getJobDetailFromBlob(rs, COL_JOB_DATAMAP);
if(is == null) {
return null;
}
Properties properties = new Properties();
if (is != null) {
try {
properties.load(is);
} finally {
is.close();
}
}
map = convertFromProperty(properties);
return map;
}
/**
* <p>
* Select the total number of jobs stored.
* </p>
*
* @param conn
* the DB Connection
* @return the total number of jobs stored
*/
public int selectNumJobs(Connection conn) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
int count = 0;
ps = conn.prepareStatement(rtp(SELECT_NUM_JOBS));
rs = ps.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
return count;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Select all of the job group names that are stored.
* </p>
*
* @param conn
* the DB Connection
* @return an array of <code>String</code> group names
*/
public String[] selectJobGroups(Connection conn) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOB_GROUPS));
rs = ps.executeQuery();
ArrayList list = new ArrayList();
while (rs.next()) {
list.add(rs.getString(1));
}
Object[] oArr = list.toArray();
String[] sArr = new String[oArr.length];
System.arraycopy(oArr, 0, sArr, 0, oArr.length);
return sArr;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Select all of the jobs contained in a given group.
* </p>
*
* @param conn
* the DB Connection
* @param groupName
* the group containing the jobs
* @return an array of <code>String</code> job names
*/
public String[] selectJobsInGroup(Connection conn, String groupName)
throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOBS_IN_GROUP));
ps.setString(1, groupName);
rs = ps.executeQuery();
ArrayList list = new ArrayList();
while (rs.next()) {
list.add(rs.getString(1));
}
Object[] oArr = list.toArray();
String[] sArr = new String[oArr.length];
System.arraycopy(oArr, 0, sArr, 0, oArr.length);
return sArr;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
//---------------------------------------------------------------------------
// triggers
//---------------------------------------------------------------------------
/**
* <p>
* Insert 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 inserted
*/
public int insertTrigger(Connection conn, Trigger trigger, String state,
JobDetail jobDetail) throws SQLException, IOException {
ByteArrayOutputStream baos = null;
if(trigger.getJobDataMap().size() > 0) {
baos = serializeJobData(trigger.getJobDataMap());
}
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(INSERT_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setString(3, trigger.getJobName());
ps.setString(4, trigger.getJobGroup());
setBoolean(ps, 5, trigger.isVolatile());
ps.setString(6, trigger.getDescription());
if(trigger.getNextFireTime() != null)
ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger
.getNextFireTime().getTime())));
else
ps.setBigDecimal(7, null);
long prevFireTime = -1;
if (trigger.getPreviousFireTime() != null) {
prevFireTime = trigger.getPreviousFireTime().getTime();
}
ps.setBigDecimal(8, new BigDecimal(String.valueOf(prevFireTime)));
ps.setString(9, state);
if (trigger instanceof SimpleTrigger && ((SimpleTrigger)trigger).hasAdditionalProperties() == false ) {
ps.setString(10, TTYPE_SIMPLE);
} else if (trigger instanceof CronTrigger && ((CronTrigger)trigger).hasAdditionalProperties() == false ) {
ps.setString(10, TTYPE_CRON);
} else {
ps.setString(10, TTYPE_BLOB);
}
ps.setBigDecimal(11, new BigDecimal(String.valueOf(trigger
.getStartTime().getTime())));
long endTime = 0;
if (trigger.getEndTime() != null) {
endTime = trigger.getEndTime().getTime();
}
ps.setBigDecimal(12, new BigDecimal(String.valueOf(endTime)));
ps.setString(13, trigger.getCalendarName());
ps.setInt(14, trigger.getMisfireInstruction());
setBytes(ps, 15, baos);
ps.setInt(16, trigger.getPriority());
insertResult = ps.executeUpdate();
} finally {
closeStatement(ps);
}
if (insertResult > 0) {
String[] trigListeners = trigger.getTriggerListenerNames();
for (int i = 0; trigListeners != null && i < trigListeners.length; i++) {
insertTriggerListener(conn, trigger, trigListeners[i]);
}
}
return insertResult;
}
/**
* <p>
* Insert the simple trigger data.
* </p>
*
* @param conn
* the DB Connection
* @param trigger
* the trigger to insert
* @return the number of rows inserted
*/
public int insertSimpleTrigger(Connection conn, SimpleTrigger trigger)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_SIMPLE_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setInt(3, trigger.getRepeatCount());
ps.setBigDecimal(4, new BigDecimal(String.valueOf(trigger
.getRepeatInterval())));
ps.setInt(5, trigger.getTimesTriggered());
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
/**
* <p>
* Insert the cron trigger data.
* </p>
*
* @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 {
closeStatement(ps);
}
}
/**
* <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 {
closeStatement(ps);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -