use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class DefaultDbRowOpSorter method sortReflexive.
protected void sortReflexive(List<DbRowOp> sortedDbRows) {
DataDomain dataDomain = dataDomainProvider.get();
EntitySorter sorter = dataDomain.getEntitySorter();
EntityResolver resolver = dataDomain.getEntityResolver();
DbEntity lastEntity = null;
int start = 0;
int idx = 0;
DbRowOp lastRow = null;
for (DbRowOp row : sortedDbRows) {
if (row.getEntity() != lastEntity) {
start = idx;
if (lastEntity != null && sorter.isReflexive(lastEntity)) {
ObjEntity objEntity = resolver.getObjEntity(lastRow.getObject().getObjectId().getEntityName());
List<DbRowOp> reflexiveSublist = sortedDbRows.subList(start, idx);
sorter.sortObjectsForEntity(objEntity, reflexiveSublist, lastRow instanceof DeleteDbRowOp);
}
lastEntity = row.getEntity();
}
lastRow = row;
idx++;
}
// sort last chunk
if (lastEntity != null && sorter.isReflexive(lastEntity)) {
ObjEntity objEntity = resolver.getObjEntity(lastRow.getObject().getObjectId().getEntityName());
List<DbRowOp> reflexiveSublist = sortedDbRows.subList(start, idx);
sorter.sortObjectsForEntity(objEntity, reflexiveSublist, lastRow instanceof DeleteDbRowOp);
}
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ObjEntityTab method initFromModel.
/**
* Updates the view from the current model state. Invoked when a currently displayed
* ObjEntity is changed.
*
* @param entity current entity
*/
private void initFromModel(final ObjEntity entity) {
// TODO: this is a hack until we implement a real MVC
qualifier.getComponent().setBackground(Color.WHITE);
name.setText(entity.getName());
superClassName.setText(entity.getSuperClassName());
className.setText(entity.getClassName());
readOnly.setSelected(entity.isReadOnly());
isAbstract.setSelected(entity.isAbstract());
comment.setText(getComment(entity));
serverOnly.setSelected(entity.isServerOnly());
clientClassName.setText(entity.getClientClassName());
clientSuperClassName.setText(entity.getClientSuperClassName());
qualifier.setText(new ExpressionConvertor().valueAsString(entity.getDeclaredQualifier()));
// TODO: fix inheritance - we should allow to select optimistic
// lock if superclass is not already locked,
// otherwise we must keep this checked in but not editable.
optimisticLocking.setSelected(entity.getDeclaredLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC);
// init DbEntities
EntityResolver resolver = mediator.getEntityResolver();
DataMap map = mediator.getCurrentDataMap();
DbEntity[] dbEntities = resolver.getDbEntities().toArray(new DbEntity[0]);
Arrays.sort(dbEntities, Comparators.getDataMapChildrenComparator());
DefaultComboBoxModel<DbEntity> dbModel = new DefaultComboBoxModel<>(dbEntities);
dbModel.setSelectedItem(entity.getDbEntity());
dbEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map));
dbEntityCombo.setModel(dbModel);
boolean isUsedInheritance = entity.getSuperEntity() != null;
dbEntityCombo.setEnabled(!isUsedInheritance);
// toggle visibility and editability rules
toggleClientFieldsVisible(map.isClientSupported());
toggleEnabled(entity.getSuperEntityName() == null, !entity.isServerOnly());
// do not show this entity or any of the subentities
List<ObjEntity> objEntities = map.getObjEntities().stream().filter(object -> entity != object && !object.isSubentityOf(entity)).sorted(Comparators.getDataMapChildrenComparator()).collect(Collectors.toList());
objEntities.add(0, NO_INHERITANCE);
DefaultComboBoxModel<ObjEntity> superEntityModel = new DefaultComboBoxModel<>(objEntities.toArray(new ObjEntity[0]));
superEntityModel.setSelectedItem(entity.getSuperEntity());
superEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map));
superEntityCombo.setModel(superEntityModel);
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class AnnotationCommitLogEntityFactory method createDescriptor.
private CommitLogEntity createDescriptor(String entityName) {
EntityResolver entityResolver = getEntityResolver();
ClassDescriptor classDescriptor = entityResolver.getClassDescriptor(entityName);
CommitLog a = classDescriptor.getObjectClass().getAnnotation(CommitLog.class);
if (a == null) {
return BLOCKED_ENTITY;
}
ObjEntity entity = entityResolver.getObjEntity(entityName);
return new MutableCommitLogLogEntity(entity).setConfidential(a.confidential()).setIgnoreProperties(a.ignoredProperties()).setIgnoreAttributes(a.ignoreAttributes()).setIgnoreToOneRelationships(a.ignoreToOneRelationships()).setIgnoreToManyRelationships(a.ignoreToManyRelationships());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ObjectIdBatchFault method fetchObjects.
private Map<String, Object> fetchObjects() {
if (sources == null) {
return Collections.emptyMap();
}
EntityResolver resolver = context.getEntityResolver();
// reasons
if (sources.size() == 1) {
String uuid = sources.get(0).getId();
String entityName = EntityIdCoder.getEntityName(uuid);
ObjEntity entity = resolver.getObjEntity(entityName);
ObjectId id = new EntityIdCoder(entity).toObjectId(uuid);
Object object = Cayenne.objectForQuery(context, new ObjectIdQuery(id));
if (object == null) {
return Collections.emptyMap();
} else {
return Collections.singletonMap(uuid, object);
}
}
Map<String, ObjectSelect<DataObject>> queriesByEntity = new HashMap<>();
Map<String, EntityIdCoder> codersByEntity = new HashMap<>();
for (ObjectIdBatchSourceItem source : sources) {
String uuid = source.getId();
String entityName = EntityIdCoder.getEntityName(uuid);
EntityIdCoder coder = codersByEntity.get(entityName);
ObjectSelect<DataObject> query;
if (coder == null) {
coder = new EntityIdCoder(resolver.getObjEntity(entityName));
codersByEntity.put(entityName, coder);
query = ObjectSelect.query(DataObject.class, entityName);
queriesByEntity.put(entityName, query);
} else {
query = queriesByEntity.get(entityName);
}
ObjectId id = coder.toObjectId(uuid);
Expression idExp = ExpressionFactory.matchAllDbExp(id.getIdSnapshot(), Expression.EQUAL_TO);
query.or(idExp);
}
int capacity = (int) Math.ceil(sources.size() / 0.75d);
Map<String, Object> results = new HashMap<>(capacity);
for (ObjectSelect<DataObject> query : queriesByEntity.values()) {
EntityIdCoder coder = codersByEntity.get(query.getEntityName());
List<DataObject> objects = query.select(context);
for (DataObject object : objects) {
String uuid = coder.toStringId(object.getObjectId());
results.put(uuid, object);
}
}
return results;
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ObjGraphBuilder method isIsolated.
@Override
protected boolean isIsolated(DataChannelDescriptor domain, Entity entity) {
if (!super.isIsolated(domain, entity)) {
return false;
}
if (((ObjEntity) entity).getSuperEntity() != null) {
return false;
}
// TODO: andrus 05/30/2010 - reindexing all DataMaps every time may be VERY slow on large projects
EntityResolver resolver = new EntityResolver(domain.getDataMaps());
EntityInheritanceTree inheritanceTree = resolver.getInheritanceTree(entity.getName());
return inheritanceTree == null || inheritanceTree.getChildren().isEmpty();
}
Aggregations