use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testDeletionOfDependentClass2.
@Test
public void testDeletionOfDependentClass2() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classAbs = schema.createAbstractClass("TestDeletionAbst");
OClass classA = schema.createClass("TestDeletionA", classAbs);
ODocument doc = new ODocument(classA);
doc.save();
assertEquals(1, classA.count());
OClass classB = schema.createClass("TestDeletionB", classA);
doc = new ODocument(classB);
doc.save();
assertEquals(1, classB.count());
assertEquals(2, classA.count());
schema.dropClass(classB.getName());
assertEquals(1, classA.count());
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class AbstractDataInstallator method onAfterInitialized.
@Override
public void onAfterInitialized(Application application) {
OrientDbWebApplication app = (OrientDbWebApplication) application;
ODatabaseSession db = getDatabase(app);
try {
installData(app, db);
} catch (Exception ex) {
LOG.error("Data can't be installed", ex);
} finally {
db.close();
app.getOrientDbSettings().getContext().invalidateCachedPools();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseSession 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.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testRemovingReadonlyField.
@Test
public void testRemovingReadonlyField() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestRemovingField");
classA.createProperty("name", OType.STRING);
OProperty property = classA.createProperty("property", OType.STRING);
property.setReadonly(true);
ODocument doc = new ODocument(classA);
doc.field("name", "My Name");
doc.field("property", "value1");
doc.save();
doc.field("name", "My Name 2");
doc.field("property", "value2");
doc.undo("property");
doc.save();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testCreationInHook.
@Test
public void testCreationInHook() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
final OClass classA = schema.createClass("TestCreationInHookMain");
final OClass classB = schema.createClass("TestCreationInHookReflect");
classA.createProperty("name", OType.STRING);
classA.createProperty("mirror", OType.LINK).setLinkedClass(classB);
classB.createProperty("name", OType.STRING);
db.registerHook(new ODocumentHookAbstract(db) {
{
setIncludeClasses(classA.getName());
}
@Override
public RESULT onRecordBeforeCreate(ODocument iDocument) {
ODocument mirror = new ODocument(classB);
mirror.field("name", (Object) iDocument.field("name"));
iDocument.field("mirror", mirror);
return RESULT.RECORD_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
for (int i = 0; i < 10; i++) {
String name = "name-" + RANDOM.nextLong();
ODocument doc = new ODocument(classA);
doc.field("name", name);
doc.save();
}
db.commit();
db.close();
db = wicket.getTester().getDatabaseSession();
for (ODocument doc : db.browseClass(classA.getName())) {
String name = doc.field("name");
assertNotNull(name);
ODocument mirror = doc.field("mirror");
assertNotNull(mirror);
assertEquals(name, mirror.field("name"));
}
}
Aggregations