Example usage for java.sql PreparedStatement clearBatch

List of usage examples for java.sql PreparedStatement clearBatch

Introduction

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

Prototype

void clearBatch() throws SQLException;

Source Link

Document

Empties this Statement object's current list of SQL commands.

Usage

From source file:module.entities.NameFinder.DB.java

public static void flushBatchLexiconEntry(PreparedStatement statement) throws SQLException {
    try {//from w ww . ja v a 2s. com
        statement.executeBatch();
        statement.clearBatch();
        batchSize = 0;
    } catch (SQLException ex) {
        System.err.println("Skipping:" + ex.getMessage());
    }
}

From source file:module.entities.NameFinder.DB.java

public static void InsertLexiconEntry(PreparedStatement statement, String lexiconType, String lemma,
        String entity, String lang) throws SQLException {
    try {/*from   w  ww.  j  a v a 2  s.c  o m*/
        statement.setString(1, lexiconType);
        statement.setString(2, lemma);
        statement.setString(3, entity);
        statement.setString(4, lang);
        statement.addBatch();
        batchSize++;
        if (batchSize == 1000) {
            statement.executeBatch();
            statement.clearBatch();
            batchSize = 0;
        }
    } catch (SQLException ex) {
        System.err.println("Skipping:" + lemma + " " + entity + " " + ex.getMessage());
    }
}

From source file:org.rimudb.Session.java

/**
 * Rollback the session.//ww  w  .  j a  va2s  . com
 * 
 * @throws RimuDBException
 */
public void rollback() throws RimuDBException {

    // Clear the batches on the prepared statements, and close the statements
    if (statementQueue.size() > 0) {
        try {
            while (statementQueue.size() > 0) {
                BatchEntry batchEntry = statementQueue.remove();
                PreparedStatement ps = batchEntry.getPreparedStatement();
                ps.clearBatch();
                ps.close();
            }
        } catch (SQLException e) {
        }
    }

    // rollback the transaction
    try {
        getConnection().rollback();
    } catch (SQLException e) {
        throw new RimuDBException(e, getClass().getName());
    }
}

From source file:com.redhat.victims.database.VictimsSQL.java

/**
 * Helper function to execute all pending patch operations in the given
 * {@link PreparedStatement}s and close it.
 *
 * @param preparedStatements//from w ww.  j  a v  a  2 s  .  co  m
 * @throws SQLException
 */
protected void executeBatchAndClose(PreparedStatement... preparedStatements) throws SQLException {
    for (PreparedStatement ps : preparedStatements) {
        ps.executeBatch();
        ps.clearBatch();
        ps.close();
    }
}

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

private void doInPreparedStatement(long sysTime, MMDDependency dependency, PreparedStatement ps)
        throws SQLException {
    // ?ID// www .ja  v a  2s  .  co  m
    ps.setString(1, dependency.getOwnerMetadata().getId());
    // ?ID
    ps.setString(2, dependency.getValueMetadata().getId());

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

    if (++super.count % super.batchSize == 0) {
        ps.executeBatch();
        ps.clearBatch();
    }
}

From source file:henu.dao.impl.CaclDaoImpl.java

@Override
public boolean recordCaclUser(long cid, long users[]) {

    int result = 0;
    try {// w ww .  j a  v  a 2  s  . co  m
        String sql = "insert into uc (cid, uid) values(?,?)";
        SqlDB.getConnection().setAutoCommit(false);
        PreparedStatement ps = SqlDB.executePreparedStatement(sql);

        for (int i = 0; i < users.length; i++) {
            ps.setLong(1, cid);
            ps.setLong(2, users[i]);
            ps.addBatch();
        }

        result = ps.executeBatch().length;
        ps.clearBatch();
        SqlDB.close();
    } catch (SQLException ex) {

    }

    return result == users.length;
}

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

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

    for (MMMetaModel metaModel : metaModels) {
        batchLoadDelete(ps, metaModel);//from ww  w  . j  a  va2  s . c o m
    }

    if (super.count % super.batchSize != 0) {
        ps.executeBatch();
        ps.clearBatch();

    }
    return null;
}

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

public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
    String startTime = DateUtil.getFormatTime(System.currentTimeMillis(), DateUtil.DATA_FORMAT);

    for (Iterator<MMMetaModel> iter = metaModels.iterator(); iter.hasNext();) {
        // ??//w  w  w. j  a  va 2  s.c  o m
        batchLoadCreate(iter.next(), ps);
    }
    // ??,???

    if (super.count % super.batchSize != 0) {
        ps.executeBatch();
        ps.clearBatch();

    }

    String logMsg = new StringBuilder(getMsg()).append(count).append(",:").append(startTime)
            .append(",?:")
            .append(DateUtil.getFormatTime(System.currentTimeMillis(), DateUtil.DATA_FORMAT)).toString();
    log.info(logMsg);
    AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.INFO, logMsg);

    return null;
    // test for callback
    // throw new SQLException();
}

From source file:com.nabla.wapp.server.auth.UserManager.java

public boolean updateUserRoleTable() throws SQLException {
    final Map<Integer, Map<Integer, Set<Integer>>> userRoles = loadUserRoles();
    Database.executeUpdate(conn, "DELETE FROM user_role;");
    final PreparedStatement stmt = conn
            .prepareStatement("INSERT INTO user_role (object_id, user_id, role_id) VALUES(?,?,?);");
    try {/*from  w w  w  .  ja v  a 2s  .c  om*/
        stmt.clearBatch();
        for (Map.Entry<Integer, Map<Integer, Set<Integer>>> e : userRoles.entrySet()) {
            if (e.getKey() == null)
                stmt.setNull(1, Types.BIGINT);
            else
                stmt.setInt(1, e.getKey());
            for (Map.Entry<Integer, Set<Integer>> ee : e.getValue().entrySet()) {
                stmt.setInt(2, ee.getKey());
                for (Integer roleId : ee.getValue()) {
                    stmt.setInt(3, roleId);
                    stmt.addBatch();
                }
            }
        }
        return Database.isBatchCompleted(stmt.executeBatch());
    } finally {
        stmt.close();
    }
}

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

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

    for (MMMetaModel metaModel : metaModels) {
        batchLoadCreate(ps, metaModel);//from w  ww  .j a  va2 s .  co  m
    }

    if (super.count % super.batchSize != 0) {
        ps.executeBatch();
        ps.clearBatch();

    }
    return null;
}