Execute the {@link PreparedStatement#addBatch() batches}, get the number of rows affected in
each batch, and close the statement.

@param stmt
must already have batches added
@since 1.4.0
349288
public static int[] batch(@Nullable PreparedStatement stmt) throws SQLException {
		int[] rows = EMPTY_INT_ARRAY;
		if (stmt != null) {
			rows = stmt.executeBatch();
			stmt.close();
		}
		return rows;
	}
734260
@Override
    public void addBatch(Node node)
    {
        if (node != null)
        {
            nodes.add(node);
        }

        onBatchLimit();

    }
1214170
@NonNull
  public BatchStatementBuilder addStatements(@NonNull Iterable<BatchableStatement<?>> statements) {
    int delta = Iterables.size(statements);
    if (statementsCount + delta > 0xFFFF) {
      throw new IllegalStateException(
          "Batch statement cannot contain more than " + 0xFFFF + " statements.");
    }
    statementsCount += delta;
    statementsBuilder.addAll(statements);
    return this;
  }
841961
public static long firstLong(PreparedStatement stmt) throws SQLException {
		ResultSet rs = stmt.executeQuery();
		long l = rs.next() ? rs.getLong(1) : Long.MIN_VALUE;
		stmt.close();
		return l;
	}
1189685
public static void checkedUpdate (
        Statement stmt, String query, int expectedCount)
        throws SQLException, PersistenceException
    {
        int modified = stmt.executeUpdate(query);
        if (modified != expectedCount) {
            String err = "Statement did not modify expected number of rows [stmt=" + stmt +
                ", expected=" + expectedCount + ", modified=" + modified + "]";
            throw new PersistenceException(err);
        }
    }
518701
public void executeBatch() throws OJBBatchUpdateException
    {
        if (batchCon != null)
        {
            try
            {
                batchCon.executeBatch();
            }
            catch (Throwable th)
            {
                throw new OJBBatchUpdateException(th);
            }
        }
    }
903785
private void executeBatch(Results results, final List<String> queries)
      throws SQLException {

    if (!options.useBatchMultiSend) {

      String sql = null;
      SQLException exception = null;

      for (int i = 0; i < queries.size() && !isInterrupted(); i++) {

        try {

          sql = queries.get(i);
          writer.startPacket(0);
          writer.write(COM_QUERY);
          writer.write(sql);
          writer.flush();
          getResult(results);

        } catch (SQLException sqlException) {
          if (exception == null) {
            exception = logQuery.exceptionWithQuery(sql, sqlException, explicitClosed);
            if (!options.continueBatchOnError) {
              throw exception;
            }
          }
        } catch (IOException e) {
          if (exception == null) {
            exception = handleIoException(e);
            if (!options.continueBatchOnError) {
              throw exception;
            }
          }
        }
      }
      stopIfInterrupted();

      if (exception != null) {
        throw exception;
      }
      return;
    }
    initializeBatchReader();
    new AbstractMultiSend(this, writer, results, queries) {

      @Override
      public void sendCmd(PacketOutputStream pos, Results results,
          List<ParameterHolder[]> parametersList, List<String> queries, int paramCount,
          BulkStatus status,
          PrepareResult prepareResult)
          throws IOException {

        String sql = queries.get(status.sendCmdCounter);
        pos.startPacket(0);
        pos.write(COM_QUERY);
        pos.write(sql);
        pos.flush();
      }

      @Override
      public SQLException handleResultException(SQLException qex, Results results,
          List<ParameterHolder[]> parametersList, List<String> queries, int currentCounter,
          int sendCmdCounter, int paramCount, PrepareResult prepareResult) {

        String sql = queries.get(currentCounter + sendCmdCounter);
        return logQuery.exceptionWithQuery(sql, qex, explicitClosed);

      }

      @Override
      public int getParamCount() {
        return -1;
      }

      @Override
      public int getTotalExecutionNumber() {
        return queries.size();
      }

    }.executeBatch();

  }
397473
protected void executeBatchAndClose(PreparedStatement... preparedStatements)
            throws SQLException {
        for (PreparedStatement ps : preparedStatements) {
            ps.executeBatch();
            ps.clearBatch();
            ps.close();
        }
    }
703642
public int[] execute(Iterable<String> sqls, int batchSize) throws SQLException {
		if (sqls == null) {
			return null;
		}
		
		List<int[]> tmpResultList = new ArrayList<int[]>();
		
		Statement stmt = null;
		try {
			int counter = 0;
			stmt = conn.createStatement();
			for (String sql : sqls) {
				stmt.addBatch(sql);
				counter ++;
				if (batchSize > 0 && counter % batchSize == 0) {
					tmpResultList.add(stmt.executeBatch());
				}
			}
			tmpResultList.add(stmt.executeBatch());

		} catch (SQLException e) {
			throw e;
		} finally {
			try {
				if (stmt != null && stmt.isClosed() == false) {
					stmt.close();
				}
			} catch (SQLException e) {
				logger.error(e.getMessage());
			}
		}
		
		int[] result = new int[0];
		for (int[] tmpResult : tmpResultList) {
			int[] tmpArray = new int[result.length + tmpResult.length];
			
			System.arraycopy(result, 0, tmpArray, 0, result.length);
			System.arraycopy(tmpResult, 0, tmpArray, result.length, tmpResult.length);
			
			result = tmpArray;
		}

		return result;
	}
981534
@Override
    public void addBatch(com.impetus.kundera.graph.Node node)
    {
        if (node != null)
        {
            nodes.add(node);
        }
        if (batchSize > 0 && batchSize == nodes.size())
        {
            executeBatch();
            nodes.clear();
        }
    }
433188
def execute(self, stmt, **params):
        
        return self.session.execute(sql.text(stmt, bind=self.bind), **params)
709645
public static void checkedUpdate (PreparedStatement stmt, int expectedCount)
        throws SQLException, PersistenceException
    {
        int modified = stmt.executeUpdate();
        if (modified != expectedCount) {
            String err = "Statement did not modify expected number of rows [stmt=" + stmt +
                ", expected=" + expectedCount + ", modified=" + modified + "]";
            throw new PersistenceException(err);
        }
    }
501809
@Override
    public String prepareBatchQuery(List<String> statements) {

        StringBuilder sb = new StringBuilder("BEGIN BATCH \n");

        for (String statement : statements) {
            sb.append(statement).append("\n");
        }

        sb.append(" APPLY BATCH;");

        return sb.toString();
    }
728817
@SuppressWarnings("unchecked")
    protected void setParameters(PreparedStatement stmt, Object[] params) throws SQLException {
        for (int i = 0; i < params.length; i++) {
            if(params[i] == null){
                stmt.setObject(i + 1, null);
            } else {
                Class<?> propertType = params[i].getClass();
                @SuppressWarnings("rawtypes")
                ValueType valueType = MirageUtil.getValueType(propertType, null, dialect, valueTypes);
                if(valueType != null){
                    valueType.set(propertType, stmt, params[i], i + 1);
                } else {
                    if(logger.isWarnEnabled()) {
                        logger.warn("valueType for " + propertType.getName() + " not found.");
                    }
                }
            }
        }
    }
1362035
public static int[] executeBatch(Connection conn, Iterable<String> sqls) throws SQLException {
		Statement statement = null;
		try {
			statement = conn.createStatement();
			for (String sql : sqls) {
				statement.addBatch(sql);
			}
			return statement.executeBatch();
		} finally {
			DbUtil.close(statement);
		}
	}
137466
private PrepareResult executeBatchStandard(int estimatedParameterCount) throws SQLException {
    int totalExecutionNumber = getTotalExecutionNumber();
    SQLException exception = null;
    BulkStatus status = new BulkStatus();

    ComStmtPrepare comStmtPrepare = null;
    FutureTask<AsyncMultiReadResult> futureReadTask = null;

    int requestNumberByBulk;
    int paramCount = estimatedParameterCount;
    try {
      do {
        status.sendEnded = false;
        status.sendSubCmdCounter = 0;
        requestNumberByBulk = Math.min(totalExecutionNumber - status.sendCmdCounter,
            protocol.getOptions().useBatchMultiSendNumber);
        protocol.changeSocketTcpNoDelay(false); //enable NAGLE algorithm temporary.

        //add prepare sub-command
        if (readPrepareStmtResult && prepareResult == null) {

          comStmtPrepare = new ComStmtPrepare(protocol, sql);
          comStmtPrepare.send(writer);

          //read prepare result
          prepareResult = comStmtPrepare.read(protocol.getReader(), protocol.isEofDeprecated());
          statementId = ((ServerPrepareResult) prepareResult).getStatementId();
          paramCount = getParamCount();
        }

        boolean useCurrentThread = false;

        for (; status.sendSubCmdCounter < requestNumberByBulk; ) {
          sendCmd(writer, results, parametersList, queries, paramCount, status, prepareResult);
          status.sendSubCmdCounter++;
          status.sendCmdCounter++;
          if (useCurrentThread) {
            try {
              protocol.getResult(results);
            } catch (SQLException qex) {
              if (((readPrepareStmtResult && prepareResult == null) || !protocol
                  .getOptions().continueBatchOnError)) {
                throw qex;
              } else {
                exception = qex;
              }
            }
          } else if (futureReadTask == null) {
            try {
              futureReadTask = new FutureTask<>(new AsyncMultiRead(comStmtPrepare, status,
                  protocol, false, this, paramCount,
                  results, parametersList, queries, prepareResult));
              AbstractQueryProtocol.readScheduler.execute(futureReadTask);
            } catch (RejectedExecutionException r) {
              useCurrentThread = true;
              try {
                protocol.getResult(results);
              } catch (SQLException qex) {
                if (((readPrepareStmtResult && prepareResult == null) || !protocol
                    .getOptions().continueBatchOnError)) {
                  throw qex;
                } else {
                  exception = qex;
                }
              }
            }
          }
        }

        status.sendEnded = true;
        if (!useCurrentThread) {
          protocol.changeSocketTcpNoDelay(protocol.getOptions().tcpNoDelay);
          try {
            AsyncMultiReadResult asyncMultiReadResult = futureReadTask.get();

            if (binaryProtocol && prepareResult == null
                && asyncMultiReadResult.getPrepareResult() != null) {
              prepareResult = asyncMultiReadResult.getPrepareResult();
              statementId = ((ServerPrepareResult) prepareResult).getStatementId();
              paramCount = prepareResult.getParamCount();
            }

            if (asyncMultiReadResult.getException() != null) {
              if (((readPrepareStmtResult && prepareResult == null) || !protocol
                  .getOptions().continueBatchOnError)) {
                throw asyncMultiReadResult.getException();
              } else {
                exception = asyncMultiReadResult.getException();
              }
            }
          } catch (ExecutionException executionException) {
            if (executionException.getCause() == null) {
              throw new SQLException("Error reading results " + executionException.getMessage());
            }
            throw new SQLException(
                "Error reading results " + executionException.getCause().getMessage());
          } catch (InterruptedException interruptedException) {
            protocol.setActiveFutureTask(futureReadTask);
            Thread.currentThread().interrupt();
            throw new SQLException("Interrupted awaiting response ",
                INTERRUPTED_EXCEPTION.getSqlState(), interruptedException);
          } finally {
            //bulk can prepare, and so if prepare cache is enable, can replace an already cached prepareStatement
            //this permit to release those old prepared statement without conflict.
            protocol.forceReleaseWaitingPrepareStatement();
          }
        }

        if (protocol.isInterrupted()) {
          //interrupted during read, must throw an exception manually
          futureReadTask.cancel(true);
          throw new SQLTimeoutException("Timeout during batch execution");
        }
        futureReadTask = null;

      } while (status.sendCmdCounter < totalExecutionNumber);

      if (exception != null) {
        throw exception;
      }

      return prepareResult;

    } catch (IOException e) {
      status.sendEnded = true;
      status.sendCmdCounter = 0; //to ensure read doesn't hang
      throw protocol.handleIoException(e);
    }

  }
1189940
@NonNull
  public BatchStatementBuilder addStatements(@NonNull BatchableStatement<?>... statements) {
    return addStatements(Arrays.asList(statements));
  }