@Override public void cleanup() { if (this.xmlObject != null) { try { this.xmlObject.free(); } catch (SQLException ex) { throw new DataAccessResourceFailureException("Could not free SQLXML object", ex); } } }
/** * 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");
@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); }
/** * 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; }
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
/** * Executes the SQL as specified by {@link #getSequenceQuery()}. */ @Override protected long getNextKey() throws DataAccessException { Connection con = DataSourceUtils.getConnection(getDataSource()); Statement stmt = null; ResultSet rs = null; try { stmt = con.createStatement(); DataSourceUtils.applyTransactionTimeout(stmt, getDataSource()); rs = stmt.executeQuery(getSequenceQuery()); if (rs.next()) { return rs.getLong(1); } else { throw new DataAccessResourceFailureException("Sequence query did not return a result"); } } catch (SQLException ex) { throw new DataAccessResourceFailureException("Could not obtain sequence value", ex); } finally { JdbcUtils.closeResultSet(rs); JdbcUtils.closeStatement(stmt); DataSourceUtils.releaseConnection(con, getDataSource()); } }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { try { Thread.sleep(1500); } catch (InterruptedException ex) { } try { Connection con = DataSourceUtils.getConnection(ds); PreparedStatement ps = con.prepareStatement("some SQL statement"); DataSourceUtils.applyTransactionTimeout(ps, ds); } catch (SQLException ex) { throw new DataAccessResourceFailureException("", ex); } } });
try { if (!rs.next()) { throw new DataAccessResourceFailureException("Identity statement failed after inserting"); throw new DataAccessResourceFailureException("Could not increment identity", ex);
@Override @Nullable public <T> T execute(ConnectionCallback<T> action) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); ConnectionFactory connectionFactory = obtainConnectionFactory(); Connection con = ConnectionFactoryUtils.getConnection(connectionFactory, getConnectionSpec()); try { return action.doInConnection(con, connectionFactory); } catch (NotSupportedException ex) { throw new CciOperationNotSupportedException("CCI operation not supported by connector", ex); } catch (ResourceException ex) { throw new DataAccessResourceFailureException("CCI operation failed", ex); } catch (SQLException ex) { throw new InvalidResultSetAccessException("Parsing of CCI ResultSet failed", ex); } finally { ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory()); } }
throw new DataAccessResourceFailureException( "Could not obtain Hibernate-managed Session for Spring-managed transaction", ex);
throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
@Override public void preHandle(WebRequest request) throws DataAccessException { String key = getParticipateAttributeName(); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); if (asyncManager.hasConcurrentResult() && applyEntityManagerBindingInterceptor(asyncManager, key)) { return; } EntityManagerFactory emf = obtainEntityManagerFactory(); if (TransactionSynchronizationManager.hasResource(emf)) { // Do not modify the EntityManager: just mark the request accordingly. Integer count = (Integer) request.getAttribute(key, WebRequest.SCOPE_REQUEST); int newCount = (count != null ? count + 1 : 1); request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); } else { logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor"); try { EntityManager em = createEntityManager(); EntityManagerHolder emHolder = new EntityManagerHolder(em); TransactionSynchronizationManager.bindResource(emf, emHolder); AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(emf, emHolder); asyncManager.registerCallableInterceptor(key, interceptor); asyncManager.registerDeferredResultInterceptor(key, interceptor); } catch (PersistenceException ex) { throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex); } } }
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);