List of usage examples for java.sql Types FLOAT
int FLOAT
To view the source code for java.sql Types FLOAT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT
.
From source file:org.sakaiproject.webservices.SakaiReport.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//from ww w. j a va2 s . c om case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; case Types.VARBINARY: case Types.BINARY: value = handleRaw(rs.getBytes(colIndex)); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.brucalipto.sqlutil.SQLManager.java
protected int executeSimpleQuery(final String preparedStatement, final SQLParameter[] params) { final SQLParameter[] parameters; if (params == null) { parameters = new SQLParameter[0]; log.debug("Going to execute a query without parameters."); } else {/*ww w . ja v a2 s. c o m*/ parameters = (SQLParameter[]) params.clone(); } Connection dbConn = null; PreparedStatement pstmt = null; try { if (this.dataSource != null) { dbConn = this.dataSource.getConnection(); } else { dbConn = this.connection; } pstmt = dbConn.prepareStatement(preparedStatement); for (int i = 0; i < parameters.length; i++) { final SQLParameter param = parameters[i]; log.debug((i + 1) + ") Going to add parameter " + param); final int sqlType = param.getSqlType(); final Object paramValue = param.getValue(); if (paramValue == null) { pstmt.setNull(i + 1, sqlType); continue; } switch (sqlType) { case Types.VARCHAR: pstmt.setString(i + 1, (String) paramValue); break; case Types.INTEGER: if (paramValue instanceof Integer) { pstmt.setInt(i + 1, ((Integer) paramValue).intValue()); } else if (paramValue instanceof Long) { pstmt.setLong(i + 1, ((Long) paramValue).longValue()); } break; case Types.DATE: pstmt.setDate(i + 1, (Date) paramValue); break; case Types.BOOLEAN: pstmt.setBoolean(i + 1, ((Boolean) paramValue).booleanValue()); break; case Types.CHAR: pstmt.setString(i + 1, ((Character) paramValue).toString()); break; case Types.DOUBLE: pstmt.setDouble(i + 1, ((Double) paramValue).doubleValue()); break; case Types.FLOAT: pstmt.setFloat(i + 1, ((Float) paramValue).floatValue()); break; case Types.TIMESTAMP: pstmt.setTimestamp(i + 1, (Timestamp) paramValue); break; default: pstmt.setObject(i + 1, paramValue); break; } } int result = pstmt.executeUpdate(); log.debug("Prepared statement '" + preparedStatement + "' correctly executed (" + result + ")"); return result; } catch (SQLException e) { log.error("Error executing prepared statement '" + preparedStatement + "'", e); } catch (Exception e) { log.error("Error executing prepared statement '" + preparedStatement + "'", e); } finally { closeResources(pstmt, dbConn); } return -1; }
From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java
private void setArgument(PreparedStatement pstmt, String argument, int targetSqlType, int index) throws SQLException { switch (targetSqlType) { case Types.INTEGER: pstmt.setInt(index, Integer.parseInt(argument)); break;// w ww . ja v a2 s. c o m case Types.DECIMAL: case Types.NUMERIC: pstmt.setBigDecimal(index, new BigDecimal(argument)); break; case Types.DOUBLE: case Types.FLOAT: pstmt.setDouble(index, Double.parseDouble(argument)); break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: pstmt.setString(index, argument); break; case Types.BIT: case Types.BOOLEAN: pstmt.setBoolean(index, Boolean.parseBoolean(argument)); break; case Types.BIGINT: pstmt.setLong(index, Long.parseLong(argument)); break; case Types.DATE: pstmt.setDate(index, Date.valueOf(argument)); break; case Types.REAL: pstmt.setFloat(index, Float.parseFloat(argument)); break; case Types.TINYINT: pstmt.setByte(index, Byte.parseByte(argument)); break; case Types.SMALLINT: pstmt.setShort(index, Short.parseShort(argument)); break; case Types.TIMESTAMP: pstmt.setTimestamp(index, Timestamp.valueOf(argument)); break; case Types.TIME: pstmt.setTime(index, Time.valueOf(argument)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: pstmt.setBytes(index, argument.getBytes()); break; case Types.NULL: pstmt.setNull(index, targetSqlType); break; default: pstmt.setObject(index, argument, targetSqlType); } }
From source file:org.apache.cassandra.cql.jdbc.HandleObjects.java
public static final ByteBuffer makeBytes(Object object, int baseType, int scaleOrLength) throws SQLException { Class<? extends Object> objectClass = object.getClass(); boolean isCollection = (Collection.class.isAssignableFrom(objectClass)); int targetSqlType = isCollection ? Types.OTHER : baseType; // Type check first switch (targetSqlType) { case Types.TINYINT: // Only Numeric classes, Strings and Booleans are supported for transformation to TINYINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "TINYINT"); break;//from ww w .j a v a 2 s. co m case Types.SMALLINT: // Only Numeric classes, Strings and Booleans are supported for transformation to SMALLINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "SMALLINT"); break; case Types.INTEGER: // Only Numeric classes, Strings and Booleans are supported for transformation to INTEGER if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "INTEGER"); break; case Types.BIGINT: // Only Numeric classes, Strings and Booleans are supported for transformation to BIGINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BIGINT"); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: // Only Numeric classes Strings and Booleans are supported for transformation to REAL,FLOAT,DOUBLE,DECIMAL if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "the floating point types"); break; case Types.NUMERIC: //NB This as a special case variation for Cassandra!! NUMERIC is transformed to java BigInteger (varint CQL type) // // Only Numeric classes Strings and Booleans are supported for transformation to NUMERIC if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "NUMERIC"); break; case Types.BIT: // Only Numeric classes Strings and Booleans are supported for transformation to BIT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BIT"); break; case Types.BOOLEAN: // Only Numeric classes Strings and Booleans are supported for transformation to BOOLEAN if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BOOLEAN"); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: if (!objectClass.isAssignableFrom(String.class)) throw makeBadMapping(objectClass, "String", "the various VARCHAR types"); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (!(objectClass.isAssignableFrom(ByteBuffer.class) || objectClass.getSimpleName().equals("byte[]"))) throw makeBadMapping(objectClass, "ByteBuffer or byte[]", "the BINARY Types"); break; case Types.DATE: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Date.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date(java and sql) or Timestamp types", "DATE"); break; case Types.TIME: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Time.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date (java), Time or Timestamp types", "TIME"); break; case Types.TIMESTAMP: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Date.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date(java and sql) or Timestamp types", "TIMESTAMP"); break; case Types.DATALINK: if (objectClass != URL.class) throw makeBadMapping(objectClass, "a URL type", "DATALINK"); break; case Types.JAVA_OBJECT: break; case Types.OTHER: // Only Collection classes for transformation to OTHER if (!(List.class.isAssignableFrom(object.getClass()) || Set.class.isAssignableFrom(object.getClass()) || Map.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "OTHER"); break; case Types.ROWID: if (objectClass != RowId.class) throw makeBadMapping(objectClass, "a RowId type", "ROWID"); break; default: throw new SQLNonTransientException("Unsupported transformation to Jdbc Type: " + targetSqlType); } // see if we can map to an supported Type switch (targetSqlType) { case Types.BIT: BigInteger bitvalue = objectToBITorTINYINTorSMALLINTorNUMERIC(objectClass, object); assert bitvalue != null; return JdbcInteger.instance.decompose((bitvalue == BigInteger.ZERO) ? BigInteger.ZERO : BigInteger.ONE); case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: BigInteger varint = objectToBITorTINYINTorSMALLINTorNUMERIC(objectClass, object); assert varint != null; return JdbcInteger.instance.decompose(varint); case Types.INTEGER: Integer value = objectToINTEGER(objectClass, object); assert value != null; return JdbcInt32.instance.decompose(value); case Types.BIGINT: Long longvalue = objectToBIGINT(objectClass, object); assert longvalue != null; return JdbcLong.instance.decompose(longvalue); case Types.BOOLEAN: Boolean bool = objectToBOOLEAN(objectClass, object); assert bool != null; return JdbcBoolean.instance.decompose(bool); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: return ByteBufferUtil.bytes((String) object); case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (objectClass.isAssignableFrom(ByteBuffer.class)) { return ((ByteBuffer) object); } else if (objectClass.getSimpleName().equals("byte[]")) { return ByteBuffer.wrap((byte[]) object); } else return null; // this should not happen case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Long millis = objectToDATEorTIMEorTIMESTAMP(objectClass, object); assert millis != null; return JdbcLong.instance.decompose(millis); case Types.DATALINK: String urlAsString = ((URL) object).toExternalForm(); return JdbcUTF8.instance.decompose(urlAsString); case Types.JAVA_OBJECT: return javaObject(object); case Types.OTHER: if (List.class.isAssignableFrom(objectClass)) { return handleAsList(objectClass, object); } else if (Set.class.isAssignableFrom(objectClass)) { return handleAsSet(objectClass, object); } else if (Map.class.isAssignableFrom(objectClass)) { return handleAsMap(objectClass, object); } else return null; case Types.ROWID: byte[] bytes = ((RowId) object).getBytes(); return ByteBuffer.wrap(bytes); default: LOG.warn("Unhandled JDBC type: " + targetSqlType); return null; } }
From source file:org.wso2.carbon.event.output.adaptor.mysql.MysqlEventAdaptorType.java
private TableInfo initializeDatabaseTableInfo(String tableName, String executionMode, String updateColumnKeys, Object message, OutputEventAdaptorConfiguration adaptorConfig) throws SQLException { TableInfo tableInfo = new TableInfo(); tableInfo.setTableName(tableName);//from w w w .j a v a 2s .c o m if (resourceBundle.getString(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_EXECUTION_MODE_UPDATE) .equalsIgnoreCase(executionMode)) { tableInfo.setUpdateMode(true); } Connection con = null; Statement stmt = null; try { DataSource dataSource = pooledDataSources.get(adaptorConfig.getOutputProperties() .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATASOURCE_NAME)); if (dataSource == null) { CarbonDataSource carbonDataSource = EventAdaptorValueHolder.getDataSourceService() .getDataSource(adaptorConfig.getOutputProperties() .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATASOURCE_NAME)); if (carbonDataSource == null) { throw new OutputEventAdaptorEventProcessingException( "There is no any data-source found called : " + adaptorConfig.getOutputProperties() .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATASOURCE_NAME)); } else { dataSource = (DataSource) carbonDataSource.getDSObject(); pooledDataSources.put(adaptorConfig, dataSource); } } con = dataSource.getConnection(); String databaseName = con.getCatalog(); tableInfo.setDatabaseName(databaseName); // create the table. StringBuilder statementBuilder = new StringBuilder("CREATE TABLE IF NOT EXISTS "); statementBuilder.append(databaseName + "." + tableName); statementBuilder.append(" ("); boolean appendComma = false; for (Map.Entry<String, Object> entry : (((Map<String, Object>) message).entrySet())) { if (appendComma) { statementBuilder.append(","); } else { appendComma = true; } statementBuilder.append(entry.getKey()).append(" "); if (entry.getValue() instanceof Integer) { statementBuilder.append("INT"); } else if (entry.getValue() instanceof Long) { statementBuilder.append("BIGINT"); } else if (entry.getValue() instanceof Float) { statementBuilder.append("FLOAT"); } else if (entry.getValue() instanceof Double) { statementBuilder.append("DOUBLE"); } else if (entry.getValue() instanceof String) { statementBuilder.append("VARCHAR(255)"); } else if (entry.getValue() instanceof Boolean) { statementBuilder.append("BOOL"); } } statementBuilder.append(")"); stmt = con.createStatement(); stmt.execute("CREATE SCHEMA IF NOT EXISTS " + databaseName); stmt.executeUpdate(statementBuilder.toString()); ArrayList<Attribute> tableInsertColumnList = new ArrayList<Attribute>(); statementBuilder = new StringBuilder("INSERT INTO "); statementBuilder.append(databaseName + "." + tableName); statementBuilder.append(" ( "); StringBuilder valuePositionsBuilder = new StringBuilder(""); appendComma = false; DatabaseMetaData databaseMetaData = con.getMetaData(); ResultSet rs = databaseMetaData.getColumns(databaseName, null, tableName, null); while (rs.next()) { AttributeType type = null; int colType = rs.getInt("DATA_TYPE"); switch (colType) { case Types.VARCHAR: type = AttributeType.STRING; break; case Types.INTEGER: type = AttributeType.INT; break; case Types.BIGINT: type = AttributeType.LONG; break; case Types.DOUBLE: type = AttributeType.DOUBLE; break; case Types.FLOAT: type = AttributeType.FLOAT; break; case Types.TINYINT: case Types.BOOLEAN: case MysqlEventAdaptorConstants.TINYINT_MYSQL_VALUE: type = AttributeType.BOOL; break; } Attribute attribute = new Attribute(rs.getString("COLUMN_NAME"), type); tableInsertColumnList.add(attribute); if (appendComma) { statementBuilder.append(","); valuePositionsBuilder.append(","); } else { appendComma = true; } statementBuilder.append(attribute.getName()); valuePositionsBuilder.append("?"); } statementBuilder.append(") VALUES ("); statementBuilder.append(valuePositionsBuilder.toString()); statementBuilder.append(")"); tableInfo.setPreparedInsertStatement(statementBuilder.toString()); tableInfo.setInsertColumnOrder(tableInsertColumnList); if (executionMode.equalsIgnoreCase( resourceBundle.getString(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_EXECUTION_MODE_UPDATE))) { // existence check query. StringBuilder existenceQueryBuilder = new StringBuilder("SELECT 1 FROM "); existenceQueryBuilder.append(databaseName + "." + tableName); existenceQueryBuilder.append(" WHERE "); String[] queryAttributes = updateColumnKeys.trim().split(","); ArrayList<Attribute> queryAttributeList = new ArrayList<Attribute>(queryAttributes.length); for (int i = 0; i < queryAttributes.length; i++) { if (i > 0) { existenceQueryBuilder.append(" AND "); } existenceQueryBuilder.append(queryAttributes[i]); existenceQueryBuilder.append(" = ? "); for (Attribute at : tableInfo.getInsertColumnOrder()) { if (queryAttributes[i].equalsIgnoreCase(at.getName())) { queryAttributeList.add(at); break; } } } tableInfo.setExistenceCheckColumnOrder(queryAttributeList); tableInfo.setPreparedExistenceCheckStatement(existenceQueryBuilder.toString()); // update query. StringBuilder updateQueryBuilder = new StringBuilder("UPDATE "); ArrayList<Attribute> updateAttributes = new ArrayList<Attribute>(); updateQueryBuilder.append(tableInfo.getDatabaseName() + "." + tableInfo.getTableName()); updateQueryBuilder.append(" SET "); appendComma = false; for (Attribute at : tableInfo.getInsertColumnOrder()) { if (!tableInfo.getExistenceCheckColumnOrder().contains(at)) { if (appendComma) { updateQueryBuilder.append(" , "); } updateQueryBuilder.append(at.getName()); updateQueryBuilder.append(" = ? "); updateAttributes.add(at); appendComma = true; } } updateQueryBuilder.append(" WHERE "); boolean appendAnd = false; for (Attribute at : tableInfo.getExistenceCheckColumnOrder()) { if (appendAnd) { updateQueryBuilder.append(" AND "); } updateQueryBuilder.append(at.getName()); updateQueryBuilder.append(" = ? "); updateAttributes.add(at); appendAnd = true; } tableInfo.setUpdateColumnOrder(updateAttributes); tableInfo.setPreparedUpdateStatement(updateQueryBuilder.toString()); } return tableInfo; } catch (SQLException e) { pooledDataSources.remove(adaptorConfig.getOutputProperties() .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATASOURCE_NAME)); log.error("error while initializing the table", e); } catch (DataSourceException e) { pooledDataSources.remove(adaptorConfig.getOutputProperties() .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATASOURCE_NAME)); log.error("error while accessing the datasource:", e); } finally { cleanupConnections(stmt, con); } return null; }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
protected Object getObjectValue(String value, Column column, BinaryEncoding encoding, boolean useVariableDates, boolean fitToColumn) throws DecoderException { Object objectValue = value;/*w w w .ja v a 2 s . co m*/ int type = column.getMappedTypeCode(); if ((value == null || (getDdlBuilder().getDatabaseInfo().isEmptyStringNulled() && value.equals(""))) && column.isRequired() && column.isOfTextType()) { objectValue = REQUIRED_FIELD_NULL_SUBSTITUTE; } if (value != null) { if (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME) { objectValue = parseDate(type, value, useVariableDates); } else if (type == Types.CHAR) { String charValue = value.toString(); if ((StringUtils.isBlank(charValue) && getDdlBuilder().getDatabaseInfo().isBlankCharColumnSpacePadded()) || (StringUtils.isNotBlank(charValue) && getDdlBuilder().getDatabaseInfo().isNonBlankCharColumnSpacePadded())) { objectValue = StringUtils.rightPad(value.toString(), column.getSizeAsInt(), ' '); } } else if (type == Types.BIGINT) { objectValue = parseBigInteger(value); } else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT || type == Types.TINYINT) { objectValue = parseInteger(value); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) { objectValue = parseBigDecimal(value); } else if (type == Types.BOOLEAN) { objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE; } else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY)) && !(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) && (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer ntext type type == -10)) { if (encoding == BinaryEncoding.NONE) { objectValue = value.getBytes(); } else if (encoding == BinaryEncoding.BASE64) { objectValue = Base64.decodeBase64(value.getBytes()); } else if (encoding == BinaryEncoding.HEX) { objectValue = Hex.decodeHex(value.toCharArray()); } } else if (type == Types.ARRAY) { objectValue = createArray(column, value); } } if (objectValue instanceof String) { String stringValue = cleanTextForTextBasedColumns((String) objectValue); int size = column.getSizeAsInt(); if (fitToColumn && size > 0 && stringValue.length() > size) { stringValue = stringValue.substring(0, size); } objectValue = stringValue; } return objectValue; }
From source file:org.springframework.jdbc.support.JdbcUtils.java
/** * Check whether the given SQL type is numeric. * @param sqlType the SQL type to be checked * @return whether the type is numeric//from w w w . jav a 2s.c o m */ public static boolean isNumeric(int sqlType) { return Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType || Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType || Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType || Types.TINYINT == sqlType; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
public static String getPartitionSizeValidationError(int colType, String column, String partitionSize) { switch (colType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: try {//w ww . ja v a 2 s. co m int intVal = Integer.parseInt(partitionSize); if (intVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.BIGINT: // TIME, DATE, and TIMESTAMP are represented as long (epoch) case Types.TIME: case Types.DATE: case Types.TIMESTAMP: try { long longVal = Long.parseLong(partitionSize); if (longVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.FLOAT: case Types.REAL: try { float floatVal = Float.parseFloat(partitionSize); if (floatVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.DOUBLE: try { double doubleVal = Double.parseDouble(partitionSize); if (doubleVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.NUMERIC: case Types.DECIMAL: try { BigDecimal decimalValue = new BigDecimal(partitionSize); if (decimalValue.signum() < 1) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; } return null; }
From source file:org.jumpmind.symmetric.io.data.DbFill.java
private Object generateRandomValueForColumn(Column column) { Object objectValue = null;/* w w w .jav a 2 s .c om*/ 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.apache.ode.bpel.extvar.jdbc.JdbcExternalVariableModule.java
private Object downcastValue(Object value, int dataType) { if (value == null) { return null; }/*from w ww . jav a 2 s . c om*/ // Try down casting the value as per its column type. try { // Some JDBC 4.0 types have been ignored to avoid compilation errors switch (dataType) { case Types.ARRAY: break; case Types.BIGINT: if (!(value instanceof BigInteger)) { value = new BigDecimal(value.toString()).longValue(); } break; case Types.BINARY: break; case Types.BIT: if (!(value instanceof Boolean)) { value = new Boolean(value.toString()); } break; case Types.BLOB: break; case Types.BOOLEAN: if (!(value instanceof Boolean)) { value = new Boolean(value.toString()); } break; case Types.CHAR: break; case Types.CLOB: break; case Types.DATALINK: break; case Types.DATE: break; case Types.DECIMAL: //ODE-872: Oracle 9g and 10g has problems with BigDecimal on Java1.5 value = new BigDecimal(new BigDecimal(value.toString()).toPlainString()); break; case Types.DISTINCT: break; case Types.DOUBLE: if (!(value instanceof Double)) { value = Double.valueOf(value.toString()).doubleValue(); } break; case Types.FLOAT: if (!(value instanceof Float)) { value = Float.valueOf(value.toString()).floatValue(); } break; case Types.INTEGER: if (!(value instanceof Integer)) { value = Double.valueOf(value.toString()).intValue(); } break; case Types.JAVA_OBJECT: break; // case Types.LONGNVARCHAR: // break; case Types.LONGVARBINARY: break; case Types.LONGVARCHAR: break; // case Types.NCHAR: // break; // case Types.NCLOB: // break; case Types.NUMERIC: //ODE-872: Oracle 9g and 10g has problems with BigDecimal on Java1.5 value = new BigDecimal(new BigDecimal(value.toString()).toPlainString()); break; // case Types.NVARCHAR: // break; case Types.OTHER: break; case Types.REAL: if (!(value instanceof Double)) { value = Float.valueOf(value.toString()).floatValue(); } break; case Types.REF: break; // case Types.ROWID: // break; case Types.SMALLINT: if (!(value instanceof Short)) { value = new Short(value.toString()).shortValue(); } break; // case Types.SQLXML: // break; case Types.STRUCT: break; case Types.TIME: break; case Types.TIMESTAMP: break; case Types.TINYINT: if (!(value instanceof Short)) { value = new Short(value.toString()).shortValue(); } break; case Types.VARBINARY: break; case Types.VARCHAR: break; default: break; } } catch (Exception e) { // couldn't cast... let's just use original value object } return value; }