protected <T extends RawEntity<K>, K> T[] peer(final EntityInfo<T, K> entityInfo, K... keys) throws SQLException { return get(entityInfo.getEntityType(), new Function<T, K>() { public T invoke(K key) { return getAndInstantiate(entityInfo, key); } }, keys); }
public final <T extends RawEntity<K>, K> T[] get(Class<T> type, K... keys) { try { return entityManager.get(type, keys); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
public final <T extends RawEntity<K>, K> T get(Class<T> type, K key) { try { return entityManager.get(type, key); } catch (SQLException e) { throw new ActiveObjectsSqlException(entityManager, e); } }
protected <T extends RawEntity<K>, K> T[] peer(final EntityInfo<T, K> entityInfo, K... keys) throws SQLException { return get(entityInfo.getEntityType(), new Function<T, K>() { public T invoke(K key) { return getAndInstantiate(entityInfo, key); } }, keys); }
/** * Cleverly overloaded method to return a single entity of the specified type rather than an array in the case where * only one ID is passed. This method meerly delegates the call to the overloaded <code>get</code> method and * functions as syntactical sugar. * * @param type The type of the entity instance to retrieve. * @param key The primary key corresponding to the entity to be retrieved. * @return An entity instance of the given type corresponding to the specified primary key, or <code>null</code> if * the entity does not exist in the database. * @see #get(Class, Object[]) */ public <T extends RawEntity<K>, K> T get(Class<T> type, K key) throws SQLException { return get(type, toArray(key))[0]; }
/** * Cleverly overloaded method to return a single entity of the specified type rather than an array in the case where * only one ID is passed. This method meerly delegates the call to the overloaded <code>get</code> method and * functions as syntactical sugar. * * @param type The type of the entity instance to retrieve. * @param key The primary key corresponding to the entity to be retrieved. * @return An entity instance of the given type corresponding to the specified primary key, or <code>null</code> if * the entity does not exist in the database. * @see #get(Class, Object[]) */ public <T extends RawEntity<K>, K> T get(Class<T> type, K key) throws SQLException { return get(type, toArray(key))[0]; }
/** * <p>Returns an array of entities of the specified type corresponding to the * varargs primary keys. If an in-memory reference already exists to a corresponding * entity (of the specified type and key), it is returned rather than creating * a new instance.</p> * * <p>If the entity is known to exist in the database, then no checks are performed * and the method returns extremely quickly. However, for any key which has not * already been verified, a query to the database is performed to determine whether * or not the entity exists. If the entity does not exist, then <code>null</code> * is returned.</p> * * @param type The type of the entities to retrieve. * @param keys The primary keys corresponding to the entities to retrieve. All * keys must be typed according to the generic type parameter of the entity's * {@link RawEntity} inheritence (if inheriting from {@link Entity}, this is <code>Integer</code> * or <code>int</code>). Thus, the <code>keys</code> array is type-checked at compile * time. * @return An array of entities of the given type corresponding with the specified * primary keys. Any entities which are non-existent will correspond to a <code>null</code> * value in the resulting array. */ public <T extends RawEntity<K>, K> T[] get(final Class<T> type, K... keys) throws SQLException { EntityInfo<T, K> entityInfo = resolveEntityInfo(type); final String primaryKeyField = entityInfo.getPrimaryKey().getName(); return get(type, findByPrimaryKey(type, primaryKeyField), keys); }
/** * <p>Returns an array of entities of the specified type corresponding to the * varargs primary keys. If an in-memory reference already exists to a corresponding * entity (of the specified type and key), it is returned rather than creating * a new instance.</p> * * <p>If the entity is known to exist in the database, then no checks are performed * and the method returns extremely quickly. However, for any key which has not * already been verified, a query to the database is performed to determine whether * or not the entity exists. If the entity does not exist, then <code>null</code> * is returned.</p> * * @param type The type of the entities to retrieve. * @param keys The primary keys corresponding to the entities to retrieve. All * keys must be typed according to the generic type parameter of the entity's * {@link RawEntity} inheritence (if inheriting from {@link Entity}, this is <code>Integer</code> * or <code>int</code>). Thus, the <code>keys</code> array is type-checked at compile * time. * @return An array of entities of the given type corresponding with the specified * primary keys. Any entities which are non-existent will correspond to a <code>null</code> * value in the resulting array. */ public <T extends RawEntity<K>, K> T[] get(final Class<T> type, K... keys) throws SQLException { EntityInfo<T, K> entityInfo = resolveEntityInfo(type); final String primaryKeyField = entityInfo.getPrimaryKey().getName(); return get(type, findByPrimaryKey(type, primaryKeyField), keys); }