Search in sources :

Example 1 with ORecordLazyMultiValue

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

the class OTraverseRecordProcess method processFields.

private void processFields(Iterator<Object> target) {
    final ODocument doc = this.target.getRecord();
    while (target.hasNext()) {
        Object field = target.next();
        final Object fieldValue;
        if (field instanceof OSQLFilterItem)
            fieldValue = ((OSQLFilterItem) field).getValue(doc, null, null);
        else
            fieldValue = doc.rawField(field.toString());
        if (fieldValue != null) {
            final OTraverseAbstractProcess<?> subProcess;
            if (fieldValue instanceof Iterator<?> || OMultiValue.isMultiValue(fieldValue)) {
                final Iterator<?> coll;
                if (fieldValue instanceof ORecordLazyMultiValue)
                    coll = ((ORecordLazyMultiValue) fieldValue).rawIterator();
                else
                    coll = OMultiValue.getMultiValueIterator(fieldValue, false);
                subProcess = new OTraverseMultiValueProcess(command, (Iterator<Object>) coll, getPath().appendField(field.toString()));
            } else if (fieldValue instanceof OIdentifiable && ((OIdentifiable) fieldValue).getRecord() instanceof ODocument) {
                subProcess = new OTraverseRecordProcess(command, (ODocument) ((OIdentifiable) fieldValue).getRecord(), getPath().appendField(field.toString()));
            } else
                continue;
            command.getContext().push(subProcess);
        }
    }
}
Also used : Iterator(java.util.Iterator) OSQLFilterItem(com.orientechnologies.orient.core.sql.filter.OSQLFilterItem) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)

Example 2 with ORecordLazyMultiValue

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

the class ORecordSerializerNetworkV0 method writeLinkMap.

private int writeLinkMap(final BytesContainer bytes, final Map<Object, OIdentifiable> map) {
    final boolean disabledAutoConversion = map instanceof ORecordLazyMultiValue && ((ORecordLazyMultiValue) map).isAutoConvertToRecord();
    if (disabledAutoConversion)
        // AVOID TO FETCH RECORD
        ((ORecordLazyMultiValue) map).setAutoConvertToRecord(false);
    try {
        final int fullPos = OVarIntSerializer.write(bytes, map.size());
        for (Entry<Object, OIdentifiable> entry : map.entrySet()) {
            // TODO:check skip of complex types
            // FIXME: changed to support only string key on map
            final OType type = OType.STRING;
            writeOType(bytes, bytes.alloc(1), type);
            writeString(bytes, entry.getKey().toString());
            if (entry.getValue() == null)
                writeNullLink(bytes);
            else
                writeOptimizedLink(bytes, entry.getValue());
        }
        return fullPos;
    } finally {
        if (disabledAutoConversion)
            ((ORecordLazyMultiValue) map).setAutoConvertToRecord(true);
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)

Example 3 with ORecordLazyMultiValue

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

the class ODocumentFieldWalker method walkDocument.

private void walkDocument(ODocument document, ODocumentFieldVisitor fieldWalker, Set<ODocument> walked) {
    if (walked.contains(document))
        return;
    walked.add(document);
    boolean oldLazyLoad = document.isLazyLoad();
    document.setLazyLoad(false);
    final boolean updateMode = fieldWalker.updateMode();
    final OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
    for (String fieldName : document.fieldNames()) {
        final OType concreteType = document.fieldType(fieldName);
        OType fieldType = concreteType;
        OType linkedType = null;
        if (fieldType == null && clazz != null) {
            OProperty property = clazz.getProperty(fieldName);
            if (property != null) {
                fieldType = property.getType();
                linkedType = property.getLinkedType();
            }
        }
        Object fieldValue = document.field(fieldName, fieldType);
        Object newValue = fieldWalker.visitField(fieldType, linkedType, fieldValue);
        boolean updated;
        if (updateMode)
            updated = updateFieldValueIfChanged(document, fieldName, fieldValue, newValue, concreteType);
        else
            updated = false;
        // 3. document is not not embedded.
        if (!updated && fieldValue != null && !(OType.LINK.equals(fieldType) || OType.LINKBAG.equals(fieldType) || OType.LINKLIST.equals(fieldType) || OType.LINKSET.equals(fieldType) || (fieldValue instanceof ORecordLazyMultiValue))) {
            if (fieldWalker.goDeeper(fieldType, linkedType, fieldValue)) {
                if (fieldValue instanceof Map)
                    walkMap((Map) fieldValue, fieldType, fieldWalker, walked);
                else if (fieldValue instanceof ODocument) {
                    final ODocument doc = (ODocument) fieldValue;
                    if (OType.EMBEDDED.equals(fieldType) || doc.isEmbedded())
                        walkDocument((ODocument) fieldValue, fieldWalker);
                } else if (OMultiValue.isIterable(fieldValue))
                    walkIterable(OMultiValue.getMultiValueIterable(fieldValue), fieldType, fieldWalker, walked);
            }
        }
        if (!fieldWalker.goFurther(fieldType, linkedType, fieldValue, newValue)) {
            document.setLazyLoad(oldLazyLoad);
            return;
        }
    }
    document.setLazyLoad(oldLazyLoad);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OType(com.orientechnologies.orient.core.metadata.schema.OType) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with ORecordLazyMultiValue

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

the class OrientVertex method getVertices.

/**
 * Returns a lazy iterable instance against vertices.
 *
 * @param iDirection The direction between OUT, IN or BOTH
 * @param iLabels    Optional varargs of Strings representing edge label to consider
 */
@Override
public Iterable<Vertex> getVertices(final Direction iDirection, final String... iLabels) {
    setCurrentGraphInThreadLocal();
    OrientBaseGraph.getEdgeClassNames(getGraph(), iLabels);
    OrientBaseGraph.encodeClassNames(iLabels);
    final ODocument doc = getRecord();
    final OMultiCollectionIterator<Vertex> iterable = new OMultiCollectionIterator<Vertex>();
    for (OTriple<String, Direction, String> connectionField : getConnectionFields(iDirection, iLabels)) {
        String fieldName = connectionField.getKey();
        OPair<Direction, String> connection = connectionField.getValue();
        final Object fieldValue = doc.rawField(fieldName);
        if (fieldValue != null)
            if (fieldValue instanceof OIdentifiable) {
                addSingleVertex(doc, iterable, fieldName, connection, fieldValue, iLabels);
            } else if (fieldValue instanceof Collection<?>) {
                Collection<?> coll = (Collection<?>) fieldValue;
                if (coll.size() == 1) {
                    // SINGLE ITEM: AVOID CALLING ITERATOR
                    if (coll instanceof ORecordLazyMultiValue)
                        addSingleVertex(doc, iterable, fieldName, connection, ((ORecordLazyMultiValue) coll).rawIterator().next(), iLabels);
                    else if (coll instanceof List<?>)
                        addSingleVertex(doc, iterable, fieldName, connection, ((List<?>) coll).get(0), iLabels);
                    else
                        addSingleVertex(doc, iterable, fieldName, connection, coll.iterator().next(), iLabels);
                } else {
                    // CREATE LAZY Iterable AGAINST COLLECTION FIELD
                    if (coll instanceof ORecordLazyMultiValue)
                        iterable.add(new OrientVertexIterator(this, coll, ((ORecordLazyMultiValue) coll).rawIterator(), connection, iLabels, coll.size()));
                    else
                        iterable.add(new OrientVertexIterator(this, coll, coll.iterator(), connection, iLabels, -1));
                }
            } else if (fieldValue instanceof ORidBag) {
                iterable.add(new OrientVertexIterator(this, fieldValue, ((ORidBag) fieldValue).rawIterator(), connection, iLabels, -1));
            }
    }
    return iterable;
}
Also used : PartitionVertex(com.tinkerpop.blueprints.util.wrappers.partition.PartitionVertex) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with ORecordLazyMultiValue

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

the class OrientVertex method getEdges.

/**
 * (Blueprints Extension) Returns all the edges from the current Vertex to another one.
 *
 * @param iDestination The target vertex
 * @param iDirection   The direction between OUT, IN or BOTH
 * @param iLabels      Optional labels as Strings to consider
 *
 * @return
 */
public Iterable<Edge> getEdges(final OrientVertex iDestination, final Direction iDirection, final String... iLabels) {
    setCurrentGraphInThreadLocal();
    final ODocument doc = getRecord();
    OrientBaseGraph.getEdgeClassNames(getGraph(), iLabels);
    OrientBaseGraph.encodeClassNames(iLabels);
    final OMultiCollectionIterator<Edge> iterable = new OMultiCollectionIterator<Edge>().setEmbedded(true);
    for (OTriple<String, Direction, String> connectionField : getConnectionFields(iDirection, iLabels)) {
        String fieldName = connectionField.getKey();
        OPair<Direction, String> connection = connectionField.getValue();
        final Object fieldValue = doc.rawField(fieldName);
        if (fieldValue != null) {
            final OIdentifiable destinationVId = iDestination != null ? (OIdentifiable) iDestination.getId() : null;
            if (fieldValue instanceof OIdentifiable) {
                addSingleEdge(doc, iterable, fieldName, connection, fieldValue, destinationVId, iLabels);
            } else if (fieldValue instanceof Collection<?>) {
                Collection<?> coll = (Collection<?>) fieldValue;
                if (coll.size() == 1) {
                    // SINGLE ITEM: AVOID CALLING ITERATOR
                    if (coll instanceof ORecordLazyMultiValue)
                        addSingleEdge(doc, iterable, fieldName, connection, ((ORecordLazyMultiValue) coll).rawIterator().next(), destinationVId, iLabels);
                    else if (coll instanceof List<?>)
                        addSingleEdge(doc, iterable, fieldName, connection, ((List<?>) coll).get(0), destinationVId, iLabels);
                    else
                        addSingleEdge(doc, iterable, fieldName, connection, coll.iterator().next(), destinationVId, iLabels);
                } else {
                    // CREATE LAZY Iterable AGAINST COLLECTION FIELD
                    if (coll instanceof ORecordLazyMultiValue) {
                        iterable.add(new OrientEdgeIterator(this, iDestination, coll, ((ORecordLazyMultiValue) coll).rawIterator(), connection, iLabels, coll.size()));
                    } else
                        iterable.add(new OrientEdgeIterator(this, iDestination, coll, coll.iterator(), connection, iLabels, -1));
                }
            } else if (fieldValue instanceof ORidBag) {
                iterable.add(new OrientEdgeIterator(this, iDestination, fieldValue, ((ORidBag) fieldValue).rawIterator(), connection, iLabels, ((ORidBag) fieldValue).size()));
            }
        }
    }
    return iterable;
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue) ORecordLazyList(com.orientechnologies.orient.core.db.record.ORecordLazyList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORecordLazyMultiValue (com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)4 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)2 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Set (java.util.Set)2 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1 OException (com.orientechnologies.common.exception.OException)1 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)1 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)1 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)1 OTrackedSet (com.orientechnologies.orient.core.db.record.OTrackedSet)1