use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OLuceneTextOperator method evaluateRecord.
@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight, OCommandContext iContext) {
OLuceneFullTextIndex index = involvedIndex(iRecord, iCurrentResult, iCondition, iLeft, iRight);
if (index == null) {
throw new OCommandExecutionException("Cannot evaluate lucene condition without index configuration.");
}
MemoryIndex memoryIndex = (MemoryIndex) iContext.getVariable(MEMORY_INDEX);
if (memoryIndex == null) {
memoryIndex = new MemoryIndex();
iContext.setVariable(MEMORY_INDEX, memoryIndex);
}
memoryIndex.reset();
try {
for (IndexableField field : index.buildDocument(iLeft).getFields()) {
memoryIndex.addField(field.name(), field.tokenStream(index.indexAnalyzer(), null));
}
return memoryIndex.search(index.buildQuery(iRight)) > 0.0f;
} catch (ParseException e) {
OLogManager.instance().error(this, "error occurred while building query", e);
} catch (IOException e) {
OLogManager.instance().error(this, "error occurred while building memory index", e);
}
return null;
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class SQLDropPropertyIndexTest method testForcePropertyDisabled.
@Test
public void testForcePropertyDisabled() throws Exception {
database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
try {
database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndexTestClass.prop1")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
}
database.getMetadata().getIndexManager().reload();
index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
Assert.assertEquals(index.getType(), "UNIQUE");
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OCommandExecutorScript method executeInContext.
public Object executeInContext(final OCommandContext iContext, final Map<Object, Object> iArgs) {
final String language = request.getLanguage();
parserText = request.getText();
parameters = iArgs;
parameters = iArgs;
if (language.equalsIgnoreCase("SQL")) {
// SPECIAL CASE: EXECUTE THE COMMANDS IN SEQUENCE
try {
parserText = preParse(parserText, iArgs);
} catch (ParseException e) {
throw new OCommandExecutionException("Invalid script:" + e.getMessage());
}
return executeSQL();
} else {
return executeJsr223Script(language, iContext, iArgs);
}
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OCommandExecutorScript method evaluateIfCondition.
private boolean evaluateIfCondition(String lastCommand) {
String cmd = lastCommand;
// remove IF
cmd = cmd.trim().substring(2);
// remove {
cmd = cmd.trim().substring(0, cmd.trim().length() - 1);
OSQLFilter condition = OSQLEngine.getInstance().parseCondition(cmd, getContext(), "IF");
Object result = null;
try {
result = condition.evaluate(null, null, getContext());
} catch (Exception e) {
throw new OCommandExecutionException("Could not evaluate IF condition: " + cmd + " - " + e.getMessage());
}
if (Boolean.TRUE.equals(result)) {
return true;
}
return false;
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OCommandExecutorScript method executeJsr223Script.
protected Object executeJsr223Script(final String language, final OCommandContext iContext, final Map<Object, Object> iArgs) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
final OScriptManager scriptManager = Orient.instance().getScriptManager();
CompiledScript compiledScript = request.getCompiledScript();
final OPartitionedObjectPool.PoolEntry<ScriptEngine> entry = scriptManager.acquireDatabaseEngine(db.getName(), language);
final ScriptEngine scriptEngine = entry.object;
try {
if (compiledScript == null) {
if (!(scriptEngine instanceof Compilable))
throw new OCommandExecutionException("Language '" + language + "' does not support compilation");
final Compilable c = (Compilable) scriptEngine;
try {
compiledScript = c.compile(parserText);
} catch (ScriptException e) {
scriptManager.throwErrorMessage(e, parserText);
}
request.setCompiledScript(compiledScript);
}
final Bindings binding = scriptManager.bind(compiledScript.getEngine().getBindings(ScriptContext.ENGINE_SCOPE), (ODatabaseDocumentTx) db, iContext, iArgs);
try {
final Object ob = compiledScript.eval(binding);
return OCommandExecutorUtility.transformResult(ob);
} catch (ScriptException e) {
throw OException.wrapException(new OCommandScriptException("Error on execution of the script", request.getText(), e.getColumnNumber()), e);
} finally {
scriptManager.unbind(binding, iContext, iArgs);
}
} finally {
scriptManager.releaseDatabaseEngine(language, db.getName(), entry);
}
}
Aggregations