use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TransactionlessForm method beforeUpdateFormComponentModels.
@Override
protected void beforeUpdateFormComponentModels() {
super.beforeUpdateFormComponentModels();
ODatabaseSession db = OrientDbWebSession.get().getDatabaseSession();
isTransactionActive = db.getTransaction().isActive();
if (isTransactionActive)
db.commit();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class WicketApplication method init.
/**
* @see org.apache.wicket.Application#init()
*/
@Override
public void init() {
super.init();
getApplicationListeners().add(new EmbeddOrientDbApplicationListener(WicketApplication.class.getResource("db.config.xml")) {
@Override
public void onAfterServerStartupAndActivation(OrientDbWebApplication app) throws Exception {
OrientDB orientDB = getServer().getContext();
orientDB.createIfNotExists(getOrientDbSettings().getDbName(), getOrientDbSettings().getDbType());
}
});
getOrientDbSettings().setDbName(DB_NAME);
getOrientDbSettings().setDbType(ODatabaseType.MEMORY);
getOrientDbSettings().setGuestUserName("admin");
getOrientDbSettings().setGuestPassword("admin");
OrientDBHttpAPIResource.mountOrientDbRestApi(this);
getApplicationListeners().add(new AbstractDataInstallator() {
@Override
protected void installData(OrientDbWebApplication app, ODatabaseSession db) {
OSchemaHelper helper = OSchemaHelper.bind(db);
helper.oClass(CLASS_NAME).oProperty(PROP_NAME, OType.STRING).oProperty(PROP_INT, OType.INTEGER).oProperty(PROP_DATE, OType.DATE);
if (helper.getOClass().count() == 0) {
Random random = new Random();
Date today = new Date(System.currentTimeMillis());
int delta = 365 * 24 * 60 * 60;
for (int i = 0; i < 50; i++) {
ODocument doc = new ODocument(helper.getOClass());
doc.field(PROP_NAME, "Name for #" + i);
doc.field(PROP_INT, i);
doc.field(PROP_DATE, new Date(today.getTime() + (random.nextInt(2 * delta) - delta) * 1000));
doc.save();
}
}
}
});
LOG.info("Wicket-OrientDB Demo Web App has been started");
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class AbstractCustomValueModel method setObject.
@Override
public void setObject(V object) {
ODatabaseSession db = OrientDbWebSession.get().getDatabaseSession();
boolean isActiveTransaction = db.getTransaction().isActive();
// Schema changes should be done outside of transaction
if (isActiveTransaction)
db.commit();
try {
setValue(objectModel.getObject(), parameterModel.getObject(), object);
} finally {
if (isActiveTransaction)
db.begin();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class DBClosure method execute.
/**
* @return result of execution
*/
public final V execute() {
ODatabaseSession db = null;
ODatabaseRecordThreadLocal orientDbThreadLocal = ODatabaseRecordThreadLocal.instance();
ODatabaseDocumentInternal oldDb = orientDbThreadLocal.getIfDefined();
if (oldDb != null) {
// Required to avoid stack of transactions
orientDbThreadLocal.remove();
}
try {
db = openNewODatabaseSession();
db.activateOnCurrentThread();
return execute(db);
} finally {
if (db != null) {
db.close();
}
if (oldDb != null) {
orientDbThreadLocal.set(oldDb);
} else {
orientDbThreadLocal.remove();
}
}
}
use of com.orientechnologies.orient.core.db.ODatabaseSession 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