/** * Synonym of {@link #first(String, Object...)}. * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.findFirst("name = ? and age > 13 and age < 19 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person oldest = Person.findFirst("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public static <T extends Model> T findFirst(String subQuery, Object... params) { return ModelDelegate.findFirst(Model.<T>modelClass(), subQuery, params); }
/** * Returns a first result for this condition. May return null if nothing found. * If last result is needed, then order by some field and call this nethod: * * Synonym of {@link #findFirst(String, Object...)}. * <pre> * //first: * Person youngestTeenager= Person.first("age > 12 and age < 20 order by age"); * * //last: * Person oldestTeenager= Person.first("age > 12 and age < 20 order by age desc"); * </pre> * * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.first("name = ? and age < 13 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person p = Person.first("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public static <T extends Model> T first(String subQuery, Object... params) { return ModelDelegate.findFirst(Model.<T>modelClass(), subQuery, params); }
T instance = findFirst(clazz, subQuery.toString(),params); if(instance != null){ return instance;
/** * Synonym of {@link #first(String, Object...)}. * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.findFirst("name = ? and age > 13 and age < 19 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person oldest = Person.findFirst("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public <T extends Model> T findFirst(String subQuery, Object... params) { return (T) ModelDelegate.findFirst(this.getClass(), subQuery, params); }
/** * Returns a first result for this condition. May return null if nothing found. * If last result is needed, then order by some field and call this nethod: * * Synonym of {@link #findFirst(String, Object...)}. * <pre> * //first: * Person youngestTeenager= Person.first("age > 12 and age < 20 order by age"); * * //last: * Person oldestTeenager= Person.first("age > 12 and age < 20 order by age desc"); * </pre> * * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.first("name = ? and age < 13 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person p = Person.first("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public <T extends Model> T first(String subQuery, Object... params) { return (T) ModelDelegate.findFirst(this.getClass(), subQuery, params); }
/** * Synonym of {@link #first(String, Object...)}. * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.findFirst("name = ? and age > 13 and age < 19 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person oldest = Person.findFirst("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public static <T extends Model> T findFirst(String subQuery, Object... params) { return ModelDelegate.findFirst(Model.<T>modelClass(), subQuery, params); }
/** * Returns a first result for this condition. May return null if nothing found. * If last result is needed, then order by some field and call this nethod: * * Synonym of {@link #findFirst(String, Object...)}. * <pre> * //first: * Person youngestTeenager= Person.first("age > 12 and age < 20 order by age"); * * //last: * Person oldestTeenager= Person.first("age > 12 and age < 20 order by age desc"); * </pre> * * * @param subQuery selection criteria, example: * <pre> * Person johnTheTeenager = Person.first("name = ? and age < 13 order by age", "John") * </pre> * Sometimes a query might be just a clause like this: * <pre> * Person p = Person.first("order by age desc") * </pre> * @param params list of parameters if question marks are used as placeholders * @return a first result for this condition. May return null if nothing found. */ public static <T extends Model> T first(String subQuery, Object... params) { return ModelDelegate.findFirst(Model.<T>modelClass(), subQuery, params); }
T instance = findFirst(clazz, subQuery.toString(),params); if(instance != null){ return instance;