// Get a connection with an HTablePool size of 10
HConnectionManager.setMaxPoolReferencesPerTablePerConnection(10);
HConnection conn = HConnectionManager.newConnection();
HStatement stmt = conn.createStatement();
stmt.execute("CREATE TABLE table12 (f1(), f3()) IF NOT tableexists('table12')");
stmt.execute("CREATE TEMP MAPPING sch9 FOR TABLE table12"
+ "("
+ "keyval key, "
+ "f1 ("
+ " val1 string alias val1, "
+ " val2 string alias val2 "
+ "), "
+ "f3 ("
+ " val1 int alias val5, "
+ " val2 int alias val6 "
+ "))");
HResultSet<HRecord> rs = stmt.executeQuery("select * from sch9");
for (HRecord rec : rs) {
int val5 = (Integer)rec.getCurrentValue("val5");
int val6 = (Integer)rec.getCurrentValue("val6");
String val1 = (String)rec.getCurrentValue("val1");
String val2 = (String)rec.getCurrentValue("val2");
System.out.print("val5: " + val5);
System.out.print(", val6: " + val6);
System.out.print(", val1: " + val1);
System.out.println(", val2: " + val2);
}
stmt.execute("DISABLE TABLE table12");
stmt.execute("DROP TABLE table12");
stmt.close();
conn.close();
// For each connection in a connection pool, assign an HTablePool max size of 25 references per table
HConnectionPoolManager.setMaxPoolReferencesPerTablePerConnection(25);
// Create connection pool with max of 25 connections and prime it with 5 initial connections
HConnectionPool connectionPool = HConnectionPoolManager.newConnectionPool(5, 25);
// Create Query Executor Pool named execPool if it doesn't already exist.
if (!QueryExecutorPoolManager.queryExecutorPoolExists("execPool"))
QueryExecutorPoolManager.newQueryExecutorPool("execPool", 5, 5, 10, Long.MAX_VALUE, true, 100);
// Take a connection from the connection pool
HConnection conn = connectionPool.takeConnection();
// Assign the connection a query executor pool name to use for queries
conn.setQueryExecutorPoolName("execPool");
// Do something with the connection
// Close the connection to release it back to the connection pool
conn.close();
HConnection conn = HConnectionManager.newConnection();
HStatement stmt = conn.createStatement();
stmt.execute("CREATE TABLE table12 (f1(), f3()) IF NOT tableexists('table12')");
stmt.execute("CREATE TEMP MAPPING sch9 FOR TABLE table12"
+ "("
+ "keyval key, "
+ "f1 ("
+ " val1 string alias val1, "
+ " val2 string alias val2 "
+ "), "
+ "f3 ("
+ " val1 int alias val5, "
+ " val2 int alias val6 "
+ "))");
if (!AsyncExecutorManager.asyncExecutorExists("async1"))
AsyncExecutorManager.newAsyncExecutor("async1", 1, 10, Long.MAX_VALUE);
conn.setAsyncExecutorName("async1");
QueryFuture future = stmt.executeQueryAsync("select * from sch9",
new QueryListenerAdapter<HRecord>() {
public void onEachRow(final HRecord rec) throws HBqlException {
int val5 = (Integer)rec.getCurrentValue("val5");
int val6 = (Integer)rec.getCurrentValue("val6");
String val1 = (String)rec.getCurrentValue("val1");
String val2 = (String)rec.getCurrentValue("val2");
System.out.print("val5: " + val5);
System.out.print(", val6: " + val6);
System.out.print(", val1: " + val1);
System.out.println(", val2: " + val2);
}
public void onException(final ExceptionSource source,
final HBqlException e) {
e.printStackTrace();
}
});
try {
future.await();
}
catch (InterruptedException e) {
e.printStackTrace();
}
stmt.close();
conn.close();