use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class DataObjectDescriptorFactory method createToManyCollectionProperty.
@Override
protected void createToManyCollectionProperty(PersistentDescriptor descriptor, ObjRelationship relationship) {
ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship.getTargetEntityName());
descriptor.addDeclaredProperty(new DataObjectToManyProperty(relationship, targetDescriptor, faultFactory.getCollectionFault()));
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class DataObjectDescriptorFactory method createToManyMapProperty.
@Override
protected void createToManyMapProperty(PersistentDescriptor descriptor, ObjRelationship relationship) {
ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship.getTargetEntityName());
Accessor mapKeyAccessor = createMapKeyAccessor(relationship, targetDescriptor);
descriptor.addDeclaredProperty(new DataObjectToManyMapProperty(relationship, targetDescriptor, faultFactory.getMapFault(mapKeyAccessor), mapKeyAccessor));
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class ObjectStore method processInvalidatedIDs.
/**
* @since 1.1
*/
void processInvalidatedIDs(Collection<ObjectId> invalidatedIDs) {
if (invalidatedIDs != null && !invalidatedIDs.isEmpty()) {
for (ObjectId oid : invalidatedIDs) {
DataObject object = (DataObject) getNode(oid);
if (object == null) {
continue;
}
switch(object.getPersistenceState()) {
case PersistenceState.COMMITTED:
object.setPersistenceState(PersistenceState.HOLLOW);
break;
case PersistenceState.MODIFIED:
DataContext context = (DataContext) object.getObjectContext();
DataRow diff = getSnapshot(oid);
// consult delegate if it exists
DataContextDelegate delegate = context.nonNullDelegate();
if (delegate.shouldMergeChanges(object, diff)) {
ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(oid.getEntityName());
DataRowUtils.forceMergeWithSnapshot(context, descriptor, object, diff);
delegate.finishedMergeChanges(object);
}
case PersistenceState.HOLLOW:
// do nothing
break;
case PersistenceState.DELETED:
// TODO: Do nothing? Or treat as merged?
break;
}
}
}
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class PrefetchProcessorJointNode method buildRowMapping.
/**
* Configures row columns mapping for this node entity.
*/
private void buildRowMapping() {
final Map<String, ColumnDescriptor> targetSource = new TreeMap<>();
// build a DB path .. find parent node that terminates the joint group...
PrefetchTreeNode jointRoot = this;
while (jointRoot.getParent() != null && !jointRoot.isDisjointPrefetch() && !jointRoot.isDisjointByIdPrefetch()) {
jointRoot = jointRoot.getParent();
}
final String prefix;
if (jointRoot != this) {
Expression objectPath = ExpressionFactory.exp(getPath(jointRoot));
ASTPath translated = (ASTPath) ((PrefetchProcessorNode) jointRoot).getResolver().getEntity().translateToDbPath(objectPath);
// make sure we do not include "db:" prefix
prefix = translated.getOperand(0) + ".";
} else {
prefix = "";
}
if (getParent() != null && !getParent().isPhantom() && getIncoming() != null && !getIncoming().getRelationship().isFlattened()) {
DbRelationship r = getIncoming().getRelationship().getDbRelationships().get(0);
for (final DbJoin join : r.getJoins()) {
appendColumn(targetSource, join.getTargetName(), prefix + join.getTargetName());
}
}
ClassDescriptor descriptor = resolver.getDescriptor();
descriptor.visitAllProperties(new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
String target = property.getAttribute().getDbAttributePath();
if (!property.getAttribute().isLazy()) {
appendColumn(targetSource, target, prefix + target);
}
return true;
}
public boolean visitToMany(ToManyProperty property) {
return visitRelationship(property);
}
public boolean visitToOne(ToOneProperty property) {
return visitRelationship(property);
}
private boolean visitRelationship(ArcProperty arc) {
DbRelationship dbRel = arc.getRelationship().getDbRelationships().get(0);
for (DbAttribute attribute : dbRel.getSourceAttributes()) {
String target = attribute.getName();
appendColumn(targetSource, target, prefix + target);
}
return true;
}
});
// append id columns ... (some may have been appended already via relationships)
for (String pkName : descriptor.getEntity().getPrimaryKeyNames()) {
appendColumn(targetSource, pkName, prefix + pkName);
}
// append inheritance discriminator columns...
for (ObjAttribute column : descriptor.getDiscriminatorColumns()) {
String target = column.getDbAttributePath();
appendColumn(targetSource, target, prefix + target);
}
int size = targetSource.size();
this.rowCapacity = (int) Math.ceil(size / 0.75);
this.columns = new ColumnDescriptor[size];
targetSource.values().toArray(columns);
}
use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.
the class PrefetchProcessorJointNode method rowFromFlatRow.
/**
* Returns a DataRow from the flat row.
*/
DataRow rowFromFlatRow(DataRow flatRow) {
DataRow row = new DataRow(rowCapacity);
// extract subset of flat row columns, recasting to the target keys
for (ColumnDescriptor column : columns) {
row.put(column.getName(), flatRow.get(column.getDataRowKey()));
}
// since JDBC row reader won't inject JOINED entity name, we have to detect it here...
ClassDescriptor descriptor = resolver.getDescriptor();
ObjEntity entity = descriptor.getEntityInheritanceTree().entityMatchingRow(row);
row.setEntityName(entity == null ? null : entity.getName());
return row;
}
Aggregations