@Test public void testFindOrCreateIt() { deleteFromTable("people"); the(Base.count("people")).shouldBeEqual(0); Person person1 = Person.findOrCreateIt("name", "yakka", "last_name", "newbie", "dob", getDate(1990, 8, 3)); the(person1).shouldNotBeNull(); the(person1.exists()).shouldBeTrue(); a(Base.count("people", "name = ? and last_name = ?", "yakka", "newbie")).shouldBeEqual(1); Person person2 = Person.findOrCreateIt("name", "yakka", "last_name", "newbie", "dob", getDate(1990, 8, 3)); the(person2).shouldNotBeNull(); the(person1.getId()).shouldBeEqual(person2.getId()); }
public static <T extends Model> T findOrCreateIt(Object... namesAndValues) { return ModelDelegate.findOrCreateIt(modelClass(), namesAndValues); }
Model extends CallbackSupport implements Externalizable, Validatable { public static <T extends Model> T findOrCreateIt(Object... namesAndValues) { return ModelDelegate.findOrCreateIt(modelClass(), namesAndValues); } }
Model extends CallbackSupport implements Externalizable, Validatable { public static <T extends Model> T findOrCreateIt(Object... namesAndValues) { return ModelDelegate.findOrCreateIt(modelClass(), namesAndValues); } protected  Model(); protected  Model(MetaModel metaModel, ModelRegistry modelRegistry); }
Model extends CallbackSupport implements Externalizable, Validatable { public static <T extends Model> T findOrCreateIt(Object... namesAndValues) { return ModelDelegate.findOrCreateIt(modelClass(), namesAndValues); } protected  Model(); protected  Model(MetaModel metaModel, ModelRegistry modelRegistry); static MetaModel getMetaModel(); static MetaModel metaModel(); T fromMap(Map input); static T findOrCreateIt(Object... namesAndValues); static T findOrInit(Object... namesAndValues); T setId(Object id); T setDate(String attributeName, Object value); java.sql.Date getDate(String attributeName); void set(String[] attributeNames, Object[] values); T set(String attributeName, Object value); boolean isModified(); boolean isFrozen(); boolean modified(); static Set<String> attributeNames(); static List<Association> associations(); boolean isNew(); boolean frozen(); boolean delete(); void delete(boolean cascade); void deleteCascade(); void deleteCascadeExcept(Association... excludedAssociations); void deleteCascadeShallow(); void deleteChildrenShallow(Class<T> clazz); static int delete(String query, Object... params); static boolean exists(Object id); boolean exists(); static int deleteAll(); static int update(String updates, String conditions, Object ... params); static int updateAll(String updates, Object ... params); Map<String, Object> toMap(); @Override String toString(); void fromXml(String xml); String toXml(boolean pretty, boolean declaration, String... attributeNames); void beforeClosingTag(StringBuilder sb, boolean pretty, String indent, String... attributeNames); String toJson(boolean pretty, String... attributeNames); void beforeClosingBrace(StringBuilder sb, boolean pretty, String indent, String... attributeNames); P parent(Class<P> parentClass); P parent(Class<P> parentClass, boolean cache); void setParents(Model... parents); void setParent(Model parent); void copyTo(Model other); void copyFrom(Model other); void refresh(); Object get(String attributeName); String getString(String attributeName); byte[] getBytes(String attributeName); BigDecimal getBigDecimal(String attributeName); Integer getInteger(String attributeName); Long getLong(String attributeName); Short getShort(String attributeName); Float getFloat(String attributeName); Time getTime(String attributeName); Timestamp getTimestamp(String attributeName); Double getDouble(String attributeName); Boolean getBoolean(String attributeName); T setString(String attributeName, Object value); T setBigDecimal(String attributeName, Object value); T setShort(String attributeName, Object value); T setInteger(String attributeName, Object value); T setLong(String attributeName, Object value); T setFloat(String attributeName, Object value); T setTime(String attributeName, Object value); T setTimestamp(String attributeName, Object value); T setDouble(String attributeName, Object value); T setBoolean(String attributeName, Object value); LazyList<C> getAll(Class<C> clazz); LazyList<C> get(Class<C> targetModelClass, String criteria, Object ... params); static ValidationBuilder addValidator(Validator validator); void addError(String key, String value); static void removeValidator(Validator validator); static List<Validator> getValidators(Class<? extends Model> clazz); static boolean belongsTo(Class<? extends Model> targetClass); static void callbackWith(CallbackListener... listeners); boolean isValid(); void validate(); void validate(boolean reset); boolean hasErrors(); void addFailedValidator(Validator validator, String errorKey); Errors errors(); Errors errors(Locale locale); static T create(Object... namesAndValues); T set(Object... namesAndValues); static T createIt(Object ... namesAndValues); static T findById(Object id); static T findByCompositeKeys(Object... values); static LazyList<T> where(String subquery, Object... params); static ScopeBuilder<T> scopes(String ... scopes); static ScopeBuilder<T> scope(String  scope); static LazyList<T> find(String subquery, Object... params); static T findFirst(String subQuery, Object... params); static T first(String subQuery, Object... params); static void findWith(final ModelListener listener, String query, Object ... params); static LazyList<T> findBySQL(String fullQuery, Object... params); static LazyList<T> findAll(); void add(Model child); void addModels(List<T> models); int remove(Model child); boolean saveIt(); void reset(); void thaw(); void defrost(); boolean save(); static Long count(); static Long count(String query, Object... params); boolean insert(); static String getTableName(); Object getId(); String getIdName(); String[] getCompositeKeys(); void manageTime(boolean manage); String toInsert(String ... replacements); String toInsert(Dialect dialect, String ... replacements); String toUpdate(String ... replacements); String toUpdate(Dialect dialect, String ... replacements); static boolean isCached(); static void purgeCache(); Long getLongId(); @Override void writeExternal(ObjectOutput out); @Override void readExternal(ObjectInput in); }
Model extends CallbackSupport implements Externalizable, Validatable { public static <T extends Model> T findOrCreateIt(Object... namesAndValues) { return ModelDelegate.findOrCreateIt(modelClass(), namesAndValues); } protected  Model(); protected  Model(MetaModel metaModel, ModelRegistry modelRegistry); static MetaModel getMetaModel(); static MetaModel metaModel(); T fromMap(Map input); static T findOrCreateIt(Object... namesAndValues); static T findOrInit(Object... namesAndValues); T setId(Object id); T setDate(String attributeName, Object value); java.sql.Date getDate(String attributeName); void set(String[] attributeNames, Object[] values); T set(String attributeName, Object value); boolean isModified(); boolean isFrozen(); boolean modified(); static Set<String> attributeNames(); static List<Association> associations(); boolean isNew(); boolean frozen(); boolean delete(); void delete(boolean cascade); void deleteCascade(); void deleteCascadeExcept(Association... excludedAssociations); void deleteCascadeShallow(); void deleteChildrenShallow(Class<T> clazz); static int delete(String query, Object... params); static boolean exists(Object id); boolean exists(); static int deleteAll(); static int update(String updates, String conditions, Object ... params); static int updateAll(String updates, Object ... params); Map<String, Object> toMap(); @Override String toString(); void fromXml(String xml); String toXml(boolean pretty, boolean declaration, String... attributeNames); void beforeClosingTag(StringBuilder sb, boolean pretty, String indent, String... attributeNames); String toJson(boolean pretty, String... attributeNames); void beforeClosingBrace(StringBuilder sb, boolean pretty, String indent, String... attributeNames); P parent(Class<P> parentClass); P parent(Class<P> parentClass, boolean cache); void setParents(Model... parents); void setParent(Model parent); void copyTo(Model other); void copyFrom(Model other); void refresh(); Object get(String attributeName); String getString(String attributeName); byte[] getBytes(String attributeName); BigDecimal getBigDecimal(String attributeName); Integer getInteger(String attributeName); Long getLong(String attributeName); Short getShort(String attributeName); Float getFloat(String attributeName); Time getTime(String attributeName); Timestamp getTimestamp(String attributeName); Double getDouble(String attributeName); Boolean getBoolean(String attributeName); T setString(String attributeName, Object value); T setBigDecimal(String attributeName, Object value); T setShort(String attributeName, Object value); T setInteger(String attributeName, Object value); T setLong(String attributeName, Object value); T setFloat(String attributeName, Object value); T setTime(String attributeName, Object value); T setTimestamp(String attributeName, Object value); T setDouble(String attributeName, Object value); T setBoolean(String attributeName, Object value); LazyList<C> getAll(Class<C> clazz); LazyList<C> get(Class<C> targetModelClass, String criteria, Object ... params); static ValidationBuilder addValidator(Validator validator); void addError(String key, String value); static void removeValidator(Validator validator); static List<Validator> getValidators(Class<? extends Model> clazz); static boolean belongsTo(Class<? extends Model> targetClass); static void callbackWith(CallbackListener... listeners); boolean isValid(); void validate(); void validate(boolean reset); boolean hasErrors(); void addFailedValidator(Validator validator, String errorKey); Errors errors(); Errors errors(Locale locale); static T create(Object... namesAndValues); T set(Object... namesAndValues); static T createIt(Object ... namesAndValues); static T findById(Object id); static T findByCompositeKeys(Object... values); static LazyList<T> where(String subquery, Object... params); static ScopeBuilder<T> scopes(String ... scopes); static ScopeBuilder<T> scope(String  scope); static LazyList<T> find(String subquery, Object... params); static T findFirst(String subQuery, Object... params); static T first(String subQuery, Object... params); static void findWith(final ModelListener listener, String query, Object ... params); static LazyList<T> findBySQL(String fullQuery, Object... params); static LazyList<T> findAll(); void add(Model child); void addModels(List<T> models); int remove(Model child); boolean saveIt(); void reset(); void thaw(); void defrost(); boolean save(); static Long count(); static Long count(String query, Object... params); boolean insert(); static String getTableName(); Object getId(); String getIdName(); String[] getCompositeKeys(); void manageTime(boolean manage); String toInsert(String ... replacements); String toInsert(Dialect dialect, String ... replacements); String toUpdate(String ... replacements); String toUpdate(Dialect dialect, String ... replacements); static boolean isCached(); static void purgeCache(); Long getLongId(); @Override void writeExternal(ObjectOutput out); @Override void readExternal(ObjectInput in);  }