Code example for Connection

Methods: commit, prepareStatement, rollback, setAutoCommit

0
                throw new RuntimeException("Unable to resolve the RSS instance on which the " +
                        "database user '" + username + "' exists");
            } 
 
            conn = getConnection(ctx, rssInstance.getName());
            conn.setAutoCommit(false);
 
            String sql = "DROP USER " + username;
            stmt = conn.prepareStatement(sql);
 
            /* Initiating the transaction */ 
            inTx = this.getEntityManager().beginTransaction();
 
            final int tenantId = RSSManagerUtil.getTenantId();
            this.getRSSDAO().getDatabaseUserDAO().removeDatabasePrivileges(
                    ctx.getEnvironmentName(), rssInstance.getId(), username, tenantId);
            this.getRSSDAO().getUserDatabaseEntryDAO().removeUserDatabaseEntriesByUser(
                    ctx.getEnvironmentName(), rssInstance.getId(), username,
                    rssInstance.getInstanceType(), tenantId);
            this.getRSSDAO().getDatabaseUserDAO().removeDatabaseUser(ctx.getEnvironmentName(),
                    rssInstance.getName(), username, tenantId);
 
            this.getRSSDAO().getDatabaseDAO().removeDatabase(ctx.getEnvironmentName(),
                    rssInstanceName, username, tenantId);
 
            /* Actual database creation is committed just before committing the meta info into RSS 
          * management repository. This is done as it is not possible to control CREATE, DROP, 
          * ALTER operations within a JTA transaction since those operations are committed 
          * implicitly */ 
            stmt.execute();
 
            /* committing the distributed transaction */ 
            if (inTx) {
                this.getEntityManager().endTransaction();
            } 
            conn.commit();
        } catch (Exception e) {
            if (inTx) {
                this.getEntityManager().rollbackTransaction();
            } 
            if (conn != null) {
                try { 
                    conn.rollback();
                } catch (SQLException e1) {
                    log.error("Error occurred while rollbacking the transaction", e);
                } 
            } 
            throw new RSSManagerException("Error occurred while dropping database user '" + 
                    username + "'", e);
        } finally { 
            RSSManagerUtil.cleanupResources(null, stmt, conn);
        } 
} 
 
    @Override 
    public void editDatabaseUserPrivileges(RSSEnvironmentContext ctx,