/**
* @return An entity if it exists in the database or null if it doesn't exist. If the entity is a SaucedEntity the
* sauce will be set.
*/
@Nullable
@CheckReturnValue
public <E extends IEntity<I, E>, I extends Serializable> E getEntity(@Nonnull final EntityKey<I, E> entityKey)
throws DatabaseException {
final EntityManager em = this.databaseConnection.getEntityManager();
try {
em.getTransaction().begin();
@Nullable final E result = em.find(entityKey.clazz, entityKey.id);
em.getTransaction().commit();
return setSauce(result);
} catch (final PersistenceException e) {
final String message = String.format("Failed to find entity of class %s for id %s on DB %s",
entityKey.clazz.getName(), entityKey.id.toString(), this.databaseConnection.getName());
throw new DatabaseException(message, e);
} finally {
em.close();
}
}
DatabaseWrapper.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:SqlSauce
作者:
评论列表
文章目录