use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OFieldTransformer method executeTransform.
@Override
public Object executeTransform(final Object input) {
if (input instanceof OIdentifiable) {
final ORecord rec = ((OIdentifiable) input).getRecord();
if (rec instanceof ODocument) {
final ODocument doc = (ODocument) rec;
if (setOperation) {
final Object newValue;
if (expression != null) {
if (sqlFilter == null)
// ONLY THE FIRST TIME
sqlFilter = new OSQLFilter(expression, context, null);
newValue = sqlFilter.evaluate(doc, null, context);
} else
newValue = value;
// SET THE TRANSFORMED FIELD BACK
doc.field(fieldName, newValue);
log(OETLProcessor.LOG_LEVELS.DEBUG, "set %s=%s in document=%s", fieldName, newValue, doc);
} else {
if (fieldName != null) {
final Object prev = doc.removeField(fieldName);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", fieldName, prev, doc);
} else {
for (String f : fieldNames) {
final Object prev = doc.removeField(f);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", f, prev, doc);
}
}
}
if (save) {
log(OETLProcessor.LOG_LEVELS.DEBUG, "saving record %s", doc);
final ODatabaseDocument db = super.pipeline.getDocumentDatabase();
db.save(doc);
}
}
}
return input;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OOrientDBLoaderTest method shouldSaveDocumentsWithPredefinedSchema.
@Test
public void shouldSaveDocumentsWithPredefinedSchema() {
//create class
ODatabaseDocument db = new ODatabaseDocumentTx(graph.getRawGraph().getURL()).open("admin", "admin");
db.command(new OCommandSQL("CREATE Class Person")).execute();
db.command(new OCommandSQL("CREATE property Person.name STRING")).execute();
db.command(new OCommandSQL("CREATE property Person.surname STRING")).execute();
db.command(new OCommandSQL("CREATE property Person.married BOOLEAN")).execute();
db.command(new OCommandSQL("CREATE property Person.birthday DATETIME")).execute();
db.close();
//store data
process("{source: { content: { value: 'name,surname,married,birthday\nJay,Miner,false,1970-01-01 05:30:00' } }, " + "extractor : { csv: {columns:['name:string','surname:string','married:boolean','birthday:datetime'], dateFormat :'yyyy-MM-dd HH:mm:ss'} }, loader: { orientdb: {\n" + " dbURL: \"memory:OETLBaseTest\", class:'Person', dbUser: \"admin\",\n" + " dbPassword: \"admin\",\n" + " dbAutoCreate: false,\n tx: false,\n" + " batchCommit: 1000,\n" + " wal : false,\n" + " dbType: \"document\" } } }");
graph.makeActive();
db = graph.getRawGraph();
List<?> res = db.query(new OSQLSynchQuery<ODocument>("SELECT FROM Person"));
assertThat(res.size()).isEqualTo(1);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateEdge method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLCreateEdge parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
// System.out.println("NEW PARSER FROM: " + queryText);
queryText = preParse(queryText, iRequest);
// System.out.println("NEW PARSER TO: " + queryText);
textRequest.setText(queryText);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword("CREATE");
parserRequiredKeyword("EDGE");
String className = null;
String tempLower = parseOptionalWord(false);
String temp = tempLower == null ? null : tempLower.toUpperCase();
while (temp != null) {
if (temp.equals("CLUSTER")) {
clusterName = parserRequiredWord(false);
} else if (temp.equals(KEYWORD_FROM)) {
from = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
} else if (temp.equals("TO")) {
to = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_CONTENT)) {
parseContent();
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
} else if (className == null && temp.length() > 0) {
className = tempLower;
OrientBaseGraph graph = OrientBaseGraph.getActiveGraph();
if (graph != null && graph.isUseClassForEdgeLabel()) {
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(temp);
} else {
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass("E");
}
}
temp = parseOptionalWord(true);
if (parserIsEnded())
break;
}
if (className == null) {
// ASSIGN DEFAULT CLASS
className = OrientEdgeType.CLASS_NAME;
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
}
// GET/CHECK CLASS NAME
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
edgeLabel = className;
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateVertex method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLCreateVertex parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
String className = null;
parserRequiredKeyword("CREATE");
parserRequiredKeyword("VERTEX");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.equals("CLUSTER")) {
clusterName = parserRequiredWord(false);
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_CONTENT)) {
parseContent();
} else if (className == null && temp.length() > 0) {
className = temp;
if (className == null)
// ASSIGN DEFAULT CLASS
className = OrientVertexType.CLASS_NAME;
// GET/CHECK CLASS NAME
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
if (className == null) {
// ASSIGN DEFAULT CLASS
className = OrientVertexType.CLASS_NAME;
// GET/CHECK CLASS NAME
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method getAnyGraph.
/**
* @return any graph if available, otherwise a Non Transactional OrientGraph implementation from the current database in thread
* local.
*/
public static OrientBaseGraph getAnyGraph(final OModifiableBoolean shouldBeShutDown) {
final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
if (result != null) {
final ODatabaseDocument 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()) {
graphDb.activateOnCurrentThread();
shouldBeShutDown.setValue(false);
return 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);
}
Aggregations