Search in sources :

Example 6 with RDBMSTypesInfo

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

the class RDBMSStoreManager method getSQLTypeInfoForJDBCType.

/**
 * Accessor for the SQL type info for the specified JDBC type.
 * @param jdbcType JDBC type
 * @param sqlType The SQL type name (if known, otherwise uses the default for this JDBC type).
 * @return SQL type info
 * @throws UnsupportedDataTypeException If the JDBC type is not found
 */
public SQLTypeInfo getSQLTypeInfoForJDBCType(int jdbcType, String sqlType) throws UnsupportedDataTypeException {
    RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, "types", null);
    JDBCTypeInfo jdbcTypeInfo = (JDBCTypeInfo) typesInfo.getChild("" + jdbcType);
    if (jdbcTypeInfo.getNumberOfChildren() == 0) {
        // No sql-type for this jdbc-type so unsupported
        throw new UnsupportedDataTypeException(Localiser.msg("051005", dba.getNameForJDBCType(jdbcType)));
    }
    SQLTypeInfo sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType != null ? sqlType : "DEFAULT");
    if (sqlTypeInfo == null && sqlType != null) {
        // Try uppercase form of sql-type
        sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType.toUpperCase());
        if (sqlTypeInfo == null) {
            // Try lowercase form of sql-type
            sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType.toLowerCase());
            if (sqlTypeInfo == null) {
                // fallback to DEFAULT
                NucleusLogger.DATASTORE_SCHEMA.debug("Attempt to find JDBC driver 'typeInfo' for jdbc-type=" + dba.getNameForJDBCType(jdbcType) + " but sql-type=" + sqlType + " is not found. Using default sql-type for this jdbc-type.");
                sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild("DEFAULT");
            }
        }
    }
    return sqlTypeInfo;
}
Also used : JDBCTypeInfo(org.datanucleus.store.rdbms.schema.JDBCTypeInfo) RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo) UnsupportedDataTypeException(org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException) SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 7 with RDBMSTypesInfo

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

the class BaseDatastoreAdapter method getSQLTypeInfoForJdbcType.

/**
 * Accessor for the SQLType info for the specified JDBC type and the SQL type name.
 * @param handler Schema handler
 * @param mconn Connection
 * @param jdbcTypeNumber JDBC type
 * @return The SQL type info
 */
protected Collection<SQLTypeInfo> getSQLTypeInfoForJdbcType(StoreSchemaHandler handler, ManagedConnection mconn, short jdbcTypeNumber) {
    RDBMSTypesInfo types = (RDBMSTypesInfo) handler.getSchemaData(mconn.getConnection(), "types", null);
    String key = "" + jdbcTypeNumber;
    org.datanucleus.store.rdbms.schema.JDBCTypeInfo jdbcType = (org.datanucleus.store.rdbms.schema.JDBCTypeInfo) types.getChild(key);
    if (jdbcType == null) {
        return null;
    }
    return jdbcType.getChildren().values();
}
Also used : RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo)

Aggregations

RDBMSTypesInfo (org.datanucleus.store.rdbms.schema.RDBMSTypesInfo)7 JDBCTypeInfo (org.datanucleus.store.rdbms.schema.JDBCTypeInfo)3 SQLTypeInfo (org.datanucleus.store.rdbms.schema.SQLTypeInfo)3 MacroString (org.datanucleus.util.MacroString)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 NucleusConnection (org.datanucleus.store.NucleusConnection)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1 UnsupportedDataTypeException (org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException)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