/**
* @return A list of all elements of the requested entity class
*/
// NOTE: this method is probably not a great idea to use for giant tables
@Nonnull
@CheckReturnValue
//returns a list of sauced entities
public <E extends SaucedEntity<I, E>, I extends Serializable> List<E> loadAll(@Nonnull final Class<E> clazz)
throws DatabaseException {
final EntityManager em = this.databaseConnection.getEntityManager();
try {
final String query = "SELECT c FROM " + clazz.getSimpleName() + " c";
em.getTransaction().begin();
final List<E> queryResult = em
.createQuery(query, clazz)
.getResultList();
em.getTransaction().commit();
return queryResult
.stream()
.map(s -> s.setSauce(this))
.collect(Collectors.toList());
} catch (final PersistenceException e) {
final String message = String.format("Failed to load all %s entities on DB %s",
clazz.getName(), this.databaseConnection.getName());
throw new DatabaseException(message, e);
} finally {
em.close();
}
}
DatabaseWrapper.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:SqlSauce
作者:
评论列表
文章目录