Search in sources :

Example 61 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.

the class UpgradeHandler_V7Test method testModelUpgrade.

@Test
public void testModelUpgrade() throws Exception {
    DataChannelDescriptor descriptor = mock(DataChannelDescriptor.class);
    DataMap map = new DataMap();
    when(descriptor.getDataMaps()).thenReturn(Collections.singletonList(map));
    ObjEntity superEntity = new ObjEntity("super");
    superEntity.addAttribute(new ObjAttribute("super"));
    superEntity.addAttribute(new ObjAttribute("simple"));
    map.addObjEntity(superEntity);
    ObjEntity subEntity = new ObjEntity("sub");
    subEntity.setSuperEntityName("super");
    subEntity.addAttribute(new ObjAttribute("super"));
    subEntity.addAttribute(new ObjAttribute("simple_sub"));
    map.addObjEntity(subEntity);
    assertNotNull(superEntity.getDeclaredAttribute("super"));
    assertNotNull(subEntity.getDeclaredAttribute("super"));
    handler.processModel(descriptor);
    assertNotNull(superEntity.getDeclaredAttribute("super"));
    assertNull(subEntity.getDeclaredAttribute("super"));
    verify(descriptor).getDataMaps();
    verifyNoMoreInteractions(descriptor);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 62 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.

the class DefaultSelectTranslator method appendColumn.

private void appendColumn(List<ColumnDescriptor> columns, ObjAttribute objAttribute, DbAttribute attribute, Set<ColumnTracker> skipSet, String label, String alias) {
    if (alias == null) {
        alias = getCurrentAlias();
    }
    if (skipSet.add(new ColumnTracker(alias, attribute))) {
        ColumnDescriptor column = (objAttribute != null) ? new ColumnDescriptor(objAttribute, attribute, alias) : new ColumnDescriptor(attribute, alias);
        if (label != null) {
            column.setDataRowKey(label);
        }
        columns.add(column);
        // TODO: andrus, 5/7/2006 - replace 'columns' collection with this map, as it is redundant
        defaultAttributesByColumn.put(column, objAttribute);
    } else if (objAttribute != null) {
        // record ObjAttribute override
        for (ColumnDescriptor column : columns) {
            if (attribute.getName().equals(column.getName())) {
                if (attributeOverrides == null) {
                    attributeOverrides = new HashMap<>();
                }
                // kick out the original attribute
                ObjAttribute original = defaultAttributesByColumn.remove(column);
                if (original != null) {
                    attributeOverrides.put(original, column);
                }
                attributeOverrides.put(objAttribute, column);
                column.setJavaClass(Void.TYPE.getName());
                break;
            }
        }
    }
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute) HashMap(java.util.HashMap) ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor)

Example 63 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.

the class DefaultSelectTranslator method appendIdColumns.

<T> List<ColumnDescriptor> appendIdColumns(final List<ColumnDescriptor> columns, ObjEntity objEntity) {
    Set<ColumnTracker> skipSet = new HashSet<>();
    DbEntity dbEntity = objEntity.getDbEntity();
    for (ObjAttribute attribute : objEntity.getPrimaryKeys()) {
        // synthetic objattributes can't reliably lookup their DbAttribute,
        // so do it manually..
        DbAttribute dbAttribute = dbEntity.getAttribute(attribute.getDbAttributeName());
        appendColumn(columns, attribute, dbAttribute, skipSet, null);
    }
    return columns;
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute) HashSet(java.util.HashSet)

Example 64 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.

the class ObjEntityHandler method createObjAttribute.

private void createObjAttribute(Attributes attributes) {
    String dbPath = attributes.getValue("db-attribute-path");
    if (dbPath == null) {
        dbPath = attributes.getValue("db-attribute-name");
    }
    lastAttribute = new ObjAttribute(attributes.getValue("name"));
    lastAttribute.setType(attributes.getValue("type"));
    lastAttribute.setUsedForLocking(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lock")));
    lastAttribute.setDbAttributePath(dbPath);
    entity.addAttribute(lastAttribute);
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute)

Example 65 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.

the class EntityMergeSupport method addMissingAttribute.

private void addMissingAttribute(ObjEntity entity, DbAttribute da) {
    ObjAttribute oa = new ObjAttribute();
    oa.setName(NameBuilder.builder(oa, entity).baseName(nameGenerator.objAttributeName(da)).name());
    oa.setEntity(entity);
    oa.setType(getTypeForObjAttribute(da));
    oa.setDbAttributePath(da.getName());
    entity.addAttribute(oa);
    fireAttributeAdded(oa);
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute)

Aggregations

ObjAttribute (org.apache.cayenne.map.ObjAttribute)81 ObjEntity (org.apache.cayenne.map.ObjEntity)57 DbAttribute (org.apache.cayenne.map.DbAttribute)31 ObjRelationship (org.apache.cayenne.map.ObjRelationship)27 DbEntity (org.apache.cayenne.map.DbEntity)26 Test (org.junit.Test)26 DbRelationship (org.apache.cayenne.map.DbRelationship)19 DbJoin (org.apache.cayenne.map.DbJoin)12 DataMap (org.apache.cayenne.map.DataMap)9 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)9 HashMap (java.util.HashMap)8 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 ArrayList (java.util.ArrayList)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)7 HashSet (java.util.HashSet)6 Expression (org.apache.cayenne.exp.Expression)6