Search in sources :

Example 6 with SQLTypeInfo

use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.

the class SQLServerAdapter method initialiseTypes.

/**
 * Initialise the types for this datastore.
 * @param handler SchemaHandler that we initialise the types for
 * @param mconn Managed connection to use
 */
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    // Add on any missing JDBC types
    SQLTypeInfo sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("UNIQUEIDENTIFIER", (short) Types.CHAR, 36, "'", "'", "", 1, false, (short) 2, false, false, false, "UNIQUEIDENTIFIER", (short) 0, (short) 0, 10);
    sqlType.setAllowsPrecisionSpec(false);
    addSQLTypeForJDBCType(handler, mconn, (short) SQLServerTypeInfo.UNIQUEIDENTIFIER, sqlType, true);
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("IMAGE", (short) Types.BLOB, 2147483647, null, null, null, 1, false, (short) 1, false, false, false, "BLOB", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BLOB, sqlType, true);
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("varbinary", (short) Types.VARBINARY, 8000, "0x", null, "(max)", 1, false, (short) 2, false, false, false, "varbinary", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.VARBINARY, sqlType, true);
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("TEXT", (short) Types.CLOB, 2147483647, null, null, null, 1, true, (short) 1, false, false, false, "TEXT", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("float", (short) Types.DOUBLE, 53, null, null, null, 1, false, (short) 2, false, false, false, null, (short) 0, (short) 0, 2);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.DOUBLE, sqlType, true);
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("IMAGE", (short) Types.LONGVARBINARY, 2147483647, null, null, null, 1, false, (short) 1, false, false, false, "LONGVARBINARY", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARBINARY, sqlType, true);
    if (datastoreMajorVersion > 9) {
        // Support for build-in TIME and DATE data type for MS SQL Server version >= 2008
        sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("TIME", (short) Types.TIME, 0, null, null, null, 1, false, (short) 1, true, true, false, "TIME", (short) 0, (short) 0, 0);
        addSQLTypeForJDBCType(handler, mconn, (short) Types.TIME, sqlType, true);
        sqlType = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo("DATE", (short) Types.DATE, 0, null, null, null, 1, false, (short) 1, true, true, false, "DATE", (short) 0, (short) 0, 0);
        addSQLTypeForJDBCType(handler, mconn, (short) Types.DATE, sqlType, true);
    }
}
Also used : SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 7 with SQLTypeInfo

use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.

the class SQLiteAdapter method initialiseTypes.

@Override
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    // Add on any missing JDBC types not provided by JDBC driver (SQLite only provides NULL, REAL, BLOB, INTEGER, TEXT)
    // DOUBLE -> "double"
    SQLTypeInfo sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("double", (short) Types.DOUBLE, 0, null, null, null, 1, true, (short) 3, false, false, false, "double", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.DOUBLE, sqlType, true);
    // FLOAT -> "float"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("float", (short) Types.FLOAT, 0, null, null, null, 1, true, (short) 3, false, false, false, "float", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.FLOAT, sqlType, true);
    // DECIMAL -> "float"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("decimal", (short) Types.DECIMAL, 0, null, null, null, 1, true, (short) 3, false, false, false, "decimal", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.DECIMAL, sqlType, true);
    // NUMERIC -> "numeric"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("numeric", (short) Types.NUMERIC, 0, null, null, null, 1, true, (short) 3, false, false, false, "numeric", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.NUMERIC, sqlType, true);
    // BOOLEAN -> "integer"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("integer", (short) Types.BOOLEAN, 0, null, null, null, 1, true, (short) 3, false, false, false, "integer", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BOOLEAN, sqlType, true);
    // BIT -> "integer"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("integer", (short) Types.BIT, 0, null, null, null, 1, true, (short) 3, false, false, false, "integer", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BIT, sqlType, true);
    // TINYINT -> "tinyint"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("tinyint", (short) Types.TINYINT, 0, null, null, null, 1, true, (short) 3, false, false, false, "tinyint", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.TINYINT, sqlType, true);
    // SMALLINT -> "smallint"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("smallint", (short) Types.SMALLINT, 0, null, null, null, 1, true, (short) 3, false, false, false, "smallint", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.SMALLINT, sqlType, true);
    // BIGINT -> "bigint"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("bigint", (short) Types.BIGINT, 0, null, null, null, 1, true, (short) 3, false, false, false, "bigint", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BIGINT, sqlType, true);
    // CHAR -> "char"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("char", (short) Types.CHAR, 255, null, null, null, 1, true, (short) 3, false, false, false, "char", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.CHAR, sqlType, true);
    // VARCHAR -> "varchar"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("varchar", (short) Types.VARCHAR, 255, null, null, null, 1, true, (short) 3, false, false, false, "varchar", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.VARCHAR, sqlType, true);
    // LONGVARCHAR -> "longvarchar"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("longvarchar", (short) Types.LONGVARCHAR, 16777215, null, null, null, 1, true, (short) 3, false, false, false, "longvarchar", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARCHAR, sqlType, true);
    // CLOB -> "clob"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("clob", (short) Types.CLOB, 2147483647, null, null, null, 1, true, (short) 3, false, false, false, "clob", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
    // DATE -> "date"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("date", (short) Types.DATE, 0, null, null, null, 1, true, (short) 3, false, false, false, "date", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.DATE, sqlType, true);
    // TIME -> "time"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("time", (short) Types.TIME, 0, null, null, null, 1, true, (short) 3, false, false, false, "time", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.TIME, sqlType, true);
    // TIMESTAMP -> "timestamp"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("timestamp", (short) Types.TIMESTAMP, 0, null, null, null, 1, true, (short) 3, false, false, false, "timestamp", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.TIMESTAMP, sqlType, true);
    // BINARY -> "blob"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("blob", (short) Types.BINARY, 255, null, null, null, 1, true, (short) 3, false, false, false, "blob", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BINARY, sqlType, true);
    // VARBINARY -> "blob"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("blob", (short) Types.VARBINARY, 255, null, null, null, 1, true, (short) 3, false, false, false, "blob", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.VARBINARY, sqlType, true);
    // LONGVARBINARY -> "blob"
    sqlType = new org.datanucleus.store.rdbms.adapter.SQLiteTypeInfo("blob", (short) Types.LONGVARBINARY, 16777215, null, null, null, 1, true, (short) 3, false, false, false, "blob", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARBINARY, sqlType, true);
}
Also used : SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 8 with SQLTypeInfo

use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.

the class H2Adapter method initialiseTypes.

/**
 * Initialise the types for this datastore.
 * @param handler SchemaHandler that we initialise the types for
 * @param mconn Managed connection to use
 */
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    SQLTypeInfo sqlType = new H2TypeInfo("UUID", (short) 1111, 2147483647, null, null, null, 1, true, (short) 3, false, false, false, "UUID", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.OTHER, sqlType, true);
    sqlType = new H2TypeInfo("GEOMETRY", (short) 1111, 2147483647, null, null, null, 1, true, (short) 3, false, false, false, "GEOMETRY", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.OTHER, sqlType, true);
    // Not explicitly admitted by H2 v2 so add it
    sqlType = new H2TypeInfo("LONGVARBINARY", (short) -4, 2147483647, "X'", "'", "LENGTH", 1, false, (short) 3, false, false, false, "LONGVARBINARY", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARBINARY, sqlType, true);
    sqlType = new H2TypeInfo("FLOAT", (short) 6, 17, null, null, null, 1, false, (short) 3, false, false, false, "FLOAT", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.FLOAT, sqlType, true);
    sqlType = new H2TypeInfo("DECIMAL", (short) 3, 2147483647, null, null, "PRECISION,SCALE", 1, false, (short) 3, false, false, false, "DECIMAL", (short) 0, (short) 0, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.DECIMAL, sqlType, true);
}
Also used : SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 9 with SQLTypeInfo

use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.

the class HSQLAdapter method initialiseTypes.

/**
 * Initialise the types for this datastore.
 * @param handler SchemaHandler that we initialise the types for
 * @param mconn Managed connection to use
 */
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    // Add on any missing JDBC types
    // CLOB - not present before v2.0
    SQLTypeInfo sqlType = new org.datanucleus.store.rdbms.adapter.HSQLTypeInfo("LONGVARCHAR", (short) Types.CLOB, 2147483647, "'", "'", null, 1, true, (short) 3, false, false, false, "LONGVARCHAR", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
    // BLOB - not present before v2.0
    sqlType = new org.datanucleus.store.rdbms.adapter.HSQLTypeInfo("LONGVARBINARY", (short) Types.BLOB, 2147483647, "'", "'", null, 1, false, (short) 3, false, false, false, "LONGVARBINARY", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BLOB, sqlType, true);
    if (datastoreMajorVersion >= 2) {
        // LONGVARBINARY - not present after v2.0
        sqlType = new org.datanucleus.store.rdbms.adapter.HSQLTypeInfo("LONGVARBINARY", (short) Types.LONGVARBINARY, 2147483647, "'", "'", null, 1, false, (short) 3, false, false, false, "LONGVARBINARY", (short) 0, (short) 0, 0);
        addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARBINARY, sqlType, true);
    }
    // LONGVARCHAR - not present in 2.0+
    sqlType = new org.datanucleus.store.rdbms.adapter.HSQLTypeInfo("LONGVARCHAR", (short) Types.LONGVARCHAR, 2147483647, "'", "'", null, 1, true, (short) 3, false, false, false, "LONGVARCHAR", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARCHAR, sqlType, true);
    if (datastoreMajorVersion >= 2 && datastoreMinorVersion >= 4) {
        // UUID
        sqlType = new org.datanucleus.store.rdbms.adapter.HSQLTypeInfo("UUID", (short) Types.BINARY, 2147483647, "'", "'", null, 1, false, (short) 3, false, false, false, "UUID", (short) 0, (short) 0, 0);
        addSQLTypeForJDBCType(handler, mconn, (short) Types.BINARY, sqlType, true);
    }
    // Update any types that need extra info relative to the JDBC info
    Collection<SQLTypeInfo> sqlTypes = getSQLTypeInfoForJdbcType(handler, mconn, (short) Types.BLOB);
    if (sqlTypes != null) {
        Iterator<SQLTypeInfo> iter = sqlTypes.iterator();
        while (iter.hasNext()) {
            sqlType = iter.next();
            // Can't add precision on a BLOB
            sqlType.setAllowsPrecisionSpec(false);
        }
    }
    sqlTypes = getSQLTypeInfoForJdbcType(handler, mconn, (short) Types.CLOB);
    if (sqlTypes != null) {
        Iterator<SQLTypeInfo> iter = sqlTypes.iterator();
        while (iter.hasNext()) {
            sqlType = iter.next();
            // Can't add precision on a CLOB
            sqlType.setAllowsPrecisionSpec(false);
        }
    }
    sqlTypes = getSQLTypeInfoForJdbcType(handler, mconn, (short) Types.LONGVARBINARY);
    if (sqlTypes != null) {
        Iterator<SQLTypeInfo> iter = sqlTypes.iterator();
        while (iter.hasNext()) {
            sqlType = iter.next();
            // Can't add precision on a LONGVARBINARY
            sqlType.setAllowsPrecisionSpec(false);
        }
    }
    sqlTypes = getSQLTypeInfoForJdbcType(handler, mconn, (short) Types.LONGVARCHAR);
    if (sqlTypes != null) {
        Iterator<SQLTypeInfo> iter = sqlTypes.iterator();
        while (iter.hasNext()) {
            sqlType = iter.next();
            // Can't add precision on a LONGVARCHAR
            sqlType.setAllowsPrecisionSpec(false);
        }
    }
}
Also used : SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 10 with SQLTypeInfo

use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.

the class MySQLAdapter method initialiseTypes.

/**
 * Initialise the types for this datastore.
 * @param handler SchemaHandler that we initialise the types for
 * @param mconn Managed connection to use
 */
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    // Add on any missing JDBC types
    // MySQL JDBC v8 has no NUMERIC, try to map it as DECIMAL SQL type - unconfirmed whether this works
    SQLTypeInfo sqlType = new org.datanucleus.store.rdbms.adapter.MySQLTypeInfo("DECIMAL", (short) Types.NUMERIC, 65, null, null, "[(M,D])] [ZEROFILL]", 1, true, (short) 3, false, false, false, "DECIMAL", (short) -308, (short) 308, 10);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.NUMERIC, sqlType, true);
    // Map BLOB JDBC type to MEDIUMBLOB SQL type if no BLOB provided
    sqlType = new org.datanucleus.store.rdbms.adapter.MySQLTypeInfo("MEDIUMBLOB", (short) Types.BLOB, 2147483647, null, null, null, 1, false, (short) 1, false, false, false, "MEDIUMBLOB", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.BLOB, sqlType, true);
    // Map CLOB JDBC type to MEDIUMTEXT SQL type if no CLOB provided
    sqlType = new org.datanucleus.store.rdbms.adapter.MySQLTypeInfo("MEDIUMTEXT", (short) Types.CLOB, 2147483647, null, null, null, 1, true, (short) 1, false, false, false, "MEDIUMTEXT", (short) 0, (short) 0, 0);
    addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
}
Also used : SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Aggregations

SQLTypeInfo (org.datanucleus.store.rdbms.schema.SQLTypeInfo)18 JDBCTypeInfo (org.datanucleus.store.rdbms.schema.JDBCTypeInfo)3 RDBMSTypesInfo (org.datanucleus.store.rdbms.schema.RDBMSTypesInfo)3 Iterator (java.util.Iterator)2 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)2 SingleFieldMapping (org.datanucleus.store.rdbms.mapping.java.SingleFieldMapping)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1 UnsupportedDataTypeException (org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException)1 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)1 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)1 RDBMSColumnInfo (org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)1 RDBMSSchemaInfo (org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)1 RDBMSTableInfo (org.datanucleus.store.rdbms.schema.RDBMSTableInfo)1