Search in sources :

Example 6 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project divide by HiddenStage.

the class OrientDBDao method query.

@Override
public List<TransientObject> query(Query query) throws DAOException {
    checkDb();
    List<TransientObject> list = new ArrayList<TransientObject>();
    OTransaction transaction = db.getTransaction();
    transaction.begin();
    try {
        String q = query.getSQL();
        System.out.println("OrientDB_Query: " + q);
        if (query.getAction().equals(QueryBuilder.QueryAction.SELECT)) {
            List<ODocument> objects = db.query(new OSQLSynchQuery<ODocument>(q));
            for (ODocument w : objects) {
                list.add(new ODocumentWrapper(w).toObject(TransientObject.class));
            }
        }
        if (query.getAction().equals(QueryBuilder.QueryAction.DELETE)) {
            //            List<ODocument> objects = db.command(new OCommandSQL("delete from io.divide.dao.TestObject1 RETURN BEFORE")).execute();
            Integer objects = db.command(new OCommandSQL(q)).execute();
            TransientObject o = new EmptyTO();
            o.put("count", objects);
            list.add(o);
            System.out.println("Delete: " + objects);
        }
        transaction.commit();
        transaction.close();
    } catch (Exception e) {
        transaction.rollback();
        transaction.close();
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OTransaction(com.orientechnologies.orient.core.tx.OTransaction) TransientObject(io.divide.shared.transitory.TransientObject) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project orientdb by orientechnologies.

the class ODocument method setDirty.

/**
   * Propagates the dirty status to the owner, if any. This happens when the object is embedded in another one.
   */
@Override
public ORecordAbstract setDirty() {
    if (_owners != null) {
        // PROPAGATES TO THE OWNER
        ORecordElement e;
        for (WeakReference<ORecordElement> o : _owners) {
            e = o.get();
            if (e != null)
                e.setDirty();
        }
    } else if (!isDirty())
        getDirtyManager().setDirty(this);
    // THIS IS IMPORTANT TO BE SURE THAT FIELDS ARE LOADED BEFORE IT'S TOO LATE AND THE RECORD _SOURCE IS NULL
    checkForFields();
    super.setDirty();
    boolean addToChangedList = false;
    ORecordElement owner;
    if (!isEmbedded())
        owner = this;
    else {
        owner = getOwner();
        while (owner != null && owner.getOwner() != null) {
            owner = owner.getOwner();
        }
    }
    if (owner instanceof ODocument && ((ODocument) owner).isTrackingChanges() && ((ODocument) owner).getIdentity().isPersistent())
        addToChangedList = true;
    if (addToChangedList) {
        final ODatabaseDocument database = getDatabaseIfDefined();
        if (database != null) {
            final OTransaction transaction = database.getTransaction();
            if (transaction instanceof OTransactionOptimistic) {
                OTransactionOptimistic transactionOptimistic = (OTransactionOptimistic) transaction;
                transactionOptimistic.addChangedDocument(this);
            }
        }
    }
    return this;
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OTransactionOptimistic(com.orientechnologies.orient.core.tx.OTransactionOptimistic)

Example 8 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project orientdb by orientechnologies.

the class OLuceneIndexNotUnique method remove.

@Override
public boolean remove(final Object key, final OIdentifiable value) {
    if (key != null) {
        OTransaction transaction = getDatabase().getTransaction();
        if (transaction.isActive()) {
            transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.REMOVE, encodeKey(key), value);
            OLuceneTxChanges transactionChanges = getTransactionChanges(transaction);
            try {
                transactionChanges.remove(key, value);
            } catch (IOException e) {
                OLogManager.instance().error(this, "Error while removing", e);
            }
            return true;
        } else {
            while (true) {
                try {
                    return storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Boolean>() {

                        @Override
                        public Boolean callEngine(OIndexEngine engine) {
                            OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
                            return indexEngine.remove(key, value);
                        }
                    });
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        }
    }
    return true;
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OLuceneTxChanges(com.orientechnologies.lucene.tx.OLuceneTxChanges) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) OLuceneIndexEngine(com.orientechnologies.lucene.engine.OLuceneIndexEngine) IOException(java.io.IOException)

Aggregations

OTransaction (com.orientechnologies.orient.core.tx.OTransaction)8 OLuceneIndexEngine (com.orientechnologies.lucene.engine.OLuceneIndexEngine)3 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)3 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 TransientObject (io.divide.shared.transitory.TransientObject)3 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OIndexEngineCallback (com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 OException (com.orientechnologies.common.exception.OException)1 OLuceneTxOperations (com.orientechnologies.lucene.OLuceneTxOperations)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OTransactionOptimistic (com.orientechnologies.orient.core.tx.OTransactionOptimistic)1 Map (java.util.Map)1 Document (org.apache.lucene.document.Document)1