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();
}
}
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());
}
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);
}
Aggregations