List of usage examples for java.sql PreparedStatement setBigDecimal
void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;
java.math.BigDecimal
value. From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>//from w w w .j a v a 2 s . co m * Get the number of triggers in the given states that have * misfired - according to the given timestamp. * </p> * * @param conn the DB Connection */ public int countMisfiredTriggersInStates(Connection conn, String state1, String state2, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(COUNT_MISFIRED_TRIGGERS_IN_STATES)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state1); ps.setString(3, state2); rs = ps.executeQuery(); if (rs.next()) { return rs.getInt(1); } throw new SQLException("No misfired trigger count returned."); } finally { closeResultSet(rs); closeStatement(ps); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>//w ww .jav a 2 s. c o m * Get the names of all of the triggers in the given group and state that * have misfired. * </p> * * @param conn * the DB Connection * @return an array of <code>{@link * org.quartz.utils.Key}</code> objects */ public Key[] selectMisfiredTriggersInGroupInState(Connection conn, String groupName, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_GROUP_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, groupName); ps.setString(3, state); rs = ps.executeQuery(); ArrayList list = new ArrayList(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); list.add(new Key(triggerName, groupName)); } Object[] oArr = list.toArray(); Key[] kArr = new Key[oArr.length]; System.arraycopy(oArr, 0, kArr, 0, oArr.length); return kArr; } finally { closeResultSet(rs); closeStatement(ps); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>/*from w w w .jav a 2 s .co m*/ * 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; }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>/*from w ww. j a v a 2s. co m*/ * 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); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>//ww w . jav a2 s . co m * 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()); setBoolean(ps, 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 && ((SimpleTrigger) trigger).hasAdditionalProperties() == false) { // updateSimpleTrigger(conn, (SimpleTrigger)trigger); ps.setString(8, TTYPE_SIMPLE); } else if (trigger instanceof CronTrigger && ((CronTrigger) trigger).hasAdditionalProperties() == false) { // 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()); ps.setInt(13, trigger.getPriority()); if (updateJobData) { setBytes(ps, 14, baos); ps.setString(15, trigger.getName()); ps.setString(16, trigger.getGroup()); } else { ps.setString(14, trigger.getName()); ps.setString(15, trigger.getGroup()); } insertResult = ps.executeUpdate(); } finally { closeStatement(ps); } 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; }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>/* ww w . ja va 2 s . c o m*/ * 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 { closeStatement(ps); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>/*from ww w . j ava 2s. c o m*/ * Select the trigger that will be fired at the given fire time. * </p> * * @param conn * the DB Connection * @param fireTime * the time that the trigger will be fired * @return a <code>{@link org.quartz.utils.Key}</code> representing the * trigger that will be fired at the given fire time, or null if no * trigger will be fired at that time */ public Key selectTriggerForFireTime(Connection conn, long fireTime) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_TRIGGER_FOR_FIRE_TIME)); ps.setString(1, STATE_WAITING); ps.setBigDecimal(2, new BigDecimal(String.valueOf(fireTime))); rs = ps.executeQuery(); if (rs.next()) { return new Key(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP)); } else { return null; } } finally { closeResultSet(rs); closeStatement(ps); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>// w w w . j av a 2s . c o m * Select the next trigger which will fire to fire between the two given timestamps * in ascending order of fire time, and then descending by priority. * </p> * * @param conn * the DB Connection * @param noLaterThan * highest value of <code>getNextFireTime()</code> of the triggers (exclusive) * @param noEarlierThan * highest value of <code>getNextFireTime()</code> of the triggers (inclusive) * * @return A (never null, possibly empty) list of the identifiers (Key objects) of the next triggers to be fired. */ public List selectTriggerToAcquire(Connection conn, long noLaterThan, long noEarlierThan) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; List nextTriggers = new LinkedList(); try { ps = conn.prepareStatement(rtp(SELECT_NEXT_TRIGGER_TO_ACQUIRE)); // Try to give jdbc driver a hint to hopefully not pull over // more than the few rows we actually need. ps.setFetchSize(5); ps.setMaxRows(5); ps.setString(1, STATE_WAITING); ps.setBigDecimal(2, new BigDecimal(String.valueOf(noLaterThan))); ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan))); rs = ps.executeQuery(); while (rs.next() && nextTriggers.size() < 5) { nextTriggers.add(new Key(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP))); } return nextTriggers; } finally { closeResultSet(rs); closeStatement(ps); } }
From source file:org.quartz.impl.jdbcjobstore.StdJDBCDelegate.java
/** * <p>//ww w . ja va 2 s. com * Insert a fired trigger. * </p> * * @param conn * the DB Connection * @param trigger * the trigger * @param state * the state that the trigger should be stored in * @return the number of rows inserted */ public int insertFiredTrigger(Connection conn, Trigger trigger, String state, JobDetail job) throws SQLException { PreparedStatement ps = null; try { ps = conn.prepareStatement(rtp(INSERT_FIRED_TRIGGER)); ps.setString(1, trigger.getFireInstanceId()); ps.setString(2, trigger.getName()); ps.setString(3, trigger.getGroup()); setBoolean(ps, 4, trigger.isVolatile()); ps.setString(5, instanceId); ps.setBigDecimal(6, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime()))); ps.setString(7, state); if (job != null) { ps.setString(8, trigger.getJobName()); ps.setString(9, trigger.getJobGroup()); setBoolean(ps, 10, job.isStateful()); setBoolean(ps, 11, job.requestsRecovery()); } else { ps.setString(8, null); ps.setString(9, null); setBoolean(ps, 10, false); setBoolean(ps, 11, false); } ps.setInt(12, trigger.getPriority()); return ps.executeUpdate(); } finally { closeStatement(ps); } }
From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java
protected boolean processNumber(String tableName, String columnName, String value, Connection conn, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException { if (value == null) { return false; // basically no way }/*from ww w . jav a 2s .c o m*/ final DfColumnMeta columnInfo = columnInfoMap.get(columnName); if (columnInfo != null) { final Class<?> columnType = getBindType(tableName, columnInfo); if (columnType != null) { if (!Number.class.isAssignableFrom(columnType)) { return false; } bindNotNullValueByColumnType(tableName, columnName, conn, ps, bindCount, value, columnType); return true; } } // if meta data is not found (basically no way) value = filterBigDecimalValue(value); if (!isBigDecimalValue(value)) { return false; } final BigDecimal bigDecimalValue = getBigDecimalValue(columnName, value); try { final long longValue = bigDecimalValue.longValueExact(); ps.setLong(bindCount, longValue); return true; } catch (ArithmeticException e) { ps.setBigDecimal(bindCount, bigDecimalValue); return true; } }