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());
}
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);
}
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;
}
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;
}
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());
}
Aggregations