Search in sources :

Example 1 with DataTypeFactory

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());
        }
    });
}
Also used : BigInteger(java.math.BigInteger) QNameType(org.qi4j.index.sql.support.common.QNameInfo.QNameType) Type(java.lang.reflect.Type) ObjectType(org.sql.generation.api.grammar.manipulation.ObjectType) SQLDataType(org.sql.generation.api.grammar.common.datatypes.SQLDataType) ParameterizedType(java.lang.reflect.ParameterizedType) SQLDataType(org.sql.generation.api.grammar.common.datatypes.SQLDataType) HashMap(java.util.HashMap) DataTypeFactory(org.sql.generation.api.grammar.factories.DataTypeFactory) SQLTypeInfo(org.qi4j.index.sql.support.api.SQLTypeInfo)

Example 2 with DataTypeFactory

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);
    }
}
Also used : TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DataTypeFactory(org.sql.generation.api.grammar.factories.DataTypeFactory) DefinitionFactory(org.sql.generation.api.grammar.factories.DefinitionFactory)

Aggregations

DataTypeFactory (org.sql.generation.api.grammar.factories.DataTypeFactory)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 BigInteger (java.math.BigInteger)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 SQLTypeInfo (org.qi4j.index.sql.support.api.SQLTypeInfo)1 QNameType (org.qi4j.index.sql.support.common.QNameInfo.QNameType)1 SQLDataType (org.sql.generation.api.grammar.common.datatypes.SQLDataType)1 DefinitionFactory (org.sql.generation.api.grammar.factories.DefinitionFactory)1 TableReferenceFactory (org.sql.generation.api.grammar.factories.TableReferenceFactory)1 ObjectType (org.sql.generation.api.grammar.manipulation.ObjectType)1