use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazySet method removeAll.
public boolean removeAll(final Collection<?> c) {
setDirty();
final ODatabasePojoAbstract<TYPE> database = getDatabase();
boolean modified = super.removeAll(c);
for (Object o : c) {
OIdentifiable record = database.getRecordByUserObject(o, false);
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(record.getIdentity());
if (!underlying.remove(database.getRecordByUserObject(o, false)))
modified = true;
}
return modified;
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazySet method retainAll.
public boolean retainAll(final Collection<?> c) {
setDirty();
final ODatabasePojoAbstract<TYPE> database = getDatabase();
boolean modified = super.retainAll(c);
Set<Object> toRetain = new HashSet<Object>();
Set<Object> toRemove = new HashSet<Object>();
for (Object o : c) {
OIdentifiable record = database.getRecordByUserObject(o, false);
toRetain.add(record);
}
for (OIdentifiable underlyingRec : underlying) {
if (toRetain.contains(underlyingRec) && sourceRecord != null) {
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(underlyingRec.getIdentity());
} else {
if (sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(underlyingRec.getIdentity());
toRemove.add(underlyingRec);
modified = true;
}
}
underlying.removeAll(toRemove);
toRemove.clear();
toRetain.clear();
return modified;
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyIterator method next.
public TYPE next(final String iFetchPlan) {
final Object value = underlying.next();
if (value == null)
return null;
if (value instanceof ORID && autoConvert2Object) {
currentElement = (OIdentifiable) value;
ORecord record = ((ODatabaseDocument) database.getUnderlying()).load((ORID) value, iFetchPlan);
if (record == null) {
OLogManager.instance().warn(this, "Record " + ((OObjectProxyMethodHandler) sourceRecord.getHandler()).getDoc().getIdentity() + " references a deleted instance");
return null;
}
TYPE o = database.getUserObjectByRecord(record, iFetchPlan);
((OObjectProxyMethodHandler) (((ProxyObject) o)).getHandler()).setParentObject(sourceRecord);
return o;
} else if (value instanceof ODocument && autoConvert2Object) {
currentElement = (OIdentifiable) value;
TYPE o = database.getUserObjectByRecord((ODocument) value, iFetchPlan);
((OObjectProxyMethodHandler) (((ProxyObject) o)).getHandler()).setParentObject(sourceRecord);
return o;
} else {
currentElement = database.getRecordByUserObject(value, false);
}
if (OObjectEntitySerializer.isToSerialize(value.getClass()))
return (TYPE) OObjectEntitySerializer.deserializeFieldValue(value.getClass(), value);
return (TYPE) value;
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyList method convertAndDetachAll.
private void convertAndDetachAll(final int iIndex, boolean nonProxiedInstance, Map<Object, Object> alreadyDetached, Map<Object, Object> lazyObjects) {
if (converted || !convertToRecord)
return;
Object o = super.get(iIndex);
if (o == null) {
final ODatabaseDocument database = getDatabase().getUnderlying();
o = recordList.get(iIndex);
ODocument doc;
if (o instanceof ORID) {
doc = database.load((ORID) o, fetchPlan);
} else {
doc = (ODocument) o;
}
if (o == null) {
OLogManager.instance().warn(this, "Record " + ((OObjectProxyMethodHandler) sourceRecord.getHandler()).getDoc().getIdentity() + " references a deleted instance");
return;
}
o = OObjectEntityEnhancer.getInstance().getProxiedInstance(doc.getClassName(), getDatabase().getEntityManager(), doc, sourceRecord);
o = ((OObjectDatabaseTx) getDatabase()).detachAll(o, nonProxiedInstance, alreadyDetached, lazyObjects);
super.set(iIndex, (TYPE) o);
}
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyList method remove.
public TYPE remove(int index) {
TYPE element;
OIdentifiable record = recordList.remove(index);
if (indexLoaded(index)) {
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(record.getIdentity());
element = (TYPE) super.remove(index);
} else {
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(record.getIdentity());
element = (TYPE) OObjectEntityEnhancer.getInstance().getProxiedInstance(((ODocument) record.getRecord()).getClassName(), getDatabase().getEntityManager(), (ODocument) record.getRecord(), sourceRecord);
}
setDirty();
return element;
}
Aggregations