/** * Returns all entities of the given type. This actually peers the call to the {@link #find(Class, Query)} method. * * @param type The type of entity to retrieve. * @return An array of all entities which correspond to the given type. */ public <T extends RawEntity<K>, K> T[] find(Class<T> type) throws SQLException { return find(type, Query.select()); }
@Override public T invoke(K k) throws SQLException { final T[] ts = find(type, primaryKeyField + " = ?", k); if (ts.length == 1) { return ts[0]; } else if (ts.length == 0) { return null; } else { throw new ActiveObjectsException("Found more that one object of type '" + type.getName() + "' for key '" + k + "'"); } } };
public final <T extends RawEntity<K>, K> T[] find(Class<T> type) { try { return entityManager.find(type); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
public final <T extends RawEntity<K>, K> T[] find(Class<T> type, Query query) { try { return entityManager.find(type, query); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
public final <T extends RawEntity<K>, K> T[] find(Class<T> type, String criteria, Object... parameters) { try { return entityManager.find(type, criteria, parameters); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
public final <T extends RawEntity<K>, K> T[] find(Class<T> type, String field, Query query) { try { return entityManager.find(type, field, query); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
/** * Returns all entities of the given type. This actually peers the call to the {@link #find(Class, Query)} method. * * @param type The type of entity to retrieve. * @return An array of all entities which correspond to the given type. */ public <T extends RawEntity<K>, K> T[] find(Class<T> type) throws SQLException { return find(type, Query.select()); }
@Override public T invoke(K k) throws SQLException { final T[] ts = find(type, primaryKeyField + " = ?", k); if (ts.length == 1) { return ts[0]; } else if (ts.length == 0) { return null; } else { throw new ActiveObjectsException("Found more that one object of type '" + type.getName() + "' for key '" + k + "'"); } } };
/** * <p>Convenience method to select a single entity of the given type with the specified, parameterized criteria. The * <code>criteria</code> String specified is appended to the SQL prepared statement immediately following the * <code>WHERE</code>.</p> * * <p>Example:</p> * * <pre>manager.findSingleEntity(Person.class, "name LIKE ? OR age > ?", "Joe", 9);</pre> * * <p>This actually delegates the call to the {@link #find(Class, String, Object...)} method, properly * parameterizing the {@link Object} object.</p> * * @param type The type of the entities to retrieve. * @param criteria A parameterized WHERE statement used to determine the results. * @param parameters A varargs array of parameters to be passed to the executed prepared statement. The length of * this array <i>must</i> match the number of parameters (denoted by the '?' char) in the <code>criteria</code>. * @return A single entity of the given type which match the specified criteria or null if none returned */ public <T extends RawEntity<K>, K> T findSingleEntity(Class<T> type, String criteria, Object... parameters) throws SQLException { T[] entities = find(type, criteria, parameters); if (entities.length < 1) { return null; } else if (entities.length > 1) { throw new IllegalStateException("Found more than one entities of type '" + type.getSimpleName() + "' that matched the criteria '" + criteria + "' and parameters '" + parameters.toString() + "'."); } return entities[0]; }
/** * <p>Convenience method to select a single entity of the given type with the specified, parameterized criteria. The * <code>criteria</code> String specified is appended to the SQL prepared statement immediately following the * <code>WHERE</code>.</p> * * <p>Example:</p> * * <pre>manager.findSingleEntity(Person.class, "name LIKE ? OR age > ?", "Joe", 9);</pre> * * <p>This actually delegates the call to the {@link #find(Class, String, Object...)} method, properly * parameterizing the {@link Object} object.</p> * * @param type The type of the entities to retrieve. * @param criteria A parameterized WHERE statement used to determine the results. * @param parameters A varargs array of parameters to be passed to the executed prepared statement. The length of * this array <i>must</i> match the number of parameters (denoted by the '?' char) in the <code>criteria</code>. * @return A single entity of the given type which match the specified criteria or null if none returned */ public <T extends RawEntity<K>, K> T findSingleEntity(Class<T> type, String criteria, Object... parameters) throws SQLException { T[] entities = find(type, criteria, parameters); if (entities.length < 1) { return null; } else if (entities.length > 1) { throw new IllegalStateException("Found more than one entities of type '" + type.getSimpleName() + "' that matched the criteria '" + criteria + "' and parameters '" + parameters.toString() + "'."); } return entities[0]; }
/** * <p>Convenience method to select all entities of the given type with the specified, parameterized criteria. The * <code>criteria</code> String specified is appended to the SQL prepared statement immediately following the * <code>WHERE</code>.</p> * * <p>Example:</p> * * <pre>manager.find(Person.class, "name LIKE ? OR age > ?", "Joe", 9);</pre> * * <p>This actually delegates the call to the {@link #find(Class, Query)} method, properly parameterizing the {@link * Query} object.</p> * * @param type The type of the entities to retrieve. * @param criteria A parameterized WHERE statement used to determine the results. * @param parameters A varargs array of parameters to be passed to the executed prepared statement. The length of * this array <i>must</i> match the number of parameters (denoted by the '?' char) in the <code>criteria</code>. * @return An array of entities of the given type which match the specified criteria. */ public <T extends RawEntity<K>, K> T[] find(Class<T> type, String criteria, Object... parameters) throws SQLException { return find(type, Query.select().where(criteria, parameters)); }
/** * <p>Convenience method to select all entities of the given type with the specified, parameterized criteria. The * <code>criteria</code> String specified is appended to the SQL prepared statement immediately following the * <code>WHERE</code>.</p> * * <p>Example:</p> * * <pre>manager.find(Person.class, "name LIKE ? OR age > ?", "Joe", 9);</pre> * * <p>This actually delegates the call to the {@link #find(Class, Query)} method, properly parameterizing the {@link * Query} object.</p> * * @param type The type of the entities to retrieve. * @param criteria A parameterized WHERE statement used to determine the results. * @param parameters A varargs array of parameters to be passed to the executed prepared statement. The length of * this array <i>must</i> match the number of parameters (denoted by the '?' char) in the <code>criteria</code>. * @return An array of entities of the given type which match the specified criteria. */ public <T extends RawEntity<K>, K> T[] find(Class<T> type, String criteria, Object... parameters) throws SQLException { return find(type, Query.select().where(criteria, parameters)); }
return find(type, selectField, query);
return find(type, selectField, query);