Search in sources :

Example 1 with OQueryAbstract

use of com.orientechnologies.orient.core.query.OQueryAbstract in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method command.

/**
   * Executes the command request and return the result back.
   */
public Object command(final OCommandRequestText iCommand) {
    while (true) {
        try {
            final OCommandExecutor executor = OCommandManager.instance().getExecutor(iCommand);
            // COPY THE CONTEXT FROM THE REQUEST
            executor.setContext(iCommand.getContext());
            executor.setProgressListener(iCommand.getProgressListener());
            executor.parse(iCommand);
            return executeCommand(iCommand, executor);
        } catch (ORetryQueryException e) {
            if (iCommand instanceof OQueryAbstract) {
                final OQueryAbstract query = (OQueryAbstract) iCommand;
                query.reset();
            }
            continue;
        }
    }
}
Also used : OCommandExecutor(com.orientechnologies.orient.core.command.OCommandExecutor) OQueryAbstract(com.orientechnologies.orient.core.query.OQueryAbstract)

Example 2 with OQueryAbstract

use of com.orientechnologies.orient.core.query.OQueryAbstract in project orientdb by orientechnologies.

the class OServerCommandGetQuery method execute.

@Override
@SuppressWarnings("unchecked")
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: query/<database>/sql/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is set to 20 by default. Set to 0 to have no limits.");
    final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
    String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
    final String text = urlParts[3];
    final String accept = iRequest.getHeader("accept");
    iRequest.data.commandInfo = "Query";
    iRequest.data.commandDetail = text;
    ODatabaseDocument db = null;
    final List<OIdentifiable> response;
    try {
        db = getProfiledDatabaseInstance(iRequest);
        final OQueryAbstract command = new OSQLSynchQuery<ODocument>(text, limit).setFetchPlan(fetchPlan);
        // REQUEST CAN'T MODIFY THE RESULT, SO IT'S CACHEABLE
        command.setCacheableResult(true);
        response = (List<OIdentifiable>) db.query(command);
        fetchPlan = command.getFetchPlan();
        Map<String, Object> additionalContent = null;
        final List<String> tips = (List<String>) command.getContext().getVariable("tips");
        if (tips != null) {
            additionalContent = new HashMap<String, Object>(1);
            additionalContent.put("warnings", tips);
        }
        iResponse.writeRecords(response, fetchPlan, null, accept, additionalContent);
    } finally {
        if (db != null)
            db.close();
    }
    return false;
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OQueryAbstract(com.orientechnologies.orient.core.query.OQueryAbstract) List(java.util.List) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OQueryAbstract (com.orientechnologies.orient.core.query.OQueryAbstract)2 OCommandExecutor (com.orientechnologies.orient.core.command.OCommandExecutor)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 List (java.util.List)1