Search in sources :

Example 6 with RDBMSColumnInfo

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

the class TableImpl method initializeColumnInfoFromDatastore.

/**
 * Initialize the default value for columns if null using the values from the datastore.
 * @param conn The JDBC Connection
 * @throws SQLException Thrown if an error occurs in the default initialisation.
 */
public void initializeColumnInfoFromDatastore(Connection conn) throws SQLException {
    Map<DatastoreIdentifier, Column> columns = new HashMap(columnsByIdentifier);
    Iterator i = storeMgr.getColumnInfoForTable(this, conn).iterator();
    while (i.hasNext()) {
        RDBMSColumnInfo ci = (RDBMSColumnInfo) i.next();
        DatastoreIdentifier colName = storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN, ci.getColumnName());
        Column col = columns.get(colName);
        if (col != null) {
            col.initializeColumnInfoFromDatastore(ci);
        }
    }
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo) HashMap(java.util.HashMap) DatastoreIdentifier(org.datanucleus.store.rdbms.identifier.DatastoreIdentifier) Iterator(java.util.Iterator)

Example 7 with RDBMSColumnInfo

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

the class DB2Adapter method newRDBMSColumnInfo.

/**
 * Method to create a column info for the current row.
 * Overrides the dataType/columnSize/decimalDigits to cater for DB2 particularities.
 * @param rs ResultSet from DatabaseMetaData.getColumns()
 * @return column info
 */
public RDBMSColumnInfo newRDBMSColumnInfo(ResultSet rs) {
    RDBMSColumnInfo info = new RDBMSColumnInfo(rs);
    short dataType = info.getDataType();
    switch(dataType) {
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            // Values > 0 inexplicably get returned here.
            info.setDecimalDigits(0);
            break;
        default:
            break;
    }
    return info;
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)

Example 8 with RDBMSColumnInfo

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

the class MySQLAdapter method newRDBMSColumnInfo.

/**
 * Method to create a column info for the current row.
 * Overrides the dataType for BLOB/CLOB as necessary
 * @param rs ResultSet from DatabaseMetaData.getColumns()
 * @return column info
 */
public RDBMSColumnInfo newRDBMSColumnInfo(ResultSet rs) {
    RDBMSColumnInfo info = super.newRDBMSColumnInfo(rs);
    short dataType = info.getDataType();
    String typeName = info.getTypeName();
    // Fix to an issue in the MySQL JDBC driver 3.1.13. For columns of type BLOB, the driver returns -4 but should return 2004
    if (dataType == Types.LONGVARBINARY && typeName.equalsIgnoreCase("mediumblob")) {
        // change it to BLOB, since it is a BLOB
        info.setDataType((short) Types.BLOB);
    }
    // Fix to an issue in the MySQL JDBC driver 3.1.13. For columns of type CLOB, the driver returns -1 but should return 2005
    if (dataType == Types.LONGVARCHAR && typeName.equalsIgnoreCase("mediumtext")) {
        // change it to CLOB, since it is a CLOB
        info.setDataType((short) Types.CLOB);
    }
    return info;
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)

Example 9 with RDBMSColumnInfo

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

the class PostgreSQLAdapter method newRDBMSColumnInfo.

/**
 * Method to create a column info for the current row.
 * Overrides the dataType/columnSize/decimalDigits to cater for Postgresql particularities.
 * @param rs ResultSet from DatabaseMetaData.getColumns()
 * @return column info
 */
public RDBMSColumnInfo newRDBMSColumnInfo(ResultSet rs) {
    RDBMSColumnInfo info = new RDBMSColumnInfo(rs);
    String typeName = info.getTypeName();
    if (typeName.equalsIgnoreCase("text")) {
        // Equate "text" to Types.LONGVARCHAR
        info.setDataType((short) Types.LONGVARCHAR);
    } else if (typeName.equalsIgnoreCase("bytea")) {
        // Equate "bytea" to Types.LONGVARBINARY
        info.setDataType((short) Types.LONGVARBINARY);
    }
    // The PostgreSQL drivers sometimes produce some truly funky metadata.
    // Observed these next two occur during unit testing when decimal_widget.big_decimal_field reported a columnSize of 65535 and a decimalDigits of 65534,
    // instead of the correct answers of 18 and 2. A -1 for either of these will cause their validation to be bypassed, which is a shame but it's all we can do.
    // No one should be surprised if we end up needing more of these.
    int columnSize = info.getColumnSize();
    if (columnSize > PostgreSQLTypeInfo.MAX_PRECISION) {
        info.setColumnSize(-1);
    }
    int decimalDigits = info.getDecimalDigits();
    if (decimalDigits > PostgreSQLTypeInfo.MAX_PRECISION) {
        info.setDecimalDigits(-1);
    }
    String columnDef = info.getColumnDef();
    if (columnDef != null) {
        // Ignore some columnDef cases where we do not support PostgreSQL specific syntax
        if (columnDef.startsWith("nextval(")) {
            // Ignore any "nextval(...)"
            info.setColumnDef(null);
        } else if (columnDef.startsWith("'") && columnDef.endsWith("'")) {
        // Ignore when we have just a string (that may contain ::)
        } else if (columnDef.contains("::")) {
            // We want to strip off any PostgreSQL-specific "::" where this is not part of a default string
            info.setColumnDef(columnDef.substring(0, columnDef.indexOf("::")));
        }
    }
    return info;
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)

Example 10 with RDBMSColumnInfo

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

the class SQLAnywhereAdapter method newRDBMSColumnInfo.

/**
 * Method to create a column info for the current row.
 * @param rs ResultSet from DatabaseMetaData.getColumns()
 * @return column info
 */
public RDBMSColumnInfo newRDBMSColumnInfo(ResultSet rs) {
    RDBMSColumnInfo info = new RDBMSColumnInfo(rs);
    short dataType = info.getDataType();
    switch(dataType) {
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            // Ensure this is set to 0
            info.setDecimalDigits(0);
            break;
        default:
            break;
    }
    return info;
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)

Aggregations

RDBMSColumnInfo (org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)12 Iterator (java.util.Iterator)5 HashMap (java.util.HashMap)3 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)3 Connection (java.sql.Connection)2 MissingColumnException (org.datanucleus.store.rdbms.exceptions.MissingColumnException)2 RDBMSTableInfo (org.datanucleus.store.rdbms.schema.RDBMSTableInfo)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 PersistenceManager (javax.jdo.PersistenceManager)1 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)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