Example #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));
   }
 }
Example #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;
   }
 }
Example #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);
     }
   }
 }
Example #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();
    }
  }
Example #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();
    }
  }
Example #6
0
  public void delete(Object entity) throws DbException {
    if (!tableIsExist(entity.getClass())) return;
    try {
      beginTransaction();

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

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

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

      setTransactionSuccessful();
    } finally {
      endTransaction();
    }
  }
Example #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();
    }
  }
Example #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();
    }
  }