Search in sources :

Example 1 with Table

use of com.lidroid.xutils.db.table.Table in project xUtils by wyouflf.

the class DbUtils method saveBindingIdWithoutTransaction.

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;
    }
}
Also used : Table(com.lidroid.xutils.db.table.Table) Id(com.lidroid.xutils.db.table.Id)

Example 2 with Table

use of com.lidroid.xutils.db.table.Table in project xUtils by wyouflf.

the class FinderLazyLoader method getFirstFromDb.

public T getFirstFromDb() throws DbException {
    T entity = null;
    Table table = finderColumn.getTable();
    if (table != null) {
        entity = table.db.findFirst(Selector.from(finderColumn.getTargetEntityType()).where(finderColumn.getTargetColumnName(), "=", finderValue));
    }
    return entity;
}
Also used : Table(com.lidroid.xutils.db.table.Table)

Example 3 with Table

use of com.lidroid.xutils.db.table.Table in project xUtils by wyouflf.

the class ForeignLazyLoader method getAllFromDb.

public List<T> getAllFromDb() throws DbException {
    List<T> entities = null;
    Table table = foreignColumn.getTable();
    if (table != null) {
        entities = table.db.findAll(Selector.from(foreignColumn.getForeignEntityType()).where(foreignColumn.getForeignColumnName(), "=", columnValue));
    }
    return entities;
}
Also used : Table(com.lidroid.xutils.db.table.Table)

Example 4 with Table

use of com.lidroid.xutils.db.table.Table in project xUtils by wyouflf.

the class FinderLazyLoader method getAllFromDb.

public List<T> getAllFromDb() throws DbException {
    List<T> entities = null;
    Table table = finderColumn.getTable();
    if (table != null) {
        entities = table.db.findAll(Selector.from(finderColumn.getTargetEntityType()).where(finderColumn.getTargetColumnName(), "=", finderValue));
    }
    return entities;
}
Also used : Table(com.lidroid.xutils.db.table.Table)

Example 5 with Table

use of com.lidroid.xutils.db.table.Table in project xUtils by wyouflf.

the class DbUtils method count.

public long count(Selector selector) throws DbException {
    Class<?> entityType = selector.getEntityType();
    if (!tableIsExist(entityType))
        return 0;
    Table table = Table.get(this, entityType);
    DbModelSelector dmSelector = selector.select("count(" + table.id.getColumnName() + ") as count");
    return findDbModelFirst(dmSelector).getLong("count");
}
Also used : Table(com.lidroid.xutils.db.table.Table)

Aggregations

Table (com.lidroid.xutils.db.table.Table)9 Cursor (android.database.Cursor)2 Id (com.lidroid.xutils.db.table.Id)2 DbException (com.lidroid.xutils.exception.DbException)2