@Override public void cleanup() { if (this.xmlObject != null) { try { this.xmlObject.free(); } catch (SQLException ex) { throw new DataAccessResourceFailureException("Could not free SQLXML object", ex); } } }
@Test public void dataTruncationTranslation() { SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES); SQLException dataAccessEx = new SQLException("", "", 5); DataTruncation dataTruncation = new DataTruncation(1, true, true, 1, 1, dataAccessEx); DataAccessResourceFailureException daex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataTruncation); assertEquals(dataTruncation, daex.getCause()); }
assertEquals("my failure", ex.getMessage());
/** * Open a Session for the SessionFactory that this filter uses. * <p>The default implementation delegates to the {@link SessionFactory#openSession} * method and sets the {@link Session}'s flush mode to "MANUAL". * @param sessionFactory the SessionFactory that this filter uses * @return the Session to use * @throws DataAccessResourceFailureException if the Session could not be created * @see FlushMode#MANUAL */ @SuppressWarnings("deprecation") protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException { try { Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); return session; } catch (HibernateException ex) { throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex); } }
/** * Obtain a JPA EntityManager from the given factory. Is aware of a corresponding * EntityManager bound to the current thread, e.g. when using JpaTransactionManager. * <p>Note: Will return {@code null} if no thread-bound EntityManager found! * @param emf the EntityManagerFactory to create the EntityManager with * @param properties the properties to be passed into the {@code createEntityManager} * call (may be {@code null}) * @return the EntityManager, or {@code null} if none found * @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained * @see JpaTransactionManager */ @Nullable public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map<?, ?> properties) throws DataAccessResourceFailureException { try { return doGetTransactionalEntityManager(emf, properties, true); } catch (PersistenceException ex) { throw new DataAccessResourceFailureException("Could not obtain JPA EntityManager", ex); } }
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof PersistenceException) { return new DataAccessResourceFailureException(ex.getMessage()); } return null; } }
TableMetaData tmd = tableMeta.get(schemaName.toUpperCase()); if (tmd == null) { throw new DataAccessResourceFailureException("Unable to locate table meta-data for '" + tableName + "' in the '" + schemaName + "' schema"); throw new DataAccessResourceFailureException( "Unable to locate table meta-data for '" + tableName + "' in the default schema");
/** * Set the file channel position. * * @param newPosition new file channel position */ private void setPosition(long newPosition) { try { channel.truncate(newPosition); channel.position(newPosition); } catch (IOException e) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); } }
@Override public void setClobAsCharacterStream( PreparedStatement ps, int paramIndex, @Nullable Reader characterStream, int contentLength) throws SQLException { if (characterStream != null) { Clob clob = ps.getConnection().createClob(); try { FileCopyUtils.copy(characterStream, clob.setCharacterStream(1)); } catch (IOException ex) { throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); } this.temporaryClobs.add(clob); ps.setClob(paramIndex, clob); } else { ps.setClob(paramIndex, (Clob) null); } if (logger.isDebugEnabled()) { logger.debug(characterStream != null ? "Copied character stream into temporary CLOB with length " + contentLength : "Set CLOB to null"); } }
@Override public void setBlobAsBinaryStream( PreparedStatement ps, int paramIndex, @Nullable InputStream binaryStream, int contentLength) throws SQLException { if (binaryStream != null) { Blob blob = ps.getConnection().createBlob(); try { FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1)); } catch (IOException ex) { throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); } this.temporaryBlobs.add(blob); ps.setBlob(paramIndex, blob); } else { ps.setBlob(paramIndex, (Blob) null); } if (logger.isDebugEnabled()) { logger.debug(binaryStream != null ? "Copied binary stream into temporary BLOB with length " + contentLength : "Set BLOB to null"); } }
/** * Open a Session for the SessionFactory that this interceptor uses. * <p>The default implementation delegates to the {@link SessionFactory#openSession} * method and sets the {@link Session}'s flush mode to "MANUAL". * @return the Session to use * @throws DataAccessResourceFailureException if the Session could not be created * @see FlushMode#MANUAL */ @SuppressWarnings("deprecation") protected Session openSession() throws DataAccessResourceFailureException { try { Session session = obtainSessionFactory().openSession(); session.setFlushMode(FlushMode.MANUAL); return session; } catch (HibernateException ex) { throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex); } }
@Override public void setClobAsAsciiStream( PreparedStatement ps, int paramIndex, @Nullable InputStream asciiStream, int contentLength) throws SQLException { if (asciiStream != null) { Clob clob = ps.getConnection().createClob(); try { FileCopyUtils.copy(asciiStream, clob.setAsciiStream(1)); } catch (IOException ex) { throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); } this.temporaryClobs.add(clob); ps.setClob(paramIndex, clob); } else { ps.setClob(paramIndex, (Clob) null); } if (logger.isDebugEnabled()) { logger.debug(asciiStream != null ? "Copied ASCII stream into temporary CLOB with length " + contentLength : "Set CLOB to null"); } }
@Override public void setValue(PreparedStatement ps, int paramIndex) throws SQLException { this.xmlObject = ps.getConnection().createSQLXML(); try { provideXml(this.xmlObject); } catch (IOException ex) { throw new DataAccessResourceFailureException("Failure encountered while providing XML", ex); } ps.setSQLXML(paramIndex, this.xmlObject); }
@Override public boolean hasNext() { try { if (peek() != null) { return true; } } catch (XMLStreamException e) { throw new DataAccessResourceFailureException("Error reading XML stream", e); } return false; }
@Override public Object next() { try { return nextEvent(); } catch (XMLStreamException e) { throw new DataAccessResourceFailureException("Error reading XML stream", e); } }
/** * Open a Session for the given SessionFactory. * <p>The default implementation delegates to the {@link SessionFactory#openSession} * method and sets the {@link Session}'s flush mode to "MANUAL". * @param sessionFactory the SessionFactory to use * @return the Session to use * @throws DataAccessResourceFailureException if the Session could not be created * @since 5.0 * @see FlushMode#MANUAL */ @SuppressWarnings("deprecation") protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException { Session session = openSession(); if (session == null) { try { session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); } catch (HibernateException ex) { throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex); } } return session; }
@Override public void update(StepExecution stepExecution) { called++; if (called == 3) { throw new DataAccessResourceFailureException("stub exception"); } } }
/** * Finishes reading the fragment in case the fragment was processed without * being read until the end. */ @Override public void markFragmentProcessed() { if (insideFragment|| startFragmentFollows) { try { while (!(nextEvent() instanceof EndDocument)) { // just read all events until EndDocument } } catch (XMLStreamException e) { throw new DataAccessResourceFailureException("Error reading XML stream", e); } } fakeDocumentEnd = false; }
/** * Open a Session for the SessionFactory that this filter uses. * <p>The default implementation delegates to the {@link SessionFactory#openSession} * method and sets the {@link Session}'s flush mode to "MANUAL". * @param sessionFactory the SessionFactory that this filter uses * @return the Session to use * @throws DataAccessResourceFailureException if the Session could not be created * @see FlushMode#MANUAL */ @SuppressWarnings("deprecation") protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException { try { Session session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); return session; } catch (HibernateException ex) { throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex); } }