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