Search in sources :

Example 1 with OObjectProxyMethodHandler

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;
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 2 with OObjectProxyMethodHandler

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();
    }
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 3 with OObjectProxyMethodHandler

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);
}
Also used : ProxyObject(javassist.util.proxy.ProxyObject) ORecord(com.orientechnologies.orient.core.record.ORecord) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 4 with OObjectProxyMethodHandler

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);
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 5 with OObjectProxyMethodHandler

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;
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Aggregations

OObjectProxyMethodHandler (com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)12 ProxyObject (javassist.util.proxy.ProxyObject)6 ORID (com.orientechnologies.orient.core.id.ORID)5 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 Proxy (javassist.util.proxy.Proxy)4 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)3 ORecord (com.orientechnologies.orient.core.record.ORecord)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashSet (java.util.HashSet)1