本文整理汇总了Java中com.db4o.ObjectContainer.commit方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectContainer.commit方法的具体用法?Java ObjectContainer.commit怎么用?Java ObjectContainer.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.db4o.ObjectContainer
的用法示例。
在下文中一共展示了ObjectContainer.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void save(T obj) {
if (obj == null) {
return;
}
synchronized (DB4OUtils.class) {
ObjectContainer oc = Db4oEmbedded.openFile(DB4OUtils
.getDataBasePath());
try {
oc.store(obj);
oc.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
oc.close();
}
}
}
示例2: create
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void create(ITransazione sale) throws ObjectAlreadyExistsDbException
{
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
int exist = client.queryByExample(sale).size();
if(exist > 0)
throw new ObjectAlreadyExistsDbException();
if(sale.getClass() != TransazioneSmartProxy.class)
client.store(new TransazioneSmartProxy(sale));
else
client.store(sale);
client.commit();
}
示例3: saveObj
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
@Override
public void saveObj(ScriptableObject obj, String type) {
ObjectContainer con = getDB(type);
HashMap<Object, Object> map;
if (obj.has("_id_", obj)) { //Update
map = con.ext().getByID((long) obj.get("_id_"));
} else { //Save
map = new HashMap<>();
}
for (Object id : obj.getAllIds()) {
map.put(id, obj.get(id));
}
con.store(map);
con.commit();
}
示例4: delete
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
@Override
public void delete(ScriptableObject obj, String type) {
//TODO delete by _id_
ObjectContainer con = getDB(type);
final HashMap<Object, Object> map = new HashMap<>();
for (Object id : obj.getAllIds()) {
map.put(id, obj.get(id));
}
ObjectSet<HashMap<Object, Object>> maps = con.query(new Predicate<HashMap<Object, Object>>() {
@Override
public boolean match(HashMap<Object, Object> et) {
for (Object key : map.keySet()) {
if (!(et.containsKey(key) && et.get(key).equals(map.get(key)))) {
return false;
}
}
return true;
}
});
while (maps.hasNext()) {
con.delete(maps.next());
}
con.commit();
}
示例5: 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();
}
}
}
示例6: saveOrUpdate
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void saveOrUpdate(final T obj, final Match<T> match) {
if (obj == null) {
return;
}
synchronized (DB4OUtils.class) {
ObjectContainer oc = Db4oEmbedded.openFile(DB4OUtils
.getDataBasePath());
try {
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) {
e.printStackTrace();
} finally {
oc.close();
}
}
}
示例7: create
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void create(IScontoVenditaStrategy sconto) throws ObjectAlreadyExistsDbException
{
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
int exist = client.queryByExample(sconto).size();
if(exist > 0)
throw new ObjectAlreadyExistsDbException();
client.store(sconto);
client.commit();
}
示例8: create
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void create(CartaCliente carta) throws ObjectAlreadyExistsDbException
{
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
CartaCliente example = new CartaCliente(carta.getId());
int exist = client.queryByExample(example).size();
System.err.println("Clienti n."+exist);
if(exist > 0)
throw new ObjectAlreadyExistsDbException();
client.store(carta);
client.commit();
}
示例9: create
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void create(IDescrizioneProdotto desc) throws ObjectAlreadyExistsDbException{
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
int result = client.queryByExample(desc).size();
if(result > 0)
throw new ObjectAlreadyExistsDbException();
if(desc.getClass() != DescrizioneProdottoSmartProxy.class)
client.store(new DescrizioneProdottoSmartProxy(desc));
else
client.store(desc);
client.commit();
}
示例10: update
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void update(IDescrizioneProdotto desc) {
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
client.store(desc);
client.commit();
}
示例11: create
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void create(IPrenotazione book) throws ObjectAlreadyExistsDbException
{
ObjectContainer client = DbManagerSingleton.getInstance().getClient();
int exist = client.queryByExample(book).size();
if(exist > 0)
throw new ObjectAlreadyExistsDbException();
if(book.getClass() != PrenotazioneSmartProxy.class)
client.store(new PrenotazioneSmartProxy(book));
else
client.store(book);
client.commit();
}
示例12: invoke
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Transactional transactional = readTransactionMetadata(methodInvocation);
if (transactional.type() != null && transactional.type() == TransactionType.READ_ONLY) {
throw new UnsupportedOperationException("Transaction type READ_ONLY is not supported with DB4O");
}
ObjectContainer oc = internalWorkManager.beginWork();
Object result;
try {
result = methodInvocation.proceed();
} catch (Exception e) {
try {
if (rollbackIfNecessary(transactional, e, oc))
oc.commit();
} finally {
if (isUnitOfWorkTransaction())
endWork();
}
throw e;
}
// normal, so commit the transaction
try {
oc.commit();
} finally {
if (isUnitOfWorkTransaction())
endWork();
}
return result;
}
示例13: deleteObj
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
@Override
public void deleteObj(ScriptableObject obj, String type) {
ObjectContainer con = getDB(type);
final HashMap<Object, Object> map = new HashMap<>();
for (Object id : obj.getAllIds()) {
map.put(id, obj.get(id));
}
ObjectSet<HashMap<Object, Object>> maps = con.query(new Predicate<HashMap<Object, Object>>() {
@Override
public boolean match(HashMap<Object, Object> et) {
for (Object key : map.keySet()) {
if (!(et.containsKey(key) && et.get(key).equals(map.get(key)))) {
return false;
}
}
return true;
}
});
if (maps.hasNext()) {
con.delete(maps.next());
con.commit();
}
}
示例14: storeSystem
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public synchronized void storeSystem(CentralAuthority system) {
ObjectContainer conn = createConnection();
conn.store(system);
conn.commit();
conn.close();
}
示例15: saveOrUpdate
import com.db4o.ObjectContainer; //导入方法依赖的package包/类
public void saveOrUpdate(final T obj, final Match<T> match) {
if (obj == null) {
return;
}
synchronized (DB4OUtils.class) {
ObjectContainer oc = Db4oEmbedded.openFile(DB4OUtils
.getDataBasePath());
try {
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) {
e.printStackTrace();
} finally {
oc.close();
}
}
}