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