Search in sources :

Example 11 with OSQLAsynchQuery

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

the class SQLAsynchQuerySpeedTest method cycle.

@Override
@SuppressWarnings("unchecked")
public void cycle() throws UnsupportedEncodingException {
    System.out.println("1 -----------------------");
    OrientTest.printRecords((List<? extends ORecord>) database.command(new OSQLAsynchQuery<ODocument>("select * from animal where column(0) < 5 or column(0) >= 3 and column(5) < 7", new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            OrientTest.printRecord(resultCount++, iRecord);
            return true;
        }

        @Override
        public void end() {
        }

        @Override
        public Object getResult() {
            return null;
        }
    })).execute());
}
Also used : OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery)

Example 12 with OSQLAsynchQuery

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

the class OMatchStatement method parse.

// ------------------------------------------------------------------
// query parsing and optimization
// ------------------------------------------------------------------
/**
 * this method parses the statement
 *
 * @param iRequest Command request implementation.
 * @param <RET>
 *
 * @return
 */
@Override
public <RET extends OCommandExecutor> RET parse(OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    if (iRequest instanceof OSQLSynchQuery) {
        request = (OSQLSynchQuery<ODocument>) iRequest;
    } else if (iRequest instanceof OSQLAsynchQuery) {
        request = (OSQLAsynchQuery<ODocument>) iRequest;
    } else {
        // BUILD A QUERY OBJECT FROM THE COMMAND REQUEST
        request = new OSQLSynchQuery<ODocument>(textRequest.getText());
        if (textRequest.getResultListener() != null) {
            request.setResultListener(textRequest.getResultListener());
        }
    }
    String queryText = textRequest.getText();
    // please, do not look at this... refactor this ASAP with new executor structure
    final InputStream is = new ByteArrayInputStream(queryText.getBytes());
    final OrientSql osql = new OrientSql(is);
    try {
        OMatchStatement result = (OMatchStatement) osql.parse();
        this.matchExpressions = result.matchExpressions;
        this.returnItems = result.returnItems;
        this.returnAliases = result.returnAliases;
        this.limit = result.limit;
    } catch (ParseException e) {
        OCommandSQLParsingException ex = new OCommandSQLParsingException(e, queryText);
        OErrorCode.QUERY_PARSE_ERROR.throwException(ex.getMessage(), ex);
    }
    assignDefaultAliases(this.matchExpressions);
    pattern = new Pattern();
    for (OMatchExpression expr : this.matchExpressions) {
        pattern.addExpression(expr);
    }
    Map<String, OWhereClause> aliasFilters = new LinkedHashMap<String, OWhereClause>();
    Map<String, String> aliasClasses = new LinkedHashMap<String, String>();
    Map<String, ORID> aliasRids = new LinkedHashMap<String, ORID>();
    for (OMatchExpression expr : this.matchExpressions) {
        addAliases(expr, aliasFilters, aliasClasses, aliasRids, context);
    }
    this.aliasFilters = aliasFilters;
    this.aliasClasses = aliasClasses;
    this.aliasRids = aliasRids;
    rebindFilters(aliasFilters);
    pattern.validate();
    return (RET) this;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ByteArrayInputStream(java.io.ByteArrayInputStream) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSQLAsynchQuery (com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery)12 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)4 OCommandResultListener (com.orientechnologies.orient.core.command.OCommandResultListener)4 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Test (org.testng.annotations.Test)2 OException (com.orientechnologies.common.exception.OException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)1 OCommandCache (com.orientechnologies.orient.core.cache.OCommandCache)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1