Search in sources :

Example 1 with OCommandExecutorSQLResultsetDelegate

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

the class OMatchStatement method query.

private Iterator<OIdentifiable> query(final String className, final OWhereClause oWhereClause, final ORID rid, final OCommandContext ctx) {
    final ODatabaseDocument database = getDatabase();
    if (className != null) {
        OClass schemaClass = database.getMetadata().getSchema().getClass(className);
        database.checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_READ, schemaClass.getName().toLowerCase(Locale.ENGLISH));
    // Iterable<ORecord> baseIterable = fetchFromIndex(schemaClass, oWhereClause);
    }
    // OSelectStatement stm = buildSelectStatement(className, oWhereClause);
    // return stm.execute(ctx);
    String text;
    if (oWhereClause == null) {
        if (rid != null) {
            text = "(select from " + rid + ")";
        } else {
            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 " + (rid != null ? rid : 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;
    }
    if (targetResult instanceof OCommandExecutorSQLSelect) {
        ((OCommandExecutorSQLSelect) targetResult).getContext().setRecordingMetrics(ctx.isRecordingMetrics());
    } else if (targetResult instanceof OCommandExecutorSQLResultsetDelegate) {
        OCommandExecutor delegate = ((OCommandExecutorSQLResultsetDelegate) targetResult).getDelegate();
        if (delegate instanceof OCommandExecutorSQLSelect) {
            delegate.getContext().setRecordingMetrics(ctx.isRecordingMetrics());
        }
    }
    return targetResult.iterator();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OSQLTarget(com.orientechnologies.orient.core.sql.filter.OSQLTarget) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutorSQLSelect(com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect) OCommandExecutorSQLResultsetDelegate(com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetDelegate)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OCommandExecutorSQLResultsetDelegate (com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetDelegate)1 OCommandExecutorSQLSelect (com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect)1 OSQLTarget (com.orientechnologies.orient.core.sql.filter.OSQLTarget)1