Search in sources :

Example 1 with JPAIdentifierFactory

use of org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory 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();
    }
}
Also used : JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DN2IdentifierFactory(org.datanucleus.store.rdbms.identifier.DN2IdentifierFactory) MacroString(org.datanucleus.util.MacroString) DN2IdentifierFactory(org.datanucleus.store.rdbms.identifier.DN2IdentifierFactory) JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) DNIdentifierFactory(org.datanucleus.store.rdbms.identifier.DNIdentifierFactory) IdentifierFactory(org.datanucleus.store.rdbms.identifier.IdentifierFactory) JPAIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory) SQLException(java.sql.SQLException) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) IOException(java.io.IOException) NucleusException(org.datanucleus.exceptions.NucleusException) UnsupportedDataTypeException(org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException) NoTableManagedException(org.datanucleus.store.rdbms.exceptions.NoTableManagedException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) IncompatibleFieldTypeException(org.datanucleus.store.types.IncompatibleFieldTypeException) DNIdentifierFactory(org.datanucleus.store.rdbms.identifier.DNIdentifierFactory) JPAIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map) MultiMap(org.datanucleus.util.MultiMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusException (org.datanucleus.exceptions.NucleusException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 NoTableManagedException (org.datanucleus.store.rdbms.exceptions.NoTableManagedException)1 UnsupportedDataTypeException (org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException)1 DN2IdentifierFactory (org.datanucleus.store.rdbms.identifier.DN2IdentifierFactory)1 DNIdentifierFactory (org.datanucleus.store.rdbms.identifier.DNIdentifierFactory)1 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)1 JPAIdentifierFactory (org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory)1 JPOXIdentifierFactory (org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory)1 IncompatibleFieldTypeException (org.datanucleus.store.types.IncompatibleFieldTypeException)1 MacroString (org.datanucleus.util.MacroString)1 MultiMap (org.datanucleus.util.MultiMap)1