use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ObjectStore method objectsUnregistered.
/**
* Evicts a collection of DataObjects from the ObjectStore, invalidates the underlying
* cache snapshots. Changes objects state to TRANSIENT. This method can be used for
* manual cleanup of Cayenne cache.
*/
// this method is exactly the same as "objectsInvalidated", only additionally it
// throws out registered objects
public synchronized void objectsUnregistered(Collection objects) {
if (objects.isEmpty()) {
return;
}
Collection<ObjectId> ids = new ArrayList<>(objects.size());
for (Object object1 : objects) {
Persistent object = (Persistent) object1;
ObjectId id = object.getObjectId();
// remove object but not snapshot
objectMap.remove(id);
changes.remove(id);
ids.add(id);
object.setObjectContext(null);
object.setPersistenceState(PersistenceState.TRANSIENT);
}
// and keep unregister local even for non-nested DC?
if (getDataRowCache() != null) {
// send an event for removed snapshots
getDataRowCache().processSnapshotChanges(this, Collections.<ObjectId, DataRow>emptyMap(), Collections.<ObjectId>emptyList(), ids, Collections.<ObjectId>emptyList());
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ObjectStore method processSnapshotEvent.
/**
* @since 1.2
*/
synchronized void processSnapshotEvent(SnapshotEvent event) {
Map<ObjectId, DataRow> modifiedDiffs = event.getModifiedDiffs();
if (modifiedDiffs != null && !modifiedDiffs.isEmpty()) {
for (Map.Entry<ObjectId, DataRow> entry : modifiedDiffs.entrySet()) {
processUpdatedSnapshot(entry.getKey(), entry.getValue());
}
}
Collection<ObjectId> deletedIDs = event.getDeletedIds();
if (deletedIDs != null && !deletedIDs.isEmpty()) {
for (ObjectId deletedID : deletedIDs) {
processDeletedID(deletedID);
}
}
processInvalidatedIDs(event.getInvalidatedIds());
processIndirectlyModifiedIDs(event.getIndirectlyModifiedIds());
// TODO: andrus, 3/28/2006 - 'SnapshotEventDecorator' serves as a bridge (or
// rather a noop wrapper) between old snapshot events and new GraphEvents. Once
// SnapshotEvents are replaced with GraphEvents (in 2.0) we won't need it
GraphDiff diff = new SnapshotEventDecorator(event);
ObjectContext originatingContext = (event.getPostedBy() instanceof ObjectContext) ? (ObjectContext) event.getPostedBy() : null;
context.fireDataChannelChanged(originatingContext, diff);
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ObjectStoreGraphDiff method preprocess.
private void preprocess(ObjectStore objectStore) {
Map<Object, ObjectDiff> changes = getChangesByObjectId();
if (!changes.isEmpty()) {
for (Entry<Object, ObjectDiff> entry : changes.entrySet()) {
ObjectId id = (ObjectId) entry.getKey();
Persistent object = (Persistent) objectStore.getNode(id);
// address manual id override.
ObjectId objectId = object.getObjectId();
if (!id.equals(objectId)) {
if (objectId != null) {
Map<String, Object> replacement = id.getReplacementIdMap();
replacement.clear();
replacement.putAll(objectId.getIdSnapshot());
}
object.setObjectId(id);
}
}
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class EJBQLPathAnaliserTranslator method processParameter.
private void processParameter(String boundName, EJBQLExpression expression) {
Object object = context.getBoundParameter(boundName);
Map<?, ?> map = null;
if (object instanceof Persistent) {
map = ((Persistent) object).getObjectId().getIdSnapshot();
} else if (object instanceof ObjectId) {
map = ((ObjectId) object).getIdSnapshot();
} else if (object instanceof Map) {
map = (Map<?, ?>) object;
}
if (map != null) {
if (map.size() == 1) {
context.rebindParameter(boundName, map.values().iterator().next());
} else {
addMultiColumnOperand(EJBQLMultiColumnOperand.getObjectOperand(context, map));
return;
}
}
if (object != null) {
context.append(" #bind($").append(boundName).append(")");
} else {
String type = null;
Node parent = ((SimpleNode) expression).jjtGetParent();
context.pushMarker("@processParameter", true);
EJBQLPathAnaliserTranslator translator = new EJBQLPathAnaliserTranslator(context);
parent.visit(translator);
translator.visitPath(parent, parent.getChildrenCount());
String id = translator.idPath;
if (id != null) {
ClassDescriptor descriptor = context.getEntityDescriptor(id);
if (descriptor == null) {
throw new EJBQLException("Unmapped id variable: " + id);
}
String pathChunk = translator.lastPathComponent;
PropertyDescriptor property = descriptor.getProperty(pathChunk);
if (property instanceof AttributeProperty) {
String atrType = ((AttributeProperty) property).getAttribute().getType();
type = TypesMapping.getSqlNameByType(TypesMapping.getSqlTypeByJava(atrType));
}
}
context.popMarker();
if (type == null) {
type = "VARCHAR";
}
// this is a hack to prevent execptions on DB's like Derby for
// expressions
// "X = NULL". The 'VARCHAR' parameter is totally bogus, but seems
// to work on
// all tested DB's... Also note what JPA spec, chapter 4.11 says:
// "Comparison
// or arithmetic operations with a NULL value always yield an
// unknown value."
// TODO: andrus 6/28/2007 Ideally we should track the type of the
// current
// expression to provide a meaningful type.
context.append(" #bind($").append(boundName).append(" '" + type + "')");
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DeletedDiffProcessor method nodeRemoved.
@Override
public void nodeRemoved(Object nodeId) {
ObjectId id = (ObjectId) nodeId;
final MutableObjectChange objectChangeSet = changeSet.getOrCreate(id, ObjectChangeType.DELETE);
// TODO: rewrite with SelectById query after Cayenne upgrade
ObjectIdQuery query = new ObjectIdQuery(id, true, ObjectIdQuery.CACHE);
QueryResponse result = channel.onQuery(null, query);
@SuppressWarnings("unchecked") List<DataRow> rows = result.firstList();
if (rows.isEmpty()) {
LOGGER.warn("No DB snapshot for object to be deleted, no changes will be recorded. ID: " + id);
return;
}
final DataRow row = rows.get(0);
ClassDescriptor descriptor = channel.getEntityResolver().getClassDescriptor(id.getEntityName());
final CommitLogEntity entity = entityFactory.getEntity(id);
descriptor.visitProperties(new PropertyVisitor() {
@Override
public boolean visitAttribute(AttributeProperty property) {
if (!entity.isIncluded(property.getName())) {
return true;
}
Object value;
if (entity.isConfidential(property.getName())) {
value = Confidential.getInstance();
} else {
String key = property.getAttribute().getDbAttributeName();
value = row.get(key);
}
if (value != null) {
objectChangeSet.attributeChanged(property.getName(), value, null);
}
return true;
}
@Override
public boolean visitToOne(ToOneProperty property) {
// TODO record FK changes?
return true;
}
@Override
public boolean visitToMany(ToManyProperty property) {
return true;
}
});
}
Aggregations