use of org.sql.generation.api.grammar.factories.DataTypeFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method initTypes.
private void initTypes() {
DataTypeFactory dt = this._vendor.getDataTypeFactory();
this._primitiveTypes = new HashMap<Class<?>, SQLDataType>();
this._primitiveTypes.put(Boolean.class, dt.sqlBoolean());
this._primitiveTypes.put(Byte.class, dt.smallInt());
this._primitiveTypes.put(Short.class, dt.smallInt());
this._primitiveTypes.put(Integer.class, dt.integer());
this._primitiveTypes.put(Long.class, dt.bigInt());
this._primitiveTypes.put(Float.class, dt.real());
this._primitiveTypes.put(Double.class, dt.doublePrecision());
this._primitiveTypes.put(Date.class, dt.timeStamp(true));
this._primitiveTypes.put(Character.class, dt.integer());
this._primitiveTypes.put(String.class, dt.sqlVarChar(5000));
this._primitiveTypes.put(BigInteger.class, dt.decimal());
this._primitiveTypes.put(BigDecimal.class, dt.decimal());
Map<Class<?>, Integer> jdbcTypes = new HashMap<Class<?>, Integer>();
jdbcTypes.put(Boolean.class, Types.BOOLEAN);
jdbcTypes.put(Byte.class, Types.SMALLINT);
jdbcTypes.put(Short.class, Types.SMALLINT);
jdbcTypes.put(Integer.class, Types.INTEGER);
jdbcTypes.put(Long.class, Types.BIGINT);
jdbcTypes.put(Float.class, Types.REAL);
jdbcTypes.put(Double.class, Types.DOUBLE);
jdbcTypes.put(Date.class, Types.TIMESTAMP);
jdbcTypes.put(Character.class, Types.INTEGER);
jdbcTypes.put(String.class, Types.VARCHAR);
jdbcTypes.put(BigInteger.class, Types.NUMERIC);
jdbcTypes.put(BigDecimal.class, Types.NUMERIC);
this._state.javaTypes2SQLTypes().set(jdbcTypes);
this._customizableTypes = new HashMap<Class<?>, SQLTypeCustomizer>();
//
this._customizableTypes.put(//
String.class, new SQLTypeCustomizer() {
@Override
public SQLDataType customizeType(Type propertyType, SQLTypeInfo sqlTypeInfo) {
return _vendor.getDataTypeFactory().sqlVarChar(sqlTypeInfo.maxLength());
}
});
//
this._customizableTypes.put(//
BigInteger.class, new SQLTypeCustomizer() {
@Override
public SQLDataType customizeType(Type propertyType, SQLTypeInfo sqlTypeInfo) {
return _vendor.getDataTypeFactory().decimal(sqlTypeInfo.maxLength());
}
});
//
this._customizableTypes.put(//
BigDecimal.class, new SQLTypeCustomizer() {
@Override
public SQLDataType customizeType(Type propertyType, SQLTypeInfo sqlTypeInfo) {
return _vendor.getDataTypeFactory().decimal(sqlTypeInfo.maxLength());
}
});
}
use of org.sql.generation.api.grammar.factories.DataTypeFactory in project qi4j-sdk by Qi4j.
the class PostgreSQLAppStartup method testRequiredCapabilities.
@Override
protected void testRequiredCapabilities(Connection connection) throws SQLException {
// If collection structure matching will ever be needed, using ltree as path to each leaf
// item in
// collection-generated tree will be very useful
// ltree module provides specific datatype for such path, which may be indexed in order to
// greatly improve
// performance
Statement stmt = connection.createStatement();
try {
DefinitionFactory d = this._vendor.getDefinitionFactory();
TableReferenceFactory t = this._vendor.getTableReferenceFactory();
DataTypeFactory dt = this._vendor.getDataTypeFactory();
stmt.execute(this._vendor.toString(d.createTableDefinitionBuilder().setTableScope(TableScope.LOCAL_TEMPORARY).setTableName(t.tableName("ltree_test")).setCommitAction(PgSQLTableCommitAction.DROP).setTableContentsSource(d.createTableElementListBuilder().addTableElement(d.createColumnDefinition("test_column", dt.userDefined("ltree"))).createExpression()).createExpression()));
} catch (SQLException sqle) {
throw new InternalError("It seems that your database doesn't have ltree as type. It is needed to store collections. Please refer to hopefully supplied instructions on how to add ltree type (hint: run <pg_install_dir>/share/contrib/ltree.sql script or command 'CREATE EXTENSION ltree;').");
} finally {
SQLUtil.closeQuietly(stmt);
}
}
Aggregations