List of usage examples for java.sql Types SMALLINT
int SMALLINT
To view the source code for java.sql Types SMALLINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT
.
From source file:org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereTriggerTemplate.java
@Override protected String buildKeyVariablesDeclare(Column[] columns, String prefix) { String text = ""; for (int i = 0; i < columns.length; i++) { text += "declare @" + prefix + "pk" + i + " "; switch (columns[i].getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: text += "bigint\n"; break; case Types.NUMERIC: case Types.DECIMAL: text += "decimal\n"; break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: text += "float\n"; break; case Types.CHAR: case Types.VARCHAR: case ColumnTypes.NVARCHAR: case ColumnTypes.LONGNVARCHAR: case Types.LONGVARCHAR: text += "varchar(1000)\n"; break; case Types.DATE: text += "date\n"; break; case Types.TIME: text += "time\n"; break; case Types.TIMESTAMP: text += "datetime\n"; break; case Types.BOOLEAN: case Types.BIT: text += "bit\n"; break; case Types.CLOB: text += "varchar(16384)\n"; break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case -10: // SQL-Server ntext binary type text += "varbinary(16384)\n"; break; case Types.OTHER: text += "varbinary(16384)\n"; break; default://w ww. j a v a 2 s . com if (columns[i].getJdbcTypeName() != null && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) { text += "interval"; break; } throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType()); } } return text; }
From source file:org.apache.torque.engine.database.model.TypeMap.java
/** * Initializes the SQL to Java map so that it * can be used by client code.//w ww . j a v a2 s . co m */ public static synchronized void initialize() { if (!isInitialized) { // Create JDBC -> Java object mappings. jdbcToJavaObjectMap = new Hashtable(); jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE); jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE); // Create JDBC -> native Java type mappings. jdbcToJavaNativeMap = new Hashtable(); jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE); jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE); jdbcToJavaNativeObjectMap = new Hashtable(); jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_OBJECT_TYPE); jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_OBJECT_TYPE); // Create JDBC -> Village asX() mappings. jdbcToVillageMethodMap = new Hashtable(); jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD); jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD); jdbcToVillageObjectMethodMap = new Hashtable(); jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_OBJECT_METHOD); jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_OBJECT_METHOD); // Create JDBC -> ParameterParser getX() mappings. jdbcToPPMethodMap = new Hashtable(); jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD); jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD); // Create JDBC -> Java object mappings. torqueTypeToJdbcTypeMap = new Hashtable(); Iterator iter = SchemaType.iterator(); while (iter.hasNext()) { SchemaType type = (SchemaType) iter.next(); torqueTypeToJdbcTypeMap.put(type, type); } torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR); torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER); // Create JDBC type code to torque type map. jdbcToTorqueTypeMap = new Hashtable(); jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR); jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR); jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB); jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC); jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL); jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT); jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT); jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT); jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER); jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT); jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL); jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT); jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE); jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY); jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY); jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB); jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE); jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME); jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP); isInitialized = true; } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set the values from the Json node to the current object (no database access) * //from w ww . j a v a 2s.com * @param node * @param ignorePrimaryKey * True will ignore primaryKey from Json * @throws WaarpDatabaseSqlException */ public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException { DbValue[] list = allFields; if (ignorePrimaryKey) { list = otherFields; } for (DbValue value : list) { if (value.column.equalsIgnoreCase("UPDATEDINFO")) { continue; } JsonNode item = node.get(value.column); if (item != null && !item.isMissingNode() && !item.isNull()) { isSaved = false; switch (value.type) { case Types.VARCHAR: case Types.LONGVARCHAR: value.setValue(item.asText()); break; case Types.BIT: value.setValue(item.asBoolean()); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value.setValue(item.asInt()); break; case Types.BIGINT: value.setValue(item.asLong()); break; case Types.REAL: case Types.DOUBLE: value.setValue(item.asDouble()); break; case Types.VARBINARY: try { value.setValue(item.binaryValue()); } catch (IOException e) { throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e); } break; case Types.DATE: value.setValue(new Date(item.asLong())); break; case Types.TIMESTAMP: value.setValue(new Timestamp(item.asLong())); break; case Types.CLOB: case Types.BLOB: default: throw new WaarpDatabaseSqlException("Unsupported type: " + value.type); } } } setFromArray(); }
From source file:ca.sqlpower.architect.ddl.LiquibaseDDLGenerator.java
private boolean isNumericType(GenericTypeDescriptor td) { int type = td.getDataType(); return (type == Types.BIGINT || type == Types.INTEGER || type == Types.DECIMAL || type == Types.DOUBLE || type == Types.FLOAT || type == Types.NUMERIC || type == Types.REAL || type == Types.SMALLINT || type == Types.TINYINT); }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java
public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize, int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction, boolean timestampToString) throws SQLException, IOException, StageException { Field field;//from w w w.j a va 2s. c o m if (userSpecifiedType != DataType.USE_COLUMN_TYPE) { // If user specifies the data type, overwrite the column type returned by database. field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex)); } else { // All types as of JDBC 2.0 are here: // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY // Good source of recommended mappings is here: // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html switch (md.getColumnType(columnIndex)) { case Types.BIGINT: field = Field.create(Field.Type.LONG, rs.getObject(columnIndex)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex)); break; case Types.BIT: case Types.BOOLEAN: field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex)); break; case Types.CHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: field = Field.create(Field.Type.STRING, rs.getObject(columnIndex)); break; case Types.CLOB: case Types.NCLOB: field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize)); break; case Types.BLOB: field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize)); break; case Types.DATE: field = Field.create(Field.Type.DATE, rs.getDate(columnIndex)); break; case Types.DECIMAL: case Types.NUMERIC: field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex)); field.setAttribute(HeaderAttributeConstants.ATTR_SCALE, String.valueOf(rs.getMetaData().getScale(columnIndex))); field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION, String.valueOf(rs.getMetaData().getPrecision(columnIndex))); break; case Types.DOUBLE: field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex)); break; case Types.FLOAT: case Types.REAL: field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex)); break; case Types.INTEGER: field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex)); break; case Types.ROWID: field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString()); break; case Types.SMALLINT: case Types.TINYINT: field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex)); break; case Types.TIME: field = Field.create(Field.Type.TIME, rs.getObject(columnIndex)); break; case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnIndex); if (timestampToString) { field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString()); } else { field = Field.create(Field.Type.DATETIME, timestamp); if (timestamp != null) { final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT; if (actualNanos > 0) { field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos)); } } } break; // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc. case Types.TIME_WITH_TIMEZONE: OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class); field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant())); break; case Types.TIMESTAMP_WITH_TIMEZONE: OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class); field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime()); break; //case Types.REF_CURSOR: // JDK8 only case Types.SQLXML: case Types.STRUCT: case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: default: if (unknownTypeAction == null) { return null; } switch (unknownTypeAction) { case STOP_PIPELINE: throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex), md.getColumnLabel(columnIndex)); case CONVERT_TO_STRING: Object value = rs.getObject(columnIndex); if (value != null) { field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString()); } else { field = Field.create(Field.Type.STRING, null); } break; default: throw new IllegalStateException("Unknown action: " + unknownTypeAction); } } } return field; }
From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java
/** * Get a ConstantNode to represent a typed null value. * * @param type Type of the null node.// www . ja v a 2 s. c o m * @throws StandardException Thrown on error * @return A ConstantNode with the specified type, and a value of null */ public ConstantNode getNullNode(DataTypeDescriptor type) throws StandardException { int constantNodeType; switch (type.getTypeId().getJDBCTypeId()) { case Types.VARCHAR: constantNodeType = C_NodeTypes.VARCHAR_CONSTANT_NODE; break; case Types.CHAR: constantNodeType = C_NodeTypes.CHAR_CONSTANT_NODE; break; case Types.TINYINT: constantNodeType = C_NodeTypes.TINYINT_CONSTANT_NODE; break; case Types.SMALLINT: constantNodeType = C_NodeTypes.SMALLINT_CONSTANT_NODE; break; case Types.INTEGER: constantNodeType = C_NodeTypes.INT_CONSTANT_NODE; break; case Types.BIGINT: constantNodeType = C_NodeTypes.LONGINT_CONSTANT_NODE; break; case Types.REAL: constantNodeType = C_NodeTypes.FLOAT_CONSTANT_NODE; break; case Types.DOUBLE: constantNodeType = C_NodeTypes.DOUBLE_CONSTANT_NODE; break; case Types.NUMERIC: case Types.DECIMAL: constantNodeType = C_NodeTypes.DECIMAL_CONSTANT_NODE; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE; break; case Types.BINARY: constantNodeType = C_NodeTypes.BIT_CONSTANT_NODE; break; case Types.VARBINARY: constantNodeType = C_NodeTypes.VARBIT_CONSTANT_NODE; break; case Types.LONGVARCHAR: constantNodeType = C_NodeTypes.LONGVARCHAR_CONSTANT_NODE; break; case Types.CLOB: constantNodeType = C_NodeTypes.CLOB_CONSTANT_NODE; break; case Types.LONGVARBINARY: constantNodeType = C_NodeTypes.LONGVARBIT_CONSTANT_NODE; break; case Types.BLOB: constantNodeType = C_NodeTypes.BLOB_CONSTANT_NODE; break; case JDBC40Translation.SQLXML: constantNodeType = C_NodeTypes.XML_CONSTANT_NODE; break; case Types.BOOLEAN: constantNodeType = C_NodeTypes.BOOLEAN_CONSTANT_NODE; break; default: if (type.getTypeId().userType()) { constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE; } else { throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE, type.getTypeId().getSQLTypeName()); } } ConstantNode constantNode = (ConstantNode) getNodeFactory().getNode(constantNodeType, type.getTypeId(), cm); constantNode.setType(type.getNullabilityType(true)); return constantNode; }
From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java
/** * Adds a calendar. If necessary, a new ID is generated and set in the * CalendarWrapper./*from www .ja va2 s .com*/ * * @param c as a CalendarWrapper object, usually without an ID set. * @throws DAOException * * @see CalendarWrapper */ public void addItem(CalendarWrapper cw) throws DAOException { if (log.isTraceEnabled()) { log.trace("PIMCalendarDAO addItem begin"); } Connection con = null; PreparedStatement ps = null; long id = 0; String allDay = null; String body = null; Short busyStatus = null; String categories = null; String companies = null; int duration = 0; Date dend = null; short importance = 0; String location = null; Short meetingStatus = null; String mileage = null; Date replyTime = null; short sensitivity = 0; Date dstart = null; String subject = null; int interval = 0; short monthOfYear = 0; short dayOfMonth = 0; String dayOfWeekMask = null; short instance = 0; String startDatePattern = null; String endDatePattern = null; Reminder reminder = null; RecurrencePattern rp = null; short recurrenceType = -1; String sId = null; int occurrences = -1; String folder = null; String dstartTimeZone = null; String dendTimeZone = null; String reminderTimeZone = null; Date completed = null; short percentComplete = -1; Timestamp lastUpdate = cw.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } try { sId = cw.getId(); if (sId == null || sId.length() == 0) { // ...as it should be sId = getNextID(); cw.setId(sId); } id = Long.parseLong(sId); CalendarContent c = cw.getCalendar().getCalendarContent(); rp = c.getRecurrencePattern(); boolean allDayB; if (c.getAllDay() != null && c.getAllDay().booleanValue()) { allDayB = true; allDay = "1"; } else { allDayB = false; allDay = "0"; } String sd = null; if (c.getDtStart() != null) { sd = c.getDtStart().getPropertyValueAsString(); dstart = getDateFromString(allDayB, sd, "000000"); } String ed = null; if ((sd != null && sd.length() > 0) || c.getDtEnd() != null) { ed = c.getDtEnd().getPropertyValueAsString(); // // Fix for Siemens S56 end date issue only for event // @todo: verify if is really need to do this // if (c instanceof Event) { if (ed == null || ed.length() == 0) { ed = sd; } } dend = getDateFromString(allDayB, ed, "235900"); } body = Property.stringFrom(c.getDescription()); if (c.getBusyStatus() != null) { busyStatus = new Short(c.getBusyStatus().shortValue()); } categories = Property.stringFrom(c.getCategories()); companies = Property.stringFrom(c.getOrganizer()); location = Property.stringFrom(c.getLocation()); folder = Property.stringFrom(c.getFolder()); dstartTimeZone = timeZoneFrom(c.getDtStart()); dendTimeZone = timeZoneFrom(c.getDtEnd()); reminderTimeZone = timeZoneFrom(c.getReminder()); meetingStatus = c.getMeetingStatus(); Integer mileageInteger = c.getMileage(); // NB: not an int... if (mileageInteger != null) { // ...therefore it may be null mileage = String.valueOf(mileageInteger); } if (c instanceof Event) { replyTime = getDateFromString(allDayB, // @todo or false? Property.stringFrom(((Event) c).getReplyTime()), "000000"); } try { sensitivity = Short.parseShort(Property.stringFrom(c.getAccessClass())); } catch (NumberFormatException nfe) { sensitivity = 0; // The short must go on } if ((subject = Property.stringFrom(c.getSummary())) == null && body != null) { int endOfSentence = body.indexOf('.'); if (endOfSentence == -1) { endOfSentence = body.length(); } if (endOfSentence > SQL_SUBJECT_DIM) { endOfSentence = SQL_SUBJECT_DIM; } subject = body.substring(0, endOfSentence); } String isInfinite = "0"; if (rp != null) { interval = rp.getInterval(); recurrenceType = rp.getTypeId(); monthOfYear = rp.getMonthOfYear(); dayOfMonth = rp.getDayOfMonth(); dayOfWeekMask = String.valueOf(rp.getDayOfWeekMask()); instance = rp.getInstance(); startDatePattern = rp.getStartDatePattern(); endDatePattern = rp.getEndDatePattern(); if (rp.isNoEndDate()) { isInfinite = "1"; } occurrences = rp.getOccurrences(); } if (c instanceof Task) { Task t = (Task) c; if (t.getDateCompleted() != null) { completed = getDateFromString(allDayB, ((Task) c).getDateCompleted().getPropertyValueAsString(), "000000"); } try { String complete = Property.stringFrom(t.getComplete()); if (complete != null && complete.equals("1")) { percentComplete = 100; } else { percentComplete = Short.parseShort(Property.stringFrom(t.getPercentComplete())); } if (percentComplete < 0 || percentComplete > 100) { throw new NumberFormatException("A percentage can't be " + percentComplete); } } catch (NumberFormatException nfe) { percentComplete = -1; // the short must go on } meetingStatus = getTaskStatus(t); } con = getUserDataSource().getRoutedConnection(userId); ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR); ps.setLong(1, id); ps.setString(2, userId); ps.setLong(3, lastUpdate.getTime()); ps.setString(4, String.valueOf(Def.PIM_STATE_NEW)); ps.setString(5, allDay); ps.setString(6, StringUtils.left(body, SQL_BODY_DIM)); if (busyStatus != null) { ps.setShort(7, busyStatus.shortValue()); } else { ps.setNull(7, Types.SMALLINT); } ps.setString(8, StringUtils.left(categories, SQL_CATEGORIES_DIM)); ps.setString(9, StringUtils.left(companies, SQL_COMPANIES_DIM)); ps.setInt(10, duration); if (dend != null) { ps.setTimestamp(11, new Timestamp(dend.getTime())); } else { ps.setNull(11, Types.TIMESTAMP); } if (c.getPriority() != null) { String priority = c.getPriority().getPropertyValueAsString(); if (priority != null && priority.length() > 0) { importance = Short.parseShort(priority); ps.setShort(12, importance); } else { ps.setNull(12, Types.SMALLINT); } } else { ps.setNull(12, Types.SMALLINT); } ps.setString(13, StringUtils.left(location, SQL_LOCATION_DIM)); if (meetingStatus != null) { ps.setShort(14, meetingStatus.shortValue()); } else { ps.setNull(14, Types.SMALLINT); } ps.setString(15, mileage); reminder = c.getReminder(); if (reminder != null && reminder.isActive()) { Timestamp reminderTime = getReminderTime(dstart, reminder); if (reminderTime == null) { ps.setNull(16, Types.TIMESTAMP); } else { ps.setTimestamp(16, reminderTime); } ps.setInt(17, reminder.getRepeatCount()); ps.setString(18, (reminder.isActive()) ? "1" : "0"); String soundFileValue = reminder.getSoundFile(); ps.setString(19, StringUtils.left(soundFileValue, SQL_SOUNDFILE_DIM)); ps.setInt(20, reminder.getOptions()); } else { ps.setNull(16, Types.TIMESTAMP); ps.setInt(17, 0); ps.setString(18, "0"); ps.setString(19, null); ps.setInt(20, 0); } if (replyTime != null) { ps.setTimestamp(21, new Timestamp(replyTime.getTime())); } else { ps.setNull(21, Types.TIMESTAMP); } ps.setShort(22, sensitivity); if (dstart != null) { ps.setTimestamp(23, new Timestamp(dstart.getTime())); } else { ps.setNull(23, Types.TIMESTAMP); } ps.setString(24, StringUtils.left(subject, SQL_SUBJECT_DIM)); ps.setShort(25, recurrenceType); ps.setInt(26, interval); ps.setShort(27, monthOfYear); ps.setShort(28, dayOfMonth); ps.setString(29, StringUtils.left(dayOfWeekMask, SQL_DAYOFWEEKMASK_DIM)); ps.setShort(30, instance); ps.setString(31, StringUtils.left(startDatePattern, SQL_STARTDATEPATTERN_DIM)); ps.setString(32, isInfinite); ps.setString(33, StringUtils.left(endDatePattern, SQL_ENDDATEPATTERN_DIM)); ps.setInt(34, occurrences); if (c instanceof Event) { ps.setInt(35, CALENDAR_EVENT_TYPE); ps.setNull(36, Types.TIMESTAMP); // completed ps.setNull(37, Types.SMALLINT); // percent_complete } else { ps.setInt(35, CALENDAR_TASK_TYPE); if (completed != null) { ps.setTimestamp(36, new Timestamp(completed.getTime())); } else { ps.setNull(36, Types.TIMESTAMP); } if (percentComplete != -1) { ps.setShort(37, percentComplete); } else { ps.setNull(37, Types.SMALLINT); } } ps.setString(38, StringUtils.left(folder, SQL_FOLDER_DIM)); ps.setString(39, StringUtils.left(dstartTimeZone, SQL_TIME_ZONE_DIM)); ps.setString(40, StringUtils.left(dendTimeZone, SQL_TIME_ZONE_DIM)); ps.setString(41, StringUtils.left(reminderTimeZone, SQL_TIME_ZONE_DIM)); ps.executeUpdate(); DBTools.close(null, ps, null); if (recurrenceType != -1) { List<ExceptionToRecurrenceRule> exceptions = rp.getExceptions(); for (ExceptionToRecurrenceRule etrr : exceptions) { ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR_EXCEPTION); ps.setLong(1, id); ps.setString(2, (etrr.isAddition() ? "1" : "0")); ps.setTimestamp(3, new Timestamp(getDateFromString(allDayB, etrr.getDate(), "000000").getTime())); ps.executeUpdate(); DBTools.close(null, ps, null); } } } catch (Exception e) { throw new DAOException("Error adding a calendar item: " + e.getMessage(), e); } finally { DBTools.close(con, ps, null); } }
From source file:org.fastcatsearch.datasource.reader.DBReader.java
@Override public SchemaSetting getAutoGeneratedSchemaSetting() { Map<String, String> properties = singleSourceConfig.getProperties(); String jdbcSourceId = properties.get("jdbcSourceId"); String dataSQL = properties.get("dataSQL"); IRService service = ServiceManager.getInstance().getService(IRService.class); Connection con = null;/* w w w . j a v a 2s . c om*/ PreparedStatement pst = null; ResultSet res = null; ResultSetMetaData meta = null; try { JDBCSourceInfo jdbcInfo = service.getJDBCSourceInfo(jdbcSourceId); if (jdbcInfo != null) { con = getConnection(jdbcInfo); } logger.trace("get jdbc connection : {}", con); if (con != null) { logger.trace("executing sql :{}", dataSQL); pst = con.prepareStatement(dataSQL); pst.setFetchSize(1); pst.setMaxRows(1); res = pst.executeQuery(); res.next(); meta = res.getMetaData(); SchemaSetting setting = new SchemaSetting(); PrimaryKeySetting primaryKeySetting = new PrimaryKeySetting(); List<FieldSetting> fieldSettingList = new ArrayList<FieldSetting>(); List<AnalyzerSetting> analyzerSetting = new ArrayList<AnalyzerSetting>(); List<GroupIndexSetting> groupIndexSetting = new ArrayList<GroupIndexSetting>(); List<IndexSetting> indexSetting = new ArrayList<IndexSetting>(); List<FieldIndexSetting> fieldIndexSetting = new ArrayList<FieldIndexSetting>(); logger.trace("columnCount:{}", meta.getColumnCount()); String tableName = null; for (int inx = 0; inx < meta.getColumnCount(); inx++) { if (tableName == null) { tableName = meta.getTableName(inx + 1); } FieldSetting field = new FieldSetting(); Type type = null; int size = 0; switch (meta.getColumnType(inx + 1)) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: type = Type.INT; break; case Types.BIGINT: type = Type.LONG; break; case Types.FLOAT: type = Type.FLOAT; break; case Types.DOUBLE: type = Type.DOUBLE; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: type = Type.DATETIME; break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: type = Type.STRING; break; default: type = Type.STRING; break; } field.setId(meta.getColumnLabel(inx + 1)); field.setName(field.getId()); field.setType(type); field.setSize(size); logger.trace("field add {}", field); fieldSettingList.add(field); } setting.setFieldSettingList(fieldSettingList); setting.setPrimaryKeySetting(primaryKeySetting); setting.setFieldIndexSettingList(fieldIndexSetting); setting.setAnalyzerSettingList(analyzerSetting); setting.setGroupIndexSettingList(groupIndexSetting); setting.setIndexSettingList(indexSetting); return setting; } } catch (IRException e) { logger.error("", e); } catch (SQLException e) { logger.error("", e); } finally { if (res != null) try { res.close(); } catch (SQLException ignore) { } if (pst != null) try { pst.close(); } catch (SQLException ignore) { } if (con != null) try { con.close(); } catch (SQLException ignore) { } } return null; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Converts the given SQL type to a value type. * * @param sqlType The sql type to be converted. * * @return The value type that fits the given sql type. */// w w w . j av a 2s . c o m private static ValueType sqlTypeToValueType(int sqlType) { ValueType valueType; switch (sqlType) { case Types.BOOLEAN: case Types.BIT: { valueType = ValueType.BOOLEAN; break; } case Types.CHAR: case Types.VARCHAR: valueType = ValueType.TEXT; break; case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.REAL: case Types.NUMERIC: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: valueType = ValueType.NUMBER; break; case Types.DATE: valueType = ValueType.DATE; break; case Types.TIME: valueType = ValueType.TIMEOFDAY; break; case Types.TIMESTAMP: valueType = ValueType.DATETIME; break; default: valueType = ValueType.TEXT; break; } return valueType; }
From source file:org.ensembl.healthcheck.util.DBUtils.java
/** * Compare a particular column in two ResultSets. * /* w ww . ja v a 2 s .c o m*/ * @param rs1 * The first ResultSet to compare. * @param rs2 * The second ResultSet to compare. * @param i * The index of the column to compare. * @return True if the type and value of the columns match. */ public static boolean compareColumns(ResultSet rs1, ResultSet rs2, int i, boolean warnNull) { try { ResultSetMetaData rsmd = rs1.getMetaData(); Connection con1 = rs1.getStatement().getConnection(); Connection con2 = rs2.getStatement().getConnection(); if (rs1.getObject(i) == null) { if (warnNull) { logger.fine("Column " + rsmd.getColumnName(i) + " is null in table " + rsmd.getTableName(i) + " in " + DBUtils.getShortDatabaseName(con1)); } return (rs2.getObject(i) == null); // true if both are null } if (rs2.getObject(i) == null) { if (warnNull) { logger.fine("Column " + rsmd.getColumnName(i) + " is null in table " + rsmd.getTableName(i) + " in " + DBUtils.getShortDatabaseName(con2)); } return (rs1.getObject(i) == null); // true if both are null } // Note deliberate early returns for performance reasons switch (rsmd.getColumnType(i)) { case Types.INTEGER: return rs1.getInt(i) == rs2.getInt(i); case Types.SMALLINT: return rs1.getInt(i) == rs2.getInt(i); case Types.TINYINT: return rs1.getInt(i) == rs2.getInt(i); case Types.VARCHAR: String s1 = rs1.getString(i); String s2 = rs2.getString(i); // ignore "AUTO_INCREMENT=" part in final part of table // definition s1 = s1.replaceAll("AUTO_INCREMENT=[0-9]+ ", ""); s2 = s2.replaceAll("AUTO_INCREMENT=[0-9]+ ", ""); return s1.equals(s2); case Types.FLOAT: return rs1.getFloat(i) == rs2.getFloat(i); case Types.DOUBLE: return rs1.getDouble(i) == rs2.getDouble(i); case Types.TIMESTAMP: return rs1.getTimestamp(i).equals(rs2.getTimestamp(i)); default: // treat everything else as a String (should deal with ENUM and // TEXT) if (rs1.getString(i) == null || rs2.getString(i) == null) { return true; // ???? } else { return rs1.getString(i).equals(rs2.getString(i)); } } // switch } catch (SQLException se) { throw new SqlUncheckedException("Could not compare two columns sets", se); } }