use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationPlusXMLTest method testMapKeyColumn.
/**
* Test of JPA @MapKeyColumn.
*/
public void testMapKeyColumn() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
assertEquals("phoneNumbers_key1", cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getColumnMetaData()[0].getName());
assertTrue(cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getColumnMetaData()[0].getUnique());
}
use of org.datanucleus.ClassLoaderResolver 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.ClassLoaderResolver 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.ClassLoaderResolver 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.ClassLoaderResolver in project tests by datanucleus.
the class SchemaHandlerTest method testForeignKeyRetrieval.
/**
* Test of the retrieval of FKs.
*/
public void testForeignKeyRetrieval() {
addClassesToSchema(new Class[] { SchemaClass1.class, SchemaClass2.class });
PersistenceManager pm = pmf.getPersistenceManager();
RDBMSStoreManager databaseMgr = (RDBMSStoreManager) storeMgr;
// Retrieve the table for SchemaClass1
ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
DatastoreClass table1 = databaseMgr.getDatastoreClass(SchemaClass1.class.getName(), clr);
// Check for the FK using the schema handler
StoreSchemaHandler handler = databaseMgr.getSchemaHandler();
Connection con = (Connection) databaseMgr.getConnectionManager().getConnection(((JDOPersistenceManager) pm).getExecutionContext()).getConnection();
RDBMSTableFKInfo fkInfo = (RDBMSTableFKInfo) handler.getSchemaData(con, "foreign-keys", new Object[] { table1 });
// Expecting single FK between SchemaClass1.other and SchemaClass2
assertEquals("Number of FKs for table " + table1 + " is wrong", 1, fkInfo.getNumberOfChildren());
// Check the FK details
ForeignKeyInfo fk = (ForeignKeyInfo) fkInfo.getChild(0);
assertEquals("FK Name is wrong", "TABLE1_FK1", ((String) fk.getProperty("fk_name")).toUpperCase());
assertEquals("PK Table Name is wrong", "SCHEMA_TABLE_2", ((String) fk.getProperty("pk_table_name")).toUpperCase());
assertEquals("FK Table Name is wrong", "SCHEMA_TABLE_1", ((String) fk.getProperty("fk_table_name")).toUpperCase());
assertEquals("PK Column Name is wrong", "TABLE2_ID", ((String) fk.getProperty("pk_column_name")).toUpperCase());
assertEquals("FK Column Name is wrong", "OTHER_ID", ((String) fk.getProperty("fk_column_name")).toUpperCase());
}
Aggregations