List of usage examples for org.springframework.jdbc UncategorizedSQLException UncategorizedSQLException
public UncategorizedSQLException(String task, @Nullable String sql, SQLException ex)
From source file:at.ac.univie.isc.asio.engine.sql.WebRowSetWriter.java
@Override public void serialize(final OutputStream output, final String statement, final Cursor<Record> cursor) throws IOException { try {//from w ww . java 2 s. c o m this.cursor = cursor; xml = XML_OUTPUT_FACTORY.createXMLStreamWriter(output, Charsets.UTF_8.name()); prelude(); properties(statement); metadata(); data(); postlude(); } catch (XMLStreamException e) { throw new IOException(e); } catch (SQLException e) { throw new UncategorizedSQLException("webrowset serialization", statement, e); } finally { Closer.quietly(xml, Closer.xmlStreamWriter()); } }
From source file:org.jamwiki.db.CacheQueryHandler.java
/** * *//* ww w .ja v a 2 s . c om*/ @Override public void insertTopicVersions(List<TopicVersion> topicVersions) { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; boolean useBatch = (topicVersions.size() > 1); try { conn = DatabaseConnection.getConnection(); if (!this.autoIncrementPrimaryKeys()) { stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION); } else if (useBatch) { // generated keys don't work in batch mode stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION_AUTO_INCREMENT); } else { stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION_AUTO_INCREMENT, Statement.RETURN_GENERATED_KEYS); } int topicVersionId = -1; if (!this.autoIncrementPrimaryKeys() || useBatch) { // manually retrieve next topic version id when using batch // mode or when the database doesn't support generated keys. topicVersionId = DatabaseConnection.executeSequenceQuery(STATEMENT_SELECT_TOPIC_VERSION_SEQUENCE); } for (TopicVersion topicVersion : topicVersions) { if (!this.autoIncrementPrimaryKeys() || useBatch) { // FIXME - if two threads update the database simultaneously then // it is possible that this code could set the topic version ID // to a value that is different from what the database ends up // using. topicVersion.setTopicVersionId(topicVersionId++); } StringReader sr = null; try { int index = 1; stmt.setInt(index++, topicVersion.getTopicVersionId()); if (topicVersion.getEditDate() == null) { topicVersion.setEditDate(new Timestamp(System.currentTimeMillis())); } stmt.setInt(index++, topicVersion.getTopicId()); stmt.setString(index++, topicVersion.getEditComment()); //pass the content into a stream to be passed to Cach sr = new StringReader(topicVersion.getVersionContent()); stmt.setCharacterStream(index++, sr, topicVersion.getVersionContent().length()); if (topicVersion.getAuthorId() == null) { stmt.setNull(index++, Types.INTEGER); } else { stmt.setInt(index++, topicVersion.getAuthorId()); } stmt.setInt(index++, topicVersion.getEditType()); stmt.setString(index++, topicVersion.getAuthorDisplay()); stmt.setTimestamp(index++, topicVersion.getEditDate()); if (topicVersion.getPreviousTopicVersionId() == null) { stmt.setNull(index++, Types.INTEGER); } else { stmt.setInt(index++, topicVersion.getPreviousTopicVersionId()); } stmt.setInt(index++, topicVersion.getCharactersChanged()); stmt.setString(index++, topicVersion.getVersionParamString()); } finally { if (sr != null) { sr.close(); } } if (useBatch) { stmt.addBatch(); } else { stmt.executeUpdate(); } if (this.autoIncrementPrimaryKeys() && !useBatch) { rs = stmt.getGeneratedKeys(); if (!rs.next()) { throw new SQLException("Unable to determine auto-generated ID for database record"); } topicVersion.setTopicVersionId(rs.getInt(1)); } } if (useBatch) { stmt.executeBatch(); } } catch (SQLException e) { throw new UncategorizedSQLException("insertTopicVersions", null, e); } finally { DatabaseConnection.closeConnection(conn, stmt, rs); } }
From source file:org.guzz.web.context.spring.TransactionManagerUtils.java
/** * Convert the given GuzzException to an appropriate exception * from the <code>org.springframework.dao</code> hierarchy. * @param ex GuzzException that occured/*from ww w .java2 s .c o m*/ * @return the corresponding DataAccessException instance * @see GuzzAccessor#convertGuzzAccessException * @see GuzzTransactionManager#convertGuzzAccessException */ public static DataAccessException convertGuzzAccessException(GuzzException ex) { if (ex instanceof JDBCException) { JDBCException e = (JDBCException) ex; return new UncategorizedSQLException(e.getMessage(), e.getSQL(), e.getSQLException()); } return new DataAccessResourceFailureException(ex.getMessage(), ex); }
From source file:org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.java
/** * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the * {@link #getFallbackTranslator() fallback translator} if necessary. *///from w w w . ja v a 2 s . c om @Override @NonNull public DataAccessException translate(String task, @Nullable String sql, SQLException ex) { Assert.notNull(ex, "Cannot translate a null SQLException"); DataAccessException dae = doTranslate(task, sql, ex); if (dae != null) { // Specific exception match found. return dae; } // Looking for a fallback... SQLExceptionTranslator fallback = getFallbackTranslator(); if (fallback != null) { dae = fallback.translate(task, sql, ex); if (dae != null) { // Fallback exception match found. return dae; } } // We couldn't identify it more precisely. return new UncategorizedSQLException(task, sql, ex); }
From source file:org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.java
public DataAccessException translate(String task, String sql, SQLException sqlEx) { if (task == null) { task = ""; }// www .j a v a2 s .co m if (sql == null) { sql = ""; } String sqlState = sqlEx.getSQLState(); // Some JDBC drivers nest the actual exception from a batched update: need to get the nested one. if (sqlState == null) { SQLException nestedEx = sqlEx.getNextException(); if (nestedEx != null) { sqlState = nestedEx.getSQLState(); } } if (sqlState != null && sqlState.length() >= 2) { String classCode = sqlState.substring(0, 2); if (BAD_SQL_CODES.contains(classCode)) { return new BadSqlGrammarException(task, sql, sqlEx); } else if (INTEGRITY_VIOLATION_CODES.contains(classCode)) { return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx); } } // We couldn't identify it more precisely. return new UncategorizedSQLException(task, sql, sqlEx); }