Search in sources :

Example 16 with OCommandRequest

use of com.orientechnologies.orient.core.command.OCommandRequest in project orientdb by orientechnologies.

the class OIndexRemote method descCursor.

@Override
public OIndexCursor descCursor() {
    final OCommandRequest cmd = formatCommand(QUERY_ENTRIES_DESC, name);
    final Collection<ODocument> result = getDatabase().command(cmd).execute();
    return new OIndexAbstractCursor() {

        private final Iterator<ODocument> documentIterator = result.iterator();

        @Override
        public Map.Entry<Object, OIdentifiable> nextEntry() {
            if (!documentIterator.hasNext())
                return null;
            final ODocument value = documentIterator.next();
            return new Map.Entry<Object, OIdentifiable>() {

                @Override
                public Object getKey() {
                    return value.field("key");
                }

                @Override
                public OIdentifiable getValue() {
                    return value.field("rid");
                }

                @Override
                public OIdentifiable setValue(OIdentifiable value) {
                    throw new UnsupportedOperationException("setValue");
                }
            };
        }
    };
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OCommandRequest

use of com.orientechnologies.orient.core.command.OCommandRequest in project orientdb by orientechnologies.

the class OIndexRemote method getKeySize.

public long getKeySize() {
    final OCommandRequest cmd = formatCommand(QUERY_KEY_SIZE, name);
    final List<ODocument> result = getDatabase().command(cmd).execute();
    return (Long) result.get(0).field("size");
}
Also used : OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 18 with OCommandRequest

use of com.orientechnologies.orient.core.command.OCommandRequest in project orientdb by orientechnologies.

the class OIndexRemote method put.

public OIndexRemote<T> put(final Object iKey, final OIdentifiable iValue) {
    if (iValue instanceof ORecord && !iValue.getIdentity().isValid())
        // SAVE IT BEFORE TO PUT
        ((ORecord) iValue).save();
    if (iValue.getIdentity().isNew())
        throw new OIndexException("Cannot insert values in manual indexes against remote protocol during a transaction. Temporary RID cannot be managed at server side");
    final OCommandRequest cmd = formatCommand(QUERY_PUT, name);
    getDatabase().command(cmd).execute(iKey, iValue.getIdentity());
    return this;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest)

Example 19 with OCommandRequest

use of com.orientechnologies.orient.core.command.OCommandRequest in project orientdb by orientechnologies.

the class OIndexRemoteMultiValue method inverseIterator.

public Iterator<Entry<Object, Collection<OIdentifiable>>> inverseIterator() {
    final OCommandRequest cmd = formatCommand(QUERY_ENTRIES, name);
    final List<ODocument> result = getDatabase().command(cmd).execute();
    final Map<Object, Collection<OIdentifiable>> map = new LinkedHashMap<Object, Collection<OIdentifiable>>();
    for (ListIterator<ODocument> it = result.listIterator(); it.hasPrevious(); ) {
        ODocument d = it.previous();
        d.setLazyLoad(false);
        Collection<OIdentifiable> rids = map.get(d.field("key"));
        if (rids == null) {
            rids = new HashSet<OIdentifiable>();
            map.put(d.field("key"), rids);
        }
        rids.add((OIdentifiable) d.field("rid"));
    }
    return map.entrySet().iterator();
}
Also used : Collection(java.util.Collection) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with OCommandRequest

use of com.orientechnologies.orient.core.command.OCommandRequest in project orientdb by orientechnologies.

the class OIndexRemoteMultiValue method iterator.

public Iterator<Entry<Object, Collection<OIdentifiable>>> iterator() {
    final OCommandRequest cmd = formatCommand(QUERY_ENTRIES, name);
    final Collection<ODocument> result = getDatabase().command(cmd).execute();
    final Map<Object, Collection<OIdentifiable>> map = new LinkedHashMap<Object, Collection<OIdentifiable>>();
    for (final ODocument d : result) {
        d.setLazyLoad(false);
        Collection<OIdentifiable> rids = map.get(d.field("key"));
        if (rids == null) {
            rids = new HashSet<OIdentifiable>();
            map.put(d.field("key"), rids);
        }
        rids.add((OIdentifiable) d.field("rid"));
    }
    return map.entrySet().iterator();
}
Also used : Collection(java.util.Collection) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

OCommandRequest (com.orientechnologies.orient.core.command.OCommandRequest)21 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OCommandGremlin (com.orientechnologies.orient.graph.gremlin.OCommandGremlin)1