use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class PersistentDescriptorFactory method getDescriptor.
protected ClassDescriptor getDescriptor(ObjEntity entity, Class<?> entityClass) {
String superEntityName = entity.getSuperEntityName();
ClassDescriptor superDescriptor = (superEntityName != null) ? descriptorMap.getDescriptor(superEntityName) : null;
PersistentDescriptor descriptor = createDescriptor();
descriptor.setEntity(entity);
descriptor.setSuperclassDescriptor(superDescriptor);
descriptor.setObjectClass(entityClass);
descriptor.setPersistenceStateAccessor(new BeanAccessor(entityClass, "persistenceState", Integer.TYPE));
// only include this entity attributes and skip superclasses...
for (ObjAttribute attribute : descriptor.getEntity().getDeclaredAttributes()) {
if (attribute instanceof EmbeddedAttribute) {
EmbeddedAttribute embedded = (EmbeddedAttribute) attribute;
for (ObjAttribute objAttribute : embedded.getAttributes()) {
createEmbeddedAttributeProperty(descriptor, embedded, objAttribute);
}
} else {
createAttributeProperty(descriptor, attribute);
}
}
// only include this entity relationships and skip superclasses...
for (ObjRelationship relationship : descriptor.getEntity().getDeclaredRelationships()) {
if (relationship.isToMany()) {
String collectionType = relationship.getCollectionType();
if (collectionType == null || ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(collectionType)) {
createToManyListProperty(descriptor, relationship);
} else if ("java.util.Map".equals(collectionType)) {
createToManyMapProperty(descriptor, relationship);
} else if ("java.util.Set".equals(collectionType)) {
createToManySetProperty(descriptor, relationship);
} else if ("java.util.Collection".equals(collectionType)) {
createToManyCollectionProperty(descriptor, relationship);
} else {
throw new IllegalArgumentException("Unsupported to-many collection type: " + collectionType);
}
} else {
createToOneProperty(descriptor, relationship);
}
}
EntityInheritanceTree inheritanceTree = descriptorMap.getResolver().getInheritanceTree(descriptor.getEntity().getName());
descriptor.setEntityInheritanceTree(inheritanceTree);
indexSubclassDescriptors(descriptor, inheritanceTree);
indexQualifiers(descriptor, inheritanceTree);
appendDeclaredRootDbEntity(descriptor, descriptor.getEntity());
indexRootDbEntities(descriptor, inheritanceTree);
indexSuperclassProperties(descriptor);
descriptor.sortProperties();
return descriptor;
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class PersistentDescriptorResultMetadata method addObjectField.
/**
* Adds a result set column mapping for a single object property of a
* specified entity that may differ from the root entity if inheritance is
* involved.
*/
void addObjectField(String entityName, String attributeName, String column) {
ObjEntity entity = classDescriptor.getEntity().getDataMap().getObjEntity(entityName);
ObjAttribute attribute = entity.getAttribute(attributeName);
fields.put(attribute.getDbAttributePath(), column);
reverseFields.put(column, attribute.getDbAttributePath());
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class DbAttributePathComboBoxEditor method createTreeModelForComboBox.
@Override
protected EntityTreeModel createTreeModelForComboBox(int attributeIndexInTable) {
ObjAttribute attribute = model.getAttribute(attributeIndexInTable).getValue();
Entity firstEntity = null;
if (attribute.getDbAttribute() == null) {
if (attribute.getParent() instanceof ObjEntity) {
DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
if (dbEnt != null) {
Collection<DbAttribute> attributes = dbEnt.getAttributes();
Collection<DbRelationship> rel = dbEnt.getRelationships();
if (!attributes.isEmpty()) {
Iterator<DbAttribute> iterator = attributes.iterator();
firstEntity = iterator.next().getEntity();
} else if (!rel.isEmpty()) {
Iterator<DbRelationship> iterator = rel.iterator();
firstEntity = iterator.next().getSourceEntity();
}
}
}
} else {
firstEntity = getFirstEntity(attribute);
}
if (firstEntity != null) {
EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
return treeModel;
}
return null;
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ProjectUtil method findObjAttributesForDbRelationship.
public static Collection<ObjAttribute> findObjAttributesForDbRelationship(ProjectController mediator, DbRelationship relationship) {
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
List<ObjAttribute> attributes = new ArrayList<>();
String[] dbAttrPathByDot;
if (domain != null) {
for (DataMap map : domain.getDataMaps()) {
for (ObjEntity entity : map.getObjEntities()) {
for (ObjAttribute objAttribute : entity.getAttributes()) {
if (objAttribute.getDbAttributePath() != null) {
dbAttrPathByDot = objAttribute.getDbAttributePath().split(Pattern.quote("."));
for (String partOfPath : dbAttrPathByDot) {
if (partOfPath.equals(relationship.getName())) {
attributes.add(objAttribute);
}
}
}
}
}
}
}
return attributes;
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class EOModelProcessorTest method testLoadModelWithDependencies.
@Test
public void testLoadModelWithDependencies() throws Exception {
URL url = getClass().getClassLoader().getResource("wotests/cross-model-relationships.eomodeld/");
assertNotNull(url);
DataMap map = processor.loadEOModel(url);
ObjEntity entity = map.getObjEntity("CrossModelRelTest");
assertNotNull(entity);
ObjAttribute a1 = entity.getAttribute("testAttribute");
assertNotNull(a1);
DbAttribute da1 = a1.getDbAttribute();
assertNotNull(da1);
assertSame(da1, entity.getDbEntity().getAttribute("TEST_ATTRIBUTE"));
// for now cross model relationships are simply ignored
// eventually we must handle those...
assertEquals(0, entity.getRelationships().size());
assertEquals(0, entity.getDbEntity().getRelationships().size());
}
Aggregations