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;
}
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);
}
}
}
}
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);
}
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);
}
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");
}
Aggregations