List of usage examples for java.sql Types DECIMAL
int DECIMAL
To view the source code for java.sql Types DECIMAL.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL
.
From source file:CSVWriter.java
private static String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; /*w ww .j a v a2 s . c om*/ switch (colType) { case Types.BIT: Object bit = rs.getObject(colIndex); if (bit != null) { value = String.valueOf(bit); } break; case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); if (!rs.wasNull()) { value = Boolean.valueOf(b).toString(); } break; case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIndex); if (bd != null) { value = "" + bd.doubleValue(); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: int intValue = rs.getInt(colIndex); if (!rs.wasNull()) { value = "" + intValue; } break; case Types.JAVA_OBJECT: Object obj = rs.getObject(colIndex); if (obj != null) { value = String.valueOf(obj); } break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { value = DATE_FORMATTER.format(date);; } break; case Types.TIME: Time t = rs.getTime(colIndex); if (t != null) { value = t.toString(); } break; case Types.TIMESTAMP: Timestamp tstamp = rs.getTimestamp(colIndex); if (tstamp != null) { value = TIMESTAMP_FORMATTER.format(tstamp); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:CreateNewTable.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;//from w w w . j a v a 2s .c o m else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.StandardRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }/* w w w . j av a 2 s. c o m*/ int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); FieldFormatter[] fFormatters = buildFormatterArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); //boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, String> keyAttr = new HashMap<String, String>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElement(doc, AbstractDBO.ROW_NAME); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; //isNull = false; col = parser.createElement(doc, AbstractDBO.COL_NAME); switch (metadata.getColumnType(j)) { case Types.DATE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DATE_TYPE); java.sql.Date dateVal = rs.getDate(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.TIME: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIME_TYPE); java.sql.Time dateVal = rs.getTime(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_TIME_FORMAT); } break; case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.DOUBLE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); double numVal = rs.getDouble(j); textVal = processDouble(col, fF, numVal); } break; case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); textVal = processDouble(col, fF, numVal); } break; case Types.BIGINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BIGINT_TYPE); long numVal = rs.getLong(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.INTEGER: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.INTEGER_TYPE); int numVal = rs.getInt(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.SMALLINT: case Types.TINYINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.SMALLINT_TYPE); short numVal = rs.getShort(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.NUMERIC: case Types.DECIMAL: { BigDecimal bigdecimal = rs.getBigDecimal(j); boolean isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.BOOLEAN: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BOOLEAN_TYPE); boolean bVal = rs.getBoolean(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(bVal); } break; case Types.SQLXML: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.XML_TYPE); SQLXML xml = rs.getSQLXML(j); boolean isNull = xml == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { textVal = xml.getString(); } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); if (textVal == null) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); boolean isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (!noKey && keyField.contains(new Integer(j))) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyAttr.put("key_" + j, textVal); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); for (Entry<String, String> keyAttrEntry : keyAttr.entrySet()) { parser.setAttribute(data, keyAttrEntry.getKey(), keyAttrEntry.getValue()); } keyAttr.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:org.jumpmind.db.platform.mssql.MsSqlDdlReader.java
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); String defaultValue = column.getDefaultValue(); // Sql Server tends to surround the returned default value with one or // two sets of parentheses if (defaultValue != null) { while (defaultValue.startsWith("(") && defaultValue.endsWith(")")) { defaultValue = defaultValue.substring(1, defaultValue.length() - 1); }/*from w w w. j a va2s . c o m*/ if (column.getMappedTypeCode() == Types.TIMESTAMP) { // Sql Server maintains the default values for DATE/TIME jdbc // types, so we have to // migrate the default value to TIMESTAMP Matcher matcher = isoDatePattern.matcher(defaultValue); Timestamp timestamp = null; if (matcher.matches()) { timestamp = new Timestamp(Date.valueOf(matcher.group(1)).getTime()); } else { matcher = isoTimePattern.matcher(defaultValue); if (matcher.matches()) { timestamp = new Timestamp(Time.valueOf(matcher.group(1)).getTime()); } } if (timestamp != null) { defaultValue = timestamp.toString(); } } else if (column.getMappedTypeCode() == Types.DECIMAL || column.getMappedTypeCode() == Types.BIGINT) { // For some reason, Sql Server 2005 always returns DECIMAL // default values with a dot // even if the scale is 0, so we remove the dot if ((column.getScale() == 0) && defaultValue.endsWith(".")) { defaultValue = defaultValue.substring(0, defaultValue.length() - 1); } } else if (TypeMap.isTextType(column.getMappedTypeCode())) { if (defaultValue.startsWith("N'") && defaultValue.endsWith("'")) { defaultValue = defaultValue.substring(2, defaultValue.length() - 1); } defaultValue = unescape(defaultValue, "'", "''"); } column.setDefaultValue(defaultValue); } if ((column.getMappedTypeCode() == Types.DECIMAL) && (column.getSizeAsInt() == 19) && (column.getScale() == 0)) { column.setMappedTypeCode(Types.BIGINT); } // These columns return sizes and/or decimal places with the metat data from MSSql Server however // the values are not adjustable through the create table so they are omitted if (column.getJdbcTypeName() != null && (column.getJdbcTypeName().equals("smallmoney") || column.getJdbcTypeName().equals("money") || column.getJdbcTypeName().equals("timestamp") || column.getJdbcTypeName().equals("uniqueidentifier") || column.getJdbcTypeName().equals("time") || column.getJdbcTypeName().equals("datetime2") || column.getJdbcTypeName().equals("date"))) { removePlatformSizeAndDecimal(column); } return column; }
From source file:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;/*from w ww . j av a 2 s . co m*/ else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:org.apache.cassandra.cql3.subquery.SubQueryProcessor.java
public String execute(String queryString, ConsistencyLevel cLevel, ThriftClientState cState) throws UnavailableException, TimedOutException, InvalidRequestException { List<TypedColumn> values = new ArrayList<TypedColumn>(); String valueString = ""; try {/* w ww . ja v a 2 s . c o m*/ // Execute query CqlResult cr = cState.getCQLQueryHandler() .process(queryString, cState.getQueryState(), QueryOptions.fromProtocolV2( ThriftConversion.fromThrift(cLevel), Collections.<ByteBuffer>emptyList())) .toThriftResult(); Iterator<CqlRow> rowsIterator = cr.getRowsIterator(); populateColumns(rowsIterator, values, cr.schema, queryString); AbstractJdbcType absJdbcType; int typeNo; for (TypedColumn tc : values) { absJdbcType = tc.getValueType(); typeNo = absJdbcType.getJdbcType(); if (typeNo == Types.INTEGER || typeNo == Types.BIGINT || typeNo == Types.DECIMAL || typeNo == Types.FLOAT || typeNo == Types.NUMERIC || typeNo == Types.DOUBLE) { valueString = valueString + tc.getValueString() + ","; } else { /** * Values apart from Integer,Decimal,Float are need to be wrapped with single quotes(' ')[This is * from the assumption that, the column type of parent query is same as reference column selected by * child query] **/ valueString = valueString + "'" + tc.getValueString() + "',"; } } if (valueString.contains(",")) { valueString = valueString.substring(0, valueString.lastIndexOf(',')); } else { // Return error with query string if no value returned throw new InvalidRequestException("SubQuery is not returning any values" + " for the query [" + queryString.toUpperCase() + "] "); } } catch (RequestExecutionException e) { ThriftConversion.rethrow(e); return null; } catch (RequestValidationException e) { // Return error with query string throw new InvalidRequestException( e.getMessage() + " for the query [" + queryString.toUpperCase() + "] "); } catch (CharacterCodingException e) { throw new InvalidRequestException( e.getMessage() + " for the query [" + queryString.toUpperCase() + "] "); } return valueString; }
From source file:com.squid.core.domain.operators.ExtendedType.java
/** * return true if the type is a number with exact precision (that is it is NOT a real, float, double) * @return//from w ww. j av a 2s . com */ @JsonIgnore public boolean isExactNumber() { switch (this.dataType) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.NUMERIC: case Types.DECIMAL: return true; default: return false; } }
From source file:org.jasig.ssp.util.importer.job.validation.map.metadata.database.MapColumnMetadata.java
public Object convertValueToType(String columnValue, MapReference mapReference, DatabaseConstraintMapValidationContext validation) { Object propertyValue = null;//from w w w . j a v a 2 s. c o m String typeAsString = ""; if (columnValue != null) { try { switch (javaSqlType) { case Types.BIGINT: typeAsString = "BIGINT"; propertyValue = Long.parseLong(columnValue); break; case Types.INTEGER: typeAsString = "INTEGER"; propertyValue = Integer.parseInt(columnValue); break; case Types.DECIMAL: typeAsString = "DECIMAL"; case Types.DOUBLE: typeAsString = "DOUBLE"; case Types.FLOAT: typeAsString = "FLOAT"; case Types.NUMERIC: typeAsString = "NUMERIC"; propertyValue = new BigDecimal(columnValue); break; case Types.DATE: typeAsString = "DATE"; propertyValue = DateUtils.parseDateStrictly(columnValue, DATE_PATTERNS); break; case Types.TIMESTAMP: typeAsString = "TIMESTAMP"; propertyValue = new java.sql.Timestamp(Long.getLong(columnValue)); break; case Types.TIME: typeAsString = "TIME"; propertyValue = new Time(DateUtils.parseDateStrictly(columnValue, TIME_PATTERNS).getTime()); break; default: typeAsString = javaSqlType.toString(); propertyValue = columnValue; break; } } catch (Exception exception) { validation.addViolation(new UnableToParseMapViolation(mapReference, columnValue, typeAsString)); propertyValue = columnValue; } } return propertyValue; }
From source file:org.dashbuilder.dataprovider.sql.JDBCUtils.java
public static ColumnType calculateType(int sqlDataType) { switch (sqlDataType) { // Category-like columns. case Types.CHAR: case Types.VARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.BIT: case Types.BOOLEAN: { return ColumnType.LABEL; }/* w ww .j a va2 s . com*/ // Text-like columns. case Types.LONGVARCHAR: case Types.LONGNVARCHAR: { return ColumnType.TEXT; } // Number-like columns. case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: { return ColumnType.NUMBER; } // Date-like columns. case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { return ColumnType.DATE; } // Unsupported default: { return null; } } }
From source file:org.apache.sqoop.hcat.HCatalogExportTest.java
public void testNumberTypes() throws Exception { final int TOTAL_RECORDS = 1 * 10; String table = getTableName().toUpperCase(); ColumnGenerator[] cols = new ColumnGenerator[] { HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "numeric(18,2)", Types.NUMERIC, HCatFieldSchema.Type.STRING, 0, 0, "1000", new BigDecimal("1000"), KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "decimal(18,2)", Types.DECIMAL, HCatFieldSchema.Type.STRING, 0, 0, "2000", new BigDecimal("2000"), KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "decimal(18,2)", Types.DECIMAL, HCatFieldSchema.Type.DECIMAL, 18, 2, HiveDecimal.create(new BigDecimal("2000")), new BigDecimal("2000"), KeyType.NOT_A_KEY), }; List<String> addlArgsArray = new ArrayList<String>(); runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols); }