use of com.orientechnologies.orient.core.sql.executor.OResultSet in project wicket-orientdb by OrienteerBAP.
the class OrientDBSettingsTest method testInstallingHooks.
@Test
public void testInstallingHooks() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OClass clazz = db.getMetadata().getSchema().getClass("TestHooks");
assertNotNull(clazz);
try (OResultSet result = db.query("select from TestHooks")) {
assertTrue(result.hasNext());
ODocument doc = (ODocument) result.next().getElement().orElse(null);
assertNotNull(doc);
assertEquals("HOOK", doc.field("name"));
}
}
use of com.orientechnologies.orient.core.sql.executor.OResultSet in project wicket-orientdb by OrienteerBAP.
the class OSchemaHelper method oDocument.
/**
* Create an {@link ODocument} if required of an current class.
* Existance of an document checked by specified primary key field name and required value
* @param pkField primary key field name
* @param pkValue required primary key value
* @return this helper
*/
public OSchemaHelper oDocument(String pkField, Object pkValue) {
checkOClass();
try (OResultSet result = db.query("select from " + lastClass.getName() + " where " + pkField + " = ? limit 1", pkValue)) {
if (result.hasNext()) {
lastDocument = (ODocument) result.next().toElement();
} else {
lastDocument = new ODocument(lastClass);
lastDocument.field(pkField, pkValue);
}
}
return this;
}
use of com.orientechnologies.orient.core.sql.executor.OResultSet in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testInHook.
@Test
public void testInHook() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass oClass = schema.createClass("TestInHook");
oClass.createProperty("a", OType.INTEGER);
oClass.createProperty("b", OType.INTEGER);
oClass.createProperty("c", OType.INTEGER);
ODocument doc = new ODocument(oClass);
doc.field("a", 2);
doc.field("b", 2);
doc.save();
doc.reload();
assertEquals(2, (Object) doc.field("a"));
assertEquals(2, (Object) doc.field("b"));
assertNull(doc.field("c"));
db.registerHook(new ODocumentHookAbstract(db) {
{
setIncludeClasses("TestInHook");
}
@Override
public void onRecordAfterCreate(ODocument iDocument) {
onRecordAfterRead(iDocument);
}
@Override
public void onRecordAfterRead(ODocument iDocument) {
String script = "select sum(a, b) as value from " + iDocument.getIdentity();
try (OResultSet result = database.query(script)) {
if (result.hasNext()) {
iDocument.field("c", (Object) result.next().getProperty("value"));
}
}
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
doc.reload();
assertEquals(2, (Object) doc.field("a"));
assertEquals(2, (Object) doc.field("b"));
assertEquals(4, (Object) doc.field("c"));
doc = new ODocument(oClass);
doc.field("a", 3);
doc.field("b", 3);
doc.save();
doc.reload();
assertEquals(3, (Object) doc.field("a"));
assertEquals(3, (Object) doc.field("b"));
assertEquals(6, (Object) doc.field("c"));
}
use of com.orientechnologies.orient.core.sql.executor.OResultSet in project wicket-orientdb by OrienteerBAP.
the class OQueryModel method size.
/**
* Get the size of the data
* @return results size
*/
public long size() {
if (size == null) {
ODatabaseSession db = OrientDbWebSession.get().getDatabaseSession();
try (OResultSet result = db.query(queryManager.getCountSql(), prepareParams())) {
if (result.hasNext()) {
Number sizeNumber = result.next().getProperty("count");
size = sizeNumber != null ? sizeNumber.longValue() : 0;
} else {
size = 0L;
}
}
}
return size;
}
use of com.orientechnologies.orient.core.sql.executor.OResultSet in project wicket-orientdb by OrienteerBAP.
the class OQueryModel method load.
@SuppressWarnings("unchecked")
protected List<K> load() {
ODatabaseSession db = OrientDbWebSession.get().getDatabaseSession();
String sql = prepareSql(null, null);
try (OResultSet result = db.query(sql, prepareParams())) {
if (transformer != null) {
return result.elementStream().map(e -> transformer.apply(e)).collect(Collectors.toCollection(LinkedList::new));
}
return result.elementStream().map(e -> (K) e).collect(Collectors.toCollection(LinkedList::new));
}
}
Aggregations