/** * Handle the case where the ResultSet contains multiple rows. * @throws DataAccessException a corresponding exception, * by default an IncorrectResultSizeDataAccessException * @see org.springframework.dao.IncorrectResultSizeDataAccessException */ protected void handleMultipleRowsFound() throws DataAccessException { throw new IncorrectResultSizeDataAccessException( "LobStreamingResultSetExtractor found multiple rows in database", 1); }
/** * Handle the case where the ResultSet does not contain a row. * @throws DataAccessException a corresponding exception, * by default an EmptyResultDataAccessException * @see org.springframework.dao.EmptyResultDataAccessException */ protected void handleNoRowFound() throws DataAccessException { throw new EmptyResultDataAccessException( "LobStreamingResultSetExtractor did not find row in database", 1); }
/** * Create a new ArgTypePreparedStatementSetter for the given arguments. * @param args the arguments to set * @param argTypes the corresponding SQL types of the arguments */ public ArgumentTypePreparedStatementSetter(@Nullable Object[] args, @Nullable int[] argTypes) { if ((args != null && argTypes == null) || (args == null && argTypes != null) || (args != null && args.length != argTypes.length)) { throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match"); } this.args = args; this.argTypes = argTypes; }
if (ex instanceof SQLTransientException) { if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); return new QueryTimeoutException(buildMessage(task, sql, ex), ex); return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
public UserDetails loadUserByUsername(String username) { throw new DataRetrievalFailureException( "This mock simulator is designed to fail"); } }
@Override public void cleanup() { if (this.xmlObject != null) { try { this.xmlObject.free(); } catch (SQLException ex) { throw new DataAccessResourceFailureException("Could not free SQLXML object", ex); } } }
/** * Delegate method to execute the insert, generating a single key. */ private Number executeInsertAndReturnKeyInternal(final List<?> values) { KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); if (kh.getKey() != null) { return kh.getKey(); } else { throw new DataIntegrityViolationException( "Unable to retrieve the generated key for the insert: " + getInsertString()); } }
/** * Analogous to the SqlQuery.execute([]) method. This is a * generic method to execute a query, taken a number of arguments. * @param parameters array of parameters. These will be objects or * object wrapper types for primitives. * @return the value of the function */ public int run(Object... parameters) { Object obj = super.findObject(parameters); if (!(obj instanceof Number)) { throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int"); } return ((Number) obj).intValue(); }
@Override public String doInTransaction(TransactionStatus status) { assertTrue(TransactionSynchronizationManager.isSynchronizationActive()); assertTrue(TransactionSynchronizationManager.isActualTransactionActive()); assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly()); throw new OptimisticLockingFailureException(""); } });
@Override public DataAccessException translate(String task, @Nullable String sql, SQLException ex) { if (ex.getErrorCode() == 2) { return new TransientDataAccessResourceException("Custom", ex); } return null; }
/** * Set whether prepared statements should be capable of returning * auto-generated keys. * @see java.sql.Connection#prepareStatement(String, int) */ public void setReturnGeneratedKeys(boolean returnGeneratedKeys) { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( "The returnGeneratedKeys flag must be set before the operation is compiled"); } this.returnGeneratedKeys = returnGeneratedKeys; }
@Override protected final Record createInputRecord(RecordFactory recordFactory, Object inObject) { try { return new CommAreaRecord(objectToBytes(inObject)); } catch (IOException ex) { throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); } }
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof PersistenceException) { return new DataAccessResourceFailureException(ex.getMessage()); } return null; } }
/** * Method to check whether we are allowed to make any configuration changes at this time. * If the class has been compiled, then no further changes to the configuration are allowed. */ protected void checkIfConfigurationModificationIsAllowed() { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( "Configuration cannot be altered once the class has been compiled or used"); } }
@Override protected final Object extractOutputData(Record record) throws DataAccessException { CommAreaRecord commAreaRecord = (CommAreaRecord) record; try { return bytesToObject(commAreaRecord.toByteArray()); } catch (IOException ex) { throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); } }
@Override @Nullable public Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException { if (this.keyList.isEmpty()) { return null; } if (this.keyList.size() > 1) { throw new InvalidDataAccessApiUsageException( "The getKeys method should only be used when keys for a single row are returned. " + "The current key list contains keys for multiple rows: " + this.keyList); } return this.keyList.get(0); }
@Override public Void doInTransaction(TransactionStatus status) { assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(connectionFactory)); CciTemplate ct = new CciTemplate(connectionFactory); ct.execute(interactionSpec, record, record); throw new DataRetrievalFailureException("error"); } });
/** * Set whether to use statements that are capable of returning * updatable ResultSets. * @see java.sql.Connection#prepareStatement(String, int, int) */ public void setUpdatableResults(boolean updatableResults) { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( "The updateableResults flag must be set before the operation is compiled"); } this.updatableResults = updatableResults; }
/** * Set the class that each row should be mapped to. */ public void setMappedClass(Class<T> mappedClass) { if (this.mappedClass == null) { initialize(mappedClass); } else { if (this.mappedClass != mappedClass) { throw new InvalidDataAccessApiUsageException("The mapped class can not be reassigned to map to " + mappedClass + " since it is already providing mapping for " + this.mappedClass); } } }
/** * Set the column names of the auto-generated keys. * @see java.sql.Connection#prepareStatement(String, String[]) */ public void setGeneratedKeysColumnNames(@Nullable String... names) { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( "The column names for the generated keys must be set before the operation is compiled"); } this.generatedKeysColumnNames = names; }