Example usage for java.sql Connection rollback

List of usage examples for java.sql Connection rollback

Introduction

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

Prototype

void rollback() throws SQLException;

Source Link

Document

Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.

Usage

From source file:com.gtwm.pb.model.manageSchema.DatabaseDefn.java

private static void rollbackConnections(Connection conn) {
    try {//w  w  w . jav  a2s .  c  o m
        if (conn != null) {
            logger.error("rolling back sql...");
            conn.rollback();
            logger.error("sql successfully rolled back");
        }
    } catch (SQLException sqlex) {
        logger.error("oh no! another sql exception was thrown");
        sqlex.printStackTrace();
        // don't rethrow, may just be because no SQL has been sent since
        // transaction start
        // TODO: check this
    }
    logger.error("rolling back hibernate...");
    HibernateUtil.currentSession().getTransaction().rollback();
    logger.error("hibernate successfully rolled back");
}

From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java

@Override
public Document saveDocument(final String user, final String password, final String db, final String table,
        final String name, final Document document) throws BackendException {
    Statement st = null;//from   www .j a va  2 s  .  c  om
    Connection conn = null;
    ResultSet rs = null;
    try {
        conn = this.connectToDB(user, password, db);
        String nameField = this.getNameField(conn, table, db);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

        rs = st.executeQuery(String.format("select count(*) from \"%s\".\"%s\" where \"%s\"='%s'",
                this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name));
        rs.next();
        int numEntries = rs.getInt(1);
        if (numEntries > 1) {
            throw new BackendException(String.format(
                    "There are more than two entries with the name '%s' in the table '%s.%s', something is wrong with the database design.",
                    name, this.getSchemaName(table, db), this.getPlainTableName(table)));
        }
        boolean isNewDocument = numEntries == 0 ? true : false;

        String insertOrUpdate = isNewDocument ? this.getInsertStatement(document, name, table, nameField, db)
                : this.getUpdateStatement(document, name, table, nameField, db);
        rs.close();
        if (!isNewDocument && document.getAllFields().containsKey("version")) {
            conn.setAutoCommit(false);
            st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            String queryString = String.format("select version from \"%s\".\"%s\" where \"%s\"='%s'",
                    this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name);
            this.logString(queryString, user);
            rs = st.executeQuery(queryString);
            rs.next();
            if (rs.getInt(1) != (Integer) document.getAllFields().get("version").getValue()) {
                conn.rollback();
                throw new BackendException(String.format(
                        "There is a new version of the record with name '%s' in table '%s.%s', please repeat editing.",
                        name, this.getSchemaName(table, db), this.getPlainTableName(table)));
            }
            this.logString(insertOrUpdate, user);
            st.executeUpdate(insertOrUpdate);
            conn.commit();
            conn.setAutoCommit(true);
        } else {
            this.logString(insertOrUpdate, user);
            st.executeUpdate(insertOrUpdate);
        }
    } catch (SQLException e) {
        throw new BackendException(e);
    } catch (ClassNotFoundException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(conn);
    }
    return document;
}

From source file:com.wso2telco.dep.operatorservice.dao.OperatorDAO.java

public void insertBlacklistAggregatoRows(final Integer appID, final String subscriber, final int operatorid,
        final String[] merchants) throws SQLException, Exception {

    Connection con = null;
    final StringBuilder sql = new StringBuilder();
    PreparedStatement pst = null;

    try {/*from   w ww . j  a  v a 2  s  .co m*/

        con = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);

        sql.append(" INSERT INTO ");
        sql.append(OparatorTable.MERCHANT_OPCO_BLACKLIST.getTObject());
        sql.append(" (application_id, operator_id, subscriber, merchant)");
        sql.append("VALUES (?, ?, ?, ?) ");

        pst = con.prepareStatement(sql.toString());

        /**
         * Set autocommit off to handle the transaction
         */
        con.setAutoCommit(false);

        /**
         * each merchant log as black listed
         */
        for (String merchant : merchants) {

            if (appID == null) {
                pst.setNull(1, Types.INTEGER);
            } else {
                pst.setInt(1, appID);
            }
            pst.setInt(2, operatorid);
            pst.setString(3, subscriber);
            pst.setString(4, merchant);
            pst.addBatch();
        }

        log.debug("sql query in insertBlacklistAggregatoRows : " + pst);

        pst.executeBatch();

        /**
         * commit the transaction if all success
         */
        con.commit();
    } catch (SQLException e) {

        log.error("database operation error in insertBlacklistAggregatoRows : ", e);
        /**
         * rollback if Exception occurs
         */
        con.rollback();

        /**
         * throw it into upper layer
         */
        throw e;
    } catch (Exception e) {

        log.error("error in insertBlacklistAggregatoRows : ", e);
        /**
         * rollback if Exception occurs
         */
        con.rollback();

        /**
         * throw it into upper layer
         */
        throw e;
    } finally {

        DbUtils.closeAllConnections(pst, con, null);
    }
}

From source file:dao.CarryonDaoDb.java

/**
 * Given a entryid, delete carryon info for the user.
 * @param entryid - the entry id/*from  ww  w.ja  v  a  2  s . co m*/
 * @param memberId - the member id
 * @param category - the category
 * @param member - the member
 * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
 */
public void deleteCarryon(String entryid, String memberId, String category, String member)
        throws BaseDaoException {

    if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(member)) {
        throw new BaseDaoException("null parameters passed");
    }

    if (WebUtil.isSanEnabled()) {
        Photo photo = getPhoto(memberId, entryid, DbConstants.READ_FROM_SLAVE);
        String btitle = null;
        if (photo != null) {
            btitle = photo.getValue(DbConstants.BTITLE);
        }
        try {
            SanUtils sanUtils = new SanUtils();
            sanUtils.deleteSanFile(member, SanConstants.sanUserPath, btitle);
        } catch (SanException e) {
            throw new BaseDaoException("deleteSanFile() in CarryonDaoDb " + member + " destFileName " + btitle,
                    e);
        }
    }

    /**
     * Set the source based on scalability
     */
    String sourceName = scalabilityManager.getWriteBlobScalability(memberId);
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds is null for sourceName = " + sourceName);
    }

    boolean exists = false;
    try {
        Object[] params = { (Object) entryid };
        List result = defaultQuery.execute(params);
        if (result != null && result.size() > 0) {
            exists = true;
        }
    } catch (Exception e) {
        throw new BaseDaoException("error while" + defaultQuery.getSql());
    }

    /**
     * if this is a default blob, delete blob and default entry in a transaction
     * if this is anot a default blob, delete the blob in the regular way.
     */
    if (exists) {
        Connection conn = null;
        try {
            conn = ds.getConnection();
            conn.setAutoCommit(false);
            deleteCarryonQuery.run(conn, entryid, memberId);
            deleteDefQuery.run(conn, memberId);
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (Exception e1) {
                try {
                    if (conn != null) {
                        conn.setAutoCommit(true);
                        conn.close();
                    }
                } catch (Exception e2) {
                    throw new BaseDaoException(
                            "error in deleting carryon entry, conn.close() while deleting carryonentry in transaction"
                                    + member + " entryid = " + entryid,
                            e2);
                }
                throw new BaseDaoException(
                        "error in rollback() carryon delete entry" + member + " entryid = " + entryid, e1);
            }
            throw new BaseDaoException("error in carryondelete entry" + member + " entryid = " + entryid, e);
        }

        try {
            conn.commit();
        } catch (Exception e3) {
            throw new BaseDaoException("commit exception", e3);
        }

        try {
            if (conn != null) {
                conn.setAutoCommit(true);
                conn.close();
            }
        } catch (Exception e4) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e5) {
                throw new BaseDaoException("connection close exception", e5);
            }
            throw new BaseDaoException("setAutoCommit(true)/connection close exception", e4);
        }
    } else { // not a default entry 
        try {
            deleteQuery.run(entryid, memberId);
        } catch (Exception e) {
            StringBuffer sb = new StringBuffer(
                    "error occured while executing in CarryonDeleteQuery(),  entryid = ");
            sb.append(entryid);
            sb.append(" memberId = ");
            sb.append(memberId);
            throw new BaseDaoException(sb.toString(), e);
        }
    }

    /* remove this entry from carryon hits, if this entry exists */
    try {
        deleteCarryonHits(entryid, memberId);
    } catch (Exception e) {
        throw new BaseDaoException("deleteCarryonHits error");
    }

    /**
     * deleteTagsQuery
     */
    sourceName = scalabilityManager.getWriteZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds is null for sourceName = " + sourceName);
    }
    try {
        deleteTagsQuery.run(memberId, entryid);
        deleteRecentQuery.run(memberId, entryid);
    } catch (Exception e) {
        throw new BaseDaoException("deleteTagsQuery error " + deleteTagsQuery.getSql() + " recent Query = "
                + deleteRecentQuery.getSql(), e);
    }

    /**
     * remove from userstreamblob based on the key (memberId+entryid)
     */
    StringBuffer sb = new StringBuffer(memberId);
    sb.append("-");
    sb.append(entryid);
    String key = sb.toString();
    Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_ENTRY);
    if (treeCache.exists(fqn, key)) {
        treeCache.remove(fqn, key);
    }

    fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_DATA);
    if (treeCache.exists(fqn, key)) {
        treeCache.remove(fqn, key);
    }

    fqn = cacheUtil.fqn(DbConstants.RECENT_CARRYON);
    if (treeCache.exists(fqn, DbConstants.RECENT_CARRYON)) {
        treeCache.remove(fqn, DbConstants.RECENT_CARRYON);
    }

    /* remove all entries for this user, key based on memberId */
    fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB);
    if (treeCache.exists(fqn, memberId)) {
        treeCache.remove(fqn, memberId);
    }

    /**
     * get stream blobs
     */
    fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT);
    sb.delete(0, sb.length());
    sb.append(memberId);
    sb.append("-");
    sb.append(category);
    if (treeCache.exists(fqn, sb.toString())) {
        treeCache.remove(fqn, sb.toString());
    }

    fqn = cacheUtil.fqn(DbConstants.USER_PAGE);
    if (treeCache.exists(fqn, member)) {
        treeCache.remove(fqn, member);
    }
}

From source file:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rajouter des Termes Non descripteurs ou synonymes
 *
 * @param ds/*from w w w  . j av a 2s  . c om*/
 * @param term
 * @param idUser
 * @return boolean
 */
public boolean addNonPreferredTerm(HikariDataSource ds, Term term, int idUser) {

    Connection conn;
    boolean status;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        conn.setAutoCommit(false);
        if (!addUSE(conn, term, idUser)) {
            conn.rollback();
            conn.close();
            return false;
        }
        if (!addUSEHistorique(conn, term, idUser, "ADD")) {
            conn.rollback();
            conn.close();
            return false;
        }
        // cette fonction permet de remplir la table Permute de NonPreferredTerm

        String idConcept = new ConceptHelper().getIdConceptOfTerm(ds, term.getId_term(),
                term.getId_thesaurus());
        String idGroup = new ConceptHelper().getGroupIdOfConcept(ds, idConcept, term.getId_thesaurus());
        splitConceptForNonPermuted(ds, idConcept, idGroup, term.getId_thesaurus(), term.getLang(),
                term.getLexical_value());

        conn.commit();
        conn.close();
        status = true;
    } catch (SQLException ex) {
        Logger.getLogger(TermHelper.class.getName()).log(Level.SEVERE, null, ex);
        status = false;
    }
    return status;
}

From source file:dao.DirectoryAuthorDaoDb.java

/**
 * @param directoryId the id of the directory
 * @param memberId memberId who is to be blocked. 
 * @param userId administrator of directory
 * @param userLogin administrator's login of directory
 * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
 *//*ww  w.j a v  a  2s .  c  o  m*/
public void blockDirectory(String directoryId, String memberId, String userId, String userLogin)
        throws BaseDaoException {

    if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId)
            || RegexStrUtil.isNull(userLogin)) {
        throw new BaseDaoException("params are null");
    }

    /**
          *  check user permissions
          */
    if (!diaryAdmin.isDiaryAdmin(userLogin) && !isAuthor(directoryId, userId)) {
        throw new BaseDaoException(
                "User does not have permission to list moderators, " + directoryId + " userId = " + userId);
    }

    /**
     *  Get scalability datasource for dirblock, partitioned on loginid
     */
    String sourceName = scalabilityManager.getWriteScalability(memberId);
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, blockDirectory() " + sourceName + " memberId = " + memberId);
    }

    /**
     *  block this directory for this member
     */
    Connection conn = null;
    try {
        conn = ds.getConnection();
        conn.setAutoCommit(false);
        addBlockQuery.run(conn, directoryId, memberId);
        deleteAuthorQuery.run(conn, directoryId, memberId);
    } catch (Exception e) {
        try {
            conn.rollback();
        } catch (Exception e1) {
            try {
                if (conn != null) {
                    conn.setAutoCommit(true);
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("conn.close() error, blockDirectory(), memberId" + memberId, e2);
            }
            throw new BaseDaoException(" rollback() exception, for blockDirectory(),  memberId = " + memberId,
                    e1);
        }
        throw new BaseDaoException(" blockDirectory exception,  memberId = " + memberId, e);
    }

    // connection commit
    try {
        conn.commit();
    } catch (Exception e3) {
        throw new BaseDaoException(" commit() exception, for blockDirectory() memberId = " + memberId, e3);
    }
    try {
        if (conn != null) {
            conn.setAutoCommit(true);
            conn.close();
        }
    } catch (Exception e4) {
        throw new BaseDaoException(
                " conn.close() exception, for commit(), blockDirectory() memberId = " + memberId, e4);
    }

    /**
     * remove from cache
     */
    Fqn fqn = cacheUtil.fqn(DbConstants.AUTHOR_BLOCKED_DIRS);
    if (treeCache.exists(fqn, memberId)) {
        treeCache.remove(fqn, memberId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIRECTORY);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_MOVE);
    if (treeCache.exists(fqn, memberId)) {
        treeCache.remove(fqn, memberId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_COPY);
    if (treeCache.exists(fqn, memberId)) {
        treeCache.remove(fqn, memberId);
    }

    removeUsersFromDirAuthorsCache(directoryId);
    fqn = cacheUtil.fqn(DbConstants.DIR_AUTHORS);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }
    fqn = cacheUtil.fqn(DbConstants.DIR_ADMINS);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.ADMIN_DIRS);
    if (treeCache.exists(fqn, DbConstants.ADMIN_DIRS)) {
        treeCache.remove(fqn, DbConstants.ADMIN_DIRS);
    }
}

From source file:dao.RegistrationDaoDb.java

public void olddeActivateAccount(String login) {
    if (RegexStrUtil.isNull(login)) {
        throw new BaseDaoException("params are null");
    }/*from w  w  w .  j av a 2  s. co m*/

    /**
     *  hdlogin, hdprofile, usertab - no partitioned
     */
    String sourceName = null;
    sourceName = scalabilityManager.getWriteZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null " + sourceName);
    }

    Hdlogin hdlogin = getLoginid(login);
    String loginid = null;
    if (hdlogin != null) {
        loginid = hdlogin.getValue(DbConstants.LOGIN_ID);
    }

    Connection conn = null;
    try {
        conn = ds.getConnection();
        conn.setAutoCommit(false);

        /**
         *  set inform flags to zero, delete
         */
        //int gender = 0; // male
        activateAccountQuery.run(conn, login, "0");
        personalinfoDeleteQuery.run(conn, loginid);
        hdprofileDeleteQuery.run(conn, loginid);

        inboxDeleteAllQuery.run(conn, loginid);
        outboxDeleteAllQuery.run(conn, loginid);

        pblogDeleteQuery.run(conn, loginid);
        pblogDeleteMsgQuery.run(conn, loginid);
        pblogDeleteTopicQuery.run(conn, loginid);

        pblogDeleteTopicAttrQuery.run(conn, loginid);
        pblogDeleteMsgAttrQuery.run(conn, loginid);
        pblogDeleteTagsQuery.run(conn, loginid);
        yourkeyWordsDeleteQuery.run(conn, loginid);

        /* not required anymore */
        //userTrafficDeleteQuery.run(conn, loginid); 
        /* not required anymore */

        pendingfriendsDeleteQuery.run(conn, loginid);
        hdfriendsDeleteQuery.run(conn, loginid);

        displayUserDeleteQuery.run(conn, loginid);
        shareUserDeleteQuery.run(conn, loginid);

        shareContactDeleteQuery.run(conn, loginid);
        memberContactDeleteQuery.run(conn, loginid);
        contactsDeleteQuery.run(conn, loginid);

        carryonDeleteQuery.run(conn, loginid);
        collblockDeleteQuery.run(conn, loginid);

        // deleting member as admin from collabrum, directories

    } catch (Exception e) {
        try {
            conn.rollback();
        } catch (Exception e1) {
            try {
                if (conn != null) {
                    conn.setAutoCommit(true);
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception", e2);
            }
            throw new BaseDaoException("error occured while rollingback entries from hdlogin/hdprofile/usertab",
                    e1);
        }
    }

    try {
        conn.commit();
    } catch (Exception e3) {
        throw new BaseDaoException("commit exception", e3);
    }

    try {
        if (conn != null) {
            conn.setAutoCommit(true);
            conn.close();
        }
    } catch (Exception e4) {
        throw new BaseDaoException("connection close exception", e4);
    }

}

From source file:forseti.JUtil.java

public static synchronized void doCallStoredProcedure(HttpServletRequest request, HttpServletResponse response,
        String BD, String SQLCall, JRetFuncBas rfb) throws ServletException, IOException {
    int idmensaje = -1;
    String mensaje = "", clave = "";

    try {//  w w  w  .  j  av  a2  s .c  om
        Connection con = JAccesoBD.getConexion(BD);
        con.setAutoCommit(false);
        Statement s = con.createStatement();
        ResultSet rs = s.executeQuery(SQLCall);
        if (rs.next()) {
            idmensaje = rs.getInt("ERR");
            mensaje = rs.getString("RES");
            clave = rs.getString("CLAVE");
        }
        s.close();
        if (idmensaje == 0)
            con.commit();
        else
            con.rollback();

        JAccesoBD.liberarConexion(con);

        //getSesion(request).setID_Mensaje((short)idmensaje, mensaje);
        rfb.setRS(idmensaje, mensaje, clave);
    } catch (SQLException e) {
        e.printStackTrace(System.out);
        //throw new RuntimeException(e.toString());
        idmensaje = 3;
        mensaje = "ERROR de SQLCall: " + p(e.getMessage());
        clave = "";
        getSesion(request).setID_Mensaje((short) idmensaje, mensaje);
        rfb.setRS(4, mensaje, clave);
    }
}

From source file:com.spvp.dal.MySqlDatabase.java

@Override
public Boolean ucitajPrognozeUBazu(ArrayList<Prognoza> prognoze) throws SQLException {

    Connection conn = null;
    Boolean status = false;// ww w. java 2  s.  c om

    try {
        conn = getConnection();
        conn.setAutoCommit(false);

        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery("SELECT AUTO_INCREMENT " + "FROM  INFORMATION_SCHEMA.TABLES "
                + "WHERE TABLE_SCHEMA = 'weather_forecasting' " + "AND   TABLE_NAME   = 'historija_prognoze';");

        int zadnjiId = -1;

        rs.next();
        zadnjiId = rs.getInt("AUTO_INCREMENT");

        int idGrada = -1;

        PreparedStatement pstmt = conn.prepareStatement(
                "INSERT INTO historija_prognoze (id, vrijeme, temp, pritisak, brzina_vjetra, vlaznost_zraka, datum) "
                        + "VALUES(?, ?,?,?,?,?,?)");

        PreparedStatement pstmt3 = conn
                .prepareStatement("INSERT INTO gradovi_prognoze (prognoza_id, grad_id) " + "VALUES(?,?)");

        for (Prognoza x : prognoze) {

            pstmt.clearParameters();
            pstmt.setInt(1, zadnjiId);
            pstmt.setString(2, x.getVrijeme());
            pstmt.setString(3, x.getTemperatura());
            pstmt.setString(4, x.getPritisakZraka());
            pstmt.setString(5, x.getBrzinaVjetra());
            pstmt.setString(6, x.getVlaznostZraka());
            pstmt.setDate(7, new java.sql.Date(x.getDatum().getTime()));
            pstmt.addBatch();

            idGrada = dajIdGradaPoImenu(x.getZaGrad().getImeGrada());

            pstmt3.clearParameters();
            pstmt3.setInt(1, zadnjiId);
            pstmt3.setInt(2, idGrada);

            pstmt3.addBatch();

            zadnjiId++;
        }

        pstmt.executeBatch();
        pstmt3.executeBatch();

        conn.commit();
        status = true;

    } catch (SQLException ex) {
        Logger.getLogger(MySqlDatabase.class.getName()).log(Level.SEVERE, null, ex);
        if (conn != null)
            conn.rollback();

    } finally {

        if (conn != null)
            conn.close();
    }

    return status;
}

From source file:dao.DirectoryAbstractDao.java

/**
 *  Adds the author for this directory./* ww w .j a v  a 2 s.c o m*/
 *  @param directoryId the directory id
 *  @param member  the member who is added as author to this directory
 *  @param userId  the user Login is used to check if this user has the permission to add authors
 *  @param userLogin  the user Login is used to check if this user has the permission to add authors
 *  @param checkPermission flag to check if the user should be a diary admin to add author
 */
public void addAuthor(String directoryId, String member, String userId, String userLogin,
        boolean checkPermission) throws BaseDaoException {

    if (checkPermission) {
        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(member)) {
            throw new BaseDaoException("params are null");
        }
        /**
           *  check if this user has permission to add authors
           */
        if (!diaryAdmin.isDiaryAdmin(userLogin) && !isAuthor(directoryId, userId)) {
            throw new BaseDaoException("User does not have permission to add authors to directory, "
                    + directoryId + " userId = " + userId);
        }
    } else {
        logger.info("need not check permission");
        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(member)) {
            throw new BaseDaoException(
                    "params are null, dont check permission for the addAuthor() as directory scope is add all as authors.");
        }
    }
    logger.info("came here 0");

    /**
    *  Get scalability datasource for diradmin, not partitioned
    */
    String sourceName = scalabilityManager.getWriteZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, addAuthor() " + sourceName + " member = " + member);
    }

    /**
    *  Add author to this directory
    */
    String memberId = null;
    Connection conn = null;
    try {
        Hdlogin hdlogin = getLoginid(member);
        logger.info("hdlogin getLoginId for member " + member);
        if (hdlogin == null) {
            throw new BaseDaoException("Hdlogin for member is null, addAuthor(), member= " + member);
        } else {
            memberId = hdlogin.getValue(DbConstants.LOGIN_ID);
            logger.info("memberId " + memberId);
            if (!RegexStrUtil.isNull(memberId)) {
                conn = ds.getConnection();
                if (conn == null) {
                    logger.info("conn is null");
                    throw new BaseDaoException("conn is null");
                }
                conn.setAutoCommit(false);
                logger.info("addAdminQuery started memberId = " + memberId + " directoryId = " + directoryId);
                addAdminQuery.run(conn, directoryId, memberId);
                logger.info("addAdminQuery completed memberId = " + memberId + " directoryId = " + directoryId);
                logger.info(
                        "deleteBlockQuery started memberId = " + memberId + " directoryId = " + directoryId);
                deleteBlockQuery.run(conn, directoryId, memberId);
                logger.info(
                        "deleteBlockQuery completed memberId = " + memberId + " directoryId = " + directoryId);
            } else {
                throw new BaseDaoException("memberId is null for member = " + member);
            }
        }
    } catch (Exception e) {
        try {
            conn.rollback();
        } catch (Exception e1) {
            try {
                if (conn != null) {
                    conn.setAutoCommit(true);
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("conn.close() error, addAuthor(), memberId" + memberId
                        + " error Msg=" + e2.getMessage(), e2);
            }
            throw new BaseDaoException(" rollback() exception, for addAuthor(),  memberId = " + memberId
                    + " error Msg=" + e1.getMessage(), e1);
        }
        logger.info("came here into exception e " + e.getMessage());
        throw new BaseDaoException(" addAuthor exception,  member = " + member + " errorMsg=" + e.getMessage(),
                e);
    }

    logger.info("came here ");
    // connection commit
    try {
        conn.commit();
    } catch (Exception e3) {
        throw new BaseDaoException(" commit() exception, for addAuthor() userId = " + userId, e3);
    }
    try {
        if (conn != null) {
            conn.setAutoCommit(true);
            conn.close();
        }
    } catch (Exception e4) {
        throw new BaseDaoException(" conn.close() exception, for commit(), addAuthor() userId = " + userId, e4);
    }

    logger.info("came here 2");

    /**
     *  member's list needs to be updated with the new query, 
     *  remove the old entries for this member
     */
    Fqn fqn = cacheUtil.fqn(DbConstants.AUTHORS_LIST);
    if (treeCache.exists(fqn, member)) {
        treeCache.remove(fqn, member);
    }

    fqn = cacheUtil.fqn(DbConstants.AUTHORS_LIST);
    if (treeCache.exists(fqn, userLogin)) {
        treeCache.remove(fqn, userLogin);
    }

    fqn = cacheUtil.fqn(DbConstants.USER_PAGE);
    if (treeCache.exists(fqn, member)) {
        treeCache.remove(fqn, member);
    }

    fqn = cacheUtil.fqn(DbConstants.DIRECTORY);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_AUTHORS);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.DIR_ADMINS);
    if (treeCache.exists(fqn, directoryId)) {
        treeCache.remove(fqn, directoryId);
    }

    fqn = cacheUtil.fqn(DbConstants.ADMIN_DIRS);
    if (treeCache.exists(fqn, DbConstants.ADMIN_DIRS)) {
        treeCache.remove(fqn, DbConstants.ADMIN_DIRS);
    }

    fqn = cacheUtil.fqn(DbConstants.AUTHORS_DIRECTORIES);
    if (treeCache.exists(fqn, member)) {
        treeCache.remove(fqn, member);
    }

    StringBuffer sb = new StringBuffer(directoryId);
    sb.append("-");
    sb.append(memberId);
    fqn = cacheUtil.fqn(DbConstants.DIR_AUTHOR);
    if (treeCache.exists(fqn, sb.toString())) {
        treeCache.remove(fqn, sb.toString());
    }

    fqn = cacheUtil.fqn(DbConstants.AUTHOR_BLOCKED_DIRS);
    if (treeCache.exists(fqn, memberId)) {
        treeCache.remove(fqn, memberId);
    }
}