use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyList method add.
public void add(int index, TYPE element) {
setDirty();
OIdentifiable record;
if (element instanceof OIdentifiable) {
record = (OIdentifiable) element;
if (converted)
converted = false;
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
recordList.add(index, record);
return;
} else if (element instanceof Proxy) {
record = (OIdentifiable) OObjectEntitySerializer.getDocument((Proxy) element);
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
recordList.add(index, record);
} else {
element = (TYPE) OObjectEntitySerializer.serializeObject(element, getDatabase());
record = (OIdentifiable) OObjectEntitySerializer.getDocument((Proxy) element);
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
recordList.add(index, record);
}
super.add(index, element);
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class ODatabasePojoAbstract method getRecordByUserObject.
public ODocument getRecordByUserObject(final Object iPojo, final boolean iCreateIfNotAvailable) {
if (iPojo instanceof ODocument)
return (ODocument) iPojo;
else if (iPojo instanceof Proxy)
return ((OObjectProxyMethodHandler) ((ProxyObject) iPojo).getHandler()).getDoc();
ODocument record = objects2Records.get(iPojo);
if (record == null) {
// SEARCH BY RID
final ORID rid = OObjectSerializerHelper.getObjectID(this, iPojo);
if (rid != null && rid.isValid()) {
record = rid2Records.get(rid);
if (record == null)
// LOAD IT
record = underlying.load(rid);
} else if (iCreateIfNotAvailable) {
record = underlying.newInstance(iPojo.getClass().getSimpleName());
} else {
return null;
}
registerUserObject(iPojo, record);
}
return record;
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyList method convert.
/**
* Convert the item requested.
*
* @param iIndex
* Position of the item to convert
*/
private void convert(final int iIndex) {
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;
}
super.set(iIndex, (TYPE) OObjectEntityEnhancer.getInstance().getProxiedInstance(doc.getClassName(), getDatabase().getEntityManager(), doc, sourceRecord));
}
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyListIterator method remove.
public void remove() {
if (lastRet == -1)
throw new IllegalStateException();
try {
list.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
} catch (IndexOutOfBoundsException e) {
throw new ConcurrentModificationException(e);
}
if (sourceRecord != null) {
((OObjectProxyMethodHandler) sourceRecord.getHandler()).setDirty();
}
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazySet method remove.
public boolean remove(final Object o) {
setDirty();
OIdentifiable record = getDatabase().getRecordByUserObject(o, false);
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(record.getIdentity());
boolean thisModified = super.remove(o);
boolean underlyingModified = underlying.remove(record);
return thisModified || underlyingModified;
}
Aggregations