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.moqui.impl.entity.EntityJavaUtil.java
public static void setPreparedStatementValue(PreparedStatement ps, int index, Object value, FieldInfo fi, boolean useBinaryTypeForBlob, EntityFacade efi) throws EntityException { try {//from w w w . j a va 2 s . co m // allow setting, and searching for, String values for all types; JDBC driver should handle this okay if (value instanceof CharSequence) { ps.setString(index, value.toString()); } else { switch (fi.typeValue) { case 1: if (value != null) { ps.setString(index, value.toString()); } else { ps.setNull(index, Types.VARCHAR); } break; case 2: if (value != null) { Class valClass = value.getClass(); if (valClass == Timestamp.class) { ps.setTimestamp(index, (Timestamp) value, efi.getCalendarForTzLc()); } else if (valClass == java.sql.Date.class) { ps.setDate(index, (java.sql.Date) value, efi.getCalendarForTzLc()); } else if (valClass == java.util.Date.class) { ps.setTimestamp(index, new Timestamp(((java.util.Date) value).getTime()), efi.getCalendarForTzLc()); } else { throw new IllegalArgumentException("Class " + valClass.getName() + " not allowed for date-time (Timestamp) fields, for field " + fi.entityName + "." + fi.name); } } else { ps.setNull(index, Types.TIMESTAMP); } break; case 3: Time tm = (Time) value; // logger.warn("=================== setting time tm=${tm} tm long=${tm.getTime()}, cal=${cal}") if (value != null) { ps.setTime(index, tm, efi.getCalendarForTzLc()); } else { ps.setNull(index, Types.TIME); } break; case 4: if (value != null) { Class valClass = value.getClass(); if (valClass == java.sql.Date.class) { java.sql.Date dt = (java.sql.Date) value; // logger.warn("=================== setting date dt=${dt} dt long=${dt.getTime()}, cal=${cal}") ps.setDate(index, dt, efi.getCalendarForTzLc()); } else if (valClass == Timestamp.class) { ps.setDate(index, new java.sql.Date(((Timestamp) value).getTime()), efi.getCalendarForTzLc()); } else if (valClass == java.util.Date.class) { ps.setDate(index, new java.sql.Date(((java.util.Date) value).getTime()), efi.getCalendarForTzLc()); } else { throw new IllegalArgumentException("Class " + valClass.getName() + " not allowed for date fields, for field " + fi.entityName + "." + fi.name); } } else { ps.setNull(index, Types.DATE); } break; case 5: if (value != null) { ps.setInt(index, ((Number) value).intValue()); } else { ps.setNull(index, Types.NUMERIC); } break; case 6: if (value != null) { ps.setLong(index, ((Number) value).longValue()); } else { ps.setNull(index, Types.NUMERIC); } break; case 7: if (value != null) { ps.setFloat(index, ((Number) value).floatValue()); } else { ps.setNull(index, Types.NUMERIC); } break; case 8: if (value != null) { ps.setDouble(index, ((Number) value).doubleValue()); } else { ps.setNull(index, Types.NUMERIC); } break; case 9: if (value != null) { Class valClass = value.getClass(); // most common cases BigDecimal, Double, Float; then allow any Number if (valClass == BigDecimal.class) { ps.setBigDecimal(index, (BigDecimal) value); } else if (valClass == Double.class) { ps.setDouble(index, (Double) value); } else if (valClass == Float.class) { ps.setFloat(index, (Float) value); } else if (value instanceof Number) { ps.setDouble(index, ((Number) value).doubleValue()); } else { throw new IllegalArgumentException("Class " + valClass.getName() + " not allowed for number-decimal (BigDecimal) fields, for field " + fi.entityName + "." + fi.name); } } else { ps.setNull(index, Types.NUMERIC); } break; case 10: if (value != null) { ps.setBoolean(index, (Boolean) value); } else { ps.setNull(index, Types.BOOLEAN); } break; case 11: if (value != null) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(value); oos.close(); byte[] buf = os.toByteArray(); os.close(); ByteArrayInputStream is = new ByteArrayInputStream(buf); ps.setBinaryStream(index, is, buf.length); is.close(); } catch (IOException ex) { throw new EntityException( "Error setting serialized object, for field " + fi.entityName + "." + fi.name, ex); } } else { if (useBinaryTypeForBlob) { ps.setNull(index, Types.BINARY); } else { ps.setNull(index, Types.BLOB); } } break; case 12: if (value instanceof byte[]) { ps.setBytes(index, (byte[]) value); /* } else if (value instanceof ArrayList) { ArrayList valueAl = (ArrayList) value; byte[] theBytes = new byte[valueAl.size()]; valueAl.toArray(theBytes); ps.setBytes(index, theBytes); */ } else if (value instanceof ByteBuffer) { ByteBuffer valueBb = (ByteBuffer) value; ps.setBytes(index, valueBb.array()); } else if (value instanceof Blob) { Blob valueBlob = (Blob) value; // calling setBytes instead of setBlob // ps.setBlob(index, (Blob) value) // Blob blb = value ps.setBytes(index, valueBlob.getBytes(1, (int) valueBlob.length())); } else { if (value != null) { throw new IllegalArgumentException("Type not supported for BLOB field: " + value.getClass().getName() + ", for field " + fi.entityName + "." + fi.name); } else { if (useBinaryTypeForBlob) { ps.setNull(index, Types.BINARY); } else { ps.setNull(index, Types.BLOB); } } } break; case 13: if (value != null) { ps.setClob(index, (Clob) value); } else { ps.setNull(index, Types.CLOB); } break; case 14: if (value != null) { ps.setTimestamp(index, (Timestamp) value); } else { ps.setNull(index, Types.TIMESTAMP); } break; // TODO: is this the best way to do collections and such? case 15: if (value != null) { ps.setObject(index, value, Types.JAVA_OBJECT); } else { ps.setNull(index, Types.JAVA_OBJECT); } break; } } } catch (SQLException sqle) { throw new EntityException("SQL Exception while setting value [" + value + "](" + (value != null ? value.getClass().getName() : "null") + "), type " + fi.type + ", for field " + fi.entityName + "." + fi.name + ": " + sqle.toString(), sqle); } catch (Exception e) { throw new EntityException( "Error while setting value for field " + fi.entityName + "." + fi.name + ": " + e.toString(), e); } }
From source file:org.ojbc.adapters.analyticaldatastore.dao.AnalyticalDatastoreDAOImpl.java
@Override public Integer saveIncident(final Incident inboundIncident) { log.debug("Inserting row into Incident table: " + inboundIncident.toString()); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { String incidentInsertStatement = ""; String[] insertArgs = null; if (inboundIncident.getIncidentID() == null) { incidentInsertStatement = "INSERT into INCIDENT (ReportingAgencyID, IncidentCaseNumber," + "IncidentLocationLatitude, IncidentLocationLongitude, IncidentLocationStreetAddress,IncidentLocationTown,IncidentDate,IncidentTime,ReportingSystem,RecordType) values (?,?,?,?,?,?,?,?,?,?)"; insertArgs = new String[] { "ReportingAgencyID", "IncidentCaseNumber" + "IncidentLocationLatitude", "IncidentLocationLongitude", "IncidentLocationStreetAddress", "IncidentLocationTown", "IncidentDate", "IncidentTime", "ReportingSystem", "RecordType" }; } else { incidentInsertStatement = "INSERT into INCIDENT (ReportingAgencyID, IncidentCaseNumber," + "IncidentLocationLatitude, IncidentLocationLongitude, IncidentLocationStreetAddress,IncidentLocationTown,IncidentDate,IncidentTime,ReportingSystem,RecordType, IncidentID) values (?,?,?,?,?,?,?,?,?,?,?)"; insertArgs = new String[] { "ReportingAgencyID", "IncidentCaseNumber" + "IncidentLocationLatitude", "IncidentLocationLongitude", "IncidentLocationStreetAddress", "IncidentLocationTown", "IncidentDate", "IncidentTime", "ReportingSystem", "RecordType", "IncidentID" }; }//ww w.jav a2s. c o m PreparedStatement ps = connection.prepareStatement(incidentInsertStatement, insertArgs); if (inboundIncident.getReportingAgencyID() != null) { ps.setInt(1, inboundIncident.getReportingAgencyID()); } else { ps.setNull(1, java.sql.Types.NULL); } ps.setString(2, inboundIncident.getIncidentCaseNumber()); ps.setBigDecimal(3, inboundIncident.getIncidentLocationLatitude()); ps.setBigDecimal(4, inboundIncident.getIncidentLocationLongitude()); ps.setString(5, inboundIncident.getIncidentLocationStreetAddress()); ps.setString(6, inboundIncident.getIncidentLocationTown()); ps.setDate(7, new java.sql.Date(inboundIncident.getIncidentDate().getTime())); ps.setTime(8, new java.sql.Time(inboundIncident.getIncidentDate().getTime())); ps.setString(9, inboundIncident.getReportingSystem()); ps.setString(10, String.valueOf(inboundIncident.getRecordType())); if (inboundIncident.getIncidentID() != null) { ps.setInt(11, inboundIncident.getIncidentID()); } return ps; } }, keyHolder); Integer returnValue = null; if (inboundIncident.getIncidentID() != null) { returnValue = inboundIncident.getIncidentID(); } else { returnValue = keyHolder.getKey().intValue(); } return returnValue; }
From source file:org.ojbc.adapters.analyticaldatastore.dao.AnalyticalDatastoreDAOImpl.java
@Override public Integer saveDisposition(final Disposition inboundDisposition) { log.debug("Inserting row into Disposition table"); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { String dispositionInsertStatement = ""; String[] insertArgs = null; //No disposition ID provided in POJO if (inboundDisposition.getDispositionID() == null) { dispositionInsertStatement = "INSERT into Disposition (PersonID,DispositionTypeID,IncidentCaseNumber,DispositionDate,ArrestingAgencyORI," + "SentenceTermDays,SentenceFineAmount,InitialChargeCode, FinalChargeCode, RecordType,IsProbationViolation,IsProbationViolationOnOldCharge,RecidivismEligibilityDate, DocketChargeNumber,InitialChargeCode1, FinalChargeCode1) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; insertArgs = new String[] { "PersonID", "DispositionTypeID", "IncidentCaseNumber", "DispositionDate,ArrestingAgencyORI," + "SentenceTermDays", "SentenceFineAmount", "InitialChargeCode", "FinalChargeCode", "RecordType", "IsProbationViolation", "IsProbationViolationOnOldCharge", "RecidivismEligibilityDate", "DocketChargeNumber", "InitialChargeCode1", "FinalChargeCode1" }; }//w ww. ja v a 2 s . co m //Disposition ID provided in POJO else { dispositionInsertStatement = "INSERT into Disposition (PersonID,DispositionTypeID,IncidentCaseNumber,DispositionDate,ArrestingAgencyORI," + "SentenceTermDays,SentenceFineAmount,InitialChargeCode, FinalChargeCode, RecordType,IsProbationViolation,IsProbationViolationOnOldCharge,RecidivismEligibilityDate, DocketChargeNumber, InitialChargeCode1, FinalChargeCode1,DispositionID) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; insertArgs = new String[] { "PersonID", "DispositionTypeID", "IncidentCaseNumber", "DispositionDate,ArrestingAgencyORI," + "SentenceTermDays", "SentenceFineAmount", "InitialChargeCode", "FinalChargeCode", "RecordType", "IsProbationViolation", "IsProbationViolationOnOldCharge", "RecidivismEligibilityDate", "DocketChargeNumber", "InitialChargeCode1", "FinalChargeCode1", "DispositionID" }; } PreparedStatement ps = connection.prepareStatement(dispositionInsertStatement, insertArgs); ps.setInt(1, inboundDisposition.getPersonID()); ps.setInt(2, inboundDisposition.getDispositionTypeID()); ps.setString(3, inboundDisposition.getIncidentCaseNumber()); ps.setDate(4, new java.sql.Date(inboundDisposition.getDispositionDate().getTime())); ps.setString(5, inboundDisposition.getArrestingAgencyORI()); if (inboundDisposition.getSentenceTermDays() != null) { ps.setBigDecimal(6, inboundDisposition.getSentenceTermDays()); } else { ps.setNull(6, java.sql.Types.NULL); } if (inboundDisposition.getSentenceFineAmount() != null) { ps.setFloat(7, inboundDisposition.getSentenceFineAmount()); } else { ps.setNull(7, java.sql.Types.NULL); } ps.setString(8, inboundDisposition.getInitialChargeCode()); ps.setString(9, inboundDisposition.getFinalChargeCode()); ps.setString(10, String.valueOf(inboundDisposition.getRecordType())); if (inboundDisposition.getIsProbationViolation() != null) { ps.setString(11, String.valueOf(inboundDisposition.getIsProbationViolation())); } else { ps.setNull(11, java.sql.Types.NULL); } if (inboundDisposition.getIsProbationViolationOnOldCharge() != null) { ps.setString(12, String.valueOf(inboundDisposition.getIsProbationViolationOnOldCharge())); } else { ps.setNull(12, java.sql.Types.NULL); } if (inboundDisposition.getRecidivismEligibilityDate() != null) { ps.setDate(13, new java.sql.Date(inboundDisposition.getRecidivismEligibilityDate().getTime())); } else { ps.setNull(13, java.sql.Types.NULL); } ps.setString(14, inboundDisposition.getDocketChargeNumber()); ps.setString(15, inboundDisposition.getInitialChargeRank()); ps.setString(16, inboundDisposition.getFinalChargeRank()); if (inboundDisposition.getDispositionID() != null) { ps.setInt(17, inboundDisposition.getDispositionID()); } return ps; } }, keyHolder); Integer returnValue = null; if (inboundDisposition.getDispositionID() != null) { returnValue = inboundDisposition.getDispositionID(); } else { returnValue = keyHolder.getKey().intValue(); } return returnValue; }
From source file:org.quartz.impl.jdbcjobstore.oracle.OracleDelegate.java
public int insertTrigger(Connection conn, Trigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException { byte[] data = null; if (trigger.getJobDataMap().size() > 0) { data = serializeJobData(trigger.getJobDataMap()).toByteArray(); }//from ww w . j a v a 2 s .c om PreparedStatement ps = null; ResultSet rs = 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()); ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime()))); 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()); ps.setBinaryStream(15, null, 0); ps.setInt(16, trigger.getPriority()); insertResult = ps.executeUpdate(); if (data != null) { ps.close(); ps = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_EMPTY_BLOB)); ps.setString(1, trigger.getName()); ps.setString(2, trigger.getGroup()); ps.executeUpdate(); ps.close(); ps = conn.prepareStatement(rtp(SELECT_ORACLE_TRIGGER_JOB_DETAIL_BLOB)); ps.setString(1, trigger.getName()); ps.setString(2, trigger.getGroup()); rs = ps.executeQuery(); int res = 0; Blob dbBlob = null; if (rs.next()) { dbBlob = writeDataToBlob(rs, 1, data); } else { return res; } rs.close(); ps.close(); ps = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_BLOB)); ps.setBlob(1, dbBlob); ps.setString(2, trigger.getName()); ps.setString(3, trigger.getGroup()); res = ps.executeUpdate(); } } finally { closeResultSet(rs); 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.oracle.OracleDelegate.java
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(); byte[] data = null; if (updateJobData && trigger.getJobDataMap().size() > 0) { data = serializeJobData(trigger.getJobDataMap()).toByteArray(); }/* w w w. j av a 2s . c o m*/ PreparedStatement ps = null; PreparedStatement ps2 = null; ResultSet rs = null; int insertResult = 0; try { ps = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER)); 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()); ps.setString(14, trigger.getName()); ps.setString(15, trigger.getGroup()); insertResult = ps.executeUpdate(); if (updateJobData) { ps.close(); ps = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_EMPTY_BLOB)); ps.setString(1, trigger.getName()); ps.setString(2, trigger.getGroup()); ps.executeUpdate(); ps.close(); ps = conn.prepareStatement(rtp(SELECT_ORACLE_TRIGGER_JOB_DETAIL_BLOB)); ps.setString(1, trigger.getName()); ps.setString(2, trigger.getGroup()); rs = ps.executeQuery(); int res = 0; if (rs.next()) { Blob dbBlob = writeDataToBlob(rs, 1, data); ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_BLOB)); ps2.setBlob(1, dbBlob); ps2.setString(2, trigger.getName()); ps2.setString(3, trigger.getGroup()); res = ps2.executeUpdate(); } } } finally { closeResultSet(rs); closeStatement(ps); closeStatement(ps2); } 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.PointbaseDelegate.java
public int insertTrigger(Connection conn, Trigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException { ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap()); int len = baos.toByteArray().length; ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); PreparedStatement ps = null; int insertResult = 0; try {//from w w w . j a va2s .com 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()); ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime()))); 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()); ps.setBinaryStream(15, bais, len); 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.PointbaseDelegate.java
public int updateTrigger(Connection conn, Trigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException { ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap()); int len = baos.toByteArray().length; ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); PreparedStatement ps = null; int insertResult = 0; try {//from w ww .ja v a 2s.co m ps = conn.prepareStatement(rtp(UPDATE_TRIGGER)); 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()); ps.setBinaryStream(14, bais, len); ps.setString(15, trigger.getName()); ps.setString(16, 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>//from ww w.ja v a 2s. co m * Get the names of all of the triggers that have misfired. * </p> * * @param conn * the DB Connection * @return an array of <code>{@link * org.quartz.utils.Key}</code> objects */ public Key[] selectMisfiredTriggers(Connection conn, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); rs = ps.executeQuery(); ArrayList list = new ArrayList(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); 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
public Key[] selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null;/*from w w w . j a v a 2s .c o m*/ try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state); rs = ps.executeQuery(); ArrayList list = new ArrayList(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); 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 ww . j a v a 2s . c o m * Get the names of all of the triggers in the given states that have * misfired - according to the given timestamp. No more than count will * be returned. * </p> * * @param conn The DB Connection * @param count The most misfired triggers to return, negative for all * @param resultList Output parameter. A List of * <code>{@link org.quartz.utils.Key}</code> objects. Must not be null. * * @return Whether there are more misfired triggers left to find beyond * the given count. */ public boolean selectMisfiredTriggersInStates(Connection conn, String state1, String state2, long ts, int count, List resultList) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_STATES)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state1); ps.setString(3, state2); rs = ps.executeQuery(); boolean hasReachedLimit = false; while (rs.next() && (hasReachedLimit == false)) { if (resultList.size() == count) { hasReachedLimit = true; } else { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); resultList.add(new Key(triggerName, groupName)); } } return hasReachedLimit; } finally { closeResultSet(rs); closeStatement(ps); } }