// ***************************** 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)); } }
private boolean saveBindingIdWithoutTransaction(Object entity) throws DbException { Class<?> entityType = entity.getClass(); Table table = Table.get(this, entityType); Id idColumn = table.id; if (idColumn.isAutoIncrement()) { execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(this, entity)); long id = getLastAutoIncrementId(table.tableName); if (id == -1) { return false; } idColumn.setAutoIncrementId(entity, id); return true; } else { execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(this, entity)); return true; } }
public void createTableIfNotExist(Class<?> entityType) throws DbException { if (!tableIsExist(entityType)) { SqlInfo sqlInfo = SqlInfoBuilder.buildCreateTableSqlInfo(this, entityType); execNonQuery(sqlInfo); String execAfterTableCreated = TableUtils.getExecAfterTableCreated(entityType); if (!TextUtils.isEmpty(execAfterTableCreated)) { execNonQuery(execAfterTableCreated); } } }
public void update(Object entity, String... updateColumnNames) throws DbException { if (!tableIsExist(entity.getClass())) return; try { beginTransaction(); execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, updateColumnNames)); setTransactionSuccessful(); } finally { endTransaction(); } }
public void delete(Class<?> entityType, WhereBuilder whereBuilder) throws DbException { if (!tableIsExist(entityType)) return; try { beginTransaction(); execNonQuery(SqlInfoBuilder.buildDeleteSqlInfo(this, entityType, whereBuilder)); setTransactionSuccessful(); } finally { endTransaction(); } }
public void delete(Object entity) throws DbException { if (!tableIsExist(entity.getClass())) return; try { beginTransaction(); execNonQuery(SqlInfoBuilder.buildDeleteSqlInfo(this, entity)); setTransactionSuccessful(); } finally { endTransaction(); } }
public void save(Object entity) throws DbException { try { beginTransaction(); createTableIfNotExist(entity.getClass()); execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(this, entity)); setTransactionSuccessful(); } finally { endTransaction(); } }
public void updateAll(List<?> entities, String... updateColumnNames) throws DbException { if (entities == null || entities.size() == 0 || !tableIsExist(entities.get(0).getClass())) return; try { beginTransaction(); for (Object entity : entities) { execNonQuery(SqlInfoBuilder.buildUpdateSqlInfo(this, entity, updateColumnNames)); } setTransactionSuccessful(); } finally { endTransaction(); } }
public void saveAll(List<?> entities) throws DbException { if (entities == null || entities.size() == 0) return; try { beginTransaction(); createTableIfNotExist(entities.get(0).getClass()); for (Object entity : entities) { execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(this, entity)); } setTransactionSuccessful(); } finally { endTransaction(); } }