Search in sources :

Example 1 with OBasicResultSet

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

the class OStorageRemote method readSynchResult.

protected Object readSynchResult(final OChannelBinaryAsynchClient network, final ODatabaseDocument database, List<ORecord> temporaryResults) throws IOException {
    final Object result;
    final byte type = network.readByte();
    switch(type) {
        case 'n':
            result = null;
            break;
        case 'r':
            result = OChannelBinaryProtocol.readIdentifiable(network);
            if (result instanceof ORecord)
                database.getLocalCache().updateRecord((ORecord) result);
            break;
        case 'l':
        case 's':
            final int tot = network.readInt();
            final Collection<OIdentifiable> coll;
            coll = type == 's' ? new HashSet<OIdentifiable>(tot) : new OBasicResultSet<OIdentifiable>(tot);
            for (int i = 0; i < tot; ++i) {
                final OIdentifiable resultItem = OChannelBinaryProtocol.readIdentifiable(network);
                if (resultItem instanceof ORecord)
                    database.getLocalCache().updateRecord((ORecord) resultItem);
                coll.add(resultItem);
            }
            result = coll;
            break;
        case 'i':
            coll = new OBasicResultSet<OIdentifiable>();
            byte status;
            while ((status = network.readByte()) > 0) {
                final OIdentifiable record = OChannelBinaryProtocol.readIdentifiable(network);
                if (record == null)
                    continue;
                if (status == 1) {
                    if (record instanceof ORecord)
                        database.getLocalCache().updateRecord((ORecord) record);
                    coll.add(record);
                }
            }
            result = coll;
            break;
        case 'w':
            final OIdentifiable record = OChannelBinaryProtocol.readIdentifiable(network);
            // ((ODocument) record).setLazyLoad(false);
            result = ((ODocument) record).field("result");
            break;
        default:
            OLogManager.instance().warn(this, "Received unexpected result from query: %d", type);
            result = null;
    }
    if (network.getSrvProtocolVersion() >= 17) {
        // LOAD THE FETCHED RECORDS IN CACHE
        byte status;
        while ((status = network.readByte()) > 0) {
            final ORecord record = (ORecord) OChannelBinaryProtocol.readIdentifiable(network);
            if (record != null && status == 2) {
                // PUT IN THE CLIENT LOCAL CACHE
                database.getLocalCache().updateRecord(record);
                if (record.getIdentity().getClusterId() == -2)
                    temporaryResults.add(record);
            }
        }
    }
    return result;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OBasicResultSet(com.orientechnologies.orient.core.sql.query.OBasicResultSet)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OBasicResultSet (com.orientechnologies.orient.core.sql.query.OBasicResultSet)1