Search in sources :

Example 6 with OObjectProxyMethodHandler

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

Example 7 with OObjectProxyMethodHandler

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;
}
Also used : Proxy(javassist.util.proxy.Proxy) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 8 with OObjectProxyMethodHandler

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));
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ProxyObject(javassist.util.proxy.ProxyObject) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 9 with OObjectProxyMethodHandler

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();
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) OObjectProxyMethodHandler(com.orientechnologies.orient.object.enhancement.OObjectProxyMethodHandler)

Example 10 with OObjectProxyMethodHandler

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;
}
Also used : 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