本文整理汇总了Java中com.db4o.ObjectContainer.rollback方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectContainer.rollback方法的具体用法?Java ObjectContainer.rollback怎么用?Java ObjectContainer.rollback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.db4o.ObjectContainer
的用法示例。
在下文中一共展示了ObjectContainer.rollback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveOrUpdateAll
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void saveOrUpdateAll(Collection<T> col, final Match<T> match)
throws Exception {
if (col == null || col.size() == 0) {
return;
}
synchronized (DB4OUtils.class) {
ObjectContainer oc = Db4oEmbedded.openFile(DB4OUtils
.getDataBasePath());
try {
for (final T obj : col) {
ObjectSet<T> os = oc.query(new Predicate<T>() {
/**
*
*/
private static final long serialVersionUID = 2793555621552211152L;
@Override
public boolean match(T t) {
// TODO Auto-generated method stub
return match.match(t, obj);
}
});
if (os.size() > 0) {
T old = os.get(0);
DB4OUtils.copyFields(obj, old);
oc.store(old);
} else {
oc.store(obj);
}
}
oc.commit();
} catch (Exception e) {
oc.rollback();
throw e;
} finally {
oc.close();
}
}
}
示例2: rollbackIfNecessary
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
/**
*
* @param transactional
* @param e
* @return Returns true if rollback did NOT occur
*/
private boolean rollbackIfNecessary(Transactional transactional, Exception e, ObjectContainer oc) {
boolean commit = true;
for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) {
if (rollBackOn.isInstance(e)) {
commit = false;
for (Class<? extends Exception> exceptOn : transactional.exceptOn()) {
// an exception to the rollback clause was found; don't rollback (i.e., commit and throw anyway)
if (exceptOn.isInstance(e)) {
commit = true;
break;
}
}
// rollback only if nothing matched the exceptOn check
if (!commit) {
oc.rollback();
}
break;
}
}
return commit;
}