Execute batch, like executeBatch(), with returning results with long[]. For when row count may
exceed Integer.MAX_VALUE.

@return an array of update counts (one element for each command in the batch)
@throws SQLException if a database error occur.
349341
@Override
  public long[] executeLargeBatch() throws SQLException {
    checkClose();
    int queryParameterSize = queryParameters.size();
    if (queryParameterSize == 0) {
      return new long[0];
    }
    executeBatchInternal(queryParameterSize);
    return results.getCmdInformation().getLargeUpdateCounts();
  }
534120
private void doFlush() throws SQLException {
		if (batchCount > 0) {
			try {
				statement.executeBatch();
				batchCount = 0;
			} catch (SQLException ex) {
				resetConnection();
				throw ex;
			}
		}
	}
1306935
public List<Object[]> select(Sql sql) throws SQLException {
		
		long start =  System.currentTimeMillis();
		
		if (sql.validate() == false) {
			return null;
		}
		
		List<Object[]> dataList = null;
		
		if (sql.isSelect()) {
			
			ResultSet rs = null;
			PreparedStatement stmt = null;

			try {
				stmt = this.createStatment(conn, sql);
				rs = stmt.executeQuery();
				
				dataList = getResultSet(rs);

			} catch (SQLException e) {
				throw e;
			} finally {
				try {
					if (rs != null && rs.isClosed() == false) {
						rs.close();
					}
					if (stmt != null && stmt.isClosed() == false) {
						stmt.close();
					}
				} catch (SQLException e) {
					throw e;
				}
			}
		}
		
		logger.debug(String.format("Execute %s used %d ms", sql.getSql(), System.currentTimeMillis() - start));
		
		return dataList;
	}
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;
	}
299433
public int executeUpdate() throws SQLException {
        return executeUpdate(new Updater() {
            
            @Override
            public int executeUpdate(final Statement statement, final String sql) throws SQLException {
                return statement.executeUpdate(sql);
            }
        });
    }
994361
public int[] batchUpdate(List<? extends Model> modelList, int batchSize) {
    	if (modelList == null || modelList.size() == 0)
    		return new int[0];
    	
    	Model model = modelList.get(0);
    	Table table = TableMapping.me().getTable(model.getClass());
    	String[] pKeys = table.getPrimaryKey();
    	Map<String, Object> attrs = model._getAttrs();
    	List<String> attrNames = new ArrayList<String>();
    	// the same as the iterator in Dialect.forModelSave() to ensure the order of the attrs
    	for (Entry<String, Object> e : attrs.entrySet()) {
    		String attr = e.getKey();
    		if (config.dialect.isPrimaryKey(attr, pKeys) == false && table.hasColumnLabel(attr))
    			attrNames.add(attr);
    	}
    	for (String pKey : pKeys)
    		attrNames.add(pKey);
    	String columns = StrKit.join(attrNames.toArray(new String[attrNames.size()]), ",");
    	
    	// update all attrs of the model not use the midifyFlag of every single model
    	Set<String> modifyFlag = attrs.keySet();	// model.getModifyFlag();
    	
    	StringBuilder sql = new StringBuilder();
    	List<Object> parasNoUse = new ArrayList<Object>();
    	config.dialect.forModelUpdate(TableMapping.me().getTable(model.getClass()), attrs, modifyFlag, sql, parasNoUse);
    	return batch(sql.toString(), columns, modelList, batchSize);
    }
797018
public <T> List<T> executeGroup(final Collection<ShardingExecuteGroup<? extends StatementExecuteUnit>> sqlExecuteGroups, final SQLExecuteCallback<T> callback) throws SQLException {
        return executeGroup(sqlExecuteGroups, null, callback);
    }
393974
public PrepareResult executeBatch() throws SQLException {
    int paramCount = getParamCount();
    if (binaryProtocol) {
      if (readPrepareStmtResult) {
        parameterTypeHeader = new ColumnType[paramCount];
        if (prepareResult == null
            && protocol.getOptions().cachePrepStmts
            && protocol.getOptions().useServerPrepStmts) {
          String key = protocol.getDatabase() + "-" + sql;
          prepareResult = protocol.prepareStatementCache().get(key);
          if (prepareResult != null && !((ServerPrepareResult) prepareResult)
              .incrementShareCounter()) {
            //in cache but been de-allocated
            prepareResult = null;
          }
        }
        statementId =
            (prepareResult == null) ? -1 : ((ServerPrepareResult) prepareResult).getStatementId();
      } else if (prepareResult != null) {
        statementId = ((ServerPrepareResult) prepareResult).getStatementId();
      }
    }
    return executeBatchStandard(paramCount);
  }
601898
public int[] updateBatch(@SQL @NotNull String sql, @NotNull List<? extends  List<?>> argumentLists) {
        SqlQuery query = SqlQuery.query(sql, "<batch-update>");

        return withCurrentTransaction(query, tx -> {
            logQuery(query);

            try (PreparedStatement ps = tx.getConnection().prepareStatement(sql)) {
                bindQueryParameters(ps, query);
                for (List<?> arguments : argumentLists) {
                    bindArguments(ps, arguments);
                    ps.addBatch();
                }
                long startTime = currentTimeMillis();
                int[] counts = ps.executeBatch();
                logQueryExecution(query, currentTimeMillis() - startTime);
                return counts;
            }
        });
    }
420120
@Override
	public final void addBatch(String s) throws SQLException {
		batchSql.add(s);

		stmt.addBatch(s);
	}
570331
public static int[] executeBatch(Connection conn, String sql, Iterable<Object[]> paramsBatch) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = StatementUtil.prepareStatementForBatch(conn, sql, paramsBatch);
			return ps.executeBatch();
		} finally {
			DbUtil.close(ps);
		}
	}
1368057
public static void updateBatch(String sql, Object[][] arg) {
        Connection connection = JDBCUtils.getConnection();
        PreparedStatement ps = null;
        try {
            ps = connection.prepareStatement(sql);
            for (int i = 0; i < arg.length; i++) {
                for (int j = 0; j < arg[i].length; j++) {
                    ps.setObject(j + 1, arg[i][j]);
                }
                ps.addBatch();
            }
            ps.executeBatch();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        JDBCUtils.release(ps, connection);
    }
161751
public int executeUpdate(Connection conn, DataObject[] objects) throws SQLException {
        PreparedStatement statement = conn.prepareStatement(_sql);
        try {
            for (DataObject object: objects) {
                load(statement, object);
                statement.addBatch();
            }
            int count = getAffectedRowCount(statement.executeBatch());
            return count;
        } finally {
            statement.close();
        }
    }
775222
private void executeInternalBatch(int size) throws SQLException {
    executeQueryPrologue(true);
    results = new Results(this, 0, true, size, false, resultSetScrollType,
            resultSetConcurrency, autoGeneratedKeys, protocol.getAutoIncrementIncrement());
    if (protocol
        .executeBatchClient(protocol.isMasterConnection(), results, prepareResult, parameterList,
            hasLongData)) {
      return;
    }

    //send query one by one, reading results for each query before sending another one
    SQLException exception = null;

    if (queryTimeout > 0) {
      for (int batchQueriesCount = 0; batchQueriesCount < size; batchQueriesCount++) {
        protocol.stopIfInterrupted();
        try {
          protocol.executeQuery(protocol.isMasterConnection(), results, prepareResult,
              parameterList.get(batchQueriesCount));
        } catch (SQLException e) {
          if (options.continueBatchOnError) {
            exception = e;
          } else {
            throw e;
          }
        }
      }

    } else {
      for (int batchQueriesCount = 0; batchQueriesCount < size; batchQueriesCount++) {
        try {
          protocol.executeQuery(protocol.isMasterConnection(), results, prepareResult,
              parameterList.get(batchQueriesCount));
        } catch (SQLException e) {
          if (options.continueBatchOnError) {
            exception = e;
          } else {
            throw e;
          }
        }
      }
    }
    if (exception != null) {
      throw exception;
    }

  }
775064
@Override
    public boolean execute() throws SQLException {
        boolean isOk = false;

        try {
            boolean result = internalStmt.execute();
            isOk = true;

            return result;
        } finally {
            poolableConn.updateLastSQLExecutionTime(isOk);
        }
    }
426666
@Override
    public int executeBatch()
    {
        BulkRequestBuilder bulkRequest = txClient.prepareBulk().setRefresh(isRefreshIndexes());

        try
        {
            for (Node node : nodes)
            {
                if (node.isDirty())
                {
                    node.handlePreEvent();
                    Object entity = node.getData();
                    Object id = node.getEntityId();
                    EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                            node.getDataClass());

                    MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                            .getMetamodel(metadata.getPersistenceUnit());

                    EntityType entityType = metaModel.entity(metadata.getEntityClazz());

                    String key = getKeyAsString(id, metadata, metaModel);

                    if (node.isInState(RemovedState.class))
                    {
                        // create a delete request.

                        DeleteRequest request = new DeleteRequest(metadata.getSchema().toLowerCase(),
                                metadata.getTableName(), key);
                        bulkRequest.add(request);

                    }
                    else if (node.isUpdate())
                    {
                        Map<String, Object> values = new HashMap<String, Object>();
                        List<RelationHolder> relationHolders = getRelationHolders(node);

                        addSource(entity, values, entityType);

                        addRelations(relationHolders, values);

                        UpdateRequest request = new UpdateRequest(metadata.getSchema().toLowerCase(),
                                metadata.getTableName(), key).doc(values);
                        bulkRequest.add(request);
                    }
                    else
                    {
                        // create an insert request.
                        Map<String, Object> values = new HashMap<String, Object>();
                        List<RelationHolder> relationHolders = getRelationHolders(node);

                        addSource(entity, values, entityType);

                        addRelations(relationHolders, values);

                        IndexRequest request = new IndexRequest(metadata.getSchema().toLowerCase(),
                                metadata.getTableName(), key).source(values);
                        bulkRequest.add(request);

                    }

                }
            }

            BulkResponse response = null;
            if (nodes != null && !nodes.isEmpty())
            {
                // bulkRequest.setRefresh(true);
                response = bulkRequest.execute().actionGet();
            }
            return response != null ? response.getItems().length : 0;
        }
        finally
        {
            clear();
        }

    }
825951
private void executeBatchMulti(Results results, final ClientPrepareResult clientPrepareResult,
      final List<ParameterHolder[]> parametersList) throws SQLException {

    cmdPrologue();
    initializeBatchReader();
    new AbstractMultiSend(this, writer, results, clientPrepareResult, parametersList) {

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

        ParameterHolder[] parameters = parametersList.get(status.sendCmdCounter);
        writer.startPacket(0);
        ComQuery.sendSubCmd(writer, clientPrepareResult, parameters, -1);
        writer.flush();
      }


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

        int counter = results.getCurrentStatNumber() - 1;
        ParameterHolder[] parameters = parametersList.get(counter);
        List<byte[]> queryParts = clientPrepareResult.getQueryParts();
        StringBuilder sql = new StringBuilder(new String(queryParts.get(0)));

        for (int i = 0; i < paramCount; i++) {
          sql.append(parameters[i].toString()).append(new String(queryParts.get(i + 1)));
        }

        return logQuery.exceptionWithQuery(sql.toString(), qex, explicitClosed);
      }


      @Override
      public int getParamCount() {
        return clientPrepareResult.getQueryParts().size() - 1;
      }


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

    }.executeBatch();

  }