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:org.georepublic.db.utils.ResultSetConverter.java
public static StringBuffer convertCsv(ResultSet rs) throws SQLException { String column_name = new String(); StringBuffer retval = new StringBuffer(); ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); for (int h = 1; h < numColumns + 1; h++) { column_name = rsmd.getColumnName(h); if (h > 1) { retval.append(","); }/*from w w w .j a v a2 s .c om*/ retval.append(column_name); } retval.append("\n"); while (rs.next()) { for (int i = 1; i < numColumns + 1; i++) { column_name = rsmd.getColumnName(i); if (StringUtils.equals(column_name, "the_geom")) { continue; } if (StringUtils.equals(column_name, "geojson")) { continue; } if (i > 1) { retval.append(","); } if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { retval.append(rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { retval.append(rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { retval.append(rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { retval.append(rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { retval.append(rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { retval.append(rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { retval.append(rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { retval.append(rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { retval.append(rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { retval.append(rs.getTimestamp(column_name)); } else { retval.append(rs.getObject(column_name)); } } retval.append("\n"); } return retval; }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the {@link Types} constant for the given SQL type name. *//*from w w w . j a v a 2s . c o m*/ public static int getJDBCType(String name) { if ("array".equalsIgnoreCase(name)) return Types.ARRAY; if ("bigint".equalsIgnoreCase(name)) return Types.BIGINT; if ("binary".equalsIgnoreCase(name)) return Types.BINARY; if ("bit".equalsIgnoreCase(name)) return Types.BIT; if ("blob".equalsIgnoreCase(name)) return Types.BLOB; if ("char".equalsIgnoreCase(name)) return Types.CHAR; if ("clob".equalsIgnoreCase(name)) return Types.CLOB; if ("date".equalsIgnoreCase(name)) return Types.DATE; if ("decimal".equalsIgnoreCase(name)) return Types.DECIMAL; if ("distinct".equalsIgnoreCase(name)) return Types.DISTINCT; if ("double".equalsIgnoreCase(name)) return Types.DOUBLE; if ("float".equalsIgnoreCase(name)) return Types.FLOAT; if ("integer".equalsIgnoreCase(name)) return Types.INTEGER; if ("java_object".equalsIgnoreCase(name)) return Types.JAVA_OBJECT; if ("longvarbinary".equalsIgnoreCase(name)) return Types.LONGVARBINARY; if ("longvarchar".equalsIgnoreCase(name)) return Types.LONGVARCHAR; if ("null".equalsIgnoreCase(name)) return Types.NULL; if ("numeric".equalsIgnoreCase(name)) return Types.NUMERIC; if ("other".equalsIgnoreCase(name)) return Types.OTHER; if ("real".equalsIgnoreCase(name)) return Types.REAL; if ("ref".equalsIgnoreCase(name)) return Types.REF; if ("smallint".equalsIgnoreCase(name)) return Types.SMALLINT; if ("struct".equalsIgnoreCase(name)) return Types.STRUCT; if ("time".equalsIgnoreCase(name)) return Types.TIME; if ("timestamp".equalsIgnoreCase(name)) return Types.TIMESTAMP; if ("tinyint".equalsIgnoreCase(name)) return Types.TINYINT; if ("varbinary".equalsIgnoreCase(name)) return Types.VARBINARY; if ("varchar".equalsIgnoreCase(name)) return Types.VARCHAR; if (name == null || name.toLowerCase().startsWith("unknown")) return Types.OTHER; throw new IllegalArgumentException("name = " + name); }
From source file:edu.harvard.i2b2.crc.dao.setfinder.QueryResultInstanceSpringDao.java
/** * Function used to update result instance Particularly its status and size * /*from w w w . j a v a 2 s . c om*/ * @param resultInstanceId * @param statusTypeId * @param setSize */ public void updatePatientSet(String resultInstanceId, int statusTypeId, String message, int setSize, int realSetSize, String obsMethod) { Date endDate = new Date(System.currentTimeMillis()); String sql = "update " + getDbSchemaName() + "qt_query_result_instance set set_size = ?, real_set_size = ? , obfusc_method = ?, status_type_id =?, end_date = ?, message = ? where result_instance_id = ?"; jdbcTemplate.update(sql, new Object[] { setSize, realSetSize, obsMethod, statusTypeId, endDate, message, resultInstanceId }, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER }); }
From source file:org.brucalipto.sqlutil.DB2SQLManager.java
/** * Method useful for using STORED PROCEDURE * @param spib The {@link SPInputBean} bean containing data to execute the stored procedure * @return The {@link SPOutputBean} containing returned values *///from ww w .ja v a2 s . c o m public SPOutputBean executeSP(final SPInputBean spib) throws SQLException { Connection conn = null; CallableStatement call = null; ResultSet resultSet = null; final String procedureName = spib.spName; SPParameter[] inputParameters = spib.inputParams; int[] outputParameters = spib.outputParams; final int inputParametersSize = inputParameters.length; final int outputParametersSize = outputParameters.length; final StringBuffer spName = new StringBuffer("call ").append(procedureName).append('('); int totalParameters = inputParametersSize + outputParametersSize; for (int i = 0; i < totalParameters; i++) { if (i != totalParameters - 1) { spName.append("?,"); } else { spName.append('?'); } } spName.append(")"); try { if (this.dataSource != null) { conn = this.dataSource.getConnection(); } else { conn = this.connection; } call = conn.prepareCall(spName.toString()); for (int i = 0; i < inputParametersSize; i++) { final SPParameter inputParam = inputParameters[i]; final int sqlType = inputParam.sqlType; final Object inputParamValue = inputParam.value; log.debug((i + 1) + ") Setting input value: " + inputParam); if (inputParamValue == null) { call.setNull(i + 1, sqlType); continue; } switch (sqlType) { case Types.VARCHAR: call.setString(i + 1, (String) inputParamValue); break; case Types.INTEGER: if (inputParamValue instanceof Integer) { call.setInt(i + 1, ((Integer) inputParamValue).intValue()); } else if (inputParamValue instanceof Long) { call.setLong(i + 1, ((Long) inputParamValue).longValue()); } break; case Types.DATE: call.setDate(i + 1, (Date) inputParamValue); break; case Types.BOOLEAN: call.setBoolean(i + 1, ((Boolean) inputParamValue).booleanValue()); break; case Types.CHAR: call.setString(i + 1, ((Character) inputParamValue).toString()); break; case Types.DOUBLE: call.setDouble(i + 1, ((Double) inputParamValue).doubleValue()); break; case Types.FLOAT: call.setFloat(i + 1, ((Float) inputParamValue).floatValue()); break; case Types.TIMESTAMP: call.setTimestamp(i + 1, (Timestamp) inputParamValue); break; default: call.setObject(i + 1, inputParamValue); break; } } for (int i = 0; i < outputParametersSize; i++) { int sqlType = outputParameters[i]; log.debug((i + 1) + ") Registering output type 'Types." + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'"); call.registerOutParameter(inputParametersSize + i + 1, sqlType); } log.debug("Going to call: '" + procedureName + "'"); long elapsedTime = System.currentTimeMillis(); boolean hasResultSet = call.execute(); log.debug("SP '" + procedureName + "' executed in " + (System.currentTimeMillis() - elapsedTime) + "millis"); if (hasResultSet) { log.debug("This SP is going to return also a resultSet"); } final SPOutputBean output = new SPOutputBean(); for (int i = 0; i < outputParametersSize; i++) { int sqlType = outputParameters[i]; log.debug((i + 1) + ") Getting output type 'Types." + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'"); final Object spResult = call.getObject(inputParametersSize + i + 1); SPParameter outParam = new SPParameter(sqlType, spResult); output.addResult(outParam); } if (hasResultSet) { RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(call.getResultSet(), false); if (log.isDebugEnabled()) { log.debug("Going to return a RowSetDynaClass with following properties:"); DynaProperty[] properties = rowSetDynaClass.getDynaProperties(); for (int i = 0; i < properties.length; i++) { log.debug("Name: '" + properties[i].getName() + "'; Type: '" + properties[i].getType().getName() + "'"); } } SPParameter outParam = new SPParameter(Types.JAVA_OBJECT, rowSetDynaClass); output.addResult(outParam); } return output; } finally { closeResources(resultSet, call, conn); } }
From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java
protected void registerDefaultJavaTypes() { registerJavaType(Types.BIT, Boolean.class.getName()); registerJavaType(Types.TINYINT, Byte.class.getName()); registerJavaType(Types.SMALLINT, Short.class.getName()); // registerJavaType(Types.CHAR, Character.class.getName()); registerJavaType(Types.CHAR, String.class.getName()); registerJavaType(Types.VARCHAR, String.class.getName()); registerJavaType(Types.DATE, Date.class.getName()); registerJavaType(Types.TIME, Time.class.getName()); registerJavaType(Types.TIMESTAMP, Timestamp.class.getName()); registerJavaType(Types.DOUBLE, Double.class.getName()); registerJavaType(Types.FLOAT, Float.class.getName()); registerJavaType(Types.INTEGER, Integer.class.getName()); registerJavaType(Types.BIGINT, BigInteger.class.getName()); // registerJavaType(Types.BIGINT, Long.class.getName()); registerJavaType(Types.NUMERIC, BigDecimal.class.getName()); registerJavaType(Types.DECIMAL, BigDecimal.class.getName()); registerJavaType(Types.BINARY, byte[].class.getName()); registerJavaType(Types.VARBINARY, byte[].class.getName()); registerJavaType(Types.BLOB, String.class.getName()); registerJavaType(Types.CLOB, String.class.getName()); registerJavaType(Types.REAL, String.class.getName()); registerJavaType(Types.OTHER, Object.class.getName()); }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.ExtendedRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }//from ww w .j a v a 2 s . co m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); buildFormatterAndNamesArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); boolean isKeyCol = false; boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, Element> keyCols = new TreeMap<String, Element>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElementNS(doc, AbstractDBO.ROW_NAME, NS); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; String colName = colNames[j]; isKeyCol = (!noKey && keyField.contains(new Integer(j))); isNull = false; col = parser.createElementNS(doc, colName, NS); if (isKeyCol) { parser.setAttribute(col, AbstractDBO.ID_NAME, String.valueOf(j)); } switch (metadata.getColumnType(j)) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); isNull = dateVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getDateFormat()); textVal = fF.formatDate(dateVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = dateFormatter.format(dateVal); } } } break; case Types.DOUBLE: case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(numVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(numVal); } } break; case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: { BigDecimal bigdecimal = rs.getBigDecimal(j); isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (isKeyCol) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyCols.put(String.valueOf(j), col); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); Element key = parser.createElementNS(doc, AbstractDBO.KEY_NAME, NS); data.appendChild(key); for (Entry<String, Element> keyColsEntry : keyCols.entrySet()) { key.appendChild(keyColsEntry.getValue()); } keyCols.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;/*w w w .j av a 2 s.co m*/ case Types.BIT: ps.setInt(index, ((Boolean) value).booleanValue() ? 1 : 0); return; case Types.TINYINT: case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Number) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:org.brucalipto.sqlutil.OracleSQLManager.java
/** * Method useful for using STORED PROCEDURE * @param spib The {@link SPInputBean} bean containing data to execute the stored procedure * @return The {@link SPOutputBean} containing returned values *///from ww w . j a v a 2s . c om public SPOutputBean executeSP(final SPInputBean spib) throws SQLException { Connection conn = null; CallableStatement call = null; ResultSet resultSet = null; final String procedureName = spib.spName; SPParameter[] inputParameters = spib.inputParams; int[] outputParameters = spib.outputParams; final int inputParametersSize = inputParameters.length; final int outputParametersSize = outputParameters.length; final StringBuffer spName = new StringBuffer("{ call ").append(procedureName).append('('); int totalParameters = inputParametersSize + outputParametersSize; for (int i = 0; i < totalParameters; i++) { if (i != totalParameters - 1) { spName.append("?,"); } else { spName.append('?'); } } spName.append(") }"); log.debug("Going to call: '" + spName + "'"); try { conn = this.dataSource.getConnection(); call = conn.prepareCall(spName.toString()); for (int i = 0; i < inputParametersSize; i++) { final SPParameter inputParam = inputParameters[i]; final int sqlType = inputParam.sqlType; final Object inputParamValue = inputParam.value; log.debug((i + 1) + ") Setting input value 'Types." + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'-'" + inputParamValue + "'"); if (inputParamValue == null) { call.setNull(i + 1, sqlType); continue; } switch (sqlType) { case Types.VARCHAR: call.setString(i + 1, (String) inputParamValue); break; case Types.INTEGER: if (inputParamValue instanceof Integer) { call.setInt(i + 1, ((Integer) inputParamValue).intValue()); } else if (inputParamValue instanceof Long) { call.setLong(i + 1, ((Long) inputParamValue).longValue()); } break; case Types.DATE: call.setDate(i + 1, (Date) inputParamValue); break; case Types.BOOLEAN: call.setBoolean(i + 1, ((Boolean) inputParamValue).booleanValue()); break; case Types.CHAR: call.setString(i + 1, ((Character) inputParamValue).toString()); break; case Types.DOUBLE: call.setDouble(i + 1, ((Double) inputParamValue).doubleValue()); break; case Types.FLOAT: call.setFloat(i + 1, ((Float) inputParamValue).floatValue()); break; case Types.TIMESTAMP: call.setTimestamp(i + 1, (Timestamp) inputParamValue); break; default: call.setObject(i + 1, inputParamValue); break; } } for (int i = 0; i < outputParametersSize; i++) { int sqlType = outputParameters[i]; log.debug((i + 1) + ") Registering output type 'Types." + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'"); call.registerOutParameter(inputParametersSize + i + 1, sqlType); } call.execute(); final SPOutputBean output = new SPOutputBean(); for (int i = 0; i < outputParametersSize; i++) { int sqlType = outputParameters[i]; log.debug((i + 1) + ") Getting output type 'Types." + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'"); final Object spResult = call.getObject(inputParametersSize + i + 1); SPParameter outParam = null; if (sqlType == SQLUtilTypes.CURSOR) { resultSet = (ResultSet) spResult; RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(resultSet, false); if (log.isDebugEnabled()) { log.debug("Going to return a RowSetDynaClass with following properties:"); DynaProperty[] properties = rowSetDynaClass.getDynaProperties(); for (int j = 0; j < properties.length; j++) { log.debug("Name: '" + properties[j].getName() + "'; Type: '" + properties[j].getType().getName() + "'"); } } outParam = new SPParameter(sqlType, rowSetDynaClass); } else { outParam = new SPParameter(sqlType, spResult); } output.addResult(outParam); } return output; } catch (SQLException sqle) { log.error("Caught SQLException", sqle); } finally { closeResources(resultSet, call, conn); } return null; }
From source file:org.easyrec.plugin.arm.store.dao.impl.RuleminingItemAssocDAOMysqlImpl.java
@Override public int insertOrUpdateItemAssoc(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); }//from w ww . j a v a 2s . c o m // validate unique key validateUniqueKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("inserting 'itemAssoc': " + itemAssoc); } // @HINT: maybe use UniqueIdService later (instead of auto_imcrement) StringBuilder sqlString = new StringBuilder("INSERT INTO "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" ("); sqlString.append(DEFAULT_TENANT_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_INFO_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())); } if (itemAssoc.isActive() != null) { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } else { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } sqlString.append(" ON DUPLICATE KEY UPDATE "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append("=?, "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append("=?, "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.isActive(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.BOOLEAN, Types.TIMESTAMP, }; } else { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, }; } PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(), argTypes); int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); return rowsAffected; }
From source file:org.easyrec.plugin.profileduke.store.dao.impl.ProfileSimilarityItemAssocDAOMysqlImpl.java
public int insertOrUpdateItemAssoc(ItemAssocVO<Integer, Integer> itemAssoc) { // validate input parameters if (itemAssoc == null) { throw new IllegalArgumentException("missing 'itemAssoc'"); }//from w w w. j a v a2 s . c om // validate unique key validateUniqueKey(itemAssoc); validateAssocValue(itemAssoc); validateViewType(itemAssoc); if (logger.isDebugEnabled()) { logger.debug("inserting 'itemAssoc': " + itemAssoc); } // @HINT: maybe use UniqueIdService later (instead of auto_imcrement) StringBuilder sqlString = new StringBuilder("INSERT INTO "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" ("); sqlString.append(DEFAULT_TENANT_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_FROM_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_ITEM_TO_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_TYPE_COLUMN_NAME); sqlString.append(", "); sqlString.append(DEFAULT_SOURCE_INFO_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())); } if (itemAssoc.isActive() != null) { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } else { sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } sqlString.append(" ON DUPLICATE KEY UPDATE "); sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME); sqlString.append("=?, "); sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME); sqlString.append("=?, "); if (itemAssoc.isActive() != null) { sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME); sqlString.append("=?, "); } sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME); sqlString.append("=?"); Object[] args; int[] argTypes; if (itemAssoc.isActive() != null) { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.isActive(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.isActive(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.BOOLEAN, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.BOOLEAN, Types.TIMESTAMP, }; } else { args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(), itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(), itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(), itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.getChangeDate(), itemAssoc.getAssocValue(), itemAssoc.getViewType(), itemAssoc.getSourceInfo(), itemAssoc.getChangeDate() }; argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, }; } PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(), argTypes); int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args)); return rowsAffected; }