public Class<?> getJavaType() { return TypeFacility.getDataTypeClass(runtimeType); }
protected String getRuntimeType(int type, String typeName, int precision) { if (importRowIdAsBinary && type == Types.ROWID) { return TypeFacility.RUNTIME_NAMES.VARBINARY; } if (type == Types.BIT && precision > 1) { type = Types.BINARY; } type = checkForUnsigned(type, typeName); String result = TypeFacility.getDataTypeNameFromSQLType(type); if (importLargeAsLob) { if (result.equals(TypeFacility.RUNTIME_NAMES.STRING) && precision > DataTypeManager.MAX_STRING_LENGTH) { result = TypeFacility.RUNTIME_NAMES.CLOB; } else if (result.equals(TypeFacility.RUNTIME_NAMES.VARBINARY) && precision > DataTypeManager.MAX_VARBINARY_BYTES) { result = TypeFacility.RUNTIME_NAMES.BLOB; } } return result; }
private Class getJavaDataType(Class type) { return TypeFacility.getRuntimeType(type); }
public static String convertType(Column column) { Class<?> clas = column.getJavaType(); String typeName = TypeFacility.getDataTypeName(clas); return convertType(typeName); }
/** * For registering specific output parameter types we need to translate these into the appropriate * java.sql.Types output parameters * We will need to match these up with the appropriate standard sql types * @param cstmt * @param parameter * @throws SQLException */ protected void registerSpecificTypeOfOutParameter(CallableStatement statement, Class<?> runtimeType, int index) throws SQLException { int typeToSet = TypeFacility.getSQLTypeFromRuntimeType(runtimeType); statement.registerOutParameter(index,typeToSet); }
@Test public void testNullClob() { assertNull(new TypeFacility().convertToRuntimeType((Clob)null)); }
/** * Get the closest runtime type for the given class */ public static Class<?> getRuntimeType(Class<?> type) { if (type.isPrimitive()) { return convertPrimitiveToObject(type); } return DataTypeManager.getRuntimeType(type); }
/** * Format the dateObject (of type date, time, or timestamp) into a string * optionally using the DatabaseTimeZone. * @param dateObject * @return Formatted string */ public String formatDateValue(java.util.Date dateObject, boolean useTimezone) { if (dateObject instanceof Timestamp && getTimestampNanoPrecision() < 9) { Timestamp ts = (Timestamp)dateObject; Timestamp newTs = new Timestamp(ts.getTime()); if (getTimestampNanoPrecision() > 0) { int mask = (int)Math.pow(10, 9-getTimestampNanoPrecision()); newTs.setNanos(ts.getNanos()/mask*mask); } else { newTs.setNanos(0); } dateObject = newTs; } if (!useTimezone) { return dateObject.toString(); } return getTypeFacility().convertDate(dateObject, getDatabaseCalendar().getTimeZone(), TimestampWithTimezone.getCalendar(), dateObject.getClass()).toString(); }
@Override public List<?> translate(Function function) { if (function.getType() == TypeFacility.RUNTIME_TYPES.INTEGER || function.getType() == TypeFacility.RUNTIME_TYPES.LONG) { Function result = ConvertModifier.createConvertFunction(getLanguageFactory(), function, TypeFacility.getDataTypeName(function.getType())); function.setType(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL); return Arrays.asList(result); } return null; } });
@Override public void bindValue(PreparedStatement pstmt, Object param, Class<?> paramType, int i) throws SQLException { int type = TypeFacility.getSQLTypeFromRuntimeType(paramType);
returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz);
private void addCast(String nativeType, DerivedColumn dc) { if (nativeType != null) { Function cast = ConvertModifier.createConvertFunction(getLanguageFactory(), dc.getExpression(), nativeType); cast.setName("cast"); //$NON-NLS-1$ dc.setExpression(cast); } else { dc.setExpression(ConvertModifier.createConvertFunction(getLanguageFactory(), dc.getExpression(), TypeFacility.getDataTypeName(dc.getExpression().getType()))); } }
int type = TypeFacility.getSQLTypeFromRuntimeType(paramType);
private boolean isSimpleType(Class type) { return type.isPrimitive() || type.equals(String.class) || type.equals(BigDecimal.class) || type.equals(Date.class) || type.equals(BigInteger.class) || TypeFacility.getRuntimeType(type) != Object.class; }
/** * IMPORTANT: only for use with default runtime type names * @param langFactory * @param expr * @param typeName * @return */ public static Function createConvertFunction(LanguageFactory langFactory, Expression expr, String typeName) { Class<?> type = TypeFacility.getDataTypeClass(typeName); return langFactory.createFunction(SourceSystemFunctions.CONVERT, new Expression[] {expr, langFactory.createLiteral(typeName, type)}, type); }
@Test public void testArrayType() { assertEquals(TypeFacility.RUNTIME_NAMES.OBJECT, TypeFacility.getDataTypeNameFromSQLType(Types.ARRAY)); }
if (entity.getIdType().getPersistenceType().equals(PersistenceType.BASIC)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType()); addColumn(mf, pkattr.getName(), TypeFacility.getDataTypeName(getJavaDataType(pkattr.getJavaType())), entityTable); mf.addPrimaryKey("PK_"+entity.getName(), Arrays.asList(pkattr.getName()), entityTable); //$NON-NLS-1$ for (Object obj:entity.getIdClassAttributes()) { SingularAttribute<?, ?> attr = (SingularAttribute)obj; addColumn(mf, attr.getName(), TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable); keys.add(attr.getName());
public String getCreateTempTableSQL(String name, List<ColumnReference> cols, boolean transactional) { SQLDialect d = getDialect(); StringBuilder sb = new StringBuilder(getCreateTemporaryTableString(transactional)).append(" "); //$NON-NLS-1$ sb.append(name).append(" ("); //$NON-NLS-1$ for (Iterator<ColumnReference> iter = cols.iterator(); iter.hasNext();) { ColumnReference col = iter.next(); sb.append(col.getName()); sb.append(" "); //$NON-NLS-1$ Integer defaultValue = JDBCSQLTypeInfo.getDefaultPrecision(col.getType()); int precision = defaultValue == null?255:defaultValue; int scale = col.getType() == TypeFacility.RUNTIME_TYPES.BIG_DECIMAL?2:0; long length = precision; if (col.getMetadataObject() != null) { precision = col.getMetadataObject().getPrecision(); scale = col.getMetadataObject().getScale(); length = col.getMetadataObject().getLength(); } sb.append(d.getTypeName(TypeFacility.getSQLTypeFromRuntimeType(col.getType()), length, precision, scale)); //sb.append(" NOT NULL"); -- needed if we will add an index if (iter.hasNext()) { sb.append(", "); //$NON-NLS-1$ } } sb.append(") "); if (getCreateTemporaryTablePostfix(transactional) != null) { sb.append(getCreateTemporaryTablePostfix(transactional)); } String sql = sb.toString(); return sql; }
for (int i = 0; i < keyColumnDataTypes.length; i++) { Object value = this.executionFactory.retrieveValue(keys, i+1, keyColumnDataTypes[i]); if (value != null && TypeFacility.getRuntimeType(value.getClass()) != keyColumnDataTypes[i]) {
if (simpleType) { Column column = addColumn(mf, String.join("_", attrPath), TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable); if (((SingularAttribute)attr).isOptional()) { column.setDefaultValue(null);