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();
}
Aggregations