-
Notifications
You must be signed in to change notification settings - Fork 4
KdbQuery
Jas edited this page Mar 14, 2017
·
1 revision
These classes allow you to run queries on a kdb+ process either synchronously or asynchronously as required.
The asynchronous query class does an asynchronous call and then blocks for the result. We are looking at adding support to return a Future
.
Other supported features:
- Auto reconnect on query if disconnected
- try-with-resources
- Execution time logging
There are 2 ways to construct a query object:
-
KdbQuery(KdbProcess)
: The query object itself will create a new connection to the specified process -
KdbQuery(KdbConnection)
: The query object uses the existing specified connection to perform the query. Note that connections should not be shared between multiple threads
There are 2 query functions which are supported:
-
query(String)
: Complete function call as a string -
query(String, KdbDict)
: Function call with single dictionary argument (generally used when querying Gateways)
The query functions either return an Object
or throw QueryExectionFailedException
if either a kdb exception or a low level I/O exception occurs during the query.
If you know the returned object will be a dictionary or table, you can use the following conversion functions:
-
KdbDict.fromObject
: ForDict
results -
KdbTable.fromObject
: ForTable
results
public void simpleQuery() throws QueryExecutionFailedException() {
KdbQuery query = new KdbSyncQuery(new KdbProcess("localhost", 1234));
Object result = query(".z.d");
System.out.println("kdb time: " + result);
query.close();
}
public KdbTable queryWithArgs throws QueryExecutionFailedException() {
KdbQuery query = new KdbSyncQuery(new KdbProcess("localhost", 1234));
KdbDict args = new KdbDict()
.add("sym", "VOD.L");
Object result = query("getTodaysTradesFor", args);
query.close();
return KdbTable.fromObject(result);
}
public KdbTable queryWithArgsAndTry() {
KdbDict args = new KdbDict()
.add("sym", "VOD.L");
try(KdbQuery query = new KdbSyncQuery(new KdbProcess("localhost", 1234))) {
Object result = query("getTodaysTradesFor", args);
return KdbTable.fromObject(result);
} catch (QueryExecutionFailedException e) {
return null;
}
}
Copyright (C) Sport Trades Ltd 2017 - 2020, John Keys and Jaskirat Rajasansir 2020 - 2021