@Nonnull
@CheckReturnValue
private <T> List<T> selectSqlQuery(@Nonnull final Function<EntityManager, Query> queryFunc,
@Nullable final Map<String, Object> parameters)
throws DatabaseException, PersistenceException, ClassCastException {
final EntityManager em = this.databaseConnection.getEntityManager();
try {
final Query q = queryFunc.apply(em);
if (parameters != null) {
parameters.forEach(q::setParameter);
}
return selectNativeSqlQuery(em, q);
} finally {
em.close();
}
}
java类javax.persistence.PersistenceException的实例源码
DatabaseWrapper.java 文件源码
项目:SqlSauce
阅读 32
收藏 0
点赞 0
评论 0
JpaLockingStrategy.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 24
收藏 0
点赞 0
评论 0
/**
* Acquire the lock object.
*
* @param em the em
* @param lock the lock
* @return true, if successful
*/
private boolean acquire(final EntityManager em, final Lock lock) {
lock.setUniqueId(uniqueId);
if (lockTimeout > 0) {
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, lockTimeout);
lock.setExpirationDate(cal.getTime());
} else {
lock.setExpirationDate(null);
}
boolean success = false;
try {
if (lock.getApplicationId() != null) {
em.merge(lock);
} else {
lock.setApplicationId(applicationId);
em.persist(lock);
}
success = true;
} catch (final PersistenceException e) {
success = false;
if (logger.isDebugEnabled()) {
logger.debug("{} could not obtain {} lock.", uniqueId, applicationId, e);
} else {
logger.info("{} could not obtain {} lock.", uniqueId, applicationId);
}
}
return success;
}
EmployeeService.java 文件源码
项目:git-rekt
阅读 29
收藏 0
点赞 0
评论 0
/**
* Removes the provided employee from the database.
*
* This operation cannot be undone, so be sure this is what you want to do.
*
* @param employee The employee to delete.
*/
public void deleteEmployee(Employee e){
try {
entityManager.getTransaction().begin();
entityManager.remove(entityManager.merge(e));
entityManager.getTransaction().commit();
} catch (PersistenceException ex) {
entityManager.getTransaction().rollback();
throw ex;
}
}
JpaLockingStrategy.java 文件源码
项目:springboot-shiro-cas-mybatis
阅读 29
收藏 0
点赞 0
评论 0
/**
* Acquire the lock object.
*
* @param em the em
* @param lock the lock
* @return true, if successful
*/
private boolean acquire(final EntityManager em, final Lock lock) {
lock.setUniqueId(uniqueId);
if (lockTimeout > 0) {
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, lockTimeout);
lock.setExpirationDate(cal.getTime());
} else {
lock.setExpirationDate(null);
}
boolean success = false;
try {
if (lock.getApplicationId() != null) {
em.merge(lock);
} else {
lock.setApplicationId(applicationId);
em.persist(lock);
}
success = true;
} catch (final PersistenceException e) {
success = false;
if (logger.isDebugEnabled()) {
logger.debug("{} could not obtain {} lock.", uniqueId, applicationId, e);
} else {
logger.info("{} could not obtain {} lock.", uniqueId, applicationId);
}
}
return success;
}
MessageServiceImpl.java 文件源码
项目:devops-cstack
阅读 24
收藏 0
点赞 0
评论 0
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Message create(Message message)
throws ServiceException {
try {
message.setCuInstanceName(cuInstanceName);
return messageDAO.save(message);
} catch (PersistenceException e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
MessageServiceImpl.java 文件源码
项目:devops-cstack
阅读 24
收藏 0
点赞 0
评论 0
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void delete(Message message)
throws ServiceException {
try {
messageDAO.delete(message);
} catch (PersistenceException e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
SearchService.java 文件源码
项目:query-search
阅读 32
收藏 0
点赞 0
评论 0
public default List<?> search(JpqlFilter filter) {
Objects.requireNonNull(filter, "jpqlFilter is required");
try {
return getRepository().search(filter);
} catch (PersistenceException e) {
throw new PersistenceException(e);
}
}
GuestFeedbackService.java 文件源码
项目:git-rekt
阅读 18
收藏 0
点赞 0
评论 0
public void createNewGuestFeedback(GuestFeedback feedback) {
try {
entityManager.getTransaction().begin();
entityManager.persist(feedback);
entityManager.getTransaction().commit();
} catch (PersistenceException e) {
entityManager.getTransaction().rollback();
throw e;
}
}
MessageServiceImpl.java 文件源码
项目:devops-cstack
阅读 30
收藏 0
点赞 0
评论 0
@Override
public List<Message> listByApp(User user, String applicationName,
int nbMessages)
throws ServiceException {
try {
Pageable pageable = new PageRequest(0, nbMessages,
sortByLastNameAsc());
Page<Message> requestedPage = messageDAO.listByApp(user,
applicationName, cuInstanceName, pageable);
return requestedPage.getContent();
} catch (PersistenceException e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
DefaultBaseDao.java 文件源码
项目:minijax
阅读 35
收藏 0
点赞 0
评论 0
/**
* Inserts a new instance in the database.
*
* @param obj The object to create.
* @return The instance with ID.
*/
@Override
public <T extends BaseEntity> T create(final T obj) {
try {
em.getTransaction().begin();
em.persist(obj);
em.getTransaction().commit();
return obj;
} catch (final PersistenceException ex) {
throw convertRollbackToConflict(ex);
}
}