use of org.datanucleus.store.rdbms.schema.RDBMSTypesInfo in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method logConfiguration.
/**
* Convenience method to log the configuration of this store manager.
*/
protected void logConfiguration() {
super.logConfiguration();
if (NucleusLogger.DATASTORE.isDebugEnabled()) {
NucleusLogger.DATASTORE.debug("Datastore Adapter : " + dba.getClass().getName());
NucleusLogger.DATASTORE.debug("Datastore : name=\"" + dba.getDatastoreProductName() + "\" version=\"" + dba.getDatastoreProductVersion() + "\"");
NucleusLogger.DATASTORE.debug("Datastore Driver : name=\"" + dba.getDatastoreDriverName() + "\" version=\"" + dba.getDatastoreDriverVersion() + "\"");
// Connection Information
String primaryDS = null;
if (getConnectionFactory() != null) {
primaryDS = "DataSource[input DataSource]";
} else if (getConnectionFactoryName() != null) {
primaryDS = "JNDI[" + getConnectionFactoryName() + "]";
} else {
primaryDS = "URL[" + getConnectionURL() + "]";
}
NucleusLogger.DATASTORE.debug("Primary Connection Factory : " + primaryDS);
String secondaryDS = null;
if (getConnectionFactory2() != null) {
secondaryDS = "DataSource[input DataSource]";
} else if (getConnectionFactory2Name() != null) {
secondaryDS = "JNDI[" + getConnectionFactory2Name() + "]";
} else {
if (getConnectionURL() != null) {
secondaryDS = "URL[" + getConnectionURL() + "]";
} else {
secondaryDS = primaryDS;
}
}
NucleusLogger.DATASTORE.debug("Secondary Connection Factory : " + secondaryDS);
if (identifierFactory != null) {
NucleusLogger.DATASTORE.debug("Datastore Identifiers :" + " factory=\"" + getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_FACTORY) + "\"" + " case=" + identifierFactory.getNamingCase().toString() + (catalogName != null ? (" catalog=" + catalogName) : "") + (schemaName != null ? (" schema=" + schemaName) : ""));
NucleusLogger.DATASTORE.debug("Supported Identifier Cases : " + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_LOWERCASE) ? "lowercase " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_LOWERCASE_QUOTED) ? "\"lowercase\" " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_MIXEDCASE) ? "MixedCase " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_MIXEDCASE_QUOTED) ? "\"MixedCase\" " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_UPPERCASE) ? "UPPERCASE " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_UPPERCASE_QUOTED) ? "\"UPPERCASE\" " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_MIXEDCASE_SENSITIVE) ? "MixedCase-Sensitive " : "") + (dba.supportsOption(DatastoreAdapter.IDENTIFIERS_MIXEDCASE_QUOTED_SENSITIVE) ? "\"MixedCase-Sensitive\" " : ""));
NucleusLogger.DATASTORE.debug("Supported Identifier Lengths (max) :" + " Table=" + dba.getDatastoreIdentifierMaxLength(IdentifierType.TABLE) + " Column=" + dba.getDatastoreIdentifierMaxLength(IdentifierType.COLUMN) + " Constraint=" + dba.getDatastoreIdentifierMaxLength(IdentifierType.CANDIDATE_KEY) + " Index=" + dba.getDatastoreIdentifierMaxLength(IdentifierType.INDEX) + " Delimiter=" + dba.getIdentifierQuoteString());
NucleusLogger.DATASTORE.debug("Support for Identifiers in DDL :" + " catalog=" + dba.supportsOption(DatastoreAdapter.CATALOGS_IN_TABLE_DEFINITIONS) + " schema=" + dba.supportsOption(DatastoreAdapter.SCHEMAS_IN_TABLE_DEFINITIONS));
}
NucleusLogger.DATASTORE.debug("Datastore : " + (getBooleanProperty(RDBMSPropertyNames.PROPERTY_RDBMS_CHECK_EXISTS_TABLES_VIEWS) ? "checkTableViewExistence" : "") + ", rdbmsConstraintCreateMode=" + getStringProperty(RDBMSPropertyNames.PROPERTY_RDBMS_CONSTRAINT_CREATE_MODE) + ", initialiseColumnInfo=" + getStringProperty(RDBMSPropertyNames.PROPERTY_RDBMS_INIT_COLUMN_INFO));
int batchLimit = getIntProperty(RDBMSPropertyNames.PROPERTY_RDBMS_STATEMENT_BATCH_LIMIT);
boolean supportBatching = dba.supportsOption(DatastoreAdapter.STATEMENT_BATCHING);
if (supportBatching) {
NucleusLogger.DATASTORE.debug("Support Statement Batching : yes (max-batch-size=" + (batchLimit == -1 ? "UNLIMITED" : "" + batchLimit) + ")");
} else {
NucleusLogger.DATASTORE.debug("Support Statement Batching : no");
}
NucleusLogger.DATASTORE.debug("Queries : Results " + "direction=" + getStringProperty(RDBMSPropertyNames.PROPERTY_RDBMS_QUERY_FETCH_DIRECTION) + ", type=" + getStringProperty(RDBMSPropertyNames.PROPERTY_RDBMS_QUERY_RESULT_SET_TYPE) + ", concurrency=" + getStringProperty(RDBMSPropertyNames.PROPERTY_RDBMS_QUERY_RESULT_SET_CONCURRENCY));
// JDBC Types
NucleusLogger.DATASTORE.debug("Java-Types : string-default-length=" + getIntProperty(RDBMSPropertyNames.PROPERTY_RDBMS_STRING_DEFAULT_LENGTH));
RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, "types", null);
if (typesInfo != null && typesInfo.getNumberOfChildren() > 0) {
StringBuilder typeStr = new StringBuilder();
Iterator<String> jdbcTypesIter = typesInfo.getChildren().keySet().iterator();
while (jdbcTypesIter.hasNext()) {
String jdbcTypeStr = jdbcTypesIter.next();
int jdbcTypeNumber = 0;
try {
jdbcTypeNumber = Short.parseShort(jdbcTypeStr);
} catch (NumberFormatException nfe) {
}
String typeName = dba.getNameForJDBCType(jdbcTypeNumber);
if (typeName == null) {
typeName = "[id=" + jdbcTypeNumber + "]";
}
typeStr.append(typeName);
if (jdbcTypesIter.hasNext()) {
typeStr.append(", ");
}
}
NucleusLogger.DATASTORE.debug("JDBC-Types : " + typeStr);
}
NucleusLogger.DATASTORE.debug("===========================================================");
}
}
use of org.datanucleus.store.rdbms.schema.RDBMSTypesInfo 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, "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, "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.RDBMSTypesInfo in project datanucleus-rdbms by datanucleus.
the class BaseDatastoreAdapter method addSQLTypeForJDBCType.
/**
* Convenience method for use by adapters to add their own fake JDBC/SQL types in where the JDBC driver doesn't provide some type.
* @param handler the schema handler managing the types
* @param mconn Connection to use
* @param jdbcTypeNumber The JDBC type
* @param sqlType The type info to use
* @param addIfNotPresent whether to add only if JDBC type not present
*/
protected void addSQLTypeForJDBCType(StoreSchemaHandler handler, ManagedConnection mconn, short jdbcTypeNumber, SQLTypeInfo sqlType, boolean addIfNotPresent) {
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 && !addIfNotPresent) {
// Already have this JDBC type so ignore
return;
} else if (jdbcType == null) {
// New JDBC type
jdbcType = new org.datanucleus.store.rdbms.schema.JDBCTypeInfo(jdbcTypeNumber);
types.addChild(jdbcType);
jdbcType.addChild(sqlType);
} else {
// Existing JDBC type so add SQL type
jdbcType.addChild(sqlType);
}
}
use of org.datanucleus.store.rdbms.schema.RDBMSTypesInfo in project datanucleus-rdbms by datanucleus.
the class BaseDatastoreAdapter method initialise.
public void initialise(StoreSchemaHandler handler, ManagedConnection mconn) {
// Initialise the datastore mappings for this datastore
RDBMSStoreManager storeMgr = (RDBMSStoreManager) handler.getStoreManager();
ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
loadDatastoreMappings(storeMgr.getNucleusContext().getPluginManager(), clr);
// Initialise any types, including artificial ones added for the datastore when not provided by the JDBC driver
initialiseTypes(handler, mconn);
RDBMSTypesInfo types = (RDBMSTypesInfo) handler.getSchemaData(mconn.getConnection(), "types", null);
Iterator<Map.Entry<Integer, String>> entryIter = supportedJdbcTypesById.entrySet().iterator();
while (entryIter.hasNext()) {
Map.Entry<Integer, String> entry = entryIter.next();
int jdbcType = entry.getKey();
if (types.getChild("" + jdbcType) == null) {
// JDBC type not supported by adapter so deregister the mapping. TODO Remove any entries from built-in types to avoid this
deregisterDatastoreMappingsForJDBCType(entry.getValue());
}
}
entryIter = unsupportedJdbcTypesById.entrySet().iterator();
while (entryIter.hasNext()) {
Map.Entry<Integer, String> entry = entryIter.next();
int jdbcType = entry.getKey();
if (types.getChild("" + jdbcType) == null) {
// JDBC type not supported by adapter so deregister the mapping. TODO Remove any entries from built-in types to avoid this
deregisterDatastoreMappingsForJDBCType(entry.getValue());
}
}
// Log the datastore mapping summary, for each Java type, showing the supported JDBC-types and SQL-types.
if (NucleusLogger.DATASTORE.isDebugEnabled()) {
Collection<String> javaTypes = new TreeSet<>(datastoreTypeMappingsByJavaType.keySet());
for (String javaType : javaTypes) {
DatastoreTypeMappings datastoreTypeMappings = datastoreTypeMappingsByJavaType.get(javaType);
if (NucleusLogger.DATASTORE.isDebugEnabled()) {
NucleusLogger.DATASTORE.debug(Localiser.msg("054009", javaType, StringUtils.collectionToString(datastoreTypeMappings.datastoreMappingByJdbcType.keySet()), StringUtils.collectionToString(datastoreTypeMappings.datastoreMappingBySqlType.keySet()), datastoreTypeMappings.defaultJdbcType, datastoreTypeMappings.defaultSqlType));
}
}
}
}
use of org.datanucleus.store.rdbms.schema.RDBMSTypesInfo 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(), "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);
}
}
Aggregations