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