Search in sources :

Example 36 with OCommandExecutionException

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) MemoryIndex(org.apache.lucene.index.memory.MemoryIndex) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) IOException(java.io.IOException)

Example 37 with OCommandExecutionException

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");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 38 with OCommandExecutionException

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);
    }
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException)

Example 39 with OCommandExecutionException

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;
}
Also used : OSQLFilter(com.orientechnologies.orient.core.sql.filter.OSQLFilter) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException)

Example 40 with OCommandExecutionException

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);
    }
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OPartitionedObjectPool(com.orientechnologies.common.concur.resource.OPartitionedObjectPool)

Aggregations

OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)82 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)19 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OException (com.orientechnologies.common.exception.OException)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 IOException (java.io.IOException)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ORecord (com.orientechnologies.orient.core.record.ORecord)4 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ArrayList (java.util.ArrayList)4 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3