Search in sources :

Example 1 with TypeMetadata

use of javax.jdo.metadata.TypeMetadata in project tests by datanucleus.

the class JDOMetadataAPITest method testInheritanceAndDiscrim.

/**
 * Test for use of annotations with inherited classes and discriminator
 */
public void testInheritanceAndDiscrim() {
    TypeMetadata typemd = pmf.getMetadata(Room.class.getName());
    assertFalse(typemd.getDetachable());
    assertEquals(IdentityType.APPLICATION, typemd.getIdentityType());
    assertFalse(typemd.getEmbeddedOnly());
    assertTrue(typemd.getRequiresExtent());
    InheritanceMetadata inhmd = typemd.getInheritanceMetadata();
    assertNotNull(inhmd);
    assertEquals(InheritanceStrategy.NEW_TABLE, inhmd.getStrategy());
    DiscriminatorMetadata dismd = inhmd.getDiscriminatorMetadata();
    assertNotNull(dismd);
    assertEquals(DiscriminatorStrategy.VALUE_MAP, dismd.getStrategy());
    assertEquals("ROOM", dismd.getValue());
    TypeMetadata typemd2 = pmf.getMetadata(MeetingRoom.class.getName());
    assertFalse(typemd2.getDetachable());
    assertEquals(IdentityType.APPLICATION, typemd2.getIdentityType());
    assertFalse(typemd2.getEmbeddedOnly());
    assertTrue(typemd2.getRequiresExtent());
    InheritanceMetadata inhmd2 = typemd2.getInheritanceMetadata();
    assertNotNull(inhmd2);
    assertEquals(InheritanceStrategy.SUPERCLASS_TABLE, inhmd2.getStrategy());
    DiscriminatorMetadata dismd2 = inhmd2.getDiscriminatorMetadata();
    assertNotNull(dismd2);
    assertEquals(DiscriminatorStrategy.VALUE_MAP, dismd2.getStrategy());
    assertEquals("MEETING_ROOM", dismd2.getValue());
}
Also used : DiscriminatorMetadata(javax.jdo.metadata.DiscriminatorMetadata) TypeMetadata(javax.jdo.metadata.TypeMetadata) MeetingRoom(org.datanucleus.samples.annotations.models.company.MeetingRoom) InheritanceMetadata(javax.jdo.metadata.InheritanceMetadata) MeetingRoom(org.datanucleus.samples.annotations.models.company.MeetingRoom) Room(org.datanucleus.samples.annotations.models.company.Room)

Example 2 with TypeMetadata

use of javax.jdo.metadata.TypeMetadata in project tests by datanucleus.

the class JDOMetadataAPITest method testClassInPackageAndJDO.

/**
 * Simple test that checks that classes retrieved have a parent package etc
 */
public void testClassInPackageAndJDO() {
    TypeMetadata typemd = pmf.getMetadata(Computer.class.getName());
    PackageMetadata pmd = (PackageMetadata) typemd.getParent();
    assertNotNull("Package of class is null!", pmd);
    assertEquals("Package name is different to expected", Computer.class.getName().substring(0, Computer.class.getName().lastIndexOf('.')), pmd.getName());
    JDOMetadata jdomd = (JDOMetadata) pmd.getParent();
    assertNotNull("JDOMetadata of package is null!", jdomd);
}
Also used : TypeMetadata(javax.jdo.metadata.TypeMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) JDOMetadata(javax.jdo.metadata.JDOMetadata) Computer(org.datanucleus.samples.annotations.embedded.Computer)

Example 3 with TypeMetadata

use of javax.jdo.metadata.TypeMetadata in project motech by motech.

the class MetadataServiceImpl method getComboboxTableName.

@Override
public String getComboboxTableName(String entityClassName, String cbFieldName) {
    TypeMetadata typeMetadata = persistenceManagerFactory.getMetadata(entityClassName);
    if (typeMetadata == null) {
        throw new IllegalArgumentException("No type metadata found for " + entityClassName);
    }
    MemberMetadata cbMetadata = findMemberMetadata(typeMetadata, cbFieldName);
    if (cbMetadata == null) {
        throw new IllegalArgumentException("No member metadata for field " + cbFieldName + " in " + entityClassName);
    }
    final String tableName = cbMetadata.getTable();
    if (tableName == null) {
        throw new IllegalArgumentException("No table name specified for member " + cbFieldName + " in " + entityClassName);
    }
    return tableName;
}
Also used : TypeMetadata(javax.jdo.metadata.TypeMetadata) MemberMetadata(javax.jdo.metadata.MemberMetadata)

Example 4 with TypeMetadata

use of javax.jdo.metadata.TypeMetadata in project tests by datanucleus.

the class JDOMetadataAPITest method getIndexes.

/**
 * Return a list of the declared indexes at class and field level.
 * @param clazz The class to read the metadata from
 * @param uniqueFlag If true returns only the indexes that are marked as true. If false returns only indexes that
 * are NOT marked as unique.
 */
List<IndexMetadata> getIndexes(final Class<?> clazz, final boolean uniqueFlag) {
    final List<IndexMetadata> indexes = new ArrayList<IndexMetadata>();
    final TypeMetadata metadata = pmf.getMetadata(clazz.getName());
    // Class level
    final IndexMetadata[] indices = metadata.getIndices();
    if (indices != null) {
        for (final IndexMetadata indexMetadata : indices) {
            if ((uniqueFlag && indexMetadata.getUnique()) || (!uniqueFlag && !indexMetadata.getUnique())) {
                indexes.add(indexMetadata);
            }
        }
    }
    // Field level
    final MemberMetadata[] members = metadata.getMembers();
    for (final MemberMetadata memberMetadata : members) {
        final IndexMetadata indexMetadata = memberMetadata.getIndexMetadata();
        if (indexMetadata != null) {
            if ((uniqueFlag && indexMetadata.getUnique()) || (!uniqueFlag && !indexMetadata.getUnique())) {
                indexes.add(indexMetadata);
            }
        }
    }
    return indexes;
}
Also used : TypeMetadata(javax.jdo.metadata.TypeMetadata) ArrayList(java.util.ArrayList) MemberMetadata(javax.jdo.metadata.MemberMetadata) IndexMetadata(javax.jdo.metadata.IndexMetadata)

Example 5 with TypeMetadata

use of javax.jdo.metadata.TypeMetadata in project tests by datanucleus.

the class AnnotationTest method testMetaAnnotations.

/**
 * Test of meta-annotations.
 */
public void testMetaAnnotations() {
    // Check that metadata has been read in correctly
    TypeMetadata typeMD = pmf.getMetadata(MyMetaClass.class.getName());
    assertNotNull(typeMD);
    assertTrue(typeMD.getDetachable());
    assertFalse(typeMD.getCacheable());
    assertTrue(typeMD.getRequiresExtent());
    assertEquals(javax.jdo.annotations.IdentityType.DATASTORE, typeMD.getIdentityType());
}
Also used : MyMetaClass(org.datanucleus.samples.annotations.meta.MyMetaClass) TypeMetadata(javax.jdo.metadata.TypeMetadata)

Aggregations

TypeMetadata (javax.jdo.metadata.TypeMetadata)5 MemberMetadata (javax.jdo.metadata.MemberMetadata)2 ArrayList (java.util.ArrayList)1 DiscriminatorMetadata (javax.jdo.metadata.DiscriminatorMetadata)1 IndexMetadata (javax.jdo.metadata.IndexMetadata)1 InheritanceMetadata (javax.jdo.metadata.InheritanceMetadata)1 JDOMetadata (javax.jdo.metadata.JDOMetadata)1 PackageMetadata (javax.jdo.metadata.PackageMetadata)1 Computer (org.datanucleus.samples.annotations.embedded.Computer)1 MyMetaClass (org.datanucleus.samples.annotations.meta.MyMetaClass)1 MeetingRoom (org.datanucleus.samples.annotations.models.company.MeetingRoom)1 Room (org.datanucleus.samples.annotations.models.company.Room)1