use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLMoveVertex method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLMoveVertex parse(final OCommandRequest iRequest) {
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword("MOVE");
parserRequiredKeyword("VERTEX");
source = parserRequiredWord(false, "Syntax error", " =><,\r\n");
if (source == null)
throw new OCommandSQLParsingException("Cannot find source");
parserRequiredKeyword("TO");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.startsWith("CLUSTER:")) {
if (className != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
clusterName = temp.substring("CLUSTER:".length());
if (database.getClusterIdByName(clusterName) == -1)
throw new OCommandSQLParsingException("Cluster '" + clusterName + "' was not found");
} else if (temp.startsWith("CLASS:")) {
if (clusterName != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
className = temp.substring("CLASS:".length());
clazz = database.getMetadata().getSchema().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_MERGE)) {
merge = parseJSON();
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
return this;
}
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();
}
Aggregations