use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyList method get.
public TYPE get(final int index) {
TYPE o = (TYPE) super.get(index);
if (o == null) {
OIdentifiable record = (OIdentifiable) recordList.get(index);
if (record == null || record.getRecord() == null) {
OLogManager.instance().warn(this, "Record " + ((OObjectProxyMethodHandler) sourceRecord.getHandler()).getDoc().getIdentity() + " references a deleted instance");
return null;
}
o = (TYPE) OObjectEntityEnhancer.getInstance().getProxiedInstance(((ODocument) record.getRecord()).getClassName(), getDatabase().getEntityManager(), (ODocument) record.getRecord(), sourceRecord);
super.set(index, o);
}
return o;
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyMap method put.
@Override
public Object put(final Object iKey, final Object e) {
try {
OIdentifiable record;
if (e instanceof OIdentifiable) {
record = (OIdentifiable) e;
converted = false;
OIdentifiable o = underlying.put(iKey, record);
if (orphanRemoval && sourceRecord != null) {
if (record != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
if (o != null && !o.getIdentity().equals(((OIdentifiable) e).getIdentity()))
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(o.getIdentity());
}
return o;
} else {
record = e != null ? getDatabase().getRecordByUserObject(e, true) : null;
// OIdentifiable oldValue = get(iKey) != null ? getDatabase().getRecordByUserObject(get(iKey), true) : null;
OIdentifiable oldValue = underlying.get(iKey);
underlying.put(iKey, record);
if (orphanRemoval && sourceRecord != null) {
if (record != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
if (((record == null && oldValue != null) || (oldValue != null && !oldValue.getIdentity().equals(record.getIdentity()))))
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(oldValue.getIdentity());
}
return super.put(iKey, e);
}
} finally {
setDirty();
}
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyMap method convert.
/**
* Assure that the requested key is converted.
*/
private void convert(final String iKey) {
if (converted || !convertToRecord)
return;
if (super.containsKey(iKey))
return;
final ORecord record = (ORecord) underlying.get(iKey);
if (record == null)
return;
TYPE o = getDatabase().getUserObjectByRecord(record, null);
((OObjectProxyMethodHandler) (((ProxyObject) o)).getHandler()).setParentObject(sourceRecord);
super.put(iKey, o);
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazyMap method remove.
@Override
public Object remove(final Object iKey) {
OIdentifiable record = underlying.remove((String) iKey);
if (orphanRemoval && record != null && sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().add(record.getIdentity());
setDirty();
return super.remove(iKey);
}
use of com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler in project orientdb by orientechnologies.
the class OObjectLazySet method add.
public boolean add(final TYPE e) {
if (underlying != null && underlying.size() > 0 && !converted) {
convertAllInternal();
}
if (converted && e instanceof ORID)
converted = false;
setDirty();
boolean thisModified = super.add(e);
if (thisModified) {
OIdentifiable record = getDatabase().getRecordByUserObject(e, false);
if (sourceRecord != null)
((OObjectProxyMethodHandler) sourceRecord.getHandler()).getOrphans().remove(record.getIdentity());
underlying.add(record);
return true;
}
return false;
}
Aggregations