Search in sources :

Example 51 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class OrientBaseGraph method getVertex.

/**
   * Returns a vertex by an ID.
   *
   * @param id Can by a String, ODocument or an OIdentifiable object.
   */
public OrientVertex getVertex(final Object id) {
    makeActive();
    if (null == id)
        throw ExceptionFactory.vertexIdCanNotBeNull();
    if (id instanceof OrientVertex)
        return (OrientVertex) id;
    else if (id instanceof ODocument)
        return getVertexInstance((OIdentifiable) id);
    setCurrentGraphInThreadLocal();
    ORID rid;
    if (id instanceof OIdentifiable)
        rid = ((OIdentifiable) id).getIdentity();
    else {
        try {
            rid = new ORecordId(id.toString());
        } catch (IllegalArgumentException iae) {
            // <cluster-id>:<cluster-position>
            return null;
        }
    }
    if (!rid.isValid())
        return null;
    final ORecord rec = rid.getRecord();
    if (rec == null || !(rec instanceof ODocument))
        return null;
    final OClass cls = ((ODocument) rec).getSchemaClass();
    if (cls != null && cls.isEdgeType())
        throw new IllegalArgumentException("Cannot retrieve a vertex with the RID " + rid + " because it is an edge");
    return getVertexInstance(rec);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 52 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class OrientVertexIterator method createGraphElement.

@Override
public Vertex createGraphElement(final Object iObject) {
    if (iObject instanceof OrientVertex)
        return (OrientVertex) iObject;
    if (iObject == null) {
        return null;
    }
    final ORecord rec = ((OIdentifiable) iObject).getRecord();
    if (rec == null || !(rec instanceof ODocument))
        return null;
    final ODocument value = (ODocument) rec;
    final OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(value);
    return OGraphCommandExecutorSQLFactory.runWithAnyGraph(new OGraphCommandExecutorSQLFactory.GraphCallBack<Vertex>() {

        @Override
        public Vertex call(OrientBaseGraph graph) {
            final OrientVertex v;
            if (immutableClass.isVertexType()) {
                // DIRECT VERTEX
                v = graph.getVertex(value);
            } else if (immutableClass.isEdgeType()) {
                // EDGE
                if (vertex.settings.isUseVertexFieldsForEdgeLabels() || OrientEdge.isLabeled(OrientEdge.getRecordLabel(value), iLabels))
                    v = graph.getVertex(OrientEdge.getConnection(value, connection.getKey().opposite()));
                else
                    v = null;
            } else
                throw new IllegalStateException("Invalid content found between connections: " + value);
            return v;
        }
    });
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ORecord(com.orientechnologies.orient.core.record.ORecord) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OGraphCommandExecutorSQLFactory(com.orientechnologies.orient.graph.sql.OGraphCommandExecutorSQLFactory) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 53 with ORecord

use of com.orientechnologies.orient.core.record.ORecord 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 54 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class OObjectLazySet method convertAllInternal.

protected void convertAllInternal() {
    if (converted || !convertToRecord)
        return;
    final Set<Object> copy = new HashSet<Object>(underlying);
    super.clear();
    final ODatabasePojoAbstract<TYPE> database = getDatabase();
    for (Object e : copy) {
        if (e != null) {
            if (e instanceof ORID)
                super.add(database.getUserObjectByRecord(((ODatabaseDocument) getDatabase().getUnderlying()).load((ORID) e, fetchPlan), fetchPlan));
            else if (e instanceof ODocument)
                super.add(database.getUserObjectByRecord((ORecord) e, fetchPlan));
            else
                super.add((TYPE) e);
        }
    }
    converted = true;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ProxyObject(javassist.util.proxy.ProxyObject) ORID(com.orientechnologies.orient.core.id.ORID) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 55 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class IndexTxAwareMultiValueGetValuesTest method getValidPositions.

private List<Long> getValidPositions(int clusterId) {
    final ORecordIteratorCluster<?> iteratorCluster = database.browseCluster(database.getClusterNameById(clusterId));
    final List<Long> positions = new ArrayList<Long>();
    for (int i = 0; i < 7; i++) {
        iteratorCluster.hasNext();
        ORecord doc = iteratorCluster.next();
        positions.add(doc.getIdentity().getClusterPosition());
    }
    return positions;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ArrayList(java.util.ArrayList)

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)177 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)80 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)35 ORID (com.orientechnologies.orient.core.id.ORID)24 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)19 IOException (java.io.IOException)18 Test (org.junit.Test)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OException (com.orientechnologies.common.exception.OException)13 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)13 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)12 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)11 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)7 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)7 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)6 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)6