Search in sources :

Example 31 with ORecord

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

the class ORecordIteratorCluster method next.

/**
 * Return the element at the current position and move forward the cursor to the next position available.
 *
 * @return the next record found, otherwise the NoSuchElementException exception is thrown when no more records are found.
 */
@SuppressWarnings("unchecked")
public REC next() {
    checkDirection(true);
    ORecord record;
    // ITERATE UNTIL THE NEXT GOOD RECORD
    while (hasNext()) {
        // FOUND
        if (currentRecord != null) {
            try {
                return (REC) currentRecord;
            } finally {
                currentRecord = null;
            }
        }
        record = getTransactionEntry();
        if (record != null)
            return (REC) record;
    }
    return null;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord)

Example 32 with ORecord

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

the class OFindReferenceHelper method browseCluster.

private static void browseCluster(final ODatabaseDocument iDatabase, final Set<ORID> iSourceRIDs, final Map<ORID, Set<ORID>> map, final String iClusterName) {
    for (ORecord record : iDatabase.browseCluster(iClusterName)) {
        if (record instanceof ODocument) {
            try {
                for (String fieldName : ((ODocument) record).fieldNames()) {
                    Object value = ((ODocument) record).field(fieldName);
                    checkObject(iSourceRIDs, map, value, (ODocument) record);
                }
            } catch (Exception e) {
                OLogManager.instance().debug(null, "Error reading record " + record.getIdentity(), e);
            }
        }
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 33 with ORecord

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

the class OSQLFunctionRuntime method execute.

/**
 * Execute a function.
 *
 * @param iCurrentRecord
 *          Current record
 * @param iCurrentResult
 *          TODO
 * @param iContext
 * @return
 */
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult, final OCommandContext iContext) {
    // RESOLVE VALUES USING THE CURRENT RECORD
    for (int i = 0; i < configuredParameters.length; ++i) {
        runtimeParameters[i] = configuredParameters[i];
        if (configuredParameters[i] instanceof OSQLFilterItemField) {
            runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
        } else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
            runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult, iContext);
        else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
            runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
        } else if (configuredParameters[i] instanceof OCommandSQL) {
            try {
                runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
            } catch (OCommandExecutorNotFoundException e) {
                // TRY WITH SIMPLE CONDITION
                final String text = ((OCommandSQL) configuredParameters[i]).getText();
                final OSQLPredicate pred = new OSQLPredicate(text);
                runtimeParameters[i] = pred.evaluate(iCurrentRecord instanceof ORecord ? (ORecord) iCurrentRecord : null, (ODocument) iCurrentResult, iContext);
                // REPLACE ORIGINAL PARAM
                configuredParameters[i] = pred;
            }
        } else if (configuredParameters[i] instanceof OSQLPredicate)
            runtimeParameters[i] = ((OSQLPredicate) configuredParameters[i]).evaluate(iCurrentRecord.getRecord(), (iCurrentRecord instanceof ODocument ? (ODocument) iCurrentResult : null), iContext);
        else if (configuredParameters[i] instanceof String) {
            if (configuredParameters[i].toString().startsWith("\"") || configuredParameters[i].toString().startsWith("'"))
                runtimeParameters[i] = OIOUtils.getStringContent(configuredParameters[i]);
        }
    }
    if (function.getMaxParams() == -1 || function.getMaxParams() > 0) {
        if (runtimeParameters.length < function.getMinParams() || (function.getMaxParams() > -1 && runtimeParameters.length > function.getMaxParams()))
            throw new OCommandExecutionException("Syntax error: function '" + function.getName() + "' needs " + (function.getMinParams() == function.getMaxParams() ? function.getMinParams() : function.getMinParams() + "-" + function.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
    }
    final Object functionResult = function.execute(iThis, iCurrentRecord, iCurrentResult, runtimeParameters, iContext);
    if (functionResult instanceof OAutoConvertToRecord)
        // FORCE AVOIDING TO CONVERT IN RECORD
        ((OAutoConvertToRecord) functionResult).setAutoConvertToRecord(false);
    return transformValue(iCurrentRecord, iContext, functionResult);
}
Also used : OSQLFilterItemVariable(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemVariable) OCommandExecutorNotFoundException(com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoConvertToRecord(com.orientechnologies.orient.core.db.record.OAutoConvertToRecord) OSQLPredicate(com.orientechnologies.orient.core.sql.filter.OSQLPredicate) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 34 with ORecord

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

the class ODatabaseDocumentSaveClusterTest method testSaveCluster.

@Test
public void testSaveCluster() {
    OClass clazz = db.getMetadata().getSchema().createClass("test");
    int res = db.addCluster("test_one");
    clazz.addCluster("test_one");
    ORecord saved = db.save(new ODocument("test"), "test_one");
    Assert.assertEquals(saved.getIdentity().getClusterId(), res);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 35 with ORecord

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

the class HookReadTest method testSelectChangedInHook.

@Test
public void testSelectChangedInHook() {
    database.registerHook(new ORecordHook() {

        @Override
        public void onUnregister() {
        }

        @Override
        public RESULT onTrigger(TYPE iType, ORecord iRecord) {
            if (iType == TYPE.AFTER_READ)
                ((ODocument) iRecord).field("read", "test");
            return RESULT.RECORD_CHANGED;
        }

        @Override
        public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
            return null;
        }
    });
    database.save(new ODocument("TestClass"));
    List<ODocument> res = database.query(new OSQLSynchQuery<Object>("select from TestClass"));
    assertEquals(res.get(0).field("read"), "test");
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)194 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)91 ORecordId (com.orientechnologies.orient.core.id.ORecordId)40 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)36 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)27 ORID (com.orientechnologies.orient.core.id.ORID)27 IOException (java.io.IOException)21 OException (com.orientechnologies.common.exception.OException)17 Test (org.junit.Test)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)15 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)8 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)8 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7