public int executeChanges(List<DbChange> changes) throws SQLException, UpdateFailureException {
        if (conn == null) {
            throw new IllegalStateException("You must first call initialize()!");
        }
        if (changes.isEmpty()) {
            return 0;
        }

        ResultSet rs = null;
        boolean mustResetToAutocommit = false;
        if (conn.getAutoCommit()) {
            mustResetToAutocommit = true;
            conn.setAutoCommit(false);
        }

        int executedChanges;
        boolean shouldCommit = false;
        try {
            executedChanges = runDBChanges(changes);
            shouldCommit = true;
        } finally {
            try {
                if (shouldCommit){
                    conn.commit();
                } else {
                    try {
                        conn.rollback();
                    } catch(Exception e){
                        logger.warn("Exception while rolling back: "+e.getMessage(), e);
                    }
                }
            } finally {
                DBUtil.close(rs);
            }

        }

        if (mustResetToAutocommit) {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
                logger.warn("Trouble reseting to autocommit: " + e.getMessage(), e);
            }
        }
        return executedChanges;
    }