public void replace(Object entity) throws DbException { try { beginTransaction(); createTableIfNotExist(entity.getClass()); execNonQuery(SqlInfoBuilder.buildReplaceSqlInfo(this, entity)); setTransactionSuccessful(); } finally { endTransaction(); } }
// ***************************** private operations with out transaction // ***************************** private void saveOrUpdateWithoutTransaction(Object entity) throws DbException { Table table = Table.get(this, entity.getClass()); Id id = table.id; if (id.isAutoIncrement()) { if (id.getColumnValue(entity) != null) { execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity)); } else { saveBindingIdWithoutTransaction(entity); } } else { execNonQuery(SqlInfoBuilder.buildReplaceSqlInfo(this, entity)); } }
public void replaceAll(List<?> entities) throws DbException { if (entities == null || entities.size() == 0) return; try { beginTransaction(); createTableIfNotExist(entities.get(0).getClass()); for (Object entity : entities) { execNonQuery(SqlInfoBuilder.buildReplaceSqlInfo(this, entity)); } setTransactionSuccessful(); } finally { endTransaction(); } }