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;
}
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;
}
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;
}
Aggregations