Search in sources :

Example 1 with SQLTypeInfo

use of org.qi4j.index.sql.support.api.SQLTypeInfo in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method initTypes.

private void initTypes() {
    DataTypeFactory dt = this._vendor.getDataTypeFactory();
    this._primitiveTypes = new HashMap<>();
    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<>();
    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<>();
    //
    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) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ObjectType(org.sql.generation.api.grammar.manipulation.ObjectType) SQLDataType(org.sql.generation.api.grammar.common.datatypes.SQLDataType) 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)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 BigInteger (java.math.BigInteger)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 DataTypeFactory (org.sql.generation.api.grammar.factories.DataTypeFactory)1 ObjectType (org.sql.generation.api.grammar.manipulation.ObjectType)1