List of usage examples for java.sql Connection commit
void commit() throws SQLException;
Connection
object. From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProgramSqlAdapter.java
public Program updateProgramPath(int id, String sourcePath) throws AdaptationException { Program program = null;/*from w w w .j a v a2 s. co m*/ Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { String query = "UPDATE Programs SET " + "sourcePath = '" + sourcePath + "' " + "WHERE id = " + id; connection = DriverManager.getConnection(CONN_STR); statement = connection.createStatement(); statement.executeUpdate(query); query = "SELECT * from Programs WHERE id = " + id; resultSet = statement.executeQuery(query); if (!resultSet.next()) { connection.rollback(); String msg = "Attempt to update program failed."; log.error(msg); throw new AdaptationException(msg); } program = getProgram(resultSet); connection.commit(); } catch (SQLException ex) { try { connection.rollback(); } catch (Exception e) { } String msg = "SQLException in updateProgramPath"; log.error(msg, ex); throw new AdaptationException(msg, ex); } finally { try { resultSet.close(); } catch (Exception ex) { } try { statement.close(); } catch (Exception ex) { } try { connection.close(); } catch (Exception ex) { } } return program; }
From source file:com.netflix.metacat.usermetadata.mysql.MysqlUserMetadataService.java
@Override public void deleteDataMetadatas(@Nonnull final List<String> uris) { try {// www. j av a2s . c o m final Connection conn = poolingDataSource.getConnection(); try { final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems()); for (List<String> subUris : subLists) { _deleteDataMetadatas(conn, subUris); } conn.commit(); } catch (SQLException e) { conn.rollback(); throw e; } finally { conn.close(); } } catch (SQLException e) { log.error("Sql exception", e); throw new UserMetadataServiceException(String.format("Failed deleting the data metadata for %s", uris), e); } }
From source file:gridool.db.partitioning.monetdb.MonetDBCopyIntoOperation.java
@Override public Serializable execute() throws SQLException { final Connection conn; try {/*from www . j a v a 2 s.c om*/ conn = getConnection(); } catch (ClassNotFoundException e) { LOG.error(e); throw new SQLException(e.getMessage()); } if (createTableDDL != null) {// prepare a table try { JDBCUtils.update(conn, createTableDDL); } catch (SQLException e) { conn.rollback(); if (LOG.isDebugEnabled()) { LOG.debug("Table already exists. Try to truncate " + tableName, e); } truncateTable(conn, tableName); // fall through } } final File loadFile = prepareLoadFile(tableName, rowsData); this.rowsData = null; final String query = complementCopyIntoQuery(copyIntoQuery, loadFile); try { JDBCUtils.update(conn, query); conn.commit(); } catch (SQLException e) { LOG.error("rollback a transaction", e); conn.rollback(); throw e; } finally { try { conn.close(); } catch (SQLException e) { LOG.debug(e); } if (!loadFile.delete()) { LOG.warn("Could not remove a tempolary file: " + loadFile.getAbsolutePath()); } } return Boolean.TRUE; }
From source file:com.cloudera.sqoop.TestIncrementalImport.java
/** * Insert rows with id = [low, hi) into tableName with * the timestamp column set to the specified ts. */// ww w.ja v a2 s . c om private void insertIdTimestampRows(String tableName, int low, int hi, Timestamp ts) throws SQLException { LOG.info("Inserting id rows in [" + low + ", " + hi + ") @ " + ts); SqoopOptions options = new SqoopOptions(); options.setConnectString(SOURCE_DB_URL); HsqldbManager manager = new HsqldbManager(options); Connection c = manager.getConnection(); PreparedStatement s = null; try { s = c.prepareStatement("INSERT INTO " + tableName + " VALUES(?,?)"); for (int i = low; i < hi; i++) { s.setInt(1, i); s.setTimestamp(2, ts); s.executeUpdate(); } c.commit(); } finally { s.close(); } }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProjectDeploymentConfigurationSqlAdapter.java
public ProjectDeploymentConfiguration deleteProjectDeploymentConfig(int id) throws AdaptationException { ProjectDeploymentConfiguration config = null; Connection connection = null; Statement statement = null;/*from w w w . j a va2s. c o m*/ ResultSet resultSet = null; try { String query = "SELECT * FROM ProjectDeploymentConfigurations " + "WHERE id = " + id; connection = DriverManager.getConnection(CONN_STR); statement = connection.createStatement(); resultSet = statement.executeQuery(query); if (!resultSet.next()) { connection.rollback(); String msg = "Attempt to delete project deployment " + "configuration failed."; log.error(msg); throw new AdaptationException(msg); } config = getProjectDeploymentConfiguration(resultSet); query = "DELETE FROM ProjectDeploymentConfigurations " + "WHERE id = " + id; statement.executeUpdate(query); connection.commit(); } catch (SQLException ex) { try { connection.rollback(); } catch (Exception e) { } String msg = "SQLException in deleteProjectDeploymentConfig"; log.error(msg, ex); throw new AdaptationException(msg, ex); } finally { try { resultSet.close(); } catch (Exception ex) { } try { statement.close(); } catch (Exception ex) { } try { connection.close(); } catch (Exception ex) { } } return config; }
From source file:eionet.cr.dao.virtuoso.VirtuosoFolderDAO.java
public void createProjectBookmarksFolder(String projectName) throws DAOException { Connection sqlConn = null; RepositoryConnection repoConn = null; try {/*from www . ja va 2s . c o m*/ sqlConn = SesameUtil.getSQLConnection(); sqlConn.setAutoCommit(false); repoConn = SesameUtil.getRepositoryConnection(); repoConn.setAutoCommit(false); ValueFactory vf = repoConn.getValueFactory(); List<Statement> statements = getProjectFolderCreationStatements(projectName, vf); repoConn.add(statements); repoConn.commit(); sqlConn.commit(); } catch (OpenRDFException e) { SesameUtil.rollback(repoConn); throw new DAOException(e.getMessage(), e); } catch (SQLException e) { SQLUtil.rollback(sqlConn); throw new DAOException(e.getMessage(), e); } finally { SQLUtil.close(sqlConn); SesameUtil.close(repoConn); } }
From source file:com.netflix.metacat.usermetadata.mysql.MysqlUserMetadataService.java
@Override public void softDeleteDataMetadatas(final String user, @Nonnull final List<String> uris) { try {// w w w . j ava 2 s . co m final Connection conn = poolingDataSource.getConnection(); try { final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems()); for (List<String> subUris : subLists) { _softDeleteDataMetadatas(conn, user, subUris); } conn.commit(); } catch (SQLException e) { conn.rollback(); throw e; } finally { conn.close(); } } catch (SQLException e) { log.error("Sql exception", e); throw new UserMetadataServiceException(String.format("Failed deleting the data metadata for %s", uris), e); } }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlTagService.java
@Override public Void delete(final QualifiedName name, final boolean updateUserMetadata) { try {// w w w .ja va 2s .co m final Connection conn = getDataSource().getConnection(); try { new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM_TAGS_BY_NAME, name.toString()); new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM, name.toString()); if (updateUserMetadata) { // Set the tags in user metadata final Map<String, Set<String>> data = Maps.newHashMap(); data.put(NAME_TAGS, Sets.newHashSet()); userMetadataService.saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true); } conn.commit(); } catch (SQLException e) { conn.rollback(); throw e; } finally { conn.close(); } } catch (SQLException e) { final String message = String.format("Failed to delete all tags for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } return null; }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProgramProfilingMessageSymbolSqlAdapter.java
public ProgramProfilingMessageSymbol deleteProfilingMessageSymbol(int id) throws AdaptationException { ProgramProfilingMessageSymbol profilingMessageSymbol = null; Connection connection = null; Statement statement = null;/*from www. j a v a2 s . co m*/ ResultSet resultSet = null; try { String query = "SELECT * FROM ProgramProfilingMessageSymbols " + "WHERE id = " + id; connection = DriverManager.getConnection(CONN_STR); statement = connection.createStatement(); resultSet = statement.executeQuery(query); if (!resultSet.next()) { connection.rollback(); String msg = "Attempt to delete program profiling message " + "symbol failed."; log.error(msg); throw new AdaptationException(msg); } profilingMessageSymbol = getProfilingMessageSymbol(resultSet); query = "DELETE FROM ProgramProfilingMessageSymbols " + "WHERE id = " + id; statement.executeUpdate(query); connection.commit(); } catch (SQLException ex) { try { connection.rollback(); } catch (Exception e) { } String msg = "SQLException in deleteProfilingMessageSymbol"; log.error(msg, ex); throw new AdaptationException(msg, ex); } finally { try { resultSet.close(); } catch (Exception ex) { } try { statement.close(); } catch (Exception ex) { } try { connection.close(); } catch (Exception ex) { } } return profilingMessageSymbol; }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.IdeaDAO.java
@Override public void removeIdea(String id) { Connection conn = null; PreparedStatement stat = null; try {/*w w w .ja va2 s. c om*/ conn = this.getConnection(); conn.setAutoCommit(false); this.getIdeaCommentDAO().removeComments(id, conn); this.removeComments(id, conn); this.removeTags(id, conn); this.removeIdea(id, conn); conn.commit(); } catch (Throwable t) { this.executeRollback(conn); _logger.error("Error removing Idea", t); throw new RuntimeException("Error removing Idea", t); } finally { closeDaoResources(null, stat, conn); } }