use of org.datanucleus.metadata.AbstractClassMetaData in project motech by motech.
the class StateManagerUtil method setTransactionVersion.
/**
* Sets the given transaction version to the instance state manager.
*
* @param instance the instance from which state manager will be retrieved
* @param version the transaction version
* @param versionFieldName the name of the version field
*/
public static void setTransactionVersion(Object instance, Object version, String versionFieldName) {
try {
StateManagerImpl stateManager = getStateManager(instance);
stateManager.setVersion(version);
AbstractClassMetaData cmd = stateManager.getClassMetaData();
int fieldPosition = cmd.getAbsolutePositionOfMember(versionFieldName);
boolean[] dirtyFields = getDirtyFields(stateManager);
// we must mark version field as non dirty
dirtyFields[fieldPosition] = false;
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new MdsException("Cannot set proper transaction version", e);
}
}
use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class JPANamingFactoryTest method testDatastoreIdColumnName.
public void testDatastoreIdColumnName() {
JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
NucleusContext nucCtx = jpaEMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(MyDatastoreId.class, clr);
NamingFactory factory = new JPANamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Column name for datastore-id is incorrect", "mydatastoreid_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class JPANamingFactoryTest method testVersionColumnName.
public void testVersionColumnName() {
JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
NucleusContext nucCtx = jpaEMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Trade4.class, clr);
NamingFactory factory = new JPANamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Column name for version is incorrect", "version", factory.getColumnName(cmd1, ColumnType.VERSION_COLUMN));
}
use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class JPANamingFactoryTest method testTableName.
public void testTableName() {
JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
NucleusContext nucCtx = jpaEMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(ByteArray.class, clr);
NamingFactory factory = new JPANamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.TABLE, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Table name is incorrect", "bytearray", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.LOWER_CASE_QUOTED);
assertEquals("Table name is incorrect", "\"bytearray\"", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.UPPER_CASE);
assertEquals("Table name is incorrect", "BYTEARRAY", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.UPPER_CASE_QUOTED);
assertEquals("Table name is incorrect", "\"BYTEARRAY\"", factory.getTableName(cmd1));
AbstractClassMetaData cmd2 = mmgr.getMetaDataForClass(SimpleClass.class, clr);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Table name is incorrect", "mysimpleclass", factory.getTableName(cmd2));
}
use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class ConvertersTest method testUseOfPersistentConverter.
/**
* Test the use of "@Persistent(converter="...")" annotation on a field.
*/
public void testUseOfPersistentConverter() {
try {
PersistenceNucleusContext nucCtx = ((JDOPersistenceManagerFactory) pmf).getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
AbstractClassMetaData cmd = nucCtx.getMetaDataManager().getMetaDataForClass(PersonWithConverters.class, clr);
// Check the converter is registered with metadata
AbstractMemberMetaData mmd = cmd.getMetaDataForMember("myBool1");
assertNotNull(mmd);
assertTrue(mmd.hasExtension("type-converter-name"));
String converterName = mmd.getValueForExtension("type-converter-name");
assertEquals("org.datanucleus.samples.converters.Boolean10Converter", converterName);
// Check the correct mapping is chosen for this field
RDBMSStoreManager storeMgr = (RDBMSStoreManager) nucCtx.getStoreManager();
DatastoreClass tbl = storeMgr.getDatastoreClass(PersonWithConverters.class.getName(), clr);
JavaTypeMapping mapping = tbl.getMemberMapping(mmd);
assertTrue(mapping instanceof TypeConverterMapping);
} catch (Exception e) {
LOG.error("Exception during test", e);
fail("Exception was thrown : " + e.getMessage());
} finally {
}
}
Aggregations