List of usage examples for org.springframework.dao TransientDataAccessResourceException TransientDataAccessResourceException
public TransientDataAccessResourceException(String msg, Throwable cause)
From source file:org.opendatakit.security.spring.UserDetailsServiceImpl.java
@Override public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException, DataAccessException { if (name == null) { throw new IllegalStateException("Username cannot be null"); }/*from ww w . ja v a 2 s . c o m*/ User user = userService.getDaemonAccountUser(); final String uriUser; final String password; final String salt; final Set<GrantedAuthority> grantedAuthorities; final boolean isEnabled = true; final boolean isCredentialNonExpired = true; try { if (credentialType == CredentialType.Username) { RegisteredUsersTable registeredUsersTable; // first call from digest, basic or forms-based auth if (name.startsWith(RegisteredUsersTable.UID_PREFIX)) { registeredUsersTable = RegisteredUsersTable.getUserByUri(name, datastore, user); if (registeredUsersTable == null) { throw new UsernameNotFoundException("UID " + name + " is not recognized."); } } else { registeredUsersTable = RegisteredUsersTable.getUniqueUserByUsername(name, datastore, user); if (registeredUsersTable == null) { throw new UsernameNotFoundException( "User " + name + " is not registered or the registered users table is corrupt."); } } uriUser = registeredUsersTable.getUri(); // Along with BasicUsingDigest* classes, we allow both types of authentication to use the // same DB field for password. switch (passwordType) { case BasicAuth: // password = registeredUsersTable.getBasicAuthPassword(); // salt = registeredUsersTable.getBasicAuthSalt(); // break; case DigestAuth: password = registeredUsersTable.getDigestAuthPassword(); salt = UUID.randomUUID().toString(); break; default: throw new AuthenticationCredentialsNotFoundException( "Password type " + passwordType.toString() + " cannot be interpretted"); } grantedAuthorities = getGrantedAuthorities(registeredUsersTable.getUri()); if (password == null) { throw new AuthenticationCredentialsNotFoundException("User " + name + " does not have a password configured. You must close and re-open your browser to clear this error."); } } else { // OAuth2 token... // there is no password for an OAuth2 credential if (passwordType != PasswordType.Random) { throw new AuthenticationCredentialsNotFoundException( "Password type " + passwordType.toString() + " cannot be interpretted"); } // set password and salt to unguessable strings... password = UUID.randomUUID().toString(); salt = UUID.randomUUID().toString(); // try to find user in registered users table... RegisteredUsersTable eUser = RegisteredUsersTable.getUniqueUserByEmail(name, datastore, user); if (eUser != null) { uriUser = eUser.getUri(); grantedAuthorities = getGrantedAuthorities(eUser.getUri()); } else { throw new UsernameNotFoundException("User " + name + " is not registered"); } } } catch (ODKDatastoreException e) { throw new TransientDataAccessResourceException("persistence layer problem", e); } return new OdkServerUser(uriUser, password, salt, "-undefined-", isEnabled, true, isCredentialNonExpired, true, grantedAuthorities); }
From source file:com.raycloud.cobarclient.mybatis.spring.MySqlSessionTemplate.java
/** * ?????/*w w w .j a v a 2s. c o m*/ * * @param statement * @param collection * @param <T> * @return */ private <T extends Object> int batchSync(final String statement, Collection<T> collection) { Map<Shard, List<T>> classifiedEntities = classify(statement, collection); final MultipleCauseException throwables = new MultipleCauseException(); int counter = 0; for (final Map.Entry<Shard, List<T>> entry : classifiedEntities.entrySet()) { Environment environment = environmentMap.get(entry.getKey().getId()); //?? final SqlSession sqlSession = SqlSessionUtils.getSqlSession(MySqlSessionTemplate.this.sqlSessionFactory, ExecutorType.BATCH, MySqlSessionTemplate.this.exceptionTranslator, environment); try { for (T item : entry.getValue()) { sqlSession.update(statement, item); } List<BatchResult> results = sqlSession.flushStatements(); int[] updateCounts = results.get(0).getUpdateCounts(); for (int i = 0; i < updateCounts.length; i++) { int value = updateCounts[i]; counter += value; } } catch (Throwable e) { Throwable unwrapped = unwrapThrowable(e); if (MySqlSessionTemplate.this.exceptionTranslator != null && unwrapped instanceof PersistenceException) { Throwable translated = MySqlSessionTemplate.this.exceptionTranslator .translateExceptionIfPossible((PersistenceException) unwrapped); if (translated != null) { unwrapped = translated; } } throwables.add(unwrapped); } finally { SqlSessionUtils.closeSqlSession(sqlSession, MySqlSessionTemplate.this.sqlSessionFactory); } } if (!throwables.getCauses().isEmpty()) { throw new TransientDataAccessResourceException( "one or more errors when performing data access operations against multiple shards", throwables); } return counter; }
From source file:com.raycloud.cobarclient.mybatis.spring.MySqlSessionTemplate.java
/** * TODO ?Multiple Thread Transaction//from w ww . j av a2 s .c o m * * @param statement * @param collection * @param <T> * @return */ private final <T extends Object> int batchAsync(final String statement, Collection<T> collection) { Map<Shard, List<T>> classifiedEntities = classify(statement, collection); final CountDownLatch latch = new CountDownLatch(classifiedEntities.size()); List<Future<Integer>> futures = new ArrayList<Future<Integer>>(); final MultipleCauseException throwables = new MultipleCauseException(); ExecutorService _executor = MtContextExecutors.getMtcExecutorService(executor); SqlSessionHolder holder = SqlSessionUtils .currentSqlSessionHolder(MySqlSessionTemplate.this.sqlSessionFactory); for (final Map.Entry<Shard, List<T>> entry : classifiedEntities.entrySet()) { futures.add(_executor.submit(new BatchAsyncCallable(entry, statement, latch, throwables, holder))); } try { latch.await(); } catch (InterruptedException e) { throw new ConcurrencyFailureException("interrupted when processing data access request in concurrency", e); } if (!throwables.getCauses().isEmpty()) { throw new TransientDataAccessResourceException( "one or more errors when performing data access operations" + " against multiple shards", throwables); } return counter(getFutureResults(futures)); }
From source file:org.springframework.jdbc.support.SQLExceptionSubclassTranslator.java
public DataAccessException translate(String task, String sql, SQLException ex) { Assert.notNull(ex, "Cannot translate a null SQLException."); if (task == null) { task = ""; }//from w w w . j av a 2 s . c o m if (sql == null) { sql = ""; } if (ex instanceof SQLTransientException) { if (ex instanceof SQLTransactionRollbackException) { return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); } if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); } if (ex instanceof SQLTimeoutException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); } } else if (ex instanceof SQLNonTransientException) { if (ex instanceof SQLDataException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLFeatureNotSupportedException) { return new BadSqlGrammarException(task, sql, ex); } else if (ex instanceof SQLIntegrityConstraintViolationException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLInvalidAuthorizationSpecException) { return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLNonTransientConnectionException) { return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLSyntaxErrorException) { return new BadSqlGrammarException(task, sql, ex); } } else if (ex instanceof SQLRecoverableException) { return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); } // We couldn't identify it more precisely - let's allow other translation strategies to kick in. return null; }