List of usage examples for java.sql Types OTHER
int OTHER
To view the source code for java.sql Types OTHER.
Click Source Link
getObject
and setObject
. From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java
/** * Creates a new platform instance.//from w w w. j a va2 s. c o m */ public SybasePlatform() { PlatformInfo info = getPlatformInfo(); info.setMaxIdentifierLength(28); info.setNullAsDefaultValueRequired(true); info.setIdentityColumnAutomaticallyRequired(true); info.setMultipleIdentityColumnsSupported(false); info.setPrimaryKeyColumnsHaveToBeRequired(true); info.setCommentPrefix("/*"); info.setCommentSuffix("*/"); info.addNativeTypeMapping(Types.ARRAY, "IMAGE"); // BIGINT is mapped back in the model reader info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)"); // we're not using the native BIT type because it is rather limited (cannot be NULL, cannot be indexed) info.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.INTEGER, "INT"); info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT"); info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.setDefaultSize(Types.BINARY, 254); info.setDefaultSize(Types.VARBINARY, 254); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); setSqlBuilder(new SybaseBuilder(this)); setModelReader(new SybaseModelReader(this)); }
From source file:org.apache.ddlutils.platform.mssql.MSSqlPlatform.java
/** * Creates a new platform instance./*from www. java2s . co m*/ */ public MSSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setMaxIdentifierLength(128); info.setPrimaryKeyColumnAutomaticallyRequired(true); info.setIdentityColumnAutomaticallyRequired(true); info.setMultipleIdentityColumnsSupported(false); info.setSupportedOnUpdateActions( new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); info.addEquivalentOnUpdateActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT); info.setSupportedOnDeleteActions( new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); info.addEquivalentOnDeleteActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT); info.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY); // BIGINT will be mapped back to BIGINT by the model reader info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)"); info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BIT", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "FLOAT", Types.FLOAT); info.addNativeTypeMapping(Types.INTEGER, "INT"); info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT"); info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP); info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME"); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); info.setDefaultSize(Types.BINARY, 254); info.setDefaultSize(Types.VARBINARY, 254); setSqlBuilder(new MSSqlBuilder(this)); setModelReader(new MSSqlModelReader(this)); }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type) { case VARCHAR: return jdbcInfo("varchar", Types.VARCHAR); case CLOB:// w w w . ja va 2s . c o m return jdbcInfo("text", Types.CLOB); case BOOLEAN: return jdbcInfo("bool", Types.BIT); case LONG: return jdbcInfo("int8", Types.BIGINT); case DOUBLE: return jdbcInfo("float8", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("timestamp", Types.TIMESTAMP); case BLOBID: return jdbcInfo("varchar(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEVAL: return jdbcInfo("varchar(36)", Types.VARCHAR); case SYSNAME: return jdbcInfo("varchar(250)", Types.VARCHAR); case TINYINT: return jdbcInfo("int2", Types.SMALLINT); case INTEGER: return jdbcInfo("int4", Types.INTEGER); case FTINDEXED: return jdbcInfo("tsvector", Types.OTHER); case FTSTORED: return jdbcInfo("tsvector", Types.OTHER); case CLUSTERNODE: return jdbcInfo("int4", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("varchar[]", Types.ARRAY); } throw new AssertionError(type); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) { // Oracle internal conversions if (expected == Types.DOUBLE && actual == Types.FLOAT) { return true; }/* w w w. ja v a2s . co m*/ if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.BIT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 1) { return true; } if (expected == Types.TINYINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 3) { return true; } if (expected == Types.INTEGER && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 10) { return true; } if (expected == Types.BIGINT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 19) { return true; } // CLOB vs VARCHAR compatibility if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NCLOB")) { return true; } if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NVARCHAR2")) { return true; } return false; }
From source file:de.swm.nis.logicaldecoding.tracktable.TrackTablePublisher.java
public void publish(DmlEvent event) { String metadata = extractMetadata(event); String changedTableSchema = event.getSchemaName(); String changedTableName = event.getTableName(); String type = event.getType().toString(); Long transactionId = event.getTransactionId(); PGobject timestamp = getTimestamp(event); PGobject oldjson = getJsonOldValues(event); PGobject newjson = getJsonNewValues(event); Object[] params;//from w ww. ja v a 2s .co m String sql; int[] types; Envelope envelope = event.getEnvelope(); if (!envelope.isNull()) { //expand if necessasry if (envelope.getHeight() < minSize && envelope.getWidth() < minSize) { envelope.expandBy(bufferSize); } //Transform Bounding Box of the change into WKB GeometryFactory geomFactory = new GeometryFactory(new PrecisionModel(), epsgCode); WKBWriter wkbWriter = new WKBWriter(2, true); byte[] wkb = wkbWriter.write(geomFactory.toGeometry(envelope)); params = new Object[] { wkb, type, changedTableSchema, changedTableName, transactionId, timestamp, metadata, oldjson, newjson }; types = new int[] { Types.BINARY, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.OTHER, Types.VARCHAR, Types.OTHER, Types.OTHER }; sql = "INSERT INTO " + schemaname + "." + tableName + "(" + regionColumnName + ", " + transactionTypeColumnName + ", " + schemaColumnName + ", " + tableColumnName + ", " + txIdColumnName + ", " + commitTimestampColumnName + ", " + metadataColumnName + ", " + jsonOldValuesColumnName + ", " + jsonNewValuesColumName + ") VALUES (?,?,?,?,?,?,?,?,?)"; } else { //geometry is null, do not include it in SQL insert statement params = new Object[] { type, changedTableSchema, changedTableName, transactionId, timestamp, metadata, oldjson, newjson }; types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.OTHER, Types.VARCHAR, Types.OTHER, Types.OTHER }; sql = "INSERT INTO " + schemaname + "." + tableName + "(" + transactionTypeColumnName + ", " + schemaColumnName + ", " + tableColumnName + ", " + txIdColumnName + ", " + commitTimestampColumnName + ", " + metadataColumnName + ", " + jsonOldValuesColumnName + ", " + jsonNewValuesColumName + ") VALUES (?,?,?,?,?,?,?,?)"; } template.update(sql, params, types); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING://from ww w . j a v a2s . co m if (type.isUnconstrained()) { return jdbcInfo("varchar", Types.VARCHAR); } else if (type.isClob()) { return jdbcInfo("text", Types.CLOB); } else { return jdbcInfo("varchar(%d)", type.length, Types.VARCHAR); } case BOOLEAN: return jdbcInfo("bool", Types.BIT); case LONG: return jdbcInfo("int8", Types.BIGINT); case DOUBLE: return jdbcInfo("float8", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("timestamp", Types.TIMESTAMP); case BLOBID: return jdbcInfo("varchar(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: return jdbcInfo("varchar(36)", Types.VARCHAR); case NODEARRAY: return jdbcInfo("varchar(36)[]", Types.ARRAY); case SYSNAME: return jdbcInfo("varchar(250)", Types.VARCHAR); case SYSNAMEARRAY: return jdbcInfo("varchar(250)[]", Types.ARRAY); case TINYINT: return jdbcInfo("int2", Types.SMALLINT); case INTEGER: return jdbcInfo("int4", Types.INTEGER); case FTINDEXED: return jdbcInfo("tsvector", Types.OTHER); case FTSTORED: return jdbcInfo("tsvector", Types.OTHER); case CLUSTERNODE: return jdbcInfo("int4", Types.INTEGER); case CLUSTERFRAGS: return jdbcInfo("varchar[]", Types.ARRAY); } throw new AssertionError(type); }
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:es.juntadeandalucia.panelGestion.persistencia.dao.impl.RemoteDataBaseDAOImpl.java
@Override public boolean createTable(Table table, Collection<ColumnVO> columns) throws Exception { boolean tableCreated = false; if (columns.size() > 0) { String schemaName = table.getSchema().getName(); String geometricField = table.getGeomField(); String geometryType = null; String epsg = table.getEpsg(); String user = table.getSchema().getUser(); String sequenceName = TableUtils.getSequenceName(table); String idColumnName = TableUtils.getIdColumnName(table); String pkeyConstraint = TableUtils.getPKeyConstraint(table); String schemaTable = TableUtils.getSchemaTable(table); String schemaSequence = schemaName + "." + sequenceName; StringBuilder sqlBuilder = new StringBuilder(); // create table sqlBuilder.append("CREATE TABLE ").append(schemaTable).append("("); // id with sequence sqlBuilder.append(idColumnName).append(" integer NOT NULL DEFAULT nextval('").append(schemaSequence) .append("'::regclass)"); // columns boolean hasX = false; boolean hasY = false; for (ColumnVO column : columns) { if (column.isInTable()) { /*/*from w w w .j av a 2 s. co m*/ * gets the column name and replace the white characters for "_" */ String columnName = column.getNameOnTable(); if (StringUtils.isEmpty(columnName)) { columnName = column.getText(); } columnName = columnName.replaceAll("\\s", "_"); String type = column.getType(); Integer length = column.getLength(); Integer precision = column.getPrecision(); Integer sqlType = column.getSqlType(); if (column.isCoordinateX()) { hasX = true; type = "numeric"; } else if (column.isCoordinateY()) { hasY = true; type = "numeric"; } else if (sqlType == Types.OTHER) { // geometry type geometryType = column.getGeometryType().toUpperCase(); } // column name sqlBuilder.append(", ").append(columnName); // column type sqlBuilder.append(" ").append(type); // column length & precision if ((length != null) && (precision != null)) { sqlBuilder.append("(").append(length).append(",").append(precision).append(")"); } else if (length != null) { sqlBuilder.append("(").append(length).append(")"); } else if (precision != null) { sqlBuilder.append("(").append(precision).append(")"); } } } if (hasX && hasY) { geometryType = "POINT"; geometricField = geomFieldName; table.setGeomField(geometricField); sqlBuilder.append(", ").append(geometricField); sqlBuilder.append(" ").append("geometry"); } else if (hasX || hasY) { throw new IllegalArgumentException("No ha especificado la coordenada ".concat(hasX ? "Y" : "X")); } // primary key constraint sqlBuilder.append(", CONSTRAINT ").append(pkeyConstraint).append(" PRIMARY KEY (").append(idColumnName) .append(")"); // constraint enforce srid if (!StringUtils.isEmpty(geometricField)) { // geometryc type constraint sqlBuilder.append(", CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(") .append(geometricField).append(") = '").append(geometryType).append("'::text OR ") .append(geometricField).append(" IS NULL)"); // geometry srid constraint Integer srid = Utils.getSRID(epsg); sqlBuilder.append(", CONSTRAINT enforce_srid_the_geom CHECK (st_srid(").append(geometricField) .append(") = ").append(srid).append(")"); } sqlBuilder.append(");"); // owner user sqlBuilder.append("ALTER TABLE ").append(schemaTable).append(" OWNER TO ").append(user).append(";"); // grants sqlBuilder.append("GRANT ALL ON TABLE ").append(schemaTable).append(" TO ").append(user).append(";"); sqlBuilder.append("GRANT SELECT ON TABLE ").append(schemaTable).append(" TO ").append(user).append(";"); String sql = sqlBuilder.toString(); connector.executeUpdate(sql); tableCreated = true; } return tableCreated; }
From source file:oscar.util.SqlUtils.java
/** * this utility-method assigns a particular value to a place holder of a PreparedStatement. it tries to find the correct setXxx() value, accoring to the field-type information * represented by "fieldType". quality: this method is bloody alpha (as you migth see :=) *//*from w w w . j a va 2 s . c om*/ public static void fillPreparedStatement(PreparedStatement ps, int col, Object val, int fieldType) throws SQLException { try { logger.info("fillPreparedStatement( ps, " + col + ", " + val + ", " + fieldType + ")..."); Object value = null; // Check for hard-coded NULL if (!("$null$".equals(val))) { value = val; } if (value != null) { switch (fieldType) { case FieldTypes.INTEGER: ps.setInt(col, Integer.parseInt((String) value)); break; case FieldTypes.NUMERIC: ps.setBigDecimal(col, createAppropriateNumeric(value)); break; case FieldTypes.CHAR: ps.setString(col, (String) value); break; case FieldTypes.DATE: ps.setDate(col, createAppropriateDate(value)); break; // #checkme case FieldTypes.TIMESTAMP: ps.setTimestamp(col, java.sql.Timestamp.valueOf((String) value)); break; case FieldTypes.DOUBLE: ps.setDouble(col, Double.valueOf((String) value).doubleValue()); break; case FieldTypes.FLOAT: ps.setFloat(col, Float.valueOf((String) value).floatValue()); break; case FieldTypes.LONG: ps.setLong(col, Long.parseLong(String.valueOf(value))); break; case FieldTypes.BLOB: FileHolder fileHolder = (FileHolder) value; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(fileHolder); out.flush(); byte[] buf = byteOut.toByteArray(); byteOut.close(); out.close(); ByteArrayInputStream bytein = new ByteArrayInputStream(buf); int byteLength = buf.length; ps.setBinaryStream(col, bytein, byteLength); // store fileHolder as a whole (this way we don't lose file meta-info!) } catch (IOException ioe) { MiscUtils.getLogger().error("Error", ioe); logger.info(ioe.toString()); throw new SQLException("error storing BLOB in database - " + ioe.toString(), null, 2); } break; case FieldTypes.DISKBLOB: ps.setString(col, (String) value); break; default: ps.setObject(col, value); // #checkme } } else { switch (fieldType) { case FieldTypes.INTEGER: ps.setNull(col, java.sql.Types.INTEGER); break; case FieldTypes.NUMERIC: ps.setNull(col, java.sql.Types.NUMERIC); break; case FieldTypes.CHAR: ps.setNull(col, java.sql.Types.CHAR); break; case FieldTypes.DATE: ps.setNull(col, java.sql.Types.DATE); break; case FieldTypes.TIMESTAMP: ps.setNull(col, java.sql.Types.TIMESTAMP); break; case FieldTypes.DOUBLE: ps.setNull(col, java.sql.Types.DOUBLE); break; case FieldTypes.FLOAT: ps.setNull(col, java.sql.Types.FLOAT); break; case FieldTypes.BLOB: ps.setNull(col, java.sql.Types.BLOB); case FieldTypes.DISKBLOB: ps.setNull(col, java.sql.Types.CHAR); default: ps.setNull(col, java.sql.Types.OTHER); } } } catch (Exception e) { throw new SQLException("Field type seems to be incorrect - " + e.toString(), null, 1); } }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: String v;//w w w.j a v a 2s . co m if (column.getType() == ColumnType.BLOBID) { v = ((Binary) value).getDigest(); } else { v = (String) value; } ps.setString(index, v); break; case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Long) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: Calendar cal = (Calendar) value; Timestamp ts = new Timestamp(cal.getTimeInMillis()); ps.setTimestamp(index, ts, cal); // cal passed for timezone return; case Types.ARRAY: Array array = createArrayOf(Types.VARCHAR, (Object[]) value, ps.getConnection()); ps.setArray(index, array); return; case Types.OTHER: if (column.getType() == ColumnType.FTSTORED) { ps.setString(index, (String) value); return; } throw new SQLException("Unhandled type: " + column.getType()); default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }