Search in sources :

Example 81 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class BasicTest method testMetaDataMultithreaded.

/**
 * Test for the MetaDataManager.
 */
public void testMetaDataMultithreaded() {
    final MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    ThreadGroup group = new ThreadGroup("tgroup");
    Thread[] threads = new Thread[500];
    final List<String> errors = new ArrayList<>();
    final Object lock = new Object();
    for (int i = 0; i < 500; i++) {
        threads[i] = new Thread(group, new Runnable() {

            public void run() {
                try {
                    synchronized (lock) {
                        lock.wait();
                    }
                } catch (InterruptedException e) {
                }
                try {
                    // this populate and initilize the class
                    mgr.getMetaDataForClass(Manager.class, new ClassLoaderResolverImpl()).isPopulated();
                } catch (Throwable e) {
                    e.printStackTrace();
                    errors.add(e.getMessage());
                }
            }
        });
    }
    for (int i = 0; i < 500; i++) {
        threads[i].start();
    }
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
    }
    synchronized (lock) {
        lock.notifyAll();
    }
    for (int i = 0; i < 500; i++) {
        try {
            threads[i].join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    assertEquals("Errors " + errors, 0, errors.size());
    org.datanucleus.metadata.AbstractClassMetaData cmd2 = mgr.getMetaDataForClass(Book.class, new ClassLoaderResolverImpl());
    if (cmd2 == null) {
        fail("Failed to load MetaData for org.jpox.samples.store.Book class");
    }
}
Also used : ArrayList(java.util.ArrayList) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) Manager(org.jpox.samples.models.company.Manager) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceManager(javax.jdo.PersistenceManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 82 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl 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 83 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl 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 84 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl 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 85 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationPlusXMLOverrideTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
    metaDataMgr = new JDOMetaDataManager(nucleusCtx);
    clr = new ClassLoaderResolverImpl();
}
Also used : PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)86 MetaDataManager (org.datanucleus.metadata.MetaDataManager)69 NucleusContext (org.datanucleus.NucleusContext)59 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)56 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 ClassMetaData (org.datanucleus.metadata.ClassMetaData)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)40 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)35 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)32 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)29 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)18 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)7 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)7 PackageMetaData (org.datanucleus.metadata.PackageMetaData)6 FetchPlan (org.datanucleus.FetchPlan)5 FetchPlanForClass (org.datanucleus.FetchPlanForClass)5 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)5 ArrayList (java.util.ArrayList)4