use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OrientEdgeIterator method createGraphElement.
@Override
public OrientEdge createGraphElement(final Object iObject) {
if (iObject instanceof OrientEdge)
return (OrientEdge) iObject;
final OIdentifiable rec = (OIdentifiable) iObject;
if (rec == null) {
// SKIP IT
OLogManager.instance().warn(this, "Record (%s) is null", iObject);
return null;
}
final ORecord record = rec.getRecord();
if (record == null) {
// SKIP IT
OLogManager.instance().warn(this, "Record (%s) is null", rec);
return null;
}
if (!(record instanceof ODocument)) {
// SKIP IT
OLogManager.instance().warn(this, "Found a record (%s) that is not an edge. Source vertex : %s, Target vertex : %s, Database : %s", rec, sourceVertex != null ? sourceVertex.getIdentity() : null, targetVertex != null ? targetVertex.getIdentity() : null, record.getDatabase().getURL());
return null;
}
final ODocument value = rec.getRecord();
if (value == null) {
return null;
}
OImmutableClass immutableSchema = ODocumentInternal.getImmutableSchemaClass(value);
if (immutableSchema == null) {
ODatabaseDocument db = value.getDatabaseIfDefined();
if (db == null) {
return null;
}
db.getMetadata().reload();
immutableSchema = ODocumentInternal.getImmutableSchemaClass(value);
if (immutableSchema == null) {
return null;
}
}
final OrientEdge edge;
if (immutableSchema.isVertexType()) {
// DIRECT VERTEX, CREATE DUMMY EDGE
OrientBaseGraph graph = this.sourceVertex.getGraph();
boolean newGraph = false;
if (graph == null) {
newGraph = true;
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null) {
graph = new OrientGraphNoTx((ODatabaseDocumentTx) db);
}
}
if (connection.getKey() == Direction.OUT) {
edge = graph.getEdgeInstance(this.sourceVertex.getIdentity(), rec.getIdentity(), connection.getValue());
} else {
edge = graph.getEdgeInstance(rec.getIdentity(), this.sourceVertex.getIdentity(), connection.getValue());
}
if (newGraph) {
graph.shutdown(false, false);
}
} else if (immutableSchema.isEdgeType()) {
// EDGE
edge = new OrientEdge(this.sourceVertex.getGraph(), rec.getIdentity(), connection.getValue());
} else
throw new IllegalStateException("Invalid content found while iterating edges, value '" + value + "' is not an edge");
if (this.sourceVertex.settings.isUseVertexFieldsForEdgeLabels() || edge.isLabeled(labels))
return edge;
return null;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OrientBaseGraph method makeActive.
public void makeActive() {
if (database == null) {
throw new ODatabaseException("Database is closed");
}
activeGraph.set(this);
final ODatabaseDocument tlDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (tlDb != database)
ODatabaseRecordThreadLocal.INSTANCE.set(getDatabase());
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method getGraphNoTx.
/**
* @return a Non Transactional OrientGraph implementation from the current database in thread local.
*/
public static OrientGraphNoTx getGraphNoTx(final OModifiableBoolean shouldBeShutDown) {
final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
if (result != null && (result instanceof OrientGraphNoTx)) {
final ODatabaseDocumentTx graphDb = result.getRawGraph();
// CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT
if (canReuseActiveGraph(graphDb, database)) {
if (!graphDb.isClosed()) {
ODatabaseRecordThreadLocal.INSTANCE.set(graphDb);
shouldBeShutDown.setValue(false);
return (OrientGraphNoTx) result;
}
}
}
// Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local
shouldBeShutDown.setValue(true);
ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) database);
return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class IndexTest method testDictionary.
public void testDictionary() {
ODatabaseDocument db = new ODatabaseDocumentTx(database.getURL());
db.open("admin", "admin");
OClass pClass = db.getMetadata().getSchema().createClass("Person2", 1, null);
pClass.createProperty("firstName", OType.STRING);
pClass.createProperty("lastName", OType.STRING);
pClass.createProperty("age", OType.INTEGER);
pClass.createIndex("testIdx", INDEX_TYPE.DICTIONARY, "firstName", "lastName");
ODocument person = new ODocument("Person2");
person.field("firstName", "foo").field("lastName", "bar").save();
person = new ODocument("Person2");
person.field("firstName", "foo").field("lastName", "bar").field("age", 32).save();
db.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class IndexTest method testIndexReturnOnlySpecifiedClass.
@Test(dependsOnMethods = "createInheritanceIndex")
public void testIndexReturnOnlySpecifiedClass() throws Exception {
List<ODocument> result;
ODatabaseDocument db = database.getUnderlying();
result = db.command(new OSQLSynchQuery("select * from ChildTestClass where testParentProperty = 10")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(10L, result.get(0).field("testParentProperty"));
result = db.command(new OCommandSQL("select * from AnotherChildTestClass where testParentProperty = 11")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(11L, result.get(0).field("testParentProperty"));
}
Aggregations