/** * Calculates the average value on a given column. * * <pre> * LitePal.average(Person.class, "age"); * </pre> * * You can also specify a where clause when calculating. * * <pre> * LitePal.where("age > ?", "15").average(Person.class, "age"); * </pre> * * @param modelClass * Which table to query from by class. * @param column * The based on column to calculate. * @return The average value on a given column. */ public static double average(Class<?> modelClass, String column) { return Operator.average(modelClass, column); }
/** * Basically same as {@link #average(String, String)} but pending to a new thread for executing. * * @param tableName * Which table to query from. * @param column * The based on column to calculate. * @return A AverageExecutor instance. */ public static AverageExecutor averageAsync(final String tableName, final String column) { return Operator.averageAsync(tableName, column); }
/** * Count the records. * * <pre> * LitePal.count(Person.class); * </pre> * * This will count all rows in person table.<br> * You can also specify a where clause when counting. * * <pre> * LitePal.where("age > ?", "15").count(Person.class); * </pre> * * @param modelClass * Which table to query from by class. * @return Count of the specified table. */ public static int count(Class<?> modelClass) { return Operator.count(modelClass); }
/** * It is mostly same as {@link LitePal#find(Class, long)} but an isEager * parameter. If set true the associated models will be loaded as well. * <br> * Note that isEager will only work for one deep level relation, considering the query efficiency. * You have to implement on your own if you need to load multiple deepness of relation at once. * * @param modelClass * Which table to query and the object type to return. * @param id * Which record to query. * @param isEager * True to load the associated models, false not. * @return An object with found data from database, or null. */ public static <T> T find(Class<T> modelClass, long id, boolean isEager) { return Operator.find(modelClass, id, isEager); }
@Override public void run() { synchronized (LitePalSupport.class) { final int rowsAffected = deleteAll(modelClass, conditions); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(rowsAffected); } }); } } } };
@Override public void run() { synchronized (LitePalSupport.class) { final int count = count(tableName); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(count); } }); } } } };
@Override public void run() { synchronized (LitePalSupport.class) { final T t = find(modelClass, id, isEager); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(t); } }); } } } };
@Override public void run() { synchronized (LitePalSupport.class) { final double average = average(tableName, column); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(average); } }); } } } };
@Override public void run() { synchronized (LitePalSupport.class) { final List<T> t = findAll(modelClass, isEager, ids); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(t); } }); } } } };
@Override public void run() { synchronized (LitePalSupport.class) { final int rowsAffected = delete(modelClass, id); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(rowsAffected); } }); } } } };
/** * Basically same as {@link #find(Class, long)} but pending to a new thread for executing. * * @param modelClass * Which table to query and the object type to return. * @param id * Which record to query. * @return A FindExecutor instance. */ public static <T> FindExecutor<T> findAsync(Class<T> modelClass, long id) { return Operator.findAsync(modelClass, id); }
/** * Basically same as {@link #count(String)} but pending to a new thread for executing. * * @param tableName * Which table to query from. * @return A CountExecutor instance. */ public static CountExecutor countAsync(final String tableName) { return Operator.countAsync(tableName); }
/** * Basically same as {@link #findAll(Class, long...)} but pending to a new thread for executing. * * @param modelClass * Which table to query and the object type to return as a list. * @param ids * Which records to query. Or do not pass it to find all records. * @return A FindMultiExecutor instance. */ public static <T> FindMultiExecutor<T> findAllAsync(Class<T> modelClass, long... ids) { return findAllAsync(modelClass, false, ids); }
/** * It is mostly same as {@link LitePal#findAll(Class, long...)} but an * isEager parameter. If set true the associated models will be loaded as well. * <br> * Note that isEager will only work for one deep level relation, considering the query efficiency. * You have to implement on your own if you need to load multiple deepness of relation at once. * * @param modelClass * Which table to query and the object type to return as a list. * @param isEager * True to load the associated models, false not. * @param ids * Which records to query. Or do not pass it to find all records. * @return An object list with found data from database, or an empty list. */ public static <T> List<T> findAll(Class<T> modelClass, boolean isEager, long... ids) { return Operator.findAll(modelClass, isEager, ids); }
/** * Deletes all records with details given if they match a set of conditions * supplied. This method constructs a single SQL DELETE statement and sends * it to the database. * * <pre> * LitePal.deleteAll(Person.class, "name = ? and age = ?", "Tom", "14"); * </pre> * * This means that all the records which name is Tom and age is 14 will be * removed.<br> * * @param modelClass * Which table to delete from by class. * @param conditions * A string array representing the WHERE part of an SQL * statement. First parameter is the WHERE clause to apply when * deleting. The way of specifying place holders is to insert one * or more question marks in the SQL. The first question mark is * replaced by the second element of the array, the next question * mark by the third, and so on. Passing empty string will update * all rows. * @return The number of rows affected. */ public static int deleteAll(Class<?> modelClass, String... conditions) { return Operator.deleteAll(modelClass, conditions); }
/** * Deletes the record in the database by id.<br> * The data in other tables which is referenced with the record will be * removed too. * * <pre> * LitePal.delete(Person.class, 1); * </pre> * * This means that the record 1 in person table will be removed. * * @param modelClass * Which table to delete from by class. * @param id * Which record to delete. * @return The number of rows affected. Including cascade delete rows. */ public static int delete(Class<?> modelClass, long id) { return Operator.delete(modelClass, id); }
/** * Finds the record by a specific id. * * <pre> * Person p = LitePal.find(Person.class, 1); * </pre> * * The modelClass determines which table to query and the object type to * return. If no record can be found, then return null. <br> * * Note that the associated models won't be loaded by default considering * the efficiency, but you can do that by using * {@link Operator#find(Class, long, boolean)}. * * @param modelClass * Which table to query and the object type to return. * @param id * Which record to query. * @return An object with found data from database, or null. */ public static <T> T find(Class<T> modelClass, long id) { return find(modelClass, id, false); }
@Override public void run() { synchronized (LitePalSupport.class) { final int rowsAffected = deleteAll(tableName, conditions); if (executor.getListener() != null) { Operator.getHandler().post(new Runnable() { @Override public void run() { executor.getListener().onFinish(rowsAffected); } }); } } } };
/** * Basically same as {@link #find(Class, long)} but pending to a new thread for executing. * * @param modelClass * Which table to query and the object type to return. * @param id * Which record to query. * @return A FindExecutor instance. */ public static <T> FindExecutor<T> findAsync(Class<T> modelClass, long id) { return findAsync(modelClass, id, false); }
/** * Basically same as {@link #count(Class)} but pending to a new thread for executing. * * @param modelClass * Which table to query from by class. * @return A CountExecutor instance. */ public static CountExecutor countAsync(final Class<?> modelClass) { return Operator.countAsync(modelClass); }