The SqlAggregator is a class that acts like a distributed connection, but within a single process. In order to use the SqlAggregator the Java application creates an array of SqlLocalConnection objects to run as shards. Then it starts all of the SqlLocalConnection objects and passes the array to the SqlAggregator constructor.
For example:
SqlLocalConnection [] shards = new SqlLocalConnection[NSHARDS]; for (int i = 0; i < NSHARDS; i++) { shards[i] = create_database("agg" + Integer.toString(i), config, is_dptr); } SqlAggregator agg = new SqlAggregator(shards, 64*1024);Once the aggregator has been created and initialized it can be used exactly as the SqlLocalConnection. For example to perform queries:
agg.executeStatement(("1:insert into MyTable (pk,value) values (?,?)", 2012, "Good bye"));When no longer required, the aggregator must be closed through the
SqlAggregator.disconnect()
method, and after that close the SqlLocalConnection objects:agg.disconnect(); for (int i = 0; i < NSHARDS; i++) { shards[i].disconnect(); }Note that class SqlAggregator directly uses the SqlLocalConnection objects passed to the constructor. So these SqlLocalConnection objects should not be used in other application code during the lifetime of the SqlAggregator object. This would cause simultaneous usage of these objects in different program threads: the application's thread and in a thread internally created by SqlAggregator to serve the SqlLocalConnections.
SQL String Length
Whereas for the
executeStatement()
and theexecuteQuery()
methods of the SqlLocalConnection class, there is no limit to the length of the statement string argument, for the SqlAggregator class the statement string length is limited by thebufferSize
argument passed to the constructor. The default value is 64 Kb. (This applies as well to the SqlRemoteConnection class). Please refer to the SQL Statement Strings page for further details.