List of usage examples for java.sql Types ARRAY
int ARRAY
To view the source code for java.sql Types ARRAY.
Click Source Link
ARRAY
. From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
/** * Extract the OUT parameter values from the callable statment and * assign them to the value of the parameter. */// w w w .j av a 2 s.c o m public void extract(ConnectionContext cc, CallableStatement stmt) throws SQLException { if (getType().getValueIndex() == StoredProcedureParameter.Type.IN) return; int index = this.getIndex(); QueryParameterType paramType = getSqlType(); int jdbcType = paramType.getJdbcType(); String identifier = paramType.getIdentifier(); // result sets are special if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER)) { ResultSet rs = (ResultSet) stmt.getObject(index); QueryResultSet qrs = new QueryResultSet(getParent().getProcedure(), cc, rs); value.getValue(cc).setValue(qrs); return; } switch (jdbcType) { case Types.VARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case Types.INTEGER: value.getValue(cc).setValue(new Integer(stmt.getInt(index))); break; case Types.DOUBLE: value.getValue(cc).setValue(new Double(stmt.getDouble(index))); break; case Types.CLOB: Clob clob = stmt.getClob(index); value.getValue(cc).setTextValue(clob.getSubString(1, (int) clob.length())); break; case java.sql.Types.ARRAY: Array array = stmt.getArray(index); value.getValue(cc).setValue(array); break; case java.sql.Types.BIGINT: long bigint = stmt.getLong(index); value.getValue(cc).setValue(new Long(bigint)); break; case java.sql.Types.BINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.BIT: boolean bit = stmt.getBoolean(index); value.getValue(cc).setValue(new Boolean(bit)); case java.sql.Types.BLOB: value.getValue(cc).setValue(stmt.getBlob(index)); break; case java.sql.Types.CHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case java.sql.Types.DATE: value.getValue(cc).setValue(stmt.getDate(index)); break; case java.sql.Types.DECIMAL: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.DISTINCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.FLOAT: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; case java.sql.Types.JAVA_OBJECT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.LONGVARBINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.LONGVARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; //case java.sql.Types.NULL: // value.getValue(cc).setValue(null); // break; case java.sql.Types.NUMERIC: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.OTHER: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.REAL: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; //case java.sql.Types.REF: // Ref ref = stmt.getRef(index); // break; case java.sql.Types.SMALLINT: short sh = stmt.getShort(index); value.getValue(cc).setValue(new Short(sh)); break; case java.sql.Types.STRUCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.TIME: value.getValue(cc).setValue(stmt.getTime(index)); break; case java.sql.Types.TIMESTAMP: value.getValue(cc).setValue(stmt.getTimestamp(index)); break; case java.sql.Types.TINYINT: byte b = stmt.getByte(index); value.getValue(cc).setValue(new Byte(b)); break; case java.sql.Types.VARBINARY: value.getValue(cc).setValue(stmt.getBytes(index)); break; default: throw new RuntimeException( "Unknown JDBC Type set for stored procedure parameter '" + this.getName() + "'."); } }
From source file:org.jumpmind.symmetric.io.data.DbFill.java
private Object generateRandomValueForColumn(Column column) { Object objectValue = null;// w ww .java2s .c o m int type = column.getMappedTypeCode(); if (column.isEnum()) { objectValue = column.getEnumValues()[new Random().nextInt(column.getEnumValues().length)]; } else if (column.isTimestampWithTimezone()) { objectValue = String.format("%s %s", FormatUtils.TIMESTAMP_FORMATTER.format(randomDate()), AppUtils.getTimezoneOffset()); } else if (type == Types.DATE) { objectValue = DateUtils.truncate(randomDate(), Calendar.DATE); } else if (type == Types.TIMESTAMP || type == Types.TIME) { objectValue = randomTimestamp(); } else if (type == Types.INTEGER || type == Types.BIGINT) { objectValue = randomInt(); } else if (type == Types.SMALLINT) { objectValue = randomSmallInt(column.getJdbcTypeName().toLowerCase().contains("unsigned")); } else if (type == Types.FLOAT) { objectValue = randomFloat(); } else if (type == Types.DOUBLE) { objectValue = randomDouble(); } else if (type == Types.TINYINT) { objectValue = randomTinyInt(); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.REAL) { objectValue = randomBigDecimal(column.getSizeAsInt(), column.getScale()); } else if (type == Types.BOOLEAN || type == Types.BIT) { objectValue = randomBoolean(); } else if (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer text type type == -10) { objectValue = randomBytes(); } else if (type == Types.ARRAY) { objectValue = null; } else if (type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.CHAR || type == Types.CLOB) { int size = 0; // Assume if the size is 0 there is no max size configured. if (column.getSizeAsInt() != 0) { size = column.getSizeAsInt() > 50 ? 50 : column.getSizeAsInt(); } else { // No max length so default to 50 size = 50; } objectValue = randomString(size); } else if (type == Types.OTHER) { if ("UUID".equalsIgnoreCase(column.getJdbcTypeName())) { objectValue = randomUUID(); } } return objectValue; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.java
@Override public void insertClusterInvalidations(Invalidations invalidations, String nodeId) throws StorageException { String sql = dialect.getClusterInsertInvalidations(); if (nodeId != null) { sql = String.format(sql, nodeId); }// w w w. j a va2 s. c o m List<Column> columns = sqlInfo.getClusterInvalidationsColumns(); PreparedStatement ps = null; try { ps = connection.prepareStatement(sql); int kind = Invalidations.MODIFIED; while (true) { Set<RowId> rowIds = invalidations.getKindSet(kind); // reorganize by id Map<Serializable, Set<String>> res = new HashMap<Serializable, Set<String>>(); for (RowId rowId : rowIds) { Set<String> tableNames = res.get(rowId.id); if (tableNames == null) { res.put(rowId.id, tableNames = new HashSet<String>()); } tableNames.add(rowId.tableName); } // do inserts for (Entry<Serializable, Set<String>> en : res.entrySet()) { Serializable id = en.getKey(); String fragments = join(en.getValue(), ' '); if (logger.isLogEnabled()) { logger.logSQL(sql, Arrays.<Serializable>asList(id, fragments, Long.valueOf(kind))); } Serializable frags; if (dialect.supportsArrays() && columns.get(1).getJdbcType() == Types.ARRAY) { frags = fragments.split(" "); } else { frags = fragments; } columns.get(0).setToPreparedStatement(ps, 1, id); columns.get(1).setToPreparedStatement(ps, 2, frags); columns.get(2).setToPreparedStatement(ps, 3, Long.valueOf(kind)); ps.execute(); countExecute(); } if (kind == Invalidations.MODIFIED) { kind = Invalidations.DELETED; } else { break; } } } catch (Exception e) { checkConnectionReset(e); throw new StorageException("Could not invalidate", e); } finally { if (ps != null) { try { closeStatement(ps); } catch (SQLException e) { log.error(e.getMessage(), e); } } } }
From source file:org.nuxeo.ecm.core.storage.sql.db.H2Fulltext.java
protected static String asString(Object data, int type) throws SQLException { if (data == null) { return ""; }//ww w. j av a 2 s . com switch (type) { case Types.BIT: case Types.BOOLEAN: case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return data.toString(); case Types.CLOB: try { if (data instanceof Clob) { data = ((Clob) data).getCharacterStream(); } return IOUtils.readStringAndClose((Reader) data, -1); } catch (IOException e) { throw DbException.convert(e); } case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BINARY: case Types.JAVA_OBJECT: case Types.OTHER: case Types.BLOB: case Types.STRUCT: case Types.REF: case Types.NULL: case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: throw new SQLException("Unsupported column data type: " + type); default: return ""; } }
From source file:org.nuxeo.ecm.core.storage.sql.Mapper.java
/** * Inserts the invalidation rows for the other cluster nodes. *//*from www. ja va 2s .c o m*/ public void insertClusterInvalidations(Invalidations invalidations) throws StorageException { String sql = sqlInfo.dialect.getClusterInsertInvalidations(); List<Column> columns = sqlInfo.getClusterInvalidationsColumns(); PreparedStatement ps = null; try { ps = connection.prepareStatement(sql); for (int kind = 1; kind <= 2; kind++) { Map<String, Set<Serializable>> map = invalidations.getKindMap(kind); // turn fragment-based map into id-based map Map<Serializable, Set<String>> m = invertMap(map); for (Entry<Serializable, Set<String>> e : m.entrySet()) { Serializable id = e.getKey(); String fragments = join(e.getValue(), ' '); if (isLogEnabled()) { logSQL(sql, Arrays.<Serializable>asList(id, fragments, Integer.valueOf(kind))); } Serializable frags; if (sqlInfo.dialect.supportsArrays() && columns.get(1).getJdbcType() == Types.ARRAY) { frags = fragments.split(" "); } else { frags = fragments; } columns.get(0).setToPreparedStatement(ps, 1, id); columns.get(1).setToPreparedStatement(ps, 2, frags); columns.get(2).setToPreparedStatement(ps, 3, Long.valueOf(kind)); ps.execute(); } } } catch (SQLException e) { checkConnectionReset(e); throw new StorageException("Could not invalidate", e); } finally { if (ps != null) { try { closePreparedStatement(ps); } catch (SQLException e) { log.error(e.getMessage()); } } } }
From source file:org.seasar.dbflute.logic.sql2entity.cmentity.DfProcedureExecutionMetaExtractor.java
protected void registerOutParameter(Connection conn, CallableStatement cs, int paramIndex, int jdbcDefType, DfProcedureColumnMeta column) throws SQLException { final ValueType valueType; {// w ww.j a v a 2 s .c o m final ValueType forcedType = getForcedValueType(column); if (forcedType != null) { valueType = forcedType; } else { if (column.isPostgreSQLCursor()) { valueType = _postgreSqlResultSetType; } else if (column.isOracleCursor()) { valueType = _oracleResultSetType; } else { valueType = TnValueTypes.getValueType(jdbcDefType); } } } try { if (column.isOracleTreatedAsArray() && column.hasTypeArrayInfo()) { cs.registerOutParameter(paramIndex, Types.ARRAY, column.getTypeArrayInfo().getTypeSqlName()); } else if (column.isOracleStruct() && column.hasTypeStructInfo()) { cs.registerOutParameter(paramIndex, Types.STRUCT, column.getTypeStructInfo().getTypeSqlName()); } else { valueType.registerOutParameter(conn, cs, paramIndex); } } catch (SQLException e) { String msg = buildOutParameterExceptionMessage(paramIndex, jdbcDefType, column, valueType); throw new DfJDBCException(msg, e); } catch (RuntimeException e) { String msg = buildOutParameterExceptionMessage(paramIndex, jdbcDefType, column, valueType); throw new IllegalStateException(msg, e); } }
From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
/** * @param vrc/*ww w . j av a 2 s. co m*/ * @param cc * * @throws SQLException */ public void retrieve(StoredProcedureParameters.ValueRetrieveContext vrc, ConnectionContext cc) throws SQLException { // TODO: This needs to be tested.. no checking for stored procedure situation yet int jdbcType = getSqlType().getJdbcType(); if (jdbcType != Types.ARRAY) { if (jdbcType == Types.VARCHAR) { vrc.addInOutValue(value != null ? value.getTextValue(cc) : null, jdbcType, type); } else { switch (jdbcType) { case Types.INTEGER: vrc.addInOutValue(value != null ? new Integer(value.getValue(cc).getIntValue()) : null, jdbcType, type); break; case Types.DOUBLE: vrc.addInOutValue(value != null ? new Double(value.getValue(cc).getDoubleValue()) : null, jdbcType, type); break; } } } else { if (value != null && type.getValueIndex() == Type.IN) { String[] textValues = value.getTextValues(cc); for (int q = 0; q < textValues.length; q++) vrc.addInOutValue(textValues[q], Types.VARCHAR, type); } } }
From source file:org.sakaiproject.warehouse.util.db.DbLoader.java
protected int getJavaSqlType(String genericDataTypeName) { // Find the type code for this generic type name int dataTypeCode = 0; if (genericDataTypeName.equalsIgnoreCase("BIT")) dataTypeCode = Types.BIT; // -7 else if (genericDataTypeName.equalsIgnoreCase("TINYINT")) dataTypeCode = Types.TINYINT; // -6 else if (genericDataTypeName.equalsIgnoreCase("SMALLINT")) dataTypeCode = Types.SMALLINT; // 5 else if (genericDataTypeName.equalsIgnoreCase("INTEGER")) dataTypeCode = Types.INTEGER; // 4 else if (genericDataTypeName.equalsIgnoreCase("BIGINT")) dataTypeCode = Types.BIGINT; // -5 else if (genericDataTypeName.equalsIgnoreCase("FLOAT")) dataTypeCode = Types.FLOAT; // 6 else if (genericDataTypeName.equalsIgnoreCase("REAL")) dataTypeCode = Types.REAL; // 7 else if (genericDataTypeName.equalsIgnoreCase("DOUBLE")) dataTypeCode = Types.DOUBLE; // 8 else if (genericDataTypeName.equalsIgnoreCase("NUMERIC")) dataTypeCode = Types.NUMERIC; // 2 else if (genericDataTypeName.equalsIgnoreCase("DECIMAL")) dataTypeCode = Types.DECIMAL; // 3 else if (genericDataTypeName.equalsIgnoreCase("CHAR")) dataTypeCode = Types.CHAR; // 1 else if (genericDataTypeName.equalsIgnoreCase("VARCHAR")) dataTypeCode = Types.VARCHAR; // 12 else if (genericDataTypeName.equalsIgnoreCase("LONGVARCHAR")) dataTypeCode = Types.LONGVARCHAR; // -1 else if (genericDataTypeName.equalsIgnoreCase("DATE")) dataTypeCode = Types.DATE; // 91 else if (genericDataTypeName.equalsIgnoreCase("TIME")) dataTypeCode = Types.TIME; // 92 else if (genericDataTypeName.equalsIgnoreCase("TIMESTAMP")) dataTypeCode = Types.TIMESTAMP; // 93 else if (genericDataTypeName.equalsIgnoreCase("BINARY")) dataTypeCode = Types.BINARY; // -2 else if (genericDataTypeName.equalsIgnoreCase("VARBINARY")) dataTypeCode = Types.VARBINARY; // -3 else if (genericDataTypeName.equalsIgnoreCase("LONGVARBINARY")) dataTypeCode = Types.LONGVARBINARY; // -4 else if (genericDataTypeName.equalsIgnoreCase("NULL")) dataTypeCode = Types.NULL; // 0 else if (genericDataTypeName.equalsIgnoreCase("OTHER")) dataTypeCode = Types.OTHER; // 1111 else if (genericDataTypeName.equalsIgnoreCase("JAVA_OBJECT")) dataTypeCode = Types.JAVA_OBJECT; // 2000 else if (genericDataTypeName.equalsIgnoreCase("DISTINCT")) dataTypeCode = Types.DISTINCT; // 2001 else if (genericDataTypeName.equalsIgnoreCase("STRUCT")) dataTypeCode = Types.STRUCT; // 2002 else if (genericDataTypeName.equalsIgnoreCase("ARRAY")) dataTypeCode = Types.ARRAY; // 2003 else if (genericDataTypeName.equalsIgnoreCase("BLOB")) dataTypeCode = Types.BLOB; // 2004 else if (genericDataTypeName.equalsIgnoreCase("CLOB")) dataTypeCode = Types.CLOB; // 2005 else if (genericDataTypeName.equalsIgnoreCase("REF")) dataTypeCode = Types.REF; // 2006 return dataTypeCode; }
From source file:org.seasar.dbflute.logic.sql2entity.cmentity.DfProcedureExecutionMetaExtractor.java
protected void bindObject(Connection conn, CallableStatement cs, int paramIndex, int jdbcDefType, Object value, DfProcedureColumnMeta column) throws SQLException { final ValueType valueType; {/*w w w . ja v a2 s . c o m*/ final ValueType forcedType = getForcedValueType(column); if (forcedType != null) { valueType = forcedType; } else { valueType = TnValueTypes.findByValueOrJdbcDefType(value, jdbcDefType); } } try { if (column.isOracleTreatedAsArray() && column.hasTypeArrayInfo()) { cs.setNull(paramIndex, Types.ARRAY, column.getTypeArrayInfo().getTypeSqlName()); } else if (column.isOracleStruct() && column.hasTypeStructInfo()) { cs.setNull(paramIndex, Types.STRUCT, column.getTypeStructInfo().getTypeSqlName()); } else { valueType.bindValue(conn, cs, paramIndex, value); } } catch (SQLException e) { String msg = buildBindingExceptionMessage(paramIndex, jdbcDefType, value, column, valueType); throw new DfJDBCException(msg, e); } catch (RuntimeException e) { String msg = buildBindingExceptionMessage(paramIndex, jdbcDefType, value, column, valueType); throw new IllegalStateException(msg, e); } }
From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
public boolean isListType() { return paramType != null && paramType.getJdbcType() == Types.ARRAY ? true : false; }