use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method printInformation.
/**
* Method to output particular information owned by this datastore.
* Supports "DATASTORE" and "SCHEMA" categories.
* @param category Category of information
* @param ps PrintStream
* @throws Exception Thrown if an error occurs in the output process
*/
public void printInformation(String category, PrintStream ps) throws Exception {
DatastoreAdapter dba = getDatastoreAdapter();
super.printInformation(category, ps);
if (category.equalsIgnoreCase("DATASTORE")) {
ps.println(dba.toString());
ps.println();
ps.println("Database TypeInfo");
RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, RDBMSSchemaHandler.TYPE_TYPES, null);
if (typesInfo != null) {
Iterator iter = typesInfo.getChildren().keySet().iterator();
while (iter.hasNext()) {
String jdbcTypeStr = (String) iter.next();
short jdbcTypeNumber = 0;
try {
jdbcTypeNumber = Short.parseShort(jdbcTypeStr);
} catch (NumberFormatException nfe) {
}
JDBCTypeInfo jdbcType = (JDBCTypeInfo) typesInfo.getChild(jdbcTypeStr);
Collection<String> sqlTypeNames = jdbcType.getChildren().keySet();
StringBuilder sqlTypesName = new StringBuilder();
String defaultSqlTypeName = null;
for (String sqlTypeName : sqlTypeNames) {
if (!sqlTypeName.equals("DEFAULT")) {
if (sqlTypesName.length() > 0) {
sqlTypesName.append(',');
}
sqlTypesName.append(sqlTypeName);
} else {
defaultSqlTypeName = ((SQLTypeInfo) jdbcType.getChild(sqlTypeName)).getTypeName();
}
}
// SQL type names for JDBC type
String typeStr = "JDBC Type=" + dba.getNameForJDBCType(jdbcTypeNumber) + " sqlTypes=" + sqlTypesName + (defaultSqlTypeName != null ? (" (default=" + defaultSqlTypeName + ")") : "");
ps.println(typeStr);
for (String sqlTypeName : sqlTypeNames) {
// SQL type details
if (!sqlTypeName.equals("DEFAULT")) {
SQLTypeInfo sqlType = (SQLTypeInfo) jdbcType.getChild(sqlTypeName);
ps.println(sqlType.toString(" "));
}
}
}
}
ps.println("");
// Print out the keywords info
ps.println("Database Keywords");
Iterator reservedWordsIter = dba.iteratorReservedWords();
while (reservedWordsIter.hasNext()) {
Object words = reservedWordsIter.next();
ps.println(words);
}
ps.println("");
} else if (category.equalsIgnoreCase("SCHEMA")) {
ps.println(dba.toString());
ps.println();
ps.println("TABLES");
ManagedConnection mc = connectionMgr.getConnection(-1);
try {
Connection conn = (Connection) mc.getConnection();
RDBMSSchemaInfo schemaInfo = (RDBMSSchemaInfo) schemaHandler.getSchemaData(conn, RDBMSSchemaHandler.TYPE_TABLES, new Object[] { this.catalogName, this.schemaName });
if (schemaInfo != null) {
Iterator tableIter = schemaInfo.getChildren().values().iterator();
while (tableIter.hasNext()) {
// Print out the table information
RDBMSTableInfo tableInfo = (RDBMSTableInfo) tableIter.next();
ps.println(tableInfo);
Iterator<StoreSchemaData> columnIter = tableInfo.getChildren().iterator();
while (columnIter.hasNext()) {
// Print out the column information
RDBMSColumnInfo colInfo = (RDBMSColumnInfo) columnIter.next();
ps.println(colInfo);
}
}
}
} finally {
if (mc != null) {
mc.release();
}
}
ps.println("");
}
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class CloudSpannerAdapter method initialiseTypes.
/**
* This function adds on any missing JDBC types when not available from driver metadata Spanner driver
* only provides the common types. We should map the missing ones.
* <p>
* JDBC type (Spanner type) as follows :-
* nvarchar (string), bigint (int64), binary (byte), double (float64), boolean (bool), date (date), timestamp (timestamp), numeric (numeric)
* <p>
* Copied the mappings from Hibernate,
* https://github.com/GoogleCloudPlatform/google-cloud-spanner-hibernate/blob/master/google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/SpannerDialect.java
* <p>
* The precision values are obtained from Spanner JDBC driver metadata
* https://github.com/googleapis/java-spanner-jdbc/blob/master/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
* @param handler SchemaHandler that we initialise the types for
* @param mconn managed connection to use
*/
@Override
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
super.initialiseTypes(handler, mconn);
SQLTypeInfo sqlType = new CloudSpannerTypeInfo("BOOL", (short) Types.BIT, 0, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, true, false, false, "BOOL", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.BIT, sqlType, true);
sqlType = new CloudSpannerTypeInfo("BYTES", (short) Types.BLOB, 10485760, null, null, "(length)", DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, true, false, false, "BYTES", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.BLOB, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.CHAR, 2621440, null, null, "(length)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typePredChar, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.CHAR, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.CLOB, 2621440, null, null, "(length)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typeSearchable, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
sqlType = new CloudSpannerTypeInfo("NUMERIC", (short) Types.DECIMAL, 2621440, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "NUMERIC", (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.DECIMAL, sqlType, true);
sqlType = new CloudSpannerTypeInfo("FLOAT64", (short) Types.FLOAT, 15, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "FLOAT64", (short) 0, (short) 0, 2);
addSQLTypeForJDBCType(handler, mconn, (short) Types.FLOAT, sqlType, true);
sqlType = new CloudSpannerTypeInfo("INT64", (short) Types.INTEGER, 19, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "INT64", (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.INTEGER, sqlType, true);
sqlType = new CloudSpannerTypeInfo("BYTES", (short) Types.LONGVARBINARY, 10485760, null, null, "(MAX)", DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, true, false, false, "BYTES", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARBINARY, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.LONGVARCHAR, 2621440, null, null, "(MAX)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typeSearchable, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.LONGVARCHAR, sqlType, true);
sqlType = new CloudSpannerTypeInfo("FLOAT64", (short) Types.REAL, 15, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "FLOAT64", (short) 0, (short) 0, 2);
addSQLTypeForJDBCType(handler, mconn, (short) Types.REAL, sqlType, true);
sqlType = new CloudSpannerTypeInfo("INT64", (short) Types.SMALLINT, 19, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "INT64", (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.SMALLINT, sqlType, true);
sqlType = new CloudSpannerTypeInfo("TIMESTAMP", (short) Types.TIME, 35, "TIMESTAMP ", null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, true, false, false, "TIMESTAMP", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.TIME, sqlType, true);
sqlType = new CloudSpannerTypeInfo("INT64", (short) Types.TINYINT, 19, null, null, null, DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, false, false, false, "INT64", (short) 0, (short) 0, 10);
addSQLTypeForJDBCType(handler, mconn, (short) Types.TINYINT, sqlType, true);
sqlType = new CloudSpannerTypeInfo("BYTES", (short) Types.VARBINARY, 10485760, null, null, "(length)", DatabaseMetaData.typeNullable, false, (short) DatabaseMetaData.typePredBasic, true, false, false, "BYTES", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.VARBINARY, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.VARCHAR, 2621440, null, null, "(length)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typeSearchable, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.VARCHAR, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.NCHAR, 2621440, null, null, "(length)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typeSearchable, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.NCHAR, sqlType, true);
sqlType = new CloudSpannerTypeInfo("STRING", (short) Types.NCLOB, 2621440, null, null, "(length)", DatabaseMetaData.typeNullable, true, (short) DatabaseMetaData.typeSearchable, true, false, false, "STRING", (short) 0, (short) 0, 0);
addSQLTypeForJDBCType(handler, mconn, (short) Types.NCLOB, sqlType, true);
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class PointbaseAdapter 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
// Based on PointbaseAdapter : PointBase version=5.1 ECF build 295, major=5, minor=1, revision=0
// Driver name=PointBase JDBC Driver, version=5.1 ECF build 295, major=5, minor=1
RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) handler.getSchemaData(mconn.getConnection(), RDBMSSchemaHandler.TYPE_TYPES, null);
JDBCTypeInfo jdbcType = (JDBCTypeInfo) typesInfo.getChild("9");
if (jdbcType != null && jdbcType.getNumberOfChildren() > 0) {
// somehow BIGINT is set to 9 in the JDBC driver so add it at its correct value
SQLTypeInfo dfltTypeInfo = (SQLTypeInfo) jdbcType.getChild("DEFAULT");
SQLTypeInfo sqlType = new SQLTypeInfo(dfltTypeInfo.getTypeName(), (short) Types.BIGINT, dfltTypeInfo.getPrecision(), dfltTypeInfo.getLiteralPrefix(), dfltTypeInfo.getLiteralSuffix(), dfltTypeInfo.getCreateParams(), dfltTypeInfo.getNullable(), dfltTypeInfo.isCaseSensitive(), dfltTypeInfo.getSearchable(), dfltTypeInfo.isUnsignedAttribute(), dfltTypeInfo.isFixedPrecScale(), dfltTypeInfo.isAutoIncrement(), dfltTypeInfo.getLocalTypeName(), dfltTypeInfo.getMinimumScale(), dfltTypeInfo.getMaximumScale(), dfltTypeInfo.getNumPrecRadix());
addSQLTypeForJDBCType(handler, mconn, (short) Types.BIGINT, sqlType, true);
}
jdbcType = (JDBCTypeInfo) typesInfo.getChild("16");
if (jdbcType != null) {
// somehow BOOLEAN is set to 16 in the JDBC driver so add it at its correct location
SQLTypeInfo dfltTypeInfo = (SQLTypeInfo) jdbcType.getChild("DEFAULT");
SQLTypeInfo sqlType = new SQLTypeInfo(dfltTypeInfo.getTypeName(), (short) Types.BOOLEAN, dfltTypeInfo.getPrecision(), dfltTypeInfo.getLiteralPrefix(), dfltTypeInfo.getLiteralSuffix(), dfltTypeInfo.getCreateParams(), dfltTypeInfo.getNullable(), dfltTypeInfo.isCaseSensitive(), dfltTypeInfo.getSearchable(), dfltTypeInfo.isUnsignedAttribute(), dfltTypeInfo.isFixedPrecScale(), dfltTypeInfo.isAutoIncrement(), dfltTypeInfo.getLocalTypeName(), dfltTypeInfo.getMinimumScale(), dfltTypeInfo.getMaximumScale(), dfltTypeInfo.getNumPrecRadix());
addSQLTypeForJDBCType(handler, mconn, (short) Types.BOOLEAN, sqlType, true);
}
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class PostgreSQLAdapter 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 when not available from driver
// Add CHAR : Not present in PSQL 8.1.405
SQLTypeInfo sqlType = new PostgreSQLTypeInfo("char", (short) Types.CHAR, 65000, null, null, null, 0, false, (short) 3, false, false, false, "char", (short) 0, (short) 0, 10);
boolean added = addSQLTypeForJDBCType(handler, mconn, (short) Types.CHAR, sqlType, true);
// Add CLOB mirrored from LONGVARCHAR ("text") from JDBC driver ** if not provided by the driver **
sqlType = new PostgreSQLTypeInfo("text", (short) Types.CLOB, 0, null, null, null, 1, true, (short) 3, true, false, false, "text", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.CLOB, sqlType, true);
if (added) {
// Mimic as if LONGVARCHAR
registerColumnMapping(String.class.getName(), org.datanucleus.store.rdbms.mapping.column.LongVarcharColumnMapping.class, JDBCType.CLOB, "text", false);
// Note that <= 5.2.2 we used ClobColumnMapping here, but PSQL uses a TEXT so why would that work?
// registerColumnMapping(String.class.getName(), org.datanucleus.store.rdbms.mapping.column.ClobColumnMapping.class, JDBCType.CLOB, "clob", false);
} else {
// Support as CLOB since provided by the driver
registerColumnMapping(String.class.getName(), org.datanucleus.store.rdbms.mapping.column.ClobColumnMapping.class, JDBCType.CLOB, "CLOB", false);
}
// Add BLOB mirrored from LONGVARBINARY ("bytea") from JDBC driver ** if not provided by the driver **
sqlType = new PostgreSQLTypeInfo("bytea", (short) Types.BLOB, 0, null, null, null, 1, true, (short) 3, true, false, false, "bytea", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.BLOB, sqlType, true);
if (added) {
// Mimic as if LONGVARBINARY
registerColumnMapping(String.class.getName(), org.datanucleus.store.rdbms.mapping.column.LongVarBinaryColumnMapping.class, JDBCType.BLOB, "bytea", false);
registerColumnMapping(byte[].class.getName(), org.datanucleus.store.rdbms.mapping.column.LongVarBinaryColumnMapping.class, JDBCType.BLOB, "bytea", false);
registerColumnMapping(java.io.Serializable.class.getName(), org.datanucleus.store.rdbms.mapping.column.LongVarBinaryColumnMapping.class, JDBCType.BLOB, "bytea", false);
} else {
// Support as BLOB since provided by the driver
registerColumnMapping(String.class.getName(), org.datanucleus.store.rdbms.mapping.column.BlobColumnMapping.class, JDBCType.BLOB, "BLOB", false);
registerColumnMapping(byte[].class.getName(), org.datanucleus.store.rdbms.mapping.column.BlobColumnMapping.class, JDBCType.BLOB, "BLOB", false);
registerColumnMapping(java.io.Serializable.class.getName(), org.datanucleus.store.rdbms.mapping.column.BlobColumnMapping.class, JDBCType.BLOB, "BLOB", false);
}
// Add BOOLEAN : Not present in PSQL 9.2.8 - just mirror what BIT does
sqlType = new PostgreSQLTypeInfo("bool", (short) Types.BOOLEAN, 0, null, null, null, 1, false, (short) 3, true, false, false, "bool", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.BOOLEAN, sqlType, true);
// Add TINYINT : Not present in PSQL 9.2.8 - just mirror what SMALLINT does
sqlType = new PostgreSQLTypeInfo("int2", (short) Types.TINYINT, 0, null, null, null, 1, false, (short) 3, false, false, false, "int2", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.TINYINT, sqlType, true);
// Add ARRAY : Not present in PSQL 9.2.8
sqlType = new PostgreSQLTypeInfo("text array", (short) Types.ARRAY, 0, null, null, null, 1, false, (short) 3, false, false, false, "text array", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.ARRAY, sqlType, true);
sqlType = new PostgreSQLTypeInfo("int array", (short) Types.ARRAY, 0, null, null, null, 1, false, (short) 3, false, false, false, "int array", (short) 0, (short) 0, 10);
added = addSQLTypeForJDBCType(handler, mconn, (short) Types.ARRAY, sqlType, true);
}
use of org.datanucleus.store.rdbms.schema.SQLTypeInfo in project datanucleus-rdbms by datanucleus.
the class SQLServerAdapter method newSQLTypeInfo.
public SQLTypeInfo newSQLTypeInfo(ResultSet rs) {
SQLTypeInfo ti = new org.datanucleus.store.rdbms.adapter.SQLServerTypeInfo(rs);
// Discard TINYINT type because it doesn't support negative values.
String typeName = ti.getTypeName();
if (typeName.toLowerCase().startsWith("tinyint")) {
return null;
}
// wrong data length in the DB (varbinary(1) for java.io.Serializable - e.g. ByteArrays)
if (typeName.toLowerCase().startsWith("varbinary")) {
return null;
}
return ti;
}
Aggregations