Search in sources :

Example 11 with OObjectProxyMethodHandler

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

Example 12 with OObjectProxyMethodHandler

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

Example 13 with OObjectProxyMethodHandler

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

Example 14 with OObjectProxyMethodHandler

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);
    }
}
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 15 with OObjectProxyMethodHandler

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;
}
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