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