List of usage examples for org.springframework.dao DataIntegrityViolationException DataIntegrityViolationException
public DataIntegrityViolationException(String msg)
From source file:xyz.vopen.passport.commons.jdbc.JdbcTemplate.java
/** * ?????(??)/* w w w .jav a 2s . co m*/ */ protected Object query(String sql, Object[] params, ResultSetHandler handler) { Connection conn = null; try { conn = getConnection(); // logger.info("dbutils.query??"); return queryRunner.query(conn, sql, handler, params); // return queryRunner.query(conn, sql, params, handler); } catch (SQLException t) { System.out.println("??" + t.getMessage()); throw new DataIntegrityViolationException(t.getMessage()); } finally { DataSourceUtils.releaseConnection(conn, this.getDataSource()); // logger.info("dbutils.query?"); } }
From source file:org.web4thejob.orm.DataReaderServiceImpl.java
@Override @SuppressWarnings("unchecked") public <E extends Entity> E findUniqueByQuery(Query query) { Criteria criteria = toDetachedCriteria(query).getExecutableCriteria(sessionFactory.getCurrentSession()) .setMaxResults(2).setCacheable(query.isCached()); if (StringUtils.hasText(query.getCacheRegion())) { criteria.setCacheRegion(query.getCacheRegion()); }/* ww w . j ava 2 s. c o m*/ //Issue #21 criteria.setFlushMode(FlushMode.MANUAL); final List<E> list = criteria.list(); if (list.size() == 0) { return null; } else if (list.size() == 1) { return list.get(0); } else { throw new DataIntegrityViolationException("expecting unique result but got many"); } }
From source file:com.expressui.core.view.security.user.UserForm.java
@Override public void preSave(User entity) { super.preSave(entity); User existingUser;// ww w. j a v a2 s .co m try { existingUser = userDao.findByLoginName(entity.getLoginName()); if (!existingUser.equals(entity)) { throw new DataIntegrityViolationException( uiMessageSource.getMessage("uniqueLoginNameValidator.errorMessage")); } } catch (NoResultException e) { // login name doesn't already exist } }
From source file:xyz.vopen.passport.commons.jdbc.JdbcTemplate.java
public int[] batch(String sql, Object[][] params) { Connection conn = null;// ww w . j a v a 2s . c o m try { conn = getConnection(); // logger.info("dbutils.batch??"); return queryRunner.batch(conn, sql, params); } catch (SQLException t) { System.out.println(t.getMessage()); throw new DataIntegrityViolationException(t.getMessage()); } finally { DataSourceUtils.releaseConnection(conn, this.getDataSource()); // logger.info("dbutils.batch?"); } }
From source file:ch.wisv.areafiftylan.users.service.UserServiceImpl.java
private void handleDuplicateUserFields(UserDTO userDTO) throws DataIntegrityViolationException { // Check if the username already exists userRepository.findOneByUsernameIgnoreCase(userDTO.getUsername()).ifPresent(u -> { throw new DataIntegrityViolationException("username already in use"); });/*from ww w. java2 s .c o m*/ // Check if the email is already in use userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).ifPresent(u -> { throw new DataIntegrityViolationException("email already in use"); }); }
From source file:org.openmrs.contrib.metadatarepository.service.impl.UserManagerImplTest.java
@Test public void testUserExistsException() { // set expectations final User user = new User("admin"); user.setEmail("matt@raibledesigns.com"); final Exception ex = new DataIntegrityViolationException(""); context.checking(new Expectations() { {/*from w w w . j a v a2 s. c om*/ one(userDao).saveUser(with(same(user))); will(throwException(ex)); } }); // run test try { userManager.saveUser(user); fail("Expected UserExistsException not thrown"); } catch (UserExistsException e) { log.debug("expected exception: " + e.getMessage()); assertNotNull(e); } }
From source file:org.openhie.openempi.service.impl.UserManagerImplTest.java
@Test public void testUserExistsException() { // set expectations final User user = new User(Constants.DEFAULT_ADMIN_USERNAME); user.setEmail("matt@raibledesigns.com"); final Exception ex = new DataIntegrityViolationException(""); context.checking(new Expectations() { {/*from w w w.j av a 2 s . c o m*/ one(userDao).saveUser(with(same(user))); will(throwException(ex)); } }); // run test try { userManager.saveUser(user); fail("Expected UserExistsException not thrown"); } catch (UserExistsException e) { log.debug("expected exception: " + e.getMessage()); assertNotNull(e); } }
From source file:com.br.helpdesk.controller.AttachmentsController.java
public void delete(Long id) throws EntityNotFoundException, DataIntegrityViolationException { Attachments attachment = attachmentsService.findById(id); if (attachment == null) { throw new EntityNotFoundException(); }/*from w w w. j av a 2 s .c o m*/ try { attachmentsService.remove(attachment); } catch (Exception e) { throw new DataIntegrityViolationException("Entidade possui dependencias e no pode ser deletada");//DEPENDENCIAS } }
From source file:org.openmrs.module.webservices.rest.resource.BaseRestMetadataResource.java
/** * Purges the entity from the database./*from ww w . j a v a 2 s . c om*/ * @param entity The entity to purge * @param context The request context */ @Override public void purge(E entity, RequestContext context) { try { getService().purge(entity); } catch (PrivilegeException p) { LOG.error("Exception occured when trying to purge entity <" + entity.getName() + "> as privilege is missing", p); throw new PrivilegeException( "Can't purge entity with name <" + entity.getName() + "> as privilege is missing"); } catch (DataIntegrityViolationException e) { LOG.error("Exception occured when trying to purge entity <" + entity.getName() + ">", e); throw new DataIntegrityViolationException( "Can't purge entity with name <" + entity.getName() + "> as it is still in use"); } }