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);
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations