/**
* Run a good old SQL query
*
* @return the number of entities updated or deleted
*/
public int executeSqlQuery(@Nonnull final String queryString,
@Nullable final Map<String, Object> parameters) throws DatabaseException {
final EntityManager em = this.databaseConnection.getEntityManager();
try {
final Query q = em.createNativeQuery(queryString);
if (parameters != null) {
parameters.forEach(q::setParameter);
}
em.getTransaction().begin();
int updated = q.executeUpdate();
em.getTransaction().commit();
return updated;
} catch (final PersistenceException e) {
final String message = String.format("Failed to execute plain SQL query %s with %s parameters on DB %s",
queryString, parameters != null ? parameters.size() : "null", this.databaseConnection.getName());
throw new DatabaseException(message, e);
} finally {
em.close();
}
}
DatabaseWrapper.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:SqlSauce
作者:
评论列表
文章目录