List of usage examples for java.sql Types TIMESTAMP
int TIMESTAMP
To view the source code for java.sql Types TIMESTAMP.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP
.
From source file:com.squid.core.domain.operators.ExtendedType.java
public static int FromTypeName(String SQLName) { if (SQLName.equals("ARRAY")) { return Types.ARRAY; }// w w w .ja v a 2s. co m if (SQLName.equals("INTEGER")) { return Types.INTEGER; } if (SQLName.equals("BINARY")) { return Types.BINARY; } if (SQLName.equals("BIT")) { return Types.BIT; } if (SQLName.equals("BLOB")) { return Types.BLOB; } if (SQLName.equals("BOOLEAN")) { return Types.BOOLEAN; } if (SQLName.equals("CHAR")) { return Types.CHAR; } if (SQLName.equals("CLOB")) { return Types.CLOB; } if (SQLName.equals("DATALINK")) { return Types.DATALINK; } if (SQLName.equals("DATE")) { return Types.DATE; } if (SQLName.equals("DECIMAL")) { return Types.DECIMAL; } if (SQLName.equals("DOUBLE")) { return Types.DOUBLE; } if (SQLName.equals("FLOAT")) { return Types.FLOAT; } if (SQLName.equals("JAVA_OBJECT")) { return Types.JAVA_OBJECT; } if (SQLName.equals("LONGNVARCHAR")) { return Types.LONGNVARCHAR; } if (SQLName.equals("LONGVARBINARY")) { return Types.LONGVARBINARY; } if (SQLName.equals("NCHAR")) { return Types.NCHAR; } if (SQLName.equals("NCLOB")) { return Types.NCLOB; } if (SQLName.equals("UNDEFINED")) { return Types.OTHER; } if (SQLName.equals("NUMERIC")) { return Types.NUMERIC; } if (SQLName.equals("NVARCHAR")) { return Types.NVARCHAR; } if (SQLName.equals("REAL")) { return Types.REAL; } if (SQLName.equals("REF")) { return Types.REF; } if (SQLName.equals("ROWID")) { return Types.ROWID; } if (SQLName.equals("SMALLINT")) { return Types.SMALLINT; } if (SQLName.equals("SQLXML")) { return Types.SQLXML; } if (SQLName.equals("STRUCT")) { return Types.STRUCT; } if (SQLName.equals("TIME")) { return Types.TIME; } if (SQLName.equals("TIMESTAMP")) { return Types.TIMESTAMP; } if (SQLName.equals("TINYINT")) { return Types.TINYINT; } if (SQLName.equals("VARCHAR")) { return Types.VARCHAR; } if (SQLName.equals("VARBINARY")) { return Types.VARBINARY; } return Types.OTHER; }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static List<Object[]> transformToList(ResultSet rs) throws SQLException { ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); List<Object[]> result = new ArrayList<>(numberOfColumns); while (rs.next()) { Object[] row = new Object[numberOfColumns]; for (int i = 0; i < numberOfColumns; i++) { if (rsMetaData.getColumnType(i + 1) == Types.TIMESTAMP) { row[i] = rs.getDate(i + 1); } else { row[i] = rs.getObject(i + 1); }//from w w w . j av a 2 s.c o m } result.add(row); } return result; }
From source file:org.pentaho.di.jdbc.Support.java
/** * Convert an existing data object to the specified JDBC type. * * @param callerReference an object reference to the caller of this method; * must be a <code>Connection</code>, * <code>Statement</code> or <code>ResultSet</code> * @param x the data object to convert * @param jdbcType the required type constant from * <code>java.sql.Types</code> * @return the converted data object// w ww .j a v a 2s .c o m * @throws SQLException if the conversion is not supported or fails */ static Object convert(Object callerReference, Object x, int jdbcType, String charSet) throws SQLException { try { switch (jdbcType) { case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: case java.sql.Types.INTEGER: if (x == null) { return INTEGER_ZERO; } else if (x instanceof Integer) { return x; } else if (x instanceof Byte) { return new Integer(((Byte) x).byteValue() & 0xFF); } else if (x instanceof Number) { return new Integer(((Number) x).intValue()); } else if (x instanceof String) { return new Integer(((String) x).trim()); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? INTEGER_ONE : INTEGER_ZERO; } break; case java.sql.Types.BIGINT: if (x == null) { return LONG_ZERO; } else if (x instanceof Long) { return x; } else if (x instanceof Byte) { return new Long(((Byte) x).byteValue() & 0xFF); } else if (x instanceof Number) { return new Long(((Number) x).longValue()); } else if (x instanceof String) { return new Long(((String) x).trim()); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? LONG_ONE : LONG_ZERO; } break; case java.sql.Types.REAL: if (x == null) { return FLOAT_ZERO; } else if (x instanceof Float) { return x; } else if (x instanceof Byte) { return new Float(((Byte) x).byteValue() & 0xFF); } else if (x instanceof Number) { return new Float(((Number) x).floatValue()); } else if (x instanceof String) { return new Float(((String) x).trim()); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? FLOAT_ONE : FLOAT_ZERO; } break; case java.sql.Types.FLOAT: case java.sql.Types.DOUBLE: if (x == null) { return DOUBLE_ZERO; } else if (x instanceof Double) { return x; } else if (x instanceof Byte) { return new Double(((Byte) x).byteValue() & 0xFF); } else if (x instanceof Number) { return new Double(((Number) x).doubleValue()); } else if (x instanceof String) { return new Double(((String) x).trim()); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? DOUBLE_ONE : DOUBLE_ZERO; } break; case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: if (x == null) { return null; } else if (x instanceof BigDecimal) { return x; } else if (x instanceof Number) { return new BigDecimal(x.toString()); } else if (x instanceof String) { return new BigDecimal((String) x); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? BIG_DECIMAL_ONE : BIG_DECIMAL_ZERO; } break; case java.sql.Types.VARCHAR: case java.sql.Types.CHAR: if (x == null) { return null; } else if (x instanceof String) { return x; } else if (x instanceof Number) { return x.toString(); } else if (x instanceof Boolean) { return ((Boolean) x).booleanValue() ? "1" : "0"; } else if (x instanceof Clob) { Clob clob = (Clob) x; long length = clob.length(); if (length > Integer.MAX_VALUE) { throw new SQLException(BaseMessages.getString(PKG, "error.normalize.lobtoobig"), "22000"); } return clob.getSubString(1, (int) length); } else if (x instanceof Blob) { Blob blob = (Blob) x; long length = blob.length(); if (length > Integer.MAX_VALUE) { throw new SQLException(BaseMessages.getString(PKG, "error.normalize.lobtoobig"), "22000"); } x = blob.getBytes(1, (int) length); } if (x instanceof byte[]) { return toHex((byte[]) x); } return x.toString(); // Last hope! case java.sql.Types.BIT: case java.sql.Types.BOOLEAN: if (x == null) { return Boolean.FALSE; } else if (x instanceof Boolean) { return x; } else if (x instanceof Number) { return (((Number) x).intValue() == 0) ? Boolean.FALSE : Boolean.TRUE; } else if (x instanceof String) { String tmp = ((String) x).trim(); return ("1".equals(tmp) || "true".equalsIgnoreCase(tmp)) ? Boolean.TRUE : Boolean.FALSE; } break; case java.sql.Types.VARBINARY: case java.sql.Types.BINARY: if (x == null) { return null; } else if (x instanceof byte[]) { return x; } else if (x instanceof Blob) { Blob blob = (Blob) x; return blob.getBytes(1, (int) blob.length()); } else if (x instanceof Clob) { Clob clob = (Clob) x; long length = clob.length(); if (length > Integer.MAX_VALUE) { throw new SQLException(BaseMessages.getString(PKG, "error.normalize.lobtoobig"), "22000"); } x = clob.getSubString(1, (int) length); } if (x instanceof String) { // // Strictly speaking this conversion is not required by // the JDBC standard but jTDS has always supported it. // if (charSet == null) { charSet = "ISO-8859-1"; } try { return ((String) x).getBytes(charSet); } catch (UnsupportedEncodingException e) { return ((String) x).getBytes(); } } else if (x instanceof UniqueIdentifier) { return ((UniqueIdentifier) x).getBytes(); } break; case java.sql.Types.TIMESTAMP: if (x == null) { return null; } else if (x instanceof DateTime) { return ((DateTime) x).toTimestamp(); } else if (x instanceof java.sql.Timestamp) { return x; } else if (x instanceof java.sql.Date) { return new java.sql.Timestamp(((java.sql.Date) x).getTime()); } else if (x instanceof java.sql.Time) { return new java.sql.Timestamp(((java.sql.Time) x).getTime()); } else if (x instanceof java.lang.String) { return java.sql.Timestamp.valueOf(((String) x).trim()); } break; case java.sql.Types.DATE: if (x == null) { return null; } else if (x instanceof DateTime) { return ((DateTime) x).toDate(); } else if (x instanceof java.sql.Date) { return x; } else if (x instanceof java.sql.Time) { return DATE_ZERO; } else if (x instanceof java.sql.Timestamp) { synchronized (cal) { cal.setTime((java.util.Date) x); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // VM1.4+ only return new java.sql.Date(cal.getTimeInMillis()); return new java.sql.Date(cal.getTime().getTime()); } } else if (x instanceof java.lang.String) { return java.sql.Date.valueOf(((String) x).trim()); } break; case java.sql.Types.TIME: if (x == null) { return null; } else if (x instanceof DateTime) { return ((DateTime) x).toTime(); } else if (x instanceof java.sql.Time) { return x; } else if (x instanceof java.sql.Date) { return TIME_ZERO; } else if (x instanceof java.sql.Timestamp) { synchronized (cal) { // VM 1.4+ only cal.setTimeInMillis(((java.sql.Timestamp)x).getTime()); cal.setTime((java.util.Date) x); cal.set(Calendar.YEAR, 1970); cal.set(Calendar.MONTH, 0); cal.set(Calendar.DAY_OF_MONTH, 1); // VM 1.4+ only return new java.sql.Time(cal.getTimeInMillis());*/ return new java.sql.Time(cal.getTime().getTime()); } } else if (x instanceof java.lang.String) { return java.sql.Time.valueOf(((String) x).trim()); } break; case java.sql.Types.OTHER: return x; case java.sql.Types.JAVA_OBJECT: throw new SQLException(BaseMessages.getString(PKG, "error.convert.badtypes", x.getClass().getName(), getJdbcTypeName(jdbcType)), "22005"); case java.sql.Types.LONGVARBINARY: case java.sql.Types.BLOB: if (x == null) { return null; } else if (x instanceof Blob) { return x; } else if (x instanceof byte[]) { return new BlobImpl(getConnection(callerReference), (byte[]) x); } else if (x instanceof Clob) { // // Convert CLOB to BLOB. Not required by the standard but we will // do it anyway. // Clob clob = (Clob) x; try { if (charSet == null) { charSet = "ISO-8859-1"; } Reader rdr = clob.getCharacterStream(); BlobImpl blob = new BlobImpl(getConnection(callerReference)); BufferedWriter out = new BufferedWriter( new OutputStreamWriter(blob.setBinaryStream(1), charSet)); // TODO Use a buffer to improve performance int c; while ((c = rdr.read()) >= 0) { out.write(c); } out.close(); rdr.close(); return blob; } catch (UnsupportedEncodingException e) { // Unlikely to happen but fall back on in memory copy x = clob.getSubString(1, (int) clob.length()); } catch (IOException e) { throw new SQLException(BaseMessages.getString(PKG, "error.generic.ioerror", e.getMessage()), "HY000"); } } if (x instanceof String) { // // Strictly speaking this conversion is also not required by // the JDBC standard but jTDS has always supported it. // BlobImpl blob = new BlobImpl(getConnection(callerReference)); String data = (String) x; if (charSet == null) { charSet = "ISO-8859-1"; } try { blob.setBytes(1, data.getBytes(charSet)); } catch (UnsupportedEncodingException e) { blob.setBytes(1, data.getBytes()); } return blob; } break; case java.sql.Types.LONGVARCHAR: case java.sql.Types.CLOB: if (x == null) { return null; } else if (x instanceof Clob) { return x; } else if (x instanceof Blob) { // // Convert BLOB to CLOB // Blob blob = (Blob) x; try { InputStream is = blob.getBinaryStream(); ClobImpl clob = new ClobImpl(getConnection(callerReference)); Writer out = clob.setCharacterStream(1); // TODO Use a buffer to improve performance int b; // These reads/writes are buffered by the undelying blob buffers while ((b = is.read()) >= 0) { out.write(hex[b >> 4]); out.write(hex[b & 0x0F]); } out.close(); is.close(); return clob; } catch (IOException e) { throw new SQLException(BaseMessages.getString(PKG, "error.generic.ioerror", e.getMessage()), "HY000"); } } else if (x instanceof Boolean) { x = ((Boolean) x).booleanValue() ? "1" : "0"; } else if (!(x instanceof byte[])) { x = x.toString(); } if (x instanceof byte[]) { ClobImpl clob = new ClobImpl(getConnection(callerReference)); clob.setString(1, toHex((byte[]) x)); return clob; } else if (x instanceof String) { return new ClobImpl(getConnection(callerReference), (String) x); } break; default: throw new SQLException( BaseMessages.getString(PKG, "error.convert.badtypeconst", getJdbcTypeName(jdbcType)), "HY004"); } throw new SQLException(BaseMessages.getString(PKG, "error.convert.badtypes", x.getClass().getName(), getJdbcTypeName(jdbcType)), "22005"); } catch (NumberFormatException nfe) { throw new SQLException( BaseMessages.getString(PKG, "error.convert.badnumber", getJdbcTypeName(jdbcType)), "22000"); } }
From source file:funcoes.funcoes.java
@SuppressWarnings("rawtypes") public static Vector<Comparable> proximaLinha(ResultSet rs, ResultSetMetaData rsmd) throws SQLException { Vector<Comparable> LinhaAtual = new Vector<Comparable>(); try {/*w w w . jav a 2s. c om*/ for (int i = 1; i <= rsmd.getColumnCount(); ++i) { switch (rsmd.getColumnType(i)) { case Types.VARCHAR: LinhaAtual.addElement(rs.getString(i)); break; case Types.TIMESTAMP: LinhaAtual.addElement(rs.getDate(i).toLocaleString().substring(0, 10)); break; case Types.INTEGER: LinhaAtual.addElement(rs.getInt(i)); break; case Types.DECIMAL: LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i))); break; case Types.DOUBLE: LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i))); break; } } } catch (SQLException e) { } return LinhaAtual; }
From source file:org.jumpmind.symmetric.service.impl.IncomingBatchService.java
public int updateIncomingBatch(ISqlTransaction transaction, IncomingBatch batch) { int count = 0; if (batch.isPersistable()) { if (batch.getStatus() == IncomingBatch.Status.ER) { batch.setErrorFlag(true);/* w ww. j a v a2s. c o m*/ } else if (batch.getStatus() == IncomingBatch.Status.OK) { batch.setErrorFlag(false); } batch.setLastUpdatedHostName(clusterService.getServerId()); batch.setLastUpdatedTime(new Date()); count = transaction.prepareAndExecute(getSql("updateIncomingBatchSql"), new Object[] { batch.getStatus().name(), batch.isErrorFlag() ? 1 : 0, batch.getNetworkMillis(), batch.getFilterMillis(), batch.getDatabaseMillis(), batch.getFailedRowNumber(), batch.getFailedLineNumber(), batch.getByteCount(), batch.getStatementCount(), batch.getFallbackInsertCount(), batch.getFallbackUpdateCount(), batch.getIgnoreCount(), batch.getMissingDeleteCount(), batch.getSkipCount(), batch.getSqlState(), batch.getSqlCode(), FormatUtils.abbreviateForLogging(batch.getSqlMessage()), batch.getLastUpdatedHostName(), batch.getLastUpdatedTime(), batch.getBatchId(), batch.getNodeId() }, new int[] { Types.CHAR, Types.SMALLINT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.VARCHAR, Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, symmetricDialect.getSqlTypeForIds(), Types.VARCHAR }); } return count; }
From source file:org.easyrec.mahout.store.impl.MahoutDataModelMappingDAOMysqlImpl.java
@Override public Float getBooleanPreferenceValue(int tenantId, Date cutoffDate, long userID, long itemID, int actionTypeId) throws TasteException { Object[] args = new Object[] { tenantId, cutoffDate, userID, itemID, actionTypeId }; int[] argTypes = new int[] { Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER, Types.INTEGER }; int numberOfActions = getJdbcTemplate().queryForInt(getBooleanPreferenceQuery, args, argTypes); if (numberOfActions == 0) { //as mahout/taste doesn't catch the NoSuchUserException, we don't throw it to save time return null; } else {// ww w. j av a2s .co m return 1f; } }
From source file:nl.nn.adapterframework.statistics.jdbc.StatisticsKeeperStore.java
public void handleScalar(Object data, String scalarName, Date value) throws SenderException { SessionInfo sessionInfo = (SessionInfo) data; PreparedStatement stmt = null; int statnamekey = -1; try {//ww w.ja va 2 s . c o m statnamekey = statnames.findOrInsert(sessionInfo.connection, scalarName); if (trace && log.isDebugEnabled()) log.debug("prepare and execute query [" + insertTimestampQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + (value == null ? "null" : DateUtils.format(value)) + "]"); stmt = sessionInfo.connection.prepareStatement(insertTimestampQuery); stmt.setLong(1, sessionInfo.eventKey); stmt.setLong(2, sessionInfo.groupKey); stmt.setLong(3, statnamekey); if (value == null) { stmt.setNull(4, Types.TIMESTAMP); } else { stmt.setTimestamp(4, new Timestamp(value.getTime())); } stmt.execute(); } catch (Exception e) { throw new SenderException("could not execute query [" + insertTimestampQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + (value == null ? "null" : DateUtils.format(value)) + "]", e); } finally { if (stmt != null) { try { stmt.close(); } catch (Exception e) { throw new SenderException("could not close statement for query [" + insertTimestampQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + (value == null ? "null" : DateUtils.format(value)) + "]", e); } } } }
From source file:org.fireflow.engine.persistence.springjdbc.PersistenceServiceSpringJdbcImpl.java
public void saveOrUpdateTaskInstance(ITaskInstance taskInstance) { // TODO wmj2003 taskinstancebiz_type?setget??? // can_be_withdrawn ?? String taskInstanceId = null; if (taskInstance.getId() == null || taskInstance.getId().trim().equals("")) { StringBuffer sql = new StringBuffer(); sql.append("INSERT "); sql.append("INTO t_ff_rt_taskinstance "); sql.append(" ( "); sql.append(" id , "); sql.append(" biz_type , "); sql.append(" task_id , "); sql.append(" activity_id , "); sql.append(" name , "); sql.append(" display_name , "); sql.append(" state , "); sql.append(" suspended , "); sql.append(" task_type , "); sql.append(" created_time , "); sql.append(" started_time , "); sql.append(" expired_time , "); sql.append(" end_time , "); sql.append(" assignment_strategy, "); sql.append(" processinstance_id , "); sql.append(" process_id , "); sql.append(" version , "); sql.append(" target_activity_id , "); sql.append(" from_activity_id , "); sql.append(" step_number , "); sql.append(" can_be_withdrawn "); sql.append(" ) "); sql.append(" VALUES "); sql.append(" ( ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?,? )"); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); }// www.jav a2 s . c o m taskInstanceId = java.util.UUID.randomUUID().toString().replace("-", ""); ((TaskInstance) taskInstance).setId(taskInstanceId);// taskinstanceid super.getJdbcTemplate().update(sql.toString(), new Object[] { taskInstanceId, taskInstance.getClass().getName(), // TODO // biz_typeTaskInstance.hbm.xmldiscriminator?? taskInstance.getTaskId(), taskInstance.getActivityId(), taskInstance.getName(), taskInstance.getDisplayName(), taskInstance.getState(), taskInstance.isSuspended() == true ? 1 : 0, taskInstance.getTaskType(), getSqlDateTime(taskInstance.getCreatedTime()), getSqlDateTime(taskInstance.getStartedTime()), getSqlDateTime(taskInstance.getExpiredTime()), getSqlDateTime(taskInstance.getEndTime()), taskInstance.getAssignmentStrategy(), taskInstance.getProcessInstanceId(), taskInstance.getProcessId(), taskInstance.getVersion(), taskInstance.getTargetActivityId(), ((TaskInstance) taskInstance).getFromActivityId(), taskInstance.getStepNumber(), ((TaskInstance) taskInstance).getCanBeWithdrawn() == true ? 1 : 0 }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER }); } else { StringBuffer sql = new StringBuffer(); sql.append("UPDATE t_ff_rt_taskinstance "); sql.append("SET "); sql.append(" biz_type = ?, "); sql.append(" task_id = ?, "); sql.append(" activity_id = ?, "); sql.append(" name = ?, "); sql.append(" display_name = ?, "); sql.append(" state = ?, "); sql.append(" suspended = ?, "); sql.append(" task_type = ?, "); sql.append(" created_time = ?, "); sql.append(" started_time = ?, "); sql.append(" expired_time = ?, "); sql.append(" end_time = ?, "); sql.append(" assignment_strategy = ?, "); sql.append(" processinstance_id = ?, "); sql.append(" process_id = ?, "); sql.append(" version = ?, "); sql.append(" target_activity_id = ?, "); sql.append(" from_activity_id = ?, "); sql.append(" step_number = ?, "); sql.append(" can_be_withdrawn = ? "); sql.append("WHERE ID = ? "); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); } super.getJdbcTemplate().update(sql.toString(), new Object[] { taskInstance.getClass().getName(), // TODO // biz_typeTaskInstance.hbm.xmldiscriminator?? taskInstance.getTaskId(), taskInstance.getActivityId(), taskInstance.getName(), taskInstance.getDisplayName(), taskInstance.getState(), taskInstance.isSuspended() == true ? 1 : 0, taskInstance.getTaskType(), getSqlDateTime(taskInstance.getCreatedTime()), getSqlDateTime(taskInstance.getStartedTime()), getSqlDateTime(taskInstance.getExpiredTime()), getSqlDateTime(taskInstance.getEndTime()), taskInstance.getAssignmentStrategy(), taskInstance.getProcessInstanceId(), taskInstance.getProcessId(), taskInstance.getVersion(), taskInstance.getTargetActivityId(), ((TaskInstance) taskInstance).getFromActivityId(), taskInstance.getStepNumber(), ((TaskInstance) taskInstance).getCanBeWithdrawn() == true ? 1 : 0, taskInstance.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR }); } }
From source file:org.easyrec.store.dao.core.impl.ItemAssocDAOMysqlImpl.java
/** * updates an item association entry in the database, uses the primary key to retrieve the entry * only changes columns:<br/>// www . j a v a 2s .c o m * - assocValue<br/> * - viewType<br/> * - changeDate<br/> */ @Override public int updateItemAssocUsingPrimaryKey(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); } validatePrimaryKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("updating 'itemAssoc' by primary key: " + itemAssoc); } StringBuilder sqlString; sqlString = new StringBuilder("UPDATE "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" SET "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append("=?, "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append("=?, "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); if (itemAssoc.getChangeDate() == null) { itemAssoc.setChangeDate(new Date(System.currentTimeMillis())); } sqlString.append("=? WHERE "); sqlString.append(DEFAULT_ID_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getId() }; argTypes = new int[] { Types.DOUBLE, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.INTEGER }; } else { args = new Object[] { itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getId() }; argTypes = new int[] { Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.INTEGER }; } return getJdbcTemplate().update(sqlString.toString(), args, argTypes); }
From source file:jongo.jdbc.JDBCExecutor.java
/** * Utility method which registers in a CallableStatement object the different {@link jongo.jdbc.StoredProcedureParam} * instances in the given list. Returns a List of {@link jongo.jdbc.StoredProcedureParam} with all the OUT parameters * registered in the CallableStatement/*from w w w . j a v a 2 s . com*/ * @param cs the CallableStatement object where the parameters are registered. * @param params a list of {@link jongo.jdbc.StoredProcedureParam} * @return a list of OUT {@link jongo.jdbc.StoredProcedureParam} * @throws SQLException if we fail to register any of the parameters in the CallableStatement */ private static List<StoredProcedureParam> addParameters(final CallableStatement cs, final List<StoredProcedureParam> params) throws SQLException { List<StoredProcedureParam> outParams = new ArrayList<StoredProcedureParam>(); int i = 1; for (StoredProcedureParam p : params) { final Integer sqlType = p.getType(); if (p.isOutParameter()) { l.debug("Adding OUT parameter " + p.toString()); cs.registerOutParameter(i++, sqlType); outParams.add(p); } else { l.debug("Adding IN parameter " + p.toString()); switch (sqlType) { case Types.BIGINT: case Types.INTEGER: case Types.TINYINT: // case Types.NUMERIC: cs.setInt(i++, Integer.valueOf(p.getValue())); break; case Types.DATE: cs.setDate(i++, (Date) JongoUtils.parseValue(p.getValue())); break; case Types.TIME: cs.setTime(i++, (Time) JongoUtils.parseValue(p.getValue())); break; case Types.TIMESTAMP: cs.setTimestamp(i++, (Timestamp) JongoUtils.parseValue(p.getValue())); break; case Types.DECIMAL: cs.setBigDecimal(i++, (BigDecimal) JongoUtils.parseValue(p.getValue())); break; case Types.DOUBLE: cs.setDouble(i++, Double.valueOf(p.getValue())); break; case Types.FLOAT: cs.setLong(i++, Long.valueOf(p.getValue())); break; default: cs.setString(i++, p.getValue()); break; } } } return outParams; }