The batch query handler is used when a client needs to send alot of queries to a server in batch mode. Depending on the client workload there could be places where a better batch query handler could improve performance. Therefore drizzle-jdbc supports pluggable batch query handlers.
First you need to build the actual batch handler, this is done by implementing a small interface:
public interface ParameterizedBatchHandler { /** * called when a set of parameters are added to a batch. * @param query the parameterized query. */ void addToBatch(ParameterizedQuery query); /** * execute the batch using protocol. Return an array of update counts * or -2 (Statement.SUCCESS_NO_INFO) if the update count is unknown. * @return a list of update counts * @throws QueryException if something goes wrong executing the query. */ int [] executeBatch() throws QueryException; }
Then a factory for creating handlers is needed, this is done by implementing another interface:
public interface ParameterizedBatchHandlerFactory { /** * Returns a parameterized batch handler. Called every time prepareStatement * is called on the connection. * x * @return a parameterized batch handler */ ParameterizedBatchHandler get(String query, Protocol protocol); }
To change out the default batch query handler, this is done:
if(connection.isWrapperFor(DrizzleConnection.class)) { DrizzleConnection dc = connection.unwrap(DrizzleConnection.class); dc.setBatchQueryHandlerFactory(new NoopBatchHandlerFactory()); }
Look at these files for more information: