Search in sources :

Example 26 with PersistenceNucleusContextImpl

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

the class BasicTest method testDependent.

/**
 * Test for defaulting of "dependent" attribute on a field and on a collection.
 */
public void testDependent() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdInh2 = mgr.getMetaDataForClass(Container.class, new ClassLoaderResolverImpl());
    AbstractMemberMetaData fmd = cmdInh2.getMetaDataForMember("members");
    // mmd doesn't have dependent attribute, so should default to false
    assertFalse(fmd.isDependent());
    assertFalse(fmd.getCollection().isDependentElement());
}
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) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 27 with PersistenceNucleusContextImpl

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

the class BasicTest method testMetaDataManagerI18N.

/**
 * Test for the MetaDataManager.
 */
public void testMetaDataManagerI18N() {
    JDOMetaDataHelper mdProc = new JDOMetaDataHelper();
    String filename = "/org/jpox/samples/i18n/UTF8.jdo";
    MetaDataManager mmgr1 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    MetaDataParser parser1 = new MetaDataParser(mmgr1, mmgr1.getNucleusContext().getPluginManager(), true, true);
    mmgr1.setValidate(false);
    FileMetaData fmd = (FileMetaData) parser1.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
    fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
    org.datanucleus.metadata.AbstractClassMetaData cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
    cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr1);
    cmd1.initialise(new ClassLoaderResolverImpl());
    MetaDataManager mmgr2 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mmgr2.setValidate(false);
    org.datanucleus.metadata.AbstractClassMetaData cmd = mmgr2.getMetaDataForClass(UTF8.class, new ClassLoaderResolverImpl());
    if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
        fail("i18n UTF-8 issues in parser");
    }
    filename = "/org/jpox/samples/i18n/ISO8859_2.jdo";
    MetaDataManager mmgr3 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    MetaDataParser parser3 = new MetaDataParser(mmgr3, mmgr3.getNucleusContext().getPluginManager(), true, true);
    mmgr3.setValidate(false);
    fmd = (FileMetaData) parser3.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
    fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
    MetaDataManager mmgr4 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mmgr4.setValidate(false);
    cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
    cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr4);
    cmd1.initialise(null);
    cmd = mmgr4.getMetaDataForClass(ISO8859_2.class, new ClassLoaderResolverImpl());
    if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
        fail("i18n ISO8859_2 issues in parser");
    }
}
Also used : JDOMetaDataHelper(org.datanucleus.api.jdo.metadata.JDOMetaDataHelper) ISO8859_2(org.jpox.samples.i18n.ISO8859_2) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataParser(org.datanucleus.metadata.xml.MetaDataParser) FileMetaData(org.datanucleus.metadata.FileMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 28 with PersistenceNucleusContextImpl

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

the class BasicTest method testPersistentProperties.

/**
 * Test that MetaData classes can be serialised.
 * Why we would ever want to serialise a MetaData definition is not known to me.
 * @throws Throwable
 */
/*public void testSerialization() throws Throwable
    {
        MetaDataManager mgr=new JDOMetaDataManager(new NucleusContext(new PersistenceConfiguration(){}));
        mgr.setValidate(false);
        AbstractClassMetaData cmdInh2 = mgr.getMetaDataForClass(Container.class, new ClassLoaderResolverImpl());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(cmdInh2);
        byte[] bytes = baos.toByteArray();

        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois;
        ois = new ObjectInputStream(bais);
        Object obj = ois.readObject();
        assertTrue(obj.toString().equals(cmdInh2.toString()));
    }*/
public void testPersistentProperties() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmd = mgr.getMetaDataForClass(Vampire.class, new ClassLoaderResolverImpl());
    assertEquals(FieldPersistenceModifier.NONE, cmd.getMetaDataForMember("_age").getPersistenceModifier());
    assertEquals(FieldPersistenceModifier.NONE, cmd.getMetaDataForMember("_name").getPersistenceModifier());
    assertEquals(FieldPersistenceModifier.PERSISTENT, cmd.getMetaDataForMember("name").getPersistenceModifier());
    assertEquals(FieldPersistenceModifier.PERSISTENT, cmd.getMetaDataForMember("age").getPersistenceModifier());
    cmd = mgr.getMetaDataForClass(Phantom.class, new ClassLoaderResolverImpl());
    assertEquals(2, cmd.getNoOfManagedMembers());
    assertEquals(FieldPersistenceModifier.PERSISTENT, cmd.getMetaDataForMember("name").getPersistenceModifier());
    assertEquals(FieldPersistenceModifier.PERSISTENT, cmd.getMetaDataForMember("age").getPersistenceModifier());
}
Also used : Phantom(org.datanucleus.samples.haunted.Phantom) 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 29 with PersistenceNucleusContextImpl

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

the class BasicTest method testFieldForeignKeyMetadata.

/**
 * Tests the foreign key declared in many forms
 */
public void testFieldForeignKeyMetadata() {
    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());
    AbstractClassMetaData cmdD3 = mgr.getMetaDataForClass(D3.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD4 = mgr.getMetaDataForClass(D4.class, new ClassLoaderResolverImpl());
    AbstractClassMetaData cmdD5 = mgr.getMetaDataForClass(D5.class, new ClassLoaderResolverImpl());
    // Foreign Key name
    assertEquals("FK1", cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName(), cmdD1.getMetaDataForManagedMemberAtAbsolutePosition(cmdD1.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName(), cmdD2.getMetaDataForManagedMemberAtAbsolutePosition(cmdD2.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName(), cmdD3.getMetaDataForManagedMemberAtAbsolutePosition(cmdD3.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName(), cmdD4.getMetaDataForManagedMemberAtAbsolutePosition(cmdD4.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName(), cmdD5.getMetaDataForManagedMemberAtAbsolutePosition(cmdD5.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getName());
    // Foreign Key delete action
    assertEquals(ForeignKeyAction.CASCADE.toString(), cmdD4.getMetaDataForManagedMemberAtAbsolutePosition(cmdD4.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getDeleteAction().toString());
    // D5 should be "restrict" since the DTD imposes a default of "restrict" when specifying the <foreign-key/> element so the
    // "delete-action" attribute is ignored.
    assertEquals(ForeignKeyAction.RESTRICT.toString(), cmdD5.getMetaDataForManagedMemberAtAbsolutePosition(cmdD5.getAbsolutePositionOfMember("name")).getForeignKeyMetaData().getDeleteAction().toString());
}
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 30 with PersistenceNucleusContextImpl

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

the class BasicTest method testPrimaryKeyMetadata.

/**
 * Tests the primary key
 */
public void testPrimaryKeyMetadata() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
    // Primary Key name
    assertEquals("THED0_PK", cmdD0.getPrimaryKeyMetaData().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)

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