/**
* So you want to load an entity, set some data, and save it again, without detaching it from the persistence
* context and without bothering with the EntityManager?
* Look no further! Functional programming to the rescue, just pass a function that does the required transformation
* on the entity.
* <p>
* NOTE that this will create a new instance of the entity if it does not exist yet.
*
*/
@Nonnull
public <E extends SaucedEntity<I, E>, I extends Serializable> E findApplyAndMerge(@Nonnull final Transfiguration<I, E> transfiguration)
throws DatabaseException {
final EntityManager em = this.databaseConnection.getEntityManager();
try {
return this.lockedWrappedTransformFunc(transfiguration).apply(em);
} catch (final PersistenceException e) {
final String message = String.format("Failed to find, apply and merge entity id %s of class %s on DB %s",
transfiguration.key.id.toString(), transfiguration.key.clazz.getName(),
this.databaseConnection.getName());
throw new DatabaseException(message, e);
} finally {
em.close();
}
}
DatabaseWrapper.java 文件源码
java
阅读 44
收藏 0
点赞 0
评论 0
项目:SqlSauce
作者:
评论列表
文章目录