Search in sources :

Example 6 with OPair

use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.

the class OCommandExecutorSQLSetAware method parseSetFields.

protected void parseSetFields(final OClass iClass, final List<OPair<String, Object>> fields) {
    String fieldName;
    String fieldValue;
    while (!parserIsEnded() && (fields.size() == 0 || parserGetLastSeparator() == ',' || parserGetCurrentChar() == ',')) {
        fieldName = parserRequiredWord(false, "Field name expected");
        if (fieldName.equalsIgnoreCase(KEYWORD_WHERE)) {
            parserGoBack();
            break;
        }
        parserNextChars(false, true, "=");
        fieldValue = parserRequiredWord(false, "Value expected", " =><,\r\n", true);
        // INSERT TRANSFORMED FIELD VALUE
        final Object v = convertValue(iClass, fieldName, getFieldValueCountingParameters(fieldValue));
        fields.add(new OPair(fieldName, v));
        parserSkipWhiteSpaces();
    }
    if (fields.size() == 0)
        throwParsingException("Entries to set <field> = <value> are missed. Example: name = 'Bill', salary = 300.2");
}
Also used : OPair(com.orientechnologies.common.util.OPair)

Example 7 with OPair

use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.

the class OCommandExecutorSQLMoveVertex method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLMoveVertex parse(final OCommandRequest iRequest) {
    final ODatabaseDocument database = getDatabase();
    init((OCommandRequestText) iRequest);
    parserRequiredKeyword("MOVE");
    parserRequiredKeyword("VERTEX");
    source = parserRequiredWord(false, "Syntax error", " =><,\r\n");
    if (source == null)
        throw new OCommandSQLParsingException("Cannot find source");
    parserRequiredKeyword("TO");
    String temp = parseOptionalWord(true);
    while (temp != null) {
        if (temp.startsWith("CLUSTER:")) {
            if (className != null)
                throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
            clusterName = temp.substring("CLUSTER:".length());
            if (database.getClusterIdByName(clusterName) == -1)
                throw new OCommandSQLParsingException("Cluster '" + clusterName + "' was not found");
        } else if (temp.startsWith("CLASS:")) {
            if (clusterName != null)
                throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
            className = temp.substring("CLASS:".length());
            clazz = database.getMetadata().getSchema().getClass(className);
            if (clazz == null)
                throw new OCommandSQLParsingException("Class '" + className + "' was not found");
        } else if (temp.equals(KEYWORD_SET)) {
            fields = new ArrayList<OPair<String, Object>>();
            parseSetFields(clazz, fields);
        } else if (temp.equals(KEYWORD_MERGE)) {
            merge = parseJSON();
        } else if (temp.equals(KEYWORD_BATCH)) {
            temp = parserNextWord(true);
            if (temp != null)
                batch = Integer.parseInt(temp);
        }
        temp = parserOptionalWord(true);
        if (parserIsEnded())
            break;
    }
    return this;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OPair(com.orientechnologies.common.util.OPair)

Example 8 with OPair

use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method readRecords.

/**
   * Returns the requested records. The returned order could be different than the requested.
   *
   * @param iRids Set of rids to load in one shot
   */
public Collection<OPair<ORecordId, ORawBuffer>> readRecords(final Collection<ORecordId> iRids) {
    checkOpeness();
    final List<OPair<ORecordId, ORawBuffer>> records = new ArrayList<OPair<ORecordId, ORawBuffer>>();
    if (iRids == null || iRids.isEmpty())
        return records;
    if (transaction.get() != null) {
        for (ORecordId rid : iRids) {
            if (!rid.isPersistent())
                throw new ORecordNotFoundException(rid, "Cannot read record " + rid + " since the position is invalid in database '" + name + '\'');
            records.add(new OPair<ORecordId, ORawBuffer>(rid, doReadRecord(getClusterById(rid.getClusterId()), rid, false)));
        }
        return records;
    }
    // CREATE GROUP OF RIDS PER CLUSTER TO REDUCE LOCKS
    final Map<Integer, List<ORecordId>> ridsPerCluster = getRidsGroupedByCluster(iRids);
    stateLock.acquireReadLock();
    try {
        for (Map.Entry<Integer, List<ORecordId>> entry : ridsPerCluster.entrySet()) {
            final int clusterId = entry.getKey();
            final OCluster clusterSegment = getClusterById(clusterId);
            for (ORecordId rid : entry.getValue()) {
                records.add(new OPair<ORecordId, ORawBuffer>(rid, doReadRecord(clusterSegment, rid, false)));
            }
        }
    } finally {
        stateLock.releaseReadLock();
    }
    return records;
}
Also used : ORecordId(com.orientechnologies.orient.core.id.ORecordId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OPair(com.orientechnologies.common.util.OPair)

Example 9 with OPair

use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.

the class OStorageRemote method updateCollection.

private void updateCollection(final Map<OBonsaiCollectionPointer, OPair<Long, Long>> changes, final OSBTreeCollectionManager collectionManager) throws IOException {
    if (collectionManager == null)
        return;
    for (Map.Entry<OBonsaiCollectionPointer, OPair<Long, Long>> entry : changes.entrySet()) {
        final OBonsaiCollectionPointer pointer = entry.getKey();
        final long mBitsOfId = entry.getValue().getKey();
        final long lBitsOfId = entry.getValue().getValue();
        collectionManager.updateCollectionPointer(new UUID(mBitsOfId, lBitsOfId), pointer);
    }
    if (ORecordSerializationContext.getDepth() <= 1)
        collectionManager.clearPendingCollections();
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OPair(com.orientechnologies.common.util.OPair)

Example 10 with OPair

use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method executeReadRecords.

/**
   * This method is internal, it can be subject to signature change or be removed, do not use.
   *
   * @Internal
   */
public Set<ORecord> executeReadRecords(final Set<ORecordId> iRids, final boolean ignoreCache) {
    checkOpeness();
    checkIfActive();
    getMetadata().makeThreadLocalSchemaSnapshot();
    ORecordSerializationContext.pushContext();
    try {
        final Set<ORecord> records = new HashSet<ORecord>(iRids.size() > 0 ? iRids.size() : 1);
        if (iRids.isEmpty())
            return records;
        final Collection<ORecordId> rids = new ArrayList<ORecordId>(iRids);
        for (Iterator<ORecordId> it = rids.iterator(); it.hasNext(); ) {
            final ORecordId rid = it.next();
            // SEARCH IN LOCAL TX
            ORecord record = getTransaction().getRecord(rid);
            if (record == OTransactionRealAbstract.DELETED_RECORD) {
                // DELETED IN TX
                it.remove();
                continue;
            }
            if (record == null && !ignoreCache)
                // SEARCH INTO THE CACHE
                record = getLocalCache().findRecord(rid);
            if (record != null) {
                // FOUND FROM CACHE
                records.add(record);
                it.remove();
            }
        }
        final Collection<OPair<ORecordId, ORawBuffer>> rawRecords = ((OAbstractPaginatedStorage) storage.getUnderlying()).readRecords(rids);
        for (OPair<ORecordId, ORawBuffer> entry : rawRecords) {
            // NO SAME RECORD TYPE: CAN'T REUSE OLD ONE BUT CREATE A NEW ONE FOR IT
            final ORecord record = Orient.instance().getRecordFactoryManager().newInstance(entry.value.recordType);
            ORecordInternal.fill(record, entry.key, entry.value.version, entry.value.buffer, false);
            records.add(record);
        }
        return records;
    } finally {
        ORecordSerializationContext.pullContext();
        getMetadata().clearThreadLocalSchemaSnapshot();
    }
}
Also used : OPair(com.orientechnologies.common.util.OPair) ORecord(com.orientechnologies.orient.core.record.ORecord) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

OPair (com.orientechnologies.common.util.OPair)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OBonsaiCollectionPointer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OOperationUnitId (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OOperationUnitId)2 StringWriter (java.io.StringWriter)2 Deque (java.util.Deque)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OException (com.orientechnologies.common.exception.OException)1 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)1 OCallable (com.orientechnologies.common.util.OCallable)1 OResettable (com.orientechnologies.common.util.OResettable)1 OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)1 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1