use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class DB2Adapter 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.DB2TypeInfo("FLOAT", (short) Types.FLOAT, 53, null, null, null, 1, false, (short) 2, false, false, false, null, (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.FLOAT, sqlType, true);
sqlType = new org.datanucleus.store.rdbms.adapter.DB2TypeInfo("NUMERIC", (short) Types.NUMERIC, 31, null, null, "PRECISION,SCALE", 1, false, (short) 2, false, false, false, null, (short) 0, (short) 31, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.NUMERIC, sqlType, true);
sqlType = new org.datanucleus.store.rdbms.adapter.DB2TypeInfo("BIGINT", (short) Types.BIGINT, 20, null, null, null, 1, false, (short) 2, false, true, false, null, (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.BIGINT, sqlType, true);
sqlType = new org.datanucleus.store.rdbms.adapter.DB2TypeInfo("XML", (short) Types.SQLXML, 2147483647, null, null, null, 1, false, (short) 2, false, false, false, null, (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.SQLXML, sqlType, true);
// DB2 doesn't have "BIT" JDBC type mapped, so map as SMALLINT
sqlType = new org.datanucleus.store.rdbms.adapter.DB2TypeInfo("SMALLINT", (short) Types.SMALLINT, 5, null, null, null, 1, false, (short) 2, false, true, false, null, (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.BIT, sqlType, true);
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class CharColumnMapping method initialize.
/**
* Method to initialise the column mapping. Provides default length specifications for the CHAR column to
* fit the data being stored.
*/
protected void initialize() {
if (column != null) {
// Default Length
if (getJavaTypeMapping() instanceof SingleFieldMapping && column.getColumnMetaData().getLength() == null) {
SingleFieldMapping m = (SingleFieldMapping) getJavaTypeMapping();
if (m.getDefaultLength(0) > 0) {
// No column length provided by user and the type has a default length so use it
column.getColumnMetaData().setLength(m.getDefaultLength(0));
}
}
column.getColumnMetaData().setJdbcType("CHAR");
column.checkString();
// Valid Values
if (getJavaTypeMapping() instanceof SingleFieldMapping) {
Object[] validValues = ((SingleFieldMapping) getJavaTypeMapping()).getValidValues(0);
if (validValues != null) {
column.setCheckConstraints(getDatastoreAdapter().getCheckConstraintForValues(column.getIdentifier(), validValues, column.isNullable()));
}
}
if (getJavaTypeMapping().getJavaType() == Boolean.class) {
// With a Boolean we'll store it as "Y", "N" (see setBoolean/getBoolean methods)
column.getColumnMetaData().setLength(1);
StringBuilder constraints = new StringBuilder("CHECK (" + column.getIdentifier() + " IN ('Y','N')");
if (column.isNullable()) {
constraints.append(" OR " + column.getIdentifier() + " IS NULL");
}
constraints.append(')');
column.setCheckConstraints(constraints.toString());
}
// Check on max length of the type against the length we have set
SQLTypeInfo typeInfo = getTypeInfo();
int maxlength = typeInfo.getPrecision();
if (column.getColumnMetaData().getLength().intValue() <= 0 || column.getColumnMetaData().getLength().intValue() > maxlength) {
if (typeInfo.isAllowsPrecisionSpec()) {
throw new NucleusUserException("String max length of " + column.getColumnMetaData().getLength() + " is outside the acceptable range [0, " + maxlength + "] for column \"" + column.getIdentifier() + "\"");
}
}
}
initTypeInfo();
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class ClassTable method manageUnmappedColumns.
/**
* Adds on management of the columns in the defined MetaData that are "unmapped" (have no field associated).
* @param theCmd ClassMetaData for the class to be managed
* @param clr The ClassLoaderResolver
*/
private void manageUnmappedColumns(AbstractClassMetaData theCmd, ClassLoaderResolver clr) {
List cols = theCmd.getUnmappedColumns();
if (cols != null && cols.size() > 0) {
Iterator colsIter = cols.iterator();
while (colsIter.hasNext()) {
ColumnMetaData colmd = (ColumnMetaData) colsIter.next();
// Create a column with the specified name and jdbc-type
if (colmd.getJdbcType() == JdbcType.VARCHAR && colmd.getLength() == null) {
colmd.setLength(storeMgr.getIntProperty(RDBMSPropertyNames.PROPERTY_RDBMS_STRING_DEFAULT_LENGTH));
}
IdentifierFactory idFactory = getStoreManager().getIdentifierFactory();
DatastoreIdentifier colIdentifier = idFactory.newIdentifier(IdentifierType.COLUMN, colmd.getName());
Column col = addColumn(null, colIdentifier, null, colmd);
SQLTypeInfo sqlTypeInfo = storeMgr.getSQLTypeInfoForJDBCType(dba.getJDBCTypeForName(colmd.getJdbcTypeName()));
col.setTypeInfo(sqlTypeInfo);
if (unmappedColumns == null) {
unmappedColumns = new HashSet();
}
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("057011", col.toString(), colmd.getJdbcType()));
}
unmappedColumns.add(col);
}
}
}
Aggregations