示例#1
0
 // ***************************** 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));
   }
 }
示例#2
0
 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;
   }
 }
示例#3
0
 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);
     }
   }
 }
示例#4
0
  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();
    }
  }
示例#5
0
  public void delete(Class<?> entityType, WhereBuilder whereBuilder) throws DbException {
    if (!tableIsExist(entityType)) return;
    try {
      beginTransaction();

      execNonQuery(SqlInfoBuilder.buildDeleteSqlInfo(this, entityType, whereBuilder));

      setTransactionSuccessful();
    } finally {
      endTransaction();
    }
  }
示例#6
0
  public void delete(Object entity) throws DbException {
    if (!tableIsExist(entity.getClass())) return;
    try {
      beginTransaction();

      execNonQuery(SqlInfoBuilder.buildDeleteSqlInfo(this, entity));

      setTransactionSuccessful();
    } finally {
      endTransaction();
    }
  }
示例#7
0
  public void save(Object entity) throws DbException {
    try {
      beginTransaction();

      createTableIfNotExist(entity.getClass());
      execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(this, entity));

      setTransactionSuccessful();
    } finally {
      endTransaction();
    }
  }
示例#8
0
  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();
    }
  }
示例#9
0
  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();
    }
  }