Search in sources :

Example 96 with AbstractClassMetaData

use of org.datanucleus.metadata.AbstractClassMetaData 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 97 with AbstractClassMetaData

use of org.datanucleus.metadata.AbstractClassMetaData 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 98 with AbstractClassMetaData

use of org.datanucleus.metadata.AbstractClassMetaData 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 99 with AbstractClassMetaData

use of org.datanucleus.metadata.AbstractClassMetaData 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)

Example 100 with AbstractClassMetaData

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

the class BasicTest method testLoadingMetaDataForPackage.

/**
 * Tests the loading of XML metadata specified in package,jdo.
 */
public void testLoadingMetaDataForPackage() {
    MetaDataManager mmgr = new PersistenceNucleusContextImpl("JDO", null).getMetaDataManager();
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    // Validate metadata for DateWidget
    AbstractClassMetaData cmd = mmgr.getMetaDataForClass(DateWidget.class, clr);
    assertNotNull("ClassMetaData is null!", cmd);
    assertEquals("Class name", DateWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    assertNotNull("Inheritance", cmd.getInheritanceMetaData());
    assertEquals("Inheritance strategy", cmd.getInheritanceMetaData().getStrategy().toString(), "new-table");
    String[] sortedFieldNames = new String[] { "dateField", "dateJdbcTimestampField", "sqlDateField", "sqlTimestampField" };
    Assert.assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        assertEquals(s, fmd.getName());
        assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        assertEquals(s + " null value handling", NullValue.NONE, fmd.getNullValue());
        assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        assertNull(s + " collection metadata", fmd.getContainer());
        assertNull(s + " map metadata", fmd.getContainer());
    }
    // Validate metadata for FloatWidget
    cmd = mmgr.getMetaDataForClass(FloatWidget.class, clr);
    assertNotNull("Metadata", cmd);
    assertEquals("Class name", FloatWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    sortedFieldNames = new String[] { "doubleField", "doubleObjField", "floatField", "floatObjField" };
    NullValue[] nullValueHandlings = new NullValue[] { NullValue.EXCEPTION, NullValue.NONE, NullValue.EXCEPTION, NullValue.NONE };
    assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        Assert.assertEquals(s, fmd.getName());
        Assert.assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        Assert.assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        Assert.assertEquals(s + " null value handling", nullValueHandlings[i], fmd.getNullValue());
        Assert.assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        Assert.assertNull(s + " collection metadata", fmd.getContainer());
        Assert.assertNull(s + " map metadata", fmd.getContainer());
    }
}
Also used : FloatWidget(org.datanucleus.samples.widget.FloatWidget) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DateWidget(org.datanucleus.samples.widget.DateWidget) LevelAboveWidget(org.datanucleus.samples.widget.LevelAboveWidget) DateWidget(org.datanucleus.samples.widget.DateWidget) FloatWidget(org.datanucleus.samples.widget.FloatWidget) Widget(org.datanucleus.samples.widget.Widget) PackageClassWidget(org.datanucleus.samples.widget.PackageClassWidget) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) NullValue(org.datanucleus.metadata.NullValue) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)204 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)90 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)69 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)59 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)55 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)42 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)42 NucleusException (org.datanucleus.exceptions.NucleusException)37 MetaDataManager (org.datanucleus.metadata.MetaDataManager)37 ArrayList (java.util.ArrayList)31 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)26 SQLTable (org.datanucleus.store.rdbms.sql.SQLTable)23 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)22 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)19 MapTable (org.datanucleus.store.rdbms.table.MapTable)18 List (java.util.List)16 ObjectProvider (org.datanucleus.state.ObjectProvider)16 PersistableMapping (org.datanucleus.store.rdbms.mapping.java.PersistableMapping)16 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)16 Iterator (java.util.Iterator)15