Example usage for java.sql Connection commit

List of usage examples for java.sql Connection commit

Introduction

In this page you can find the example usage for java.sql Connection commit.

Prototype

void commit() throws SQLException;

Source Link

Document

Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this Connection object.

Usage

From source file:org.silverpeas.dbbuilder.DBBuilder.java

private static void processDB(DBXmlDocument xmlFile, UninstallInformations processesToCacheIntoDB,
        MetaInstructions sqlMetaInstructions, String[] tagsToProcess) throws Exception {
    Element root = xmlFile.getDocument().getRootElement();
    @SuppressWarnings("unchecked")
    List<Element> modules = root.getChildren(DBXmlDocument.ELT_MODULE);
    for (Element module : modules) {
        Connection connection = null;
        try {//w  ww .j a  v  a2s .  c o  m
            connection = ConnectionFactory.getConnection();
            connection.setAutoCommit(false);
            processSQLFiles(connection, module, tagsToProcess, sqlMetaInstructions);
            cacheIntoDb(connection, processesToCacheIntoDB
                    .getInformations(module.getAttributeValue(DBXmlDocument.ATT_MODULE_ID)));
            if (params.isSimulate()) {
                DbUtils.rollback(connection);
            } else {
                connection.commit();
            }
        } catch (Exception e) {
            DbUtils.rollback(connection);
            throw e;
        } finally {
            DbUtils.closeQuietly(connection);
        }
    }
    console.printMessage("DB Status after build :");
    checkDBStatus();
}

From source file:kenh.xscript.database.elements.Commit.java

public void process(@Attribute(ATTRIBUTE_REF) java.sql.Connection conn) throws UnsupportedScriptException {
    try {//  ww  w . j  a  va 2  s  . c  o m
        if (!conn.isClosed()) {
            if (!conn.getAutoCommit())
                conn.commit();
        }
    } catch (Exception e) {
        throw new UnsupportedScriptException(this, e);
    }
}

From source file:com.globalsight.ling.tm3.integration.EnableTm3Command.java

@SuppressWarnings("unchecked")
@Override//from w w w.ja v a  2s . com
protected void handle(CommandLine command) throws Exception {

    List<String> args = command.getArgList();
    if (args.size() != 1) {
        usage();
    }
    long companyId = 0;
    try {
        companyId = Long.valueOf(args.get(0));
    } catch (NumberFormatException e) {
        die("Not a company id: " + args.get(0));
    }

    // Verify it's a valid company.
    Company company = CompanyWrapper.getCompanyById(companyId);
    if (company == null) {
        die("Non-existent company: " + companyId);
    }

    Connection conn = DbUtil.getConnection();
    conn.setAutoCommit(false);
    try {
        new Tm3Enabler(conn, company).enable(this);
        conn.commit();
    } finally {
        DbUtil.silentReturnConnection(conn);
    }
}

From source file:com.aurel.track.admin.customize.category.filter.PredefinedQueryBL.java

/**
 * Add the hardcoded filters Use JDBC because negative objectIDs should be
 * added/*from  w w w  .  j a v  a  2  s .  c o m*/
 */
public static void addHardcodedFilters() {
    LOGGER.info("Add hardcoded filters");
    FilterFacade filterFacade = FilterFacadeFactory.getInstance()
            .getFilterFacade(TQueryRepositoryBean.QUERY_PURPOSE.TREE_FILTER, true);
    List<TPersonBean> personBeans = PersonBL.loadPersons();
    // Get not closed stateIDs
    List<TStateBean> notClosedStateBeans = StatusBL.loadNotClosedStates();
    List<Integer> notClosedStateIDs = GeneralUtils.createIntegerListFromBeanList(notClosedStateBeans);
    Integer[] notClosedStatesArr = GeneralUtils.createIntegerArrFromCollection(notClosedStateIDs);
    // get closed stateIDs
    List<TStateBean> closedStateBeans = StatusBL.loadClosedStates();
    List<Integer> closedStateIDs = GeneralUtils.createIntegerListFromBeanList(closedStateBeans);
    Integer[] closedStatesArr = GeneralUtils.createIntegerArrFromCollection(closedStateIDs);
    List<String> predefinedFilterClobStms = new ArrayList<String>();
    List<String> predefinedFilterStms = new ArrayList<String>();
    ILabelBean allItemsFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.ALL_ITEMS);
    if (allItemsFilterBean == null) {
        LOGGER.info("Add 'All issues' filter");
        predefinedFilterClobStms
                .add(addPredefinedQueryClob(PREDEFINED_QUERY.ALL_ITEMS, getAllIssuesExpression()));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.ALL_ITEMS, "All issues"));
    }
    ILabelBean unresolvedBean = filterFacade.getByKey(PREDEFINED_QUERY.OUTSTANDING);
    if (unresolvedBean == null) {
        LOGGER.info("Add 'Outstanding' filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.OUTSTANDING,
                getOutstandingExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.OUTSTANDING, "Outstanding"));
    }
    ILabelBean myFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.MY_ITEMS);
    if (myFilterBean == null) {
        LOGGER.info("Add 'My items' filter");
        predefinedFilterClobStms.add(
                addPredefinedQueryClob(PREDEFINED_QUERY.MY_ITEMS, getMyItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.MY_ITEMS, "My items"));
    }
    ILabelBean managersBean = filterFacade.getByKey(PREDEFINED_QUERY.MANAGERS_ITEMS);
    if (managersBean == null) {
        LOGGER.info("Add manager filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.MANAGERS_ITEMS,
                getManagerItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.MANAGERS_ITEMS, "I''m the manager"));
    }
    ILabelBean responsibleBean = filterFacade.getByKey(PREDEFINED_QUERY.RESPONSIBLES_ITEMS);
    if (responsibleBean == null) {
        LOGGER.info("Add responsible filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.RESPONSIBLES_ITEMS,
                getResponsibleItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.RESPONSIBLES_ITEMS, "I''m responsible"));
    }
    ILabelBean reporterBean = filterFacade.getByKey(PREDEFINED_QUERY.AUTHOR_ITEMS);
    if (reporterBean == null) {
        LOGGER.info("Add author filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.AUTHOR_ITEMS,
                getReporterItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.AUTHOR_ITEMS, "I''m the author"));
    }
    ILabelBean watcherBean = filterFacade.getByKey(PREDEFINED_QUERY.WATCHER_ITEMS);
    if (watcherBean == null) {
        LOGGER.info("Add watcher filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.WATCHER_ITEMS,
                getWatcherItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.WATCHER_ITEMS, "I''m watcher"));
    }
    ILabelBean meetingsBean = filterFacade.getByKey(PREDEFINED_QUERY.MEETINGS);
    if (meetingsBean == null) {
        LOGGER.info("Add 'Meetings' filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.MEETINGS,
                getMeetingItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.MEETINGS, "Meetings"));
    }
    ILabelBean unscheduledBean = filterFacade.getByKey(PREDEFINED_QUERY.UNSCHEDULED);
    if (unscheduledBean == null) {
        LOGGER.info("Add 'Unscheduled' filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.UNSCHEDULED,
                getUnscheduledItemsExpression(notClosedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.UNSCHEDULED, "Unscheduled"));
    }
    ILabelBean closedRecentlyBean = filterFacade.getByKey(PREDEFINED_QUERY.CLOSED_RECENTLY);
    if (closedRecentlyBean == null) {
        LOGGER.info("Add 'Closed recently' filter");
        predefinedFilterClobStms.add(addPredefinedQueryClob(PREDEFINED_QUERY.CLOSED_RECENTLY,
                getRecentlyClosedItemsExpression(closedStatesArr)));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.CLOSED_RECENTLY, "Closed recently"));
    }
    ILabelBean addedRecentlyBean = filterFacade.getByKey(PREDEFINED_QUERY.ADDED_RECENTLY);
    if (addedRecentlyBean == null) {
        LOGGER.info("Add 'Added recently' filter");
        predefinedFilterClobStms.add(
                addPredefinedQueryClob(PREDEFINED_QUERY.ADDED_RECENTLY, getRecentlyAddedItemsExpression()));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.ADDED_RECENTLY, "Added recently"));
    }
    ILabelBean updatedRecentlyBean = filterFacade.getByKey(PREDEFINED_QUERY.UPDATED_RECENTLY);
    if (updatedRecentlyBean == null) {
        LOGGER.info("Add 'Updated recently' filter");
        predefinedFilterClobStms.add(
                addPredefinedQueryClob(PREDEFINED_QUERY.UPDATED_RECENTLY, getRecentlyUpdatedItemsExpression()));
        predefinedFilterStms.add(addPredefinedQuery(PREDEFINED_QUERY.UPDATED_RECENTLY, "Updated recently"));
    }
    ILabelBean scrumBoardFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.SCRUM_BOARD);
    if (scrumBoardFilterBean == null) {
        LOGGER.info("Add 'Scrum board' filter");
        predefinedFilterClobStms
                .add(addPredefinedQueryClob(PREDEFINED_QUERY.SCRUM_BOARD, getAllIssuesExpression()));
        predefinedFilterStms.add(addPredefinedFilterWitView(PREDEFINED_QUERY.SCRUM_BOARD, "Scrum board",
                IssueListViewDescriptor.CARD));
    }

    ILabelBean kanbanBoardFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.KANBAN_BOARD);
    if (kanbanBoardFilterBean == null) {
        LOGGER.info("Add 'Kanban board' filter");
        predefinedFilterClobStms
                .add(addPredefinedQueryClob(PREDEFINED_QUERY.KANBAN_BOARD, getAllIssuesExpression()));
        predefinedFilterStms.add(addPredefinedFilterWitView(PREDEFINED_QUERY.KANBAN_BOARD, "Kanban board",
                IssueListViewDescriptor.CARD));
    }
    Connection cono = null;
    try {
        cono = InitDatabase.getConnection();
        Statement ostmt = cono.createStatement();
        cono.setAutoCommit(false);
        for (String filterClobStmt : predefinedFilterClobStms) {
            ostmt.executeUpdate(filterClobStmt);
        }
        for (String filterStmt : predefinedFilterStms) {
            ostmt.executeUpdate(filterStmt);
        }
        cono.commit();
        cono.setAutoCommit(true);
    } catch (Exception e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } finally {
        try {
            if (cono != null) {
                cono.close();
            }
        } catch (Exception e) {
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    // include in menu for all users
    List<Integer> filterIDs = MenuitemFilterBL.getFilterIDsToSubscribe();
    LOGGER.info("Number of filters to subscribe " + filterIDs.size());
    if (!filterIDs.isEmpty()) {
        for (TPersonBean personBean : personBeans) {
            Integer personID = personBean.getObjectID();
            MenuitemFilterBL.subscribePersonsToFilters(personID, filterIDs);
        }
    }
    scrumBoardFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.SCRUM_BOARD);
    if (scrumBoardFilterBean != null) {
        addCardLayout(scrumBoardFilterBean.getObjectID(), SystemFields.INTEGER_STATE,
                SystemFields.INTEGER_PRIORITY, (List) notClosedStateBeans);
    }
    kanbanBoardFilterBean = filterFacade.getByKey(PREDEFINED_QUERY.KANBAN_BOARD);
    if (kanbanBoardFilterBean != null) {
        addCardLayout(kanbanBoardFilterBean.getObjectID(), SystemFields.INTEGER_RESPONSIBLE,
                SystemFields.INTEGER_PRIORITY, (List) PersonBL.loadActivePersons());
    }
}

From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.common.JdbcTransactionListener.java

public void afterCommit() {
    //      if (logger.isDebugEnabled())
    //         logger.debug("[afterCommit]" + AlfrescoTransactionSupport.getTransactionId());
    Connection connection = getConnection();
    try {//  w w  w .  j  a va  2  s. c o m
        connection.commit();
    } catch (SQLException e) {
        /*
         * If an exception occurs here, then the data will not be committed to database
         * and hence the database will no longer be synchronized
         */
        logger.error("COMMIT INTO THE SYNCHRONIZATION DATABASE FAILED! THE DATABASE IS NOW UNCONSISTENT...", e);
    } finally {
        if (logger.isDebugEnabled())
            logger.debug("[afterCommit] Releasing existing connection");
        releaseConnection(connection);
    }
}

From source file:net.sourceforge.vulcan.spring.jdbc.JdbcSchemaMigrator.java

private void executeSql(final Resource resource) throws IOException {
    final String text = loadResource(resource);
    log.info("Running migration script " + resource.getFilename());

    final String[] commands = text.split(";");

    for (String command : commands) {
        final String trimmed = command.trim();
        if (StringUtils.isBlank(trimmed)) {
            continue;
        }//from   w ww  . j  ava2  s .  c  om

        jdbcTemplate.execute(new StatementCallback() {
            public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
                stmt.execute(trimmed);
                final Connection conn = stmt.getConnection();
                if (!conn.getAutoCommit()) {
                    conn.commit();
                }
                return null;
            }
        });
    }
}

From source file:ccc.cli.Schema.java

private void commit(final Connection newConnection) {
    try {/*from ww w .j  a  v a 2 s  .c  o  m*/
        newConnection.commit();
        LOG.info("Commited.");
    } catch (final SQLException e) {
        LOG.info("Error commiting changes.", e);
    }
}

From source file:de.langmi.spring.batch.examples.readers.jdbc.JdbcPagingItemReaderTests.java

/**
 * Shutdown HSQLDB properly./*w  ww .  ja  v a 2 s  .  c o m*/
 *
 * @throws Exception 
 */
@After
public void tearDown() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement st = conn.createStatement();
    st.execute("SHUTDOWN");
    conn.commit();
    st.close();
}

From source file:com.moss.blankslate.PostgresqlCatalogFactory.java

private void deleteCatalog(String name) throws Exception {
    //      Thread.sleep(500);

    JdbcConnectionConfig config = new JdbcConnectionConfig(DatabaseType.DB_TYPE_POSTGRESQL, null, hostname,
            null, "postgres", LOGIN, password);
    Connection adminConnection = config.createConnection();
    adminConnection.createStatement().execute("drop database \"" + name + "\"");
    adminConnection.commit();
    adminConnection.close();/* ww  w  . j  a  v  a 2s. c  om*/
    assertClosed(adminConnection);
}

From source file:com.devwebsphere.jdbc.loader.JDBCTxCallback.java

/**
 * This is called when a WXS transaction commits. If a Data instance was created for the transaction then
 * commit it and clean up.//from w ww  .j ava  2 s . com
 */
public void commit(TxID tx) throws TransactionCallbackException {
    if (tx.getSession().getObjectGrid().getObjectGridType() == ObjectGrid.SERVER) {
        try {
            Connection c = (Connection) tx.getSlot(dataSlot);
            if (c != null) {
                c.commit();
                c.close();
                tx.putSlot(dataSlot, null);
            }
        } catch (SQLException e) {
            throw new TransactionCallbackException(e);
        }
    }
}