use of org.datanucleus.store.rdbms.identifier.DNIdentifierFactory in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method initialiseIdentifierFactory.
/**
* Method to create the IdentifierFactory to be used by this store.
* Relies on the datastore adapter existing before creation
* @param nucleusContext context
*/
protected void initialiseIdentifierFactory(NucleusContext nucleusContext) {
if (dba == null) {
throw new NucleusException("DatastoreAdapter not yet created so cannot create IdentifierFactory!");
}
String idFactoryName = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_FACTORY);
try {
// Create the control properties for identifier generation
Map props = new HashMap();
if (catalogName != null) {
props.put("DefaultCatalog", catalogName);
}
if (schemaName != null) {
props.put("DefaultSchema", schemaName);
}
String val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_CASE);
props.put("RequiredCase", val != null ? val : getDefaultIdentifierCase());
val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_WORD_SEPARATOR);
if (val != null) {
props.put("WordSeparator", val);
}
val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_TABLE_PREFIX);
if (val != null) {
props.put("TablePrefix", val);
}
val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_TABLE_SUFFIX);
if (val != null) {
props.put("TableSuffix", val);
}
props.put("NamingFactory", getNamingFactory());
// Create the IdentifierFactory
ClassLoaderResolver clr = nucleusContext.getClassLoaderResolver(null);
if ("datanucleus2".equalsIgnoreCase(idFactoryName)) {
identifierFactory = new DN2IdentifierFactory(dba, clr, props);
} else if ("jpa".equalsIgnoreCase(idFactoryName)) {
identifierFactory = new JPAIdentifierFactory(dba, clr, props);
} else if ("datanucleus1".equalsIgnoreCase(idFactoryName)) {
identifierFactory = new DNIdentifierFactory(dba, clr, props);
} else if ("jpox".equalsIgnoreCase(idFactoryName)) {
identifierFactory = new JPOXIdentifierFactory(dba, clr, props);
} else {
// Fallback to the plugin mechanism
Class[] argTypes = new Class[] { DatastoreAdapter.class, ClassConstants.CLASS_LOADER_RESOLVER, Map.class };
Object[] args = new Object[] { dba, nucleusContext.getClassLoaderResolver(null), props };
identifierFactory = (IdentifierFactory) nucleusContext.getPluginManager().createExecutableExtension("org.datanucleus.store.rdbms.identifierfactory", "name", idFactoryName, "class-name", argTypes, args);
}
} catch (ClassNotFoundException cnfe) {
throw new NucleusUserException(Localiser.msg("039004", idFactoryName), cnfe).setFatal();
} catch (Exception e) {
NucleusLogger.PERSISTENCE.error("Exception creating IdentifierFactory", e);
throw new NucleusException(Localiser.msg("039005", idFactoryName), e).setFatal();
}
}
Aggregations