Search in sources :

Example 1 with JPOXIdentifierFactory

use of org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory 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(IdentifierFactory.PROPERTY_DEFAULT_CATALOG, catalogName);
        }
        if (schemaName != null) {
            props.put(IdentifierFactory.PROPERTY_DEFAULT_SCHEMA, schemaName);
        }
        String val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_CASE);
        props.put(IdentifierFactory.PROPERTY_REQUIRED_CASE, val != null ? val : getDefaultIdentifierCase());
        val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_WORD_SEPARATOR);
        if (val != null) {
            props.put(IdentifierFactory.PROPERTY_WORD_SEPARATOR, val);
        }
        val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_TABLE_PREFIX);
        if (val != null) {
            props.put(IdentifierFactory.PROPERTY_TABLE_PREFIX, val);
        }
        val = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_TABLE_SUFFIX);
        if (val != null) {
            props.put(IdentifierFactory.PROPERTY_TABLE_SUFFIX, val);
        }
        props.put(IdentifierFactory.PROPERTY_NAMING_FACTORY, getNamingFactory());
        // Create the IdentifierFactory
        ClassLoaderResolver clr = nucleusContext.getClassLoaderResolver(null);
        if ("datanucleus2".equalsIgnoreCase(idFactoryName)) {
            identifierFactory = new DN2IdentifierFactory(dba, clr, props);
        } else if ("jpa".equalsIgnoreCase(idFactoryName) || "jakarta".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)

Example 2 with JPOXIdentifierFactory

use of org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory in project tests by datanucleus.

the class IdentifierFactoryTest method testJPOXTruncate.

/**
 * Verify that JPOXIdentifierFactory does truncation with a 2-character hashcode, as was done in JPOX
 * 1.2.0 (this had been changed to 4-character hashcode in datanucleus)
 */
public void testJPOXTruncate() {
    class SubclassForTesting extends JPOXIdentifierFactory {

        private SubclassForTesting(DatastoreAdapter dba, ClassLoaderResolver clr, Map props) {
            super(dba, clr, props);
        }

        public String publicTestTruncate(String string, int length) {
            return truncate(string, length);
        }
    }
    RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
    SubclassForTesting jpoxCompatibilityIdentifierFactory = new SubclassForTesting(srm.getDatastoreAdapter(), new ClassLoaderResolverImpl(), new Properties());
    assertEquals("BIDIR_CONTAINED_LEVEL2_I2S", jpoxCompatibilityIdentifierFactory.publicTestTruncate("BIDIR_CONTAINED_LEVEL2_INTEGER", 26).toUpperCase());
}
Also used : JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 3 with JPOXIdentifierFactory

use of org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory in project tests by datanucleus.

the class IdentifierFactoryTest method testJPOX.

/**
 * Verify that putting "datanucleus.identifierFactory=jpox" results in JPOXIdentifierFactory being used
 */
public void testJPOX() {
    Properties props = new Properties();
    props.put("datanucleus.identifierFactory", "jpox");
    PersistenceManagerFactory pmf2 = getPMF(1, props);
    PersistenceManager pm = pmf2.getPersistenceManager();
    ExecutionContext ec = ((JDOPersistenceManager) pm).getExecutionContext();
    IdentifierFactory identifierFactory = ((RDBMSStoreManager) ec.getStoreManager()).getIdentifierFactory();
    assertTrue(identifierFactory instanceof JPOXIdentifierFactory);
}
Also used : JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) ExecutionContext(org.datanucleus.ExecutionContext) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) Properties(java.util.Properties) JPOXIdentifierFactory(org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory) IdentifierFactory(org.datanucleus.store.rdbms.identifier.IdentifierFactory) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

JPOXIdentifierFactory (org.datanucleus.store.rdbms.identifier.JPOXIdentifierFactory)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)2 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)2 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PersistenceManager (javax.jdo.PersistenceManager)1 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)1 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)1 ExecutionContext (org.datanucleus.ExecutionContext)1 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)1 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusException (org.datanucleus.exceptions.NucleusException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1