Search in sources :

Example 1 with ColumnEntity

use of org.xutils.db.table.ColumnEntity in project xUtils3 by wyouflf.

the class SqlInfoBuilder method buildDeleteSqlInfo.

//*********************************************** delete sql ***********************************************
public static SqlInfo buildDeleteSqlInfo(TableEntity<?> table, Object entity) throws DbException {
    SqlInfo result = new SqlInfo();
    ColumnEntity id = table.getId();
    Object idValue = id.getColumnValue(entity);
    if (idValue == null) {
        throw new DbException("this entity[" + table.getEntityType() + "]'s id value is null");
    }
    StringBuilder builder = new StringBuilder("DELETE FROM ");
    builder.append("\"").append(table.getName()).append("\"");
    builder.append(" WHERE ").append(WhereBuilder.b(id.getName(), "=", idValue));
    result.setSql(builder.toString());
    return result;
}
Also used : ColumnEntity(org.xutils.db.table.ColumnEntity) DbException(org.xutils.ex.DbException)

Example 2 with ColumnEntity

use of org.xutils.db.table.ColumnEntity in project xUtils3 by wyouflf.

the class SqlInfoBuilder method buildDeleteSqlInfoById.

public static SqlInfo buildDeleteSqlInfoById(TableEntity<?> table, Object idValue) throws DbException {
    SqlInfo result = new SqlInfo();
    ColumnEntity id = table.getId();
    if (idValue == null) {
        throw new DbException("this entity[" + table.getEntityType() + "]'s id value is null");
    }
    StringBuilder builder = new StringBuilder("DELETE FROM ");
    builder.append("\"").append(table.getName()).append("\"");
    builder.append(" WHERE ").append(WhereBuilder.b(id.getName(), "=", idValue));
    result.setSql(builder.toString());
    return result;
}
Also used : ColumnEntity(org.xutils.db.table.ColumnEntity) DbException(org.xutils.ex.DbException)

Example 3 with ColumnEntity

use of org.xutils.db.table.ColumnEntity in project xUtils3 by wyouflf.

the class SqlInfoBuilder method buildCreateTableSqlInfo.

//*********************************************** others ***********************************************
public static SqlInfo buildCreateTableSqlInfo(TableEntity<?> table) throws DbException {
    ColumnEntity id = table.getId();
    StringBuilder builder = new StringBuilder();
    builder.append("CREATE TABLE IF NOT EXISTS ");
    builder.append("\"").append(table.getName()).append("\"");
    builder.append(" ( ");
    if (id.isAutoId()) {
        builder.append("\"").append(id.getName()).append("\"").append(" INTEGER PRIMARY KEY AUTOINCREMENT, ");
    } else {
        builder.append("\"").append(id.getName()).append("\"").append(id.getColumnDbType()).append(" PRIMARY KEY, ");
    }
    Collection<ColumnEntity> columns = table.getColumnMap().values();
    for (ColumnEntity column : columns) {
        if (column.isId())
            continue;
        builder.append("\"").append(column.getName()).append("\"");
        builder.append(' ').append(column.getColumnDbType());
        builder.append(' ').append(column.getProperty());
        builder.append(',');
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append(" )");
    return new SqlInfo(builder.toString());
}
Also used : ColumnEntity(org.xutils.db.table.ColumnEntity)

Example 4 with ColumnEntity

use of org.xutils.db.table.ColumnEntity in project xUtils3 by wyouflf.

the class CursorUtils method getEntity.

public static <T> T getEntity(TableEntity<T> table, final Cursor cursor) throws Throwable {
    T entity = table.createEntity();
    HashMap<String, ColumnEntity> columnMap = table.getColumnMap();
    int columnCount = cursor.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
        String columnName = cursor.getColumnName(i);
        ColumnEntity column = columnMap.get(columnName);
        if (column != null) {
            column.setValueFromCursor(entity, cursor, i);
        }
    }
    return entity;
}
Also used : ColumnEntity(org.xutils.db.table.ColumnEntity)

Example 5 with ColumnEntity

use of org.xutils.db.table.ColumnEntity in project xUtils3 by wyouflf.

the class DbManagerImpl method saveBindingIdWithoutTransaction.

private boolean saveBindingIdWithoutTransaction(TableEntity<?> table, Object entity) throws DbException {
    ColumnEntity id = table.getId();
    if (id.isAutoId()) {
        execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(table, entity));
        long idValue = getLastAutoIncrementId(table.getName());
        if (idValue == -1) {
            return false;
        }
        id.setAutoIdValue(entity, idValue);
        return true;
    } else {
        execNonQuery(SqlInfoBuilder.buildInsertSqlInfo(table, entity));
        return true;
    }
}
Also used : ColumnEntity(org.xutils.db.table.ColumnEntity)

Aggregations

ColumnEntity (org.xutils.db.table.ColumnEntity)7 DbException (org.xutils.ex.DbException)3 KeyValue (org.xutils.common.util.KeyValue)2 ArrayList (java.util.ArrayList)1