use of javax.jdo.metadata.MemberMetadata in project tests by datanucleus.
the class JDOMetadataAPITest method assertFields.
private void assertFields(final Class<?> clazz, final List<IndexMetadata> indexes, final String... fieldNames) {
if (fieldNames == null) {
assertTrue("More indices than expected returned! " + clazz.getSimpleName(), indexes.isEmpty());
} else {
assertFalse("More indices than expected returned! " + clazz.getSimpleName(), indexes.size() > fieldNames.length);
Set<String> indexesNames = new HashSet<String>();
for (final IndexMetadata indexMetada : indexes) {
MemberMetadata[] members = indexMetada.getMembers();
if (members == null) {
FieldMetadata fieldMetadata = (FieldMetadata) indexMetada.getParent();
indexesNames.add(fieldMetadata.getName());
} else {
for (MemberMetadata memberMetadata : members) {
memberMetadata.getIndexMetadata();
indexesNames.add(memberMetadata.getName());
}
}
}
for (final String name : fieldNames) {
assertTrue("Index not returned: " + name, indexesNames.contains(name));
}
}
}
use of javax.jdo.metadata.MemberMetadata 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.MemberMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method fixRelationMetadata.
private void fixRelationMetadata(PackageMetadata pmd, EntityDto entity, FieldDto field) {
RelationshipHolder holder = new RelationshipHolder(field);
// this must be set here cause we can't get related class metadata before metadata enhancement
if (shouldSetCascadeDelete(holder, EntityType.STANDARD)) {
String relatedClass = ClassName.getSimpleName(holder.getRelatedClass());
MemberMetadata rfmd = getFieldMetadata(getClassMetadata(pmd, relatedClass), holder.getRelatedField());
ForeignKeyMetadata rfkmd = getOrCreateRelFkMetadata(rfmd, entity, field);
rfkmd.setDeleteAction(ForeignKeyAction.CASCADE);
}
}
use of javax.jdo.metadata.MemberMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method fixEnhancerIssuesInMetadata.
@Override
public void fixEnhancerIssuesInMetadata(JDOMetadata jdoMetadata, SchemaHolder schemaHolder) {
for (PackageMetadata pmd : jdoMetadata.getPackages()) {
for (ClassMetadata cmd : pmd.getClasses()) {
String className = String.format("%s.%s", pmd.getName(), cmd.getName());
EntityType entityType = EntityType.forClassName(className);
if (entityType == EntityType.STANDARD) {
EntityDto entity = schemaHolder.getEntityByClassName(className);
if (null != entity) {
for (MemberMetadata mmd : cmd.getMembers()) {
CollectionMetadata collMd = mmd.getCollectionMetadata();
FieldDto field = schemaHolder.getFieldByName(entity, mmd.getName());
if (null != collMd) {
fixCollectionMetadata(collMd, field);
}
if (null != field && field.getType().isRelationship()) {
fixRelationMetadata(pmd, entity, field);
}
// Defining column name for join and element results in setting it both as XML attribute and child element
fixDuplicateColumnDefinitions(mmd);
}
}
}
}
}
}
use of javax.jdo.metadata.MemberMetadata 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;
}
Aggregations