Example usage for java.sql PreparedStatement clearParameters

List of usage examples for java.sql PreparedStatement clearParameters

Introduction

In this page you can find the example usage for java.sql PreparedStatement clearParameters.

Prototype

void clearParameters() throws SQLException;

Source Link

Document

Clears the current parameter values immediately.

Usage

From source file:org.sakaiproject.search.component.service.impl.SearchIndexBuilderWorkerImpl.java

public void clearHardLock() {
    String nodeID = getNodeID();//from w w w .j ava2  s.c  om

    Connection connection = null;
    PreparedStatement clearLock = null;
    try {
        connection = dataSource.getConnection();

        clearLock = connection.prepareStatement(CLEAR_LOCK_SQL);
        clearLock.clearParameters();
        clearLock.setString(1, NO_NODE);
        clearLock.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
        clearLock.setString(3, nodeID);
        clearLock.setString(4, LOCKKEY);
        if (clearLock.executeUpdate() == 1) {
            log.debug("UNLOCK - OK::" + nodeID + "::now");

        } else {
            log.debug("UNLOCK - no-lock::" + nodeID + "::now");
        }
        connection.commit();

    } catch (Exception ex) {
        try {
            if (connection != null) {
                connection.rollback();
            }
        } catch (SQLException e) {
        }
        log.error("Failed to clear lock" + ex.getMessage());
    } finally {
        if (clearLock != null) {
            try {
                clearLock.close();
            } catch (SQLException e) {
                log.error("Error Closing Prepared Statement ", e);
            }
        }
        if (connection != null) {
            try {
                connection.close();
                log.debug("Connection Closed");
            } catch (SQLException e) {
                log.error("Error Closing Connection", e);
            }
        }
    }

}

From source file:org.wso2.carbon.repository.core.jdbc.dao.JDBCLogsDAO.java

private void addLogRecords(LogRecord[] logRecords, JDBCDataAccessManager dataAccessManager)
        throws RepositoryException {
    PreparedStatement s = null;
    Connection conn = null;//from   www  .j a va  2  s  .co  m

    try {
        conn = dataAccessManager.getDataSource().getConnection();
        if (conn.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        }
        conn.setAutoCommit(false);
        String sql = "INSERT INTO REG_LOG (REG_PATH, REG_USER_ID, REG_LOGGED_TIME, "
                + "REG_ACTION, REG_ACTION_DATA, REG_TENANT_ID) " + "VALUES (?, ?, ?, ?, ?, ?)";

        s = conn.prepareStatement(sql);
        for (LogRecord logRecord : logRecords) {
            s.clearParameters();
            s.setString(1, logRecord.getResourcePath());
            s.setString(2, logRecord.getUserName());
            s.setTimestamp(3, new Timestamp(logRecord.getTimestamp().getTime()));
            s.setInt(4, logRecord.getAction().getId());
            s.setString(5, logRecord.getActionData());
            s.setInt(6, logRecord.getTenantId());
            s.addBatch();
        }
        int[] status = s.executeBatch();
        if (log.isDebugEnabled()) {
            log.debug("Successfully added " + status.length + " log records.");
        }
        conn.commit();

    } catch (SQLException e) {
        try {
            if (conn != null) {
                conn.rollback();
            }
        } catch (SQLException e1) {
            log.error("Failed to rollback log insertion.", e);
        }
        String msg = "Failed to update log batch records " + ". " + e.getMessage();
        log.error(msg, e);
        throw new RepositoryDBException(msg, e);
    } finally {
        try {
            if (s != null) {
                s.close();
            }
            if (conn != null && !(conn.isClosed())) {
                conn.close();
            }
        } catch (SQLException ex) {
            String msg = InternalConstants.RESULT_SET_PREPARED_STATEMENT_CLOSE_ERROR;
            log.error(msg, ex);
        }
    }
}

From source file:org.sakaiproject.search.indexer.impl.SearchBuilderQueueManager.java

private List<SearchBuilderItem> findPendingAndLock(int batchSize, Connection connection) throws SQLException {
    // Pending is the first 100 items
    // State == PENDING
    // Action != Unknown
    long start = System.currentTimeMillis();
    try {//  w ww.java  2  s  . c o m
        log.debug("TXFind pending with " + connection); //$NON-NLS-1$

        SearchBuilderItem masterItem = getMasterItem(connection);
        try {

            Integer masterAction = getMasterAction(masterItem);
            log.debug(" Master Item is " + masterItem.getName() + ":" //$NON-NLS-1$ //$NON-NLS-2$
                    + masterItem.getSearchaction() + ":" //$NON-NLS-1$
                    + masterItem.getSearchstate() + "::" //$NON-NLS-1$
                    + masterItem.getVersion());
            if (SearchBuilderItem.ACTION_REFRESH.equals(masterAction)) {
                log.debug(" Master Action is " + masterAction); //$NON-NLS-1$
                log.debug("  REFRESH = " + SearchBuilderItem.ACTION_REFRESH); //$NON-NLS-1$
                log.debug("  RELOAD = " + SearchBuilderItem.ACTION_REBUILD); //$NON-NLS-1$
                // get a complete list of all items, before the master
                // action version
                // if there are none, update the master action action to
                // completed
                // and return a blank list

                refreshIndex(connection, masterItem);

            } else if (SearchBuilderItem.ACTION_REBUILD.equals(masterAction)) {
                rebuildIndex(connection, masterItem);
            } else {
                // get all site masters and perform the required action.
                List<SearchBuilderItem> siteMasters = getSiteMasterItems(connection);
                for (Iterator<SearchBuilderItem> i = siteMasters.iterator(); i.hasNext();) {
                    SearchBuilderItem siteMaster = (SearchBuilderItem) i.next();
                    try {
                        Integer action = getSiteMasterAction(siteMaster);
                        if (SearchBuilderItem.ACTION_REBUILD.equals(action)) {
                            rebuildIndex(connection, siteMaster);
                        } else if (SearchBuilderItem.ACTION_REFRESH.equals(action)) {
                            refreshIndex(connection, siteMaster);
                        }
                    } finally {
                        // any value > 1000 is a lock
                        if (siteMaster.getLock() == nodeLock) {
                            List<SearchBuilderItem> l = new ArrayList<SearchBuilderItem>();
                            l.add(siteMaster);
                            commitPendingAndUnLock(l, connection);
                        }
                    }
                }
            }
        } finally {
            if (masterItem.getLock() == nodeLock) {
                List<SearchBuilderItem> l = new ArrayList<SearchBuilderItem>();
                l.add(masterItem);
                commitPendingAndUnLock(l, connection);
            }
        }
        PreparedStatement pst = null;
        PreparedStatement lockedPst = null;
        ResultSet rst = null;
        try {
            pst = connection.prepareStatement("select " //$NON-NLS-1$
                    + SEARCH_BUILDER_ITEM_FIELDS + " from " //$NON-NLS-1$
                    + SEARCH_BUILDER_ITEM_T + " where searchstate = ? and     " //$NON-NLS-1$
                    + "        itemscope = ?  order by version "); //$NON-NLS-1$
            lockedPst = connection.prepareStatement("update " //$NON-NLS-1$
                    + SEARCH_BUILDER_ITEM_T + " set searchstate = ? " //$NON-NLS-1$
                    + " where id = ?  and  searchstate = ? "); //$NON-NLS-1$
            pst.clearParameters();
            pst.setInt(1, SearchBuilderItem.STATE_PENDING.intValue());
            pst.setInt(2, SearchBuilderItem.ITEM.intValue());
            rst = pst.executeQuery();
            List<SearchBuilderItem> a = new ArrayList<SearchBuilderItem>();
            while (rst.next() && a.size() < batchSize) {

                SearchBuilderItemImpl sbi = new SearchBuilderItemImpl();
                populateSearchBuilderItem(rst, sbi);
                if (!SearchBuilderItem.ACTION_UNKNOWN.equals(sbi.getSearchaction())) {
                    lockedPst.clearParameters();
                    lockedPst.setInt(1, nodeLock);
                    lockedPst.setString(2, sbi.getId());
                    lockedPst.setInt(3, SearchBuilderItem.STATE_PENDING.intValue());
                    if (lockedPst.executeUpdate() == 1) {
                        sbi.setSearchstate(SearchBuilderItem.STATE_LOCKED);
                        sbi.setLock(nodeLock);
                        a.add(sbi);
                    }
                    connection.commit();
                }

            }
            return a;
        } finally {
            try {
                if (rst != null)
                    rst.close();
            } catch (Exception ex) {
                log.warn("Error closing result set", ex);
            }
            try {
                if (pst != null)
                    pst.close();
            } catch (Exception ex) {
                log.warn("Error closing statement", ex);
            }
        }

    } finally {
        long finish = System.currentTimeMillis();
        log.debug(" findPending took " + (finish - start) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:org.sakaiproject.nakamura.lite.storage.jdbc.JDBCStorageClient.java

public void remove(String keySpace, String columnFamily, String key) throws StorageClientException {
    checkClosed();/* w w w .  ja  v  a 2  s.  c o m*/
    PreparedStatement deleteStringRow = null;
    PreparedStatement deleteBlockRow = null;
    String rid = rowHash(keySpace, columnFamily, key);
    boolean autoCommit = false;
    try {
        autoCommit = startBlock();
        deleteStringRow = getStatement(keySpace, columnFamily, SQL_DELETE_STRING_ROW, rid, null);
        inc("deleteStringRow");
        deleteStringRow.clearWarnings();
        deleteStringRow.clearParameters();
        deleteStringRow.setString(1, rid);
        deleteStringRow.executeUpdate();

        deleteBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_DELETE_ROW, rid, null);
        inc("deleteBlockRow");
        deleteBlockRow.clearWarnings();
        deleteBlockRow.clearParameters();
        deleteBlockRow.setString(1, rid);
        deleteBlockRow.executeUpdate();
        endBlock(autoCommit);
    } catch (SQLException e) {
        abandonBlock(autoCommit);
        LOGGER.warn("Failed to perform delete operation on {}:{}:{} ",
                new Object[] { keySpace, columnFamily, key }, e);
        throw new StorageClientException(e.getMessage(), e);
    } finally {
        close(deleteStringRow, "deleteStringRow");
        close(deleteBlockRow, "deleteBlockRow");
    }
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.helper.ExtractorLogHelper.java

public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
    String taskInstanceId = AdapterExtractorContext.getInstance().getTaskInstanceId();

    for (ExtractorLog extractorLog : extractorLogs) {
        ExtractorLogLevel level = extractorLog.getLevel();
        if (!TaskInstance.STATE_IMPORTED_ERROR
                .equals(AdapterExtractorContext.getInstance().getReturnStatus())) {
            // ?error??
            if (level == ExtractorLogLevel.ERROR) {
                AdapterExtractorContext.getInstance().setReturnStatus(TaskInstance.STATE_IMPORTED_ERROR);
            } else if (level == ExtractorLogLevel.WARN) {
                AdapterExtractorContext.getInstance().setReturnStatus(TaskInstance.STATE_IMPORTED_WARN);
            }//from  w ww.j  ava  2 s  .  c o m
        }
        if (extractorLog.getMessage() == null) // 
            continue;

        ps.setString(1, taskInstanceId);
        ps.setString(2, String.valueOf(level.ordinal()));
        ps.setLong(3, extractorLog.getLogTime());
        // ?
        boolean msgTooLength = extractorLog.getMessage().length() > AdapterExtractorContext.getInstance()
                .getMaxLogSize();
        String message = msgTooLength
                ? extractorLog.getMessage().substring(0, AdapterExtractorContext.getInstance().getMaxLogSize())
                : extractorLog.getMessage();
        ps.setString(4, message);
        ps.setString(5, extractorLog.getLogType());

        ps.addBatch();
        ps.clearParameters();
    }

    ps.executeBatch();
    ps.clearBatch();

    return null;
}

From source file:com.commander4j.db.JDBDespatch.java

public boolean updateUserID(String despatchNO, String userID) {
    boolean result = false;

    setDespatchNo(despatchNO);// w  w w .j  av  a 2s.  c om
    setUserID(userID);

    logger.debug("updateUserID [" + getDespatchNo() + "] [" + getUserID() + "]");

    if (isValid(false) == true) {
        try {
            PreparedStatement stmtupdate;
            stmtupdate = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(
                    Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.setUserID"));

            stmtupdate.setString(1, getUserID());
            stmtupdate.setString(2, getDespatchNo());

            stmtupdate.execute();

            stmtupdate.clearParameters();
            Common.hostList.getHost(getHostID()).getConnection(getSessionID()).commit();
            stmtupdate.close();
            result = true;
        } catch (SQLException e) {
            setErrorMessage(e.getMessage());
        }
    }

    return result;
}

From source file:org.apache.roller.weblogger.business.startup.DatabaseInstaller.java

/**
 * Upgrade database for Roller 3.0.0/*from  w ww  .  j av  a 2s.c  om*/
 */
private void upgradeTo300(Connection con, boolean runScripts) throws StartupException {
    SQLScriptRunner runner = null;
    try {
        if (runScripts) {
            String handle = getDatabaseHandle(con);
            String scriptPath = handle + "/240-to-300-migration.sql";
            successMessage("Running database upgrade script: " + scriptPath);
            runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
            runner.runScript(con, true);
            messages.addAll(runner.getMessages());
        }

        /*
         * For Roller 3.0.0 we are allowing each weblogentry to track a
         * locale now so that we can support multi-lingual blogs.  As part
         * of the upgrade process we want to do 2 things ..
         *
         * 1. make sure all weblogs have a locale
         * 2. set the locale on all entries to the locale for the weblog
         */

        successMessage("Doing upgrade to 300 ...");

        // get system default language
        String locale = java.util.Locale.getDefault().getLanguage();

        successMessage("Setting website locale to " + locale + " for websites with no locale");

        // update all weblogs where locale is "null"
        PreparedStatement updateNullWeblogLocale = con
                .prepareStatement("update website set locale = ? where locale is NULL");
        // update all weblogs where locale is empty string ""
        PreparedStatement updateEmptyWeblogLocale = con
                .prepareStatement("update website set locale = ? where locale = ''");
        updateNullWeblogLocale.setString(1, locale);
        updateEmptyWeblogLocale.setString(1, locale);
        updateNullWeblogLocale.executeUpdate();
        updateEmptyWeblogLocale.executeUpdate();

        successMessage("Setting weblogentry locales to website locale");

        // get all entries and the locale of its website
        PreparedStatement selectWeblogsLocale = con.prepareStatement("select weblogentry.id,website.locale "
                + "from weblogentry,website " + "where weblogentry.websiteid = website.id");

        // set the locale for an entry
        PreparedStatement updateWeblogLocale = con
                .prepareStatement("update weblogentry set locale = ? where id = ?");

        ResultSet websiteSet = selectWeblogsLocale.executeQuery();
        while (websiteSet.next()) {
            String entryid = websiteSet.getString(1);
            String entrylocale = websiteSet.getString(2);

            // update entry locale
            updateWeblogLocale.clearParameters();
            updateWeblogLocale.setString(1, entrylocale);
            updateWeblogLocale.setString(2, entryid);
            updateWeblogLocale.executeUpdate();
        }

        if (!con.getAutoCommit())
            con.commit();

        successMessage("Upgrade to 300 complete.");

    } catch (Exception e) {
        log.error("ERROR running 310 database upgrade script", e);
        if (runner != null)
            messages.addAll(runner.getMessages());

        errorMessage("Problem upgrading database to version 300", e);
        throw new StartupException("Problem upgrading database to version 300", e);
    }

    updateDatabaseVersion(con, 300);
}

From source file:com.enonic.vertical.engine.handlers.SectionHandler.java

private void copySecConTypeFilter(int sourceKey, MenuItemKey targetKey) throws SQLException {
    String sql1 = XDG.generateSelectSQL(this.db.tSecConTypeFilter2, this.db.tSecConTypeFilter2.sctf_mei_lKey)
            .toString();//www  .j  a  va2 s.c  o  m
    String sql2 = XDG.generateInsertSQL(this.db.tSecConTypeFilter2).toString();

    Connection con = null;
    PreparedStatement stmt1 = null;
    PreparedStatement stmt2 = null;
    ResultSet result = null;
    try {
        con = getConnection();
        stmt1 = con.prepareStatement(sql1);
        stmt2 = con.prepareStatement(sql2);

        stmt1.setInt(1, sourceKey);
        result = stmt1.executeQuery();

        while (result.next()) {
            stmt2.clearParameters();

            int sectionFilterKey = getCommonHandler().getNextKey(db.tSecConTypeFilter2.getName());
            stmt2.setInt(1, sectionFilterKey);
            stmt2.setInt(2, targetKey.toInt());
            stmt2.setInt(3, result.getInt(2));

            stmt2.executeUpdate();
        }
    } finally {
        close(result);
        close(stmt2);
        close(stmt1);
        close(con);
    }
}

From source file:com.enonic.vertical.engine.handlers.SectionHandler.java

private void copySectionContent(int sourceKey, MenuItemKey targetKey) throws SQLException {
    String sql1 = XDG.generateSelectSQL(this.db.tSectionContent2, this.db.tSectionContent2.sco_mei_lKey)
            .toString();//from ww w.ja v  a  2s .  c o m
    String sql2 = XDG.generateInsertSQL(this.db.tSectionContent2).toString();

    Connection con = null;
    PreparedStatement stmt1 = null;
    PreparedStatement stmt2 = null;
    ResultSet result = null;
    try {
        con = getConnection();
        stmt1 = con.prepareStatement(sql1);
        stmt2 = con.prepareStatement(sql2);

        stmt1.setInt(1, sourceKey);
        result = stmt1.executeQuery();

        while (result.next()) {
            stmt2.clearParameters();

            int newSectionContentPK = getCommonHandler().getNextKey(db.tSectionContent2);
            stmt2.setInt(1, newSectionContentPK);
            stmt2.setInt(2, result.getInt(2));
            stmt2.setInt(3, targetKey.toInt());
            stmt2.setInt(4, result.getInt(4));
            stmt2.setInt(5, result.getInt(5));
            // No.6 = Timestamp!

            stmt2.executeUpdate();
        }
    } finally {
        close(result);
        close(stmt2);
        close(stmt1);
        close(con);
    }
}

From source file:org.sakaiproject.nakamura.lite.storage.jdbc.JDBCStorageClient.java

public void insert(String keySpace, String columnFamily, String key, Map<String, Object> values,
        boolean probablyNew) throws StorageClientException {
    checkClosed();//from   w ww. j a  va 2 s  . c  o  m

    Map<String, PreparedStatement> statementCache = Maps.newHashMap();
    boolean autoCommit = true;
    try {
        autoCommit = startBlock();
        String rid = rowHash(keySpace, columnFamily, key);
        for (Entry<String, Object> e : values.entrySet()) {
            String k = e.getKey();
            Object o = e.getValue();
            if (o instanceof byte[]) {
                throw new RuntimeException(
                        "Invalid content in " + k + ", storing byte[] rather than streaming it");
            }
        }

        Map<String, Object> m = get(keySpace, columnFamily, key);
        for (Entry<String, Object> e : values.entrySet()) {
            String k = e.getKey();
            Object o = e.getValue();

            if (o instanceof RemoveProperty || o == null) {
                m.remove(k);
            } else {
                m.put(k, o);
            }
        }
        LOGGER.debug("Saving {} {} {} ", new Object[] { key, rid, m });
        if (probablyNew && !UPDATE_FIRST_SEQUENCE.equals(getSql(SQL_STATEMENT_SEQUENCE))) {
            PreparedStatement insertBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW, rid,
                    statementCache);
            insertBlockRow.clearWarnings();
            insertBlockRow.clearParameters();
            insertBlockRow.setString(1, rid);
            InputStream insertStream = null;
            try {
                insertStream = Types.storeMapToStream(rid, m, columnFamily);
            } catch (UTFDataFormatException e) {
                throw new DataFormatException(INVALID_DATA_ERROR, e);
            }
            if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) {
                insertBlockRow.setBinaryStream(2, insertStream, insertStream.available());
            } else {
                insertBlockRow.setBinaryStream(2, insertStream);
            }
            int rowsInserted = 0;
            try {
                rowsInserted = insertBlockRow.executeUpdate();
            } catch (SQLException e) {
                LOGGER.debug(e.getMessage(), e);
            }
            if (rowsInserted == 0) {
                PreparedStatement updateBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW,
                        rid, statementCache);
                updateBlockRow.clearWarnings();
                updateBlockRow.clearParameters();
                updateBlockRow.setString(2, rid);
                try {
                    insertStream = Types.storeMapToStream(rid, m, columnFamily);
                } catch (UTFDataFormatException e) {
                    throw new DataFormatException(INVALID_DATA_ERROR, e);
                }
                if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) {
                    updateBlockRow.setBinaryStream(1, insertStream, insertStream.available());
                } else {
                    updateBlockRow.setBinaryStream(1, insertStream);
                }
                if (updateBlockRow.executeUpdate() == 0) {
                    throw new StorageClientException("Failed to save " + rid);
                } else {
                    LOGGER.debug("Updated {} ", rid);
                }
            } else {
                LOGGER.debug("Inserted {} ", rid);
            }
        } else {
            PreparedStatement updateBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW, rid,
                    statementCache);
            updateBlockRow.clearWarnings();
            updateBlockRow.clearParameters();
            updateBlockRow.setString(2, rid);
            InputStream updateStream = null;
            try {
                updateStream = Types.storeMapToStream(rid, m, columnFamily);
            } catch (UTFDataFormatException e) {
                throw new DataFormatException(INVALID_DATA_ERROR, e);
            }
            if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) {
                updateBlockRow.setBinaryStream(1, updateStream, updateStream.available());
            } else {
                updateBlockRow.setBinaryStream(1, updateStream);
            }
            if (updateBlockRow.executeUpdate() == 0) {
                PreparedStatement insertBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW,
                        rid, statementCache);
                insertBlockRow.clearWarnings();
                insertBlockRow.clearParameters();
                insertBlockRow.setString(1, rid);
                try {
                    updateStream = Types.storeMapToStream(rid, m, columnFamily);
                } catch (UTFDataFormatException e) {
                    throw new DataFormatException(INVALID_DATA_ERROR, e);
                }
                if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) {
                    insertBlockRow.setBinaryStream(2, updateStream, updateStream.available());
                } else {
                    insertBlockRow.setBinaryStream(2, updateStream);
                }
                if (insertBlockRow.executeUpdate() == 0) {
                    throw new StorageClientException("Failed to save " + rid);
                } else {
                    LOGGER.debug("Inserted {} ", rid);
                }
            } else {
                LOGGER.debug("Updated {} ", rid);
            }
        }
        if ("1".equals(getSql(USE_BATCH_INSERTS))) {
            Set<PreparedStatement> removeSet = Sets.newHashSet();
            // execute the updates and add the necessary inserts.
            Map<PreparedStatement, List<Entry<String, Object>>> insertSequence = Maps.newHashMap();

            Set<PreparedStatement> insertSet = Sets.newHashSet();

            for (Entry<String, Object> e : values.entrySet()) {
                String k = e.getKey();
                Object o = e.getValue();
                if (shouldIndex(keySpace, columnFamily, k)) {
                    if (o instanceof RemoveProperty || o == null) {
                        PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                                SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                        removeStringColumn.setString(1, rid);
                        removeStringColumn.setString(2, k);
                        removeStringColumn.addBatch();
                        removeSet.add(removeStringColumn);
                    } else {
                        // remove all previous values
                        PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                                SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                        removeStringColumn.setString(1, rid);
                        removeStringColumn.setString(2, k);
                        removeStringColumn.addBatch();
                        removeSet.add(removeStringColumn);
                        // insert new values, as we just removed them we know we can insert, no need to attempt update
                        // the only thing that we know is the colum value changes so we have to re-index the whole
                        // property
                        Object[] valueMembers = (o instanceof Object[]) ? (Object[]) o : new Object[] { o };
                        for (Object ov : valueMembers) {
                            String valueMember = ov.toString();
                            PreparedStatement insertStringColumn = getStatement(keySpace, columnFamily,
                                    SQL_INSERT_STRING_COLUMN, rid, statementCache);
                            insertStringColumn.setString(1, valueMember);
                            insertStringColumn.setString(2, rid);
                            insertStringColumn.setString(3, k);
                            insertStringColumn.addBatch();
                            LOGGER.debug("Insert Index {} {}", k, valueMember);
                            insertSet.add(insertStringColumn);
                            List<Entry<String, Object>> insertSeq = insertSequence.get(insertStringColumn);
                            if (insertSeq == null) {
                                insertSeq = Lists.newArrayList();
                                insertSequence.put(insertStringColumn, insertSeq);
                            }
                            insertSeq.add(e);
                        }
                    }
                }
            }

            if (!StorageClientUtils.isRoot(key)) {
                // create a holding map containing a rowhash of the parent and then process the entry to generate a update operation.
                Map<String, Object> autoIndexMap = ImmutableMap.of(InternalContent.PARENT_HASH_FIELD,
                        (Object) rowHash(keySpace, columnFamily, StorageClientUtils.getParentObjectPath(key)));
                for (Entry<String, Object> e : autoIndexMap.entrySet()) {
                    // remove all previous values
                    PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                            SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                    removeStringColumn.setString(1, rid);
                    removeStringColumn.setString(2, e.getKey());
                    removeStringColumn.addBatch();
                    removeSet.add(removeStringColumn);
                    PreparedStatement insertStringColumn = getStatement(keySpace, columnFamily,
                            SQL_INSERT_STRING_COLUMN, rid, statementCache);
                    insertStringColumn.setString(1, (String) e.getValue());
                    insertStringColumn.setString(2, rid);
                    insertStringColumn.setString(3, e.getKey());
                    insertStringColumn.addBatch();
                    LOGGER.debug("Insert {} {}", e.getKey(), e.getValue());
                    insertSet.add(insertStringColumn);
                    List<Entry<String, Object>> insertSeq = insertSequence.get(insertStringColumn);
                    if (insertSeq == null) {
                        insertSeq = Lists.newArrayList();
                        insertSequence.put(insertStringColumn, insertSeq);
                    }
                    insertSeq.add(e);
                }
            }

            LOGGER.debug("Remove set {}", removeSet);

            for (PreparedStatement pst : removeSet) {
                pst.executeBatch();
            }

            LOGGER.debug("Insert set {}", insertSet);
            for (PreparedStatement pst : insertSet) {
                int[] res = pst.executeBatch();
                List<Entry<String, Object>> insertSeq = insertSequence.get(pst);
                for (int i = 0; i < res.length; i++) {
                    Entry<String, Object> e = insertSeq.get(i);
                    if (res[i] <= 0 && res[i] != -2) { // Oracle drivers respond with -2 on a successful insert when the number is not known http://download.oracle.com/javase/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.html
                        LOGGER.warn("Index failed for {} {} ", new Object[] { rid, e.getKey(), e.getValue() });

                    } else {
                        LOGGER.debug("Index inserted for {} {} ",
                                new Object[] { rid, e.getKey(), e.getValue() });

                    }
                }
            }

        } else {
            for (Entry<String, Object> e : values.entrySet()) {
                String k = e.getKey();
                Object o = e.getValue();
                if (shouldIndex(keySpace, columnFamily, k)) {
                    if (o instanceof RemoveProperty || o == null) {
                        PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                                SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                        removeStringColumn.clearWarnings();
                        removeStringColumn.clearParameters();
                        removeStringColumn.setString(1, rid);
                        removeStringColumn.setString(2, k);
                        int nrows = removeStringColumn.executeUpdate();
                        if (nrows == 0) {
                            m = get(keySpace, columnFamily, key);
                            LOGGER.debug("Column Not present did not remove {} {} Current Column:{} ",
                                    new Object[] { getRowId(keySpace, columnFamily, key), k, m });
                        } else {
                            LOGGER.debug("Removed Index {} {} {} ",
                                    new Object[] { getRowId(keySpace, columnFamily, key), k, nrows });
                        }
                    } else {
                        PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                                SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                        removeStringColumn.clearWarnings();
                        removeStringColumn.clearParameters();
                        removeStringColumn.setString(1, rid);
                        removeStringColumn.setString(2, k);
                        int nrows = removeStringColumn.executeUpdate();
                        if (nrows == 0) {
                            m = get(keySpace, columnFamily, key);
                            LOGGER.debug("Column Not present did not remove {} {} Current Column:{} ",
                                    new Object[] { getRowId(keySpace, columnFamily, key), k, m });
                        } else {
                            LOGGER.debug("Removed Index {} {} {} ",
                                    new Object[] { getRowId(keySpace, columnFamily, key), k, nrows });
                        }
                        Object[] os = (o instanceof Object[]) ? (Object[]) o : new Object[] { o };
                        for (Object ov : os) {
                            String v = ov.toString();
                            PreparedStatement insertStringColumn = getStatement(keySpace, columnFamily,
                                    SQL_INSERT_STRING_COLUMN, rid, statementCache);
                            insertStringColumn.clearWarnings();
                            insertStringColumn.clearParameters();
                            insertStringColumn.setString(1, v);
                            insertStringColumn.setString(2, rid);
                            insertStringColumn.setString(3, k);
                            LOGGER.debug("Non Batch Insert Index {} {}", k, v);
                            if (insertStringColumn.executeUpdate() == 0) {
                                throw new StorageClientException("Failed to save "
                                        + getRowId(keySpace, columnFamily, key) + "  column:[" + k + "] ");
                            } else {
                                LOGGER.debug("Inserted Index {} {} [{}]",
                                        new Object[] { getRowId(keySpace, columnFamily, key), k, v });
                            }
                        }
                    }
                }
            }

            if (!StorageClientUtils.isRoot(key)) {
                String parent = StorageClientUtils.getParentObjectPath(key);
                String hash = rowHash(keySpace, columnFamily, parent);
                LOGGER.debug("Hash of {}:{}:{} is {} ", new Object[] { keySpace, columnFamily, parent, hash });
                Map<String, Object> autoIndexMap = ImmutableMap.of(InternalContent.PARENT_HASH_FIELD,
                        (Object) hash);
                for (Entry<String, Object> e : autoIndexMap.entrySet()) {
                    String k = e.getKey();
                    Object v = e.getValue();
                    PreparedStatement removeStringColumn = getStatement(keySpace, columnFamily,
                            SQL_REMOVE_STRING_COLUMN, rid, statementCache);
                    removeStringColumn.clearWarnings();
                    removeStringColumn.clearParameters();
                    removeStringColumn.setString(1, rid);
                    removeStringColumn.setString(2, k);
                    int nrows = removeStringColumn.executeUpdate();
                    if (nrows == 0) {
                        m = get(keySpace, columnFamily, key);
                        LOGGER.debug("Column Not present did not remove {} {} Current Column:{} ",
                                new Object[] { getRowId(keySpace, columnFamily, key), k, m });
                    } else {
                        LOGGER.debug("Removed Index {} {} {} ",
                                new Object[] { getRowId(keySpace, columnFamily, key), k, nrows });
                    }

                    PreparedStatement insertStringColumn = getStatement(keySpace, columnFamily,
                            SQL_INSERT_STRING_COLUMN, rid, statementCache);
                    insertStringColumn.clearWarnings();
                    insertStringColumn.clearParameters();
                    insertStringColumn.setString(1, v.toString());
                    insertStringColumn.setString(2, rid);
                    insertStringColumn.setString(3, k);
                    LOGGER.debug("Non Batch Insert Index {} {}", k, v);
                    if (insertStringColumn.executeUpdate() == 0) {
                        throw new StorageClientException("Failed to save "
                                + getRowId(keySpace, columnFamily, key) + "  column:[" + k + "] ");
                    } else {
                        LOGGER.debug("Inserted Index {} {} [{}]",
                                new Object[] { getRowId(keySpace, columnFamily, key), k, v });
                    }
                }
            }

        }
        endBlock(autoCommit);
    } catch (SQLException e) {
        abandonBlock(autoCommit);
        LOGGER.warn("Failed to perform insert/update operation on {}:{}:{} ",
                new Object[] { keySpace, columnFamily, key }, e);
        throw new StorageClientException(e.getMessage(), e);
    } catch (IOException e) {
        abandonBlock(autoCommit);
        LOGGER.warn("Failed to perform insert/update operation on {}:{}:{} ",
                new Object[] { keySpace, columnFamily, key }, e);
        throw new StorageClientException(e.getMessage(), e);
    } finally {
        close(statementCache);
    }
}