List of usage examples for org.springframework.dao DataAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:org.kuali.rice.ken.service.impl.ConcurrentJob.java
/** * Main processing method which invokes subclass implementations of template methods * to obtain available work items, and process them concurrently * @return a ProcessingResult object containing the results of processing *///from w w w .j a v a 2 s . co m @SuppressWarnings("unchecked") public ProcessingResult run() { if (LOG.isDebugEnabled()) { LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] STARTING RUN"); } final ProcessingResult result = new ProcessingResult(); // retrieve list of available work items in a transaction Collection<T> items = null; try { items = (Collection<T>) createNewTransaction().execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus txStatus) { return takeAvailableWorkItems(); } }); } catch (DataAccessException dae) { if (dae instanceof OptimisticLockingFailureException || dae.contains(OptimisticLockingFailureException.class) || dae.contains(OptimisticLockException.class)) { // anticipated in the case that another thread is trying to grab items LOG.info("Contention while taking work items: " + dae.getMessage()); } else { // in addition to logging a message, should we throw an exception or log a failure here? LOG.error("Error taking work items", dae); Throwable t = dae.getMostSpecificCause(); if (t != null && t instanceof SQLException) { SQLException sqle = (SQLException) t; if (sqle.getErrorCode() == ORACLE_00054 && StringUtils.contains(sqle.getMessage(), "resource busy")) { // this is expected and non-fatal given that these jobs will run again LOG.warn("Select for update lock contention encountered: " + sqle.getMessage()); } else if (sqle.getErrorCode() == ORACLE_00060 && StringUtils.contains(sqle.getMessage(), "deadlock detected")) { // this is bad...two parties are waiting forever somewhere... // database is probably wedged now :( LOG.error("Select for update deadlock encountered! " + sqle.getMessage()); } } } return result; } catch (UnexpectedRollbackException ure) { LOG.error("UnexpectedRollbackException", ure); return result; } catch (TransactionException te) { LOG.error("Error occurred obtaining available work items", te); result.addFailure("Error occurred obtaining available work items: " + te); return result; } Collection<Collection<T>> groupedWorkItems = groupWorkItems(items, result); // now iterate over all work groups and process each Iterator<Collection<T>> i = groupedWorkItems.iterator(); List<Future> futures = new ArrayList<Future>(); while (i.hasNext()) { final Collection<T> workUnit = i.next(); LOG.info("Processing work unit: " + workUnit); /* performed within transaction */ /* executor manages threads to run work items... */ futures.add(executor.submit(new Callable() { public Object call() throws Exception { ProcessingResult result = new ProcessingResult(); try { Collection<?> successes = (Collection<Object>) createNewTransaction() .execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus txStatus) { return processWorkItems(workUnit); } }); result.addAllSuccesses(successes); } catch (Exception e) { LOG.error("Error occurred processing work unit " + workUnit, e); for (final T workItem : workUnit) { LOG.error("Error occurred processing work item " + workItem, e); result.addFailure("Error occurred processing work item " + workItem + ": " + e); unlockWorkItemAtomically(workItem); } } return result; } })); } // wait for workers to finish for (Future f : futures) { try { ProcessingResult workResult = (ProcessingResult) f.get(); result.add(workResult); } catch (Exception e) { String message = "Error obtaining work result: " + e; LOG.error(message, e); result.addFailure(message); } } if (LOG.isDebugEnabled()) { LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] FINISHED RUN - " + result); } return result; }
From source file:org.kuali.rice.kew.docsearch.dao.impl.DocumentSearchDAOJdbcImpl.java
@Override public DocumentSearchResults.Builder findDocuments(final DocumentSearchGenerator documentSearchGenerator, final DocumentSearchCriteria criteria, final boolean criteriaModified, final List<RemotableAttributeField> searchFields) { final int maxResultCap = getMaxResultCap(criteria); try {/*from w w w.j ava 2 s. co m*/ final JdbcTemplate template = new JdbcTemplate(dataSource); return template.execute(new ConnectionCallback<DocumentSearchResults.Builder>() { @Override public DocumentSearchResults.Builder doInConnection(final Connection con) throws SQLException { final Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); try { final int fetchIterationLimit = getFetchMoreIterationLimit(); final int fetchLimit = fetchIterationLimit * maxResultCap; statement.setFetchSize(maxResultCap + 1); statement.setMaxRows(fetchLimit + 1); PerformanceLogger perfLog = new PerformanceLogger(); String sql = documentSearchGenerator.generateSearchSql(criteria, searchFields); perfLog.log("Time to generate search sql from documentSearchGenerator class: " + documentSearchGenerator.getClass().getName(), true); LOG.info("Executing document search with statement max rows: " + statement.getMaxRows()); LOG.info( "Executing document search with statement fetch size: " + statement.getFetchSize()); perfLog = new PerformanceLogger(); final ResultSet rs = statement.executeQuery(sql); try { perfLog.log("Time to execute doc search database query.", true); final Statement searchAttributeStatement = con .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); try { return documentSearchGenerator.processResultSet(criteria, criteriaModified, searchAttributeStatement, rs, maxResultCap, fetchLimit); } finally { try { searchAttributeStatement.close(); } catch (SQLException e) { LOG.warn("Could not close search attribute statement."); } } } finally { try { rs.close(); } catch (SQLException e) { LOG.warn("Could not close result set."); } } } finally { try { statement.close(); } catch (SQLException e) { LOG.warn("Could not close statement."); } } } }); } catch (DataAccessException dae) { String errorMsg = "DataAccessException: " + dae.getMessage(); LOG.error("getList() " + errorMsg, dae); throw new RuntimeException(errorMsg, dae); } catch (Exception e) { String errorMsg = "LookupException: " + e.getMessage(); LOG.error("getList() " + errorMsg, e); throw new RuntimeException(errorMsg, e); } }
From source file:org.linagora.linshare.auth.dao.LdapAuthenticationProvider.java
@Override protected UserDetails retrieveUser(String login, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { UserDetails loadedUser;/*from w w w .j a v a 2s . c om*/ logger.debug("Retrieving user detail for ldap authentication with login : " + login); User foundUser = null; String domainIdentifier = null; // Getting password from context String password = (String) authentication.getCredentials(); if (password.isEmpty()) { String message = "User password is empty, authentification failed"; ldapUserDetailsProvider.logAuthError(login, domainIdentifier, message); logger.error(message); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } try { // Getting domain from context if (authentication.getDetails() != null && authentication.getDetails() instanceof String) { domainIdentifier = (String) authentication.getDetails(); } foundUser = ldapUserDetailsProvider.retrieveUser(domainIdentifier, login); try { ldapUserDetailsProvider.auth(foundUser.getDomain().getUserProvider(), foundUser.getMail(), password); } catch (BadCredentialsException e1) { logger.debug("Authentication failed: password does not match stored value"); String message = "Bad credentials."; ldapUserDetailsProvider.logAuthError(foundUser, foundUser.getDomainId(), message); logger.error(message); throw new BadCredentialsException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), foundUser); } catch (Exception e) { logger.error(e.getMessage()); throw new AuthenticationServiceException( "Could not authenticate user : " + foundUser.getDomainId() + " : " + foundUser.getMail(), e); } User user = null; try { user = ldapUserDetailsProvider.findOrCreateUser(foundUser.getDomainId(), foundUser.getMail()); } catch (BusinessException e) { logger.error(e); throw new AuthenticationServiceException( "Could not create user account : " + foundUser.getDomainId() + " : " + foundUser.getMail(), e); } List<GrantedAuthority> grantedAuthorities = RoleProvider.getRoles(user); loadedUser = new org.springframework.security.core.userdetails.User(user.getLsUuid(), "", true, true, true, true, grantedAuthorities); } catch (DataAccessException repositoryProblem) { throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); } return loadedUser; }
From source file:org.mifosplatform.portfolio.savings.service.SavingsProductWritePlatformServiceJpaRepositoryImpl.java
private void logAsErrorUnexpectedDataIntegrityException(final DataAccessException dae) { this.logger.error(dae.getMessage(), dae); }
From source file:org.osaf.cosmo.acegisecurity.providers.ticket.TicketAuthenticationProvider.java
private Ticket findTicket(String path, String key) { try {//from w ww. ja v a 2 s . co m if (log.isDebugEnabled()) log.debug("authenticating ticket " + key + " for resource at path " + path); Item item = findItem(path); Ticket ticket = contentDao.getTicket(item, key); if (ticket == null) return null; if (ticket.hasTimedOut()) { if (log.isDebugEnabled()) log.debug("removing timed out ticket " + ticket.getKey()); contentDao.removeTicket(item, ticket); return null; } return ticket; } catch (DataAccessException e) { throw new AuthenticationServiceException(e.getMessage(), e); } }
From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java
public boolean addAvailabilityCheck(AvailabilityCheck availabilityCheck) { if (log.isDebugEnabled()) { log.debug("addAvailabilityCheck( " + availabilityCheck.toString() + ")"); }// w w w. ja va 2 s . c om // entity_ref, scheduled_time try { JdbcTemplate template = getJdbcTemplate(); String sql = getStatement("insert.AvailabilityCheck"); template.update(sql, new Object[] { availabilityCheck.getEntityReference(), availabilityCheck.getEntityTypeId(), availabilityCheck.getScheduledTime() }); return true; } catch (DataIntegrityViolationException e) { // this means we're trying to insert a duplicate log.debug("addAvailabilityCheck() " + e); return false; } catch (DataAccessException ex) { log.warn("addAvailabilityCheck: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); return false; } catch (Exception e) { log.warn("addAvailabilityCheck: Error executing query: " + e.getClass() + ":" + e.getMessage()); return false; } }
From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java
public boolean addCalendarItem(CalendarItem calendarItem) { if (log.isDebugEnabled()) { log.debug("addCalendarItem( " + calendarItem.toString() + ")"); }/* w w w. j a v a2 s .c om*/ // calendar_time, title , entity_url, entity_ref, source_type, context_id, realm_id String subtype = calendarItem.getSubtype(); // DASH-191 if (subtype != null && subtype.length() > MAX_LENGTH_SUBTYPE_FIELD) { StringBuilder buf = new StringBuilder(); buf.append("addCalendarItem(). Truncating subtype "); buf.append(subtype); buf.append(" for entity "); buf.append(calendarItem.getEntityReference()); log.warn(buf); subtype = subtype.substring(0, MAX_LENGTH_SUBTYPE_FIELD - 1); } try { JdbcTemplate template = getJdbcTemplate(); Object[] params = null; String sql = null; if (calendarItem.getRepeatingCalendarItem() == null) { sql = getStatement("insert.CalendarItem"); params = new Object[] { calendarItem.getCalendarTime(), calendarItem.getCalendarTimeLabelKey(), calendarItem.getTitle(), calendarItem.getEntityReference(), subtype, calendarItem.getSourceType().getId(), calendarItem.getContext().getId() }; } else { sql = getStatement("insert.CalendarItem.repeats"); params = new Object[] { calendarItem.getCalendarTime(), calendarItem.getCalendarTimeLabelKey(), calendarItem.getTitle(), calendarItem.getEntityReference(), subtype, calendarItem.getSourceType().getId(), calendarItem.getContext().getId(), calendarItem.getRepeatingCalendarItem().getId(), calendarItem.getSequenceNumber() }; } int result = template.update(sql, params); return result > 0; } catch (DataIntegrityViolationException e) { // this means we're trying to insert a duplicate log.warn("addCalendarItem() " + e); } catch (DataAccessException ex) { log.warn("addCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); // System.out.println("addCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); } return false; }
From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java
public boolean addCalendarLink(CalendarLink calendarLink) { if (log.isDebugEnabled()) { log.debug("addCalendarLink( " + calendarLink.toString() + ")"); }// w w w . j a v a 2 s . c om // person_id, item_id, context_id, realm_id try { getJdbcTemplate().update(getStatement("insert.CalendarLink"), new Object[] { calendarLink.getPerson().getId(), calendarLink.getCalendarItem().getId(), calendarLink.getContext().getId(), calendarLink.isHidden(), calendarLink.isSticky() }); return true; } catch (DataIntegrityViolationException e) { // this means we're trying to insert a duplicate log.debug("addCalendarLink() " + e); return false; } catch (DataAccessException ex) { log.warn("addCalendarLink: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); return false; } }
From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java
public int addCalendarLinks(final List<CalendarLink> calendarLinks) { if (log.isDebugEnabled()) { log.debug("addCalendarLinks( " + calendarLinks.size() + ")"); }/* w w w .j ava 2 s .c o m*/ // person_id, item_id, context_id, realm_id int count = 0; try { String sql = getStatement("insert.CalendarLink"); int[] updates = getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { CalendarLink calendarLink = calendarLinks.get(i); ps.setLong(1, calendarLink.getPerson().getId()); ps.setLong(2, calendarLink.getCalendarItem().getId()); ps.setLong(3, calendarLink.getContext().getId()); ps.setBoolean(4, calendarLink.isHidden()); ps.setBoolean(5, calendarLink.isSticky()); } @Override public int getBatchSize() { return calendarLinks.size(); } }); if (updates != null && updates.length > 0) { for (int u : updates) { count += u; } } } catch (DataIntegrityViolationException e) { // this means we're trying to insert a duplicate log.debug("addCalendarLinks() " + e); } catch (DataAccessException ex) { log.warn("addCalendarLinks: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); } return count; }
From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java
public boolean addContext(Context context) { if (log.isDebugEnabled()) { log.debug("addContext( " + context.toString() + ")"); }//from w ww .j a va 2 s. com // context_id, context_url, context_title String sql = getStatement("insert.Context"); try { int rows = getJdbcTemplate().update(sql, new Object[] { context.getContextId(), context.getContextUrl(), context.getContextTitle() }); return true; } catch (DataIntegrityViolationException e) { // this means we're trying to insert a duplicate log.debug("addContext() " + e); return false; } catch (DataAccessException ex) { log.warn("addContext: Error executing query: " + ex.getClass() + ":" + ex.getMessage()); return false; } catch (Exception e) { log.warn("addCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage()); return false; } }