Search in sources :

Example 26 with ODatabaseSession

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();
}
Also used : ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession)

Example 27 with ODatabaseSession

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");
}
Also used : OrientDB(com.orientechnologies.orient.core.db.OrientDB) AbstractDataInstallator(ru.ydn.wicket.wicketorientdb.AbstractDataInstallator) OSchemaHelper(ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper) Random(java.util.Random) EmbeddOrientDbApplicationListener(ru.ydn.wicket.wicketorientdb.EmbeddOrientDbApplicationListener) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) Date(java.sql.Date) OrientDbWebApplication(ru.ydn.wicket.wicketorientdb.OrientDbWebApplication) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 28 with ODatabaseSession

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();
    }
}
Also used : ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession)

Example 29 with ODatabaseSession

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();
        }
    }
}
Also used : ODatabaseRecordThreadLocal(com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 30 with ODatabaseSession

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));
    }
}
Also used : java.util(java.util) ConvertToODocumentFunction(ru.ydn.wicket.wicketorientdb.utils.ConvertToODocumentFunction) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) DocumentWrapperTransformer(ru.ydn.wicket.wicketorientdb.utils.DocumentWrapperTransformer) StringQueryManager(ru.ydn.wicket.wicketorientdb.utils.query.StringQueryManager) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) IFilterCriteriaManager(ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager) IModel(org.apache.wicket.model.IModel) FilterCriteriaType(ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaType) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Function(com.google.common.base.Function) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) OrientDbWebSession(ru.ydn.wicket.wicketorientdb.OrientDbWebSession) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) IQueryManager(ru.ydn.wicket.wicketorientdb.utils.query.IQueryManager) IFilterCriteria(ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteria) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) OSchemaUtils(ru.ydn.wicket.wicketorientdb.utils.OSchemaUtils) GetObjectFunction(ru.ydn.wicket.wicketorientdb.utils.GetObjectFunction) ORecord(com.orientechnologies.orient.core.record.ORecord) OResultSet(com.orientechnologies.orient.core.sql.executor.OResultSet) SortOrder(org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder) OElement(com.orientechnologies.orient.core.record.OElement) OResultSet(com.orientechnologies.orient.core.sql.executor.OResultSet) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession)

Aggregations

ODatabaseSession (com.orientechnologies.orient.core.db.ODatabaseSession)31 Test (org.junit.Test)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)19 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)17 Ignore (org.junit.Ignore)10 ORID (com.orientechnologies.orient.core.id.ORID)6 ODocumentHookAbstract (com.orientechnologies.orient.core.hook.ODocumentHookAbstract)5 OResultSet (com.orientechnologies.orient.core.sql.executor.OResultSet)4 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OSchemaHelper (ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper)2 Function (com.google.common.base.Function)1 Maps (com.google.common.collect.Maps)1 OResettable (com.orientechnologies.common.util.OResettable)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseRecordThreadLocal (com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal)1 OrientDB (com.orientechnologies.orient.core.db.OrientDB)1