Search in sources :

Example 11 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OTraverseRecordProcess method processFields.

private void processFields(Iterator<Object> target) {
    final ODocument doc = this.target.getRecord();
    while (target.hasNext()) {
        Object field = target.next();
        final Object fieldValue;
        if (field instanceof OSQLFilterItem)
            fieldValue = ((OSQLFilterItem) field).getValue(doc, null, null);
        else
            fieldValue = doc.rawField(field.toString());
        if (fieldValue != null) {
            final OTraverseAbstractProcess<?> subProcess;
            if (fieldValue instanceof Iterator<?> || OMultiValue.isMultiValue(fieldValue)) {
                final Iterator<?> coll;
                if (fieldValue instanceof ORecordLazyMultiValue)
                    coll = ((ORecordLazyMultiValue) fieldValue).rawIterator();
                else
                    coll = OMultiValue.getMultiValueIterator(fieldValue, false);
                subProcess = new OTraverseMultiValueProcess(command, (Iterator<Object>) coll, getPath().appendField(field.toString()));
            } else if (fieldValue instanceof OIdentifiable && ((OIdentifiable) fieldValue).getRecord() instanceof ODocument) {
                subProcess = new OTraverseRecordProcess(command, (ODocument) ((OIdentifiable) fieldValue).getRecord(), getPath().appendField(field.toString()));
            } else
                continue;
            command.getContext().push(subProcess);
        }
    }
}
Also used : Iterator(java.util.Iterator) OSQLFilterItem(com.orientechnologies.orient.core.sql.filter.OSQLFilterItem) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)

Example 12 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OClassImpl method firePropertyNameMigration.

public void firePropertyNameMigration(final ODatabaseDocument database, final String propertyName, final String newPropertyName, final OType type) {
    final boolean strictSQL = ((ODatabaseInternal) database).getStorage().getConfiguration().isStrictSql();
    database.query(new OSQLAsynchQuery<Object>("select from " + getEscapedName(name, strictSQL) + " where " + getEscapedName(propertyName, strictSQL) + " is not null ", new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            final ODocument record = ((OIdentifiable) iRecord).getRecord();
            record.setFieldType(propertyName, type);
            record.field(newPropertyName, record.field(propertyName), type);
            database.save(record);
            return true;
        }

        @Override
        public void end() {
        }

        @Override
        public Object getResult() {
            return null;
        }
    }));
}
Also used : ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OIndexMultiValues method remove.

@Override
public boolean remove(Object key, final OIdentifiable value) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null) {
                return false;
            }
            final OModifiableBoolean removed = new OModifiableBoolean(false);
            final Callable<Object> creator = new EntityRemover(value, removed, values);
            while (true) try {
                storage.updateIndexEntry(indexId, key, creator);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return removed.getValue();
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 14 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OIndexMultiValues method get.

public Set<OIdentifiable> get(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null)
                return Collections.emptySet();
            return Collections.unmodifiableSet(values);
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 15 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OFetchHelper method fetchCollectionRidMap.

@SuppressWarnings("unchecked")
private static void fetchCollectionRidMap(final OFetchPlan iFetchPlan, final Object fieldValue, final String fieldName, final int iCurrentLevel, final int iLevelFromRoot, final int iFieldDepthLevel, final Map<ORID, Integer> parsedRecords, final String iFieldPathFromRoot, final OFetchContext iContext) throws IOException {
    final Iterable<OIdentifiable> linked = (Iterable<OIdentifiable>) fieldValue;
    for (OIdentifiable d : linked) {
        if (d != null) {
            // GO RECURSIVELY
            d = d.getRecord();
            updateRidMap(iFetchPlan, (ODocument) d, iCurrentLevel, iLevelFromRoot, iFieldDepthLevel, parsedRecords, iFieldPathFromRoot, iContext);
        }
    }
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21