Search in sources :

Example 96 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class BasicTest method testDatastoreIdentityMetadata.

/**
 * Tests datastore identity declared in many forms
 */
public void testDatastoreIdentityMetadata() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
    assertEquals("identity", cmdD0.getIdentityMetaData().getValueStrategy().toString());
    assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD1.getIdentityMetaData().getValueStrategy());
    assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD2.getIdentityMetaData().getValueStrategy());
    assertEquals("D_ID", cmdD0.getIdentityMetaData().getColumnMetaData().getName());
    assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD1.getIdentityMetaData().getColumnMetaData().getName());
    assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD2.getIdentityMetaData().getColumnMetaData().getName());
}
Also used : JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 97 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class BasicTest method testFieldColumnMetadata.

/**
 * Tests the column field declared in many forms
 */
public void testFieldColumnMetadata() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
    assertEquals("NNN", cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD1.getMetaDataForManagedMemberAtAbsolutePosition(cmdD1.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD2.getMetaDataForManagedMemberAtAbsolutePosition(cmdD2.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
}
Also used : JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 98 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class BasicTest method testFieldDeclaredInSubClassMetadata.

/**
 * Tests a field declared in the metadata of a subclass, like Subclass.field
 */
public void testFieldDeclaredInSubClassMetadata() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(Pet.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(Dog.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(Cat.class, new ClassLoaderResolverImpl());
    assertNotNull(cmdD0.getMetaDataForMember("name"));
    assertNotNull(cmdD1.getMetaDataForMember("name"));
    assertEquals("dog", cmdD1.getMetaDataForMember("name").getColumnMetaData()[0].getName());
    assertNotNull(cmdD2.getMetaDataForMember("name"));
    assertEquals("cat", cmdD2.getMetaDataForMember("name").getColumnMetaData()[0].getName());
}
Also used : JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 99 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class DN2NamingFactoryTest method testEmbeddedCollectionColumnNames.

/**
 * Test where the sample has embedded collection element.
 */
public void testEmbeddedCollectionColumnNames() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    AbstractClassMetaData networkCmd = mmgr.getMetaDataForClass(Network.class, clr);
    AbstractMemberMetaData devicesMmd = networkCmd.getMetaDataForMember("devices");
    AbstractClassMetaData deviceCmd = mmgr.getMetaDataForClass(Device.class, clr);
    AbstractMemberMetaData deviceNameMmd = deviceCmd.getMetaDataForMember("name");
    AbstractMemberMetaData deviceDescMmd = deviceCmd.getMetaDataForMember("description");
    List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
    colMmds.add(devicesMmd);
    colMmds.add(deviceNameMmd);
    String colName = factory.getColumnName(colMmds, 0);
    assertEquals("device_name", colName);
    colMmds.clear();
    colMmds.add(devicesMmd);
    colMmds.add(deviceDescMmd);
    colName = factory.getColumnName(colMmds, 0);
    assertEquals("devices_description", colName);
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ArrayList(java.util.ArrayList) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 100 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class DN2NamingFactoryTest method testDatastoreIdColumnName.

public void testDatastoreIdColumnName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Gym.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Column name for datastore-id is incorrect", "gym_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Aggregations

MetaDataManager (org.datanucleus.metadata.MetaDataManager)102 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)72 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)69 NucleusContext (org.datanucleus.NucleusContext)65 ClassMetaData (org.datanucleus.metadata.ClassMetaData)55 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)41 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)40 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)31 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)19 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 ArrayList (java.util.ArrayList)11 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)9 PackageMetaData (org.datanucleus.metadata.PackageMetaData)8 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 FetchPlanForClass (org.datanucleus.FetchPlanForClass)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6