Search in sources :

Example 1 with OSQLTarget

use of com.orientechnologies.orient.core.sql.filter.OSQLTarget in project orientdb by orientechnologies.

the class OInCondition method query.

private Object query(String text, OCommandContext ctx) {
    OSQLTarget target = new OSQLTarget(text, ctx);
    Iterable targetResult = (Iterable) target.getTargetRecords();
    if (targetResult == null) {
        return null;
    }
    return targetResult.iterator();
}
Also used : OSQLTarget(com.orientechnologies.orient.core.sql.filter.OSQLTarget)

Example 2 with OSQLTarget

use of com.orientechnologies.orient.core.sql.filter.OSQLTarget in project orientdb by orientechnologies.

the class OMatchStatement method query.

private Iterator<OIdentifiable> query(String className, OWhereClause oWhereClause, OCommandContext ctx) {
    final ODatabaseDocument database = getDatabase();
    OClass schemaClass = database.getMetadata().getSchema().getClass(className);
    database.checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_READ, schemaClass.getName().toLowerCase());
    Iterable<ORecord> baseIterable = fetchFromIndex(schemaClass, oWhereClause);
    // OSelectStatement stm = buildSelectStatement(className, oWhereClause);
    // return stm.execute(ctx);
    String text;
    if (oWhereClause == null) {
        text = "(select from " + className + ")";
    } else {
        StringBuilder builder = new StringBuilder();
        oWhereClause.toString(ctx.getInputParameters(), builder);
        synchronized (oWhereClause) {
            //this instance is shared...
            replaceIdentifier(oWhereClause, "$currentMatch", "@this");
            text = "(select from " + className + " where " + builder.toString().replaceAll("\\$currentMatch", "@this") + ")";
            replaceIdentifier(oWhereClause, "@this", "$currentMatch");
        }
    }
    OSQLTarget target = new OSQLTarget(text, ctx);
    Iterable targetResult = (Iterable) target.getTargetRecords();
    if (targetResult == null) {
        return null;
    }
    return targetResult.iterator();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OSQLTarget(com.orientechnologies.orient.core.sql.filter.OSQLTarget) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 3 with OSQLTarget

use of com.orientechnologies.orient.core.sql.filter.OSQLTarget in project orientdb by orientechnologies.

the class OSQLCommandTask method execute.

public Object execute(ODistributedRequestId requestId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
    if (ODistributedServerLog.isDebugEnabled())
        ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Execute command=%s db=%s", text.toString(), database.getName());
    Object res;
    while (true) {
        try {
            final OCommandRequest cmd = database.command(new OCommandSQL(text));
            OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) cmd);
            executor.parse(cmd);
            final OCommandExecutor exec = executor instanceof OCommandExecutorSQLDelegate ? ((OCommandExecutorSQLDelegate) executor).getDelegate() : executor;
            if (exec instanceof OCommandExecutorSQLSelect && clusters.size() > 0) {
                // REWRITE THE TARGET TO USE CLUSTERS
                final StringBuilder buffer = new StringBuilder("cluster:[");
                int i = 0;
                for (String c : clusters) {
                    if (i++ > 0)
                        buffer.append(',');
                    buffer.append(c);
                }
                buffer.append("]");
                ((OCommandExecutorSQLSelect) exec).setParsedTarget(new OSQLTarget(buffer.toString(), exec.getContext()));
            }
            if (params != null)
                // EXECUTE WITH PARAMETERS
                res = executor.execute(params);
            else
                res = executor.execute(null);
            break;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    return res;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLTarget(com.orientechnologies.orient.core.sql.filter.OSQLTarget) OCommandExecutorSQLDelegate(com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate) OCommandExecutorSQLSelect(com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException)

Aggregations

OSQLTarget (com.orientechnologies.orient.core.sql.filter.OSQLTarget)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OCommandExecutorSQLDelegate (com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate)1 OCommandExecutorSQLSelect (com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1