expressionFactory = new SQLExpressionFactory(this);
// Retrieve the Database Adapter for this datastore
try
{
ManagedConnection mc = getConnection(-1);
Connection conn = (Connection)mc.getConnection();
if (conn == null)
{
//somehow we haven't got an exception from the JDBC driver
//to troubleshoot the user should telnet to ip/port of database and check if he can open a connection
//this may be due to security / firewall things.
throw new NucleusDataStoreException(LOCALISER_RDBMS.msg("050007"));
}
try
{
dba = RDBMSAdapterFactory.getInstance().getDatastoreAdapter(clr, conn,
getStringProperty("datanucleus.rdbms.datastoreAdapterClassName"),
ctx.getPluginManager());
dba.initialiseTypes(schemaHandler, mc);
dba.removeUnsupportedMappings(schemaHandler, mc);
// User specified default catalog/schema name - check for validity, and store
if (hasPropertyNotNull("datanucleus.mapping.Catalog"))
{
if (!((RDBMSAdapter)dba).supportsOption(RDBMSAdapter.CATALOGS_IN_TABLE_DEFINITIONS))
{
NucleusLogger.DATASTORE.warn(LOCALISER_RDBMS.msg("050002",
getStringProperty("datanucleus.mapping.Catalog")));
}
else
{
catalogName = getStringProperty("datanucleus.mapping.Catalog");
}
}
if (hasPropertyNotNull("datanucleus.mapping.Schema"))
{
if (!((RDBMSAdapter)dba).supportsOption(DatastoreAdapter.SCHEMAS_IN_TABLE_DEFINITIONS))
{
NucleusLogger.DATASTORE.warn(LOCALISER_RDBMS.msg("050002",
getStringProperty("datanucleus.mapping.Schema")));
}
else
{
schemaName = getStringProperty("datanucleus.mapping.Schema");
}
}
// Create an identifier factory - needs the database adapter to exist first
initialiseIdentifierFactory(ctx);
// Now that we have the identifier factory, make sure any user-provided names were valid!
if (schemaName != null)
{
String validSchemaName = identifierFactory.getIdentifierInAdapterCase(schemaName);
if (!validSchemaName.equals(schemaName))
{
NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER_RDBMS.msg("020192", "schema", schemaName, validSchemaName));
schemaName = validSchemaName;
}
}
if (catalogName != null)
{
String validCatalogName = identifierFactory.getIdentifierInAdapterCase(catalogName);
if (!validCatalogName.equals(catalogName))
{
NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER_RDBMS.msg("020192", "catalog", catalogName, validCatalogName));
catalogName = validCatalogName;
}
}
// Create the SQL controller
sqlController = new SQLController(((RDBMSAdapter)dba).supportsOption(RDBMSAdapter.STATEMENT_BATCHING),
getIntProperty("datanucleus.rdbms.statementBatchLimit"),
getIntProperty("datanucleus.datastoreReadTimeout"),
getBooleanProperty("datanucleus.rdbms.sqlParamValuesInBrackets"));
// TODO These ought to be stored with the StoreManager, not the NucleusContext
// Initialise any properties controlling the adapter
// Just use properties matching the pattern "datanucleus.rdbms.adapter.*"
Map<String, Object> dbaProps = new HashMap();
Map<String, Object> omfProps = ctx.getPersistenceConfiguration().getPersistenceProperties();
Iterator<Map.Entry<String, Object>> propIter = omfProps.entrySet().iterator();
while (propIter.hasNext())
{
Map.Entry<String, Object> entry = propIter.next();
String prop = entry.getKey();
if (prop.startsWith("datanucleus.rdbms.adapter."))
{
dbaProps.put(prop, entry.getValue());
}
}
if (dbaProps.size() > 0)
{
dba.setProperties(dbaProps);
}
// Initialise the Schema
initialiseSchema(conn, clr);
// Log the configuration of the RDBMS
logConfiguration();
}
finally
{
mc.close();
}
}
catch (NucleusException ne)
{
NucleusLogger.DATASTORE_SCHEMA.error(LOCALISER_RDBMS.msg("050004"), ne);