Skip to content

Commit 0284f05

Browse files
updating code for opensourcing
1 parent 3325384 commit 0284f05

5 files changed

Lines changed: 34 additions & 172 deletions

File tree

src/main/java/uk/co/aquaq/kdb/connection/KdbConnectionWrapper.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import org.slf4j.LoggerFactory;
88
import org.springframework.stereotype.Component;
99
import uk.co.aquaq.kdb.request.KdbRequest;
10-
11-
import javax.annotation.PostConstruct;
12-
import javax.annotation.PreDestroy;
1310
import java.io.IOException;
1411
import java.net.UnknownHostException;
1512

@@ -28,16 +25,6 @@ public class KdbConnectionWrapper {
2825
@Value("${kdb.password}")
2926
private String password;
3027

31-
@PostConstruct
32-
public void postConstruct() {
33-
open();
34-
}
35-
36-
@PreDestroy
37-
public void preDestroy() throws IOException {
38-
close();
39-
}
40-
4128
private void open(){
4229
try {
4330
connectionToKdb = new c(hostname, port, getCredentials());
@@ -60,25 +47,39 @@ private void close() throws IOException{
6047
if (connectionToKdb != null) {
6148
connectionToKdb.close();
6249
connectionToKdb = null;
63-
} else {
64-
throw new KdbConnectionException("Cannot close Connection");
6550
}
6651
}
6752

6853
public void executeAsyncQuery(String query) throws IOException {
69-
connectionToKdb.ks(query);
54+
try {
55+
connectionToKdb.ks(query);
56+
}
57+
finally {
58+
close();
59+
}
7060
}
7161

7262
public Object executeDeferredSyncFunction(KdbRequest kdbRequest) throws c.KException , IOException{
73-
connectionToKdb.ks(kdbRequest.getFunctionTemplate(),
74-
new Object[]{kdbRequest.getFunctionName().toCharArray(),
75-
kdbRequest.getArguments().toCharArray()},
76-
kdbRequest.getCredentialDictionary());
77-
78-
return connectionToKdb.k();
63+
try {
64+
open();
65+
connectionToKdb.ks(kdbRequest.getFunctionTemplate(),
66+
new Object[]{kdbRequest.getFunctionName().toCharArray(),
67+
kdbRequest.getArguments().toCharArray()},
68+
kdbRequest.getCredentialDictionary());
69+
Object response=connectionToKdb.k();
70+
logger.warn(kdbRequest.hashCode()+"response:"+response.toString());
71+
return response;
72+
}finally {
73+
close();
74+
}
7975
}
8076

8177
public Object syncQuery(String query) throws IOException, c.KException {
82-
return c.td(connectionToKdb.k(query));
78+
try {
79+
open();
80+
return c.td(connectionToKdb.k(query));
81+
}finally {
82+
close();
83+
}
8384
}
8485
}

src/main/java/uk/co/aquaq/kdb/request/KdbRequestBuilder.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package uk.co.aquaq.kdb.request;
22

33
import com.kx.c;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.stereotype.Component;
46
import uk.co.aquaq.kdb.security.BasicCredentials;
57

68
import java.util.Iterator;
79
import java.util.Map;
8-
10+
@Component
911
public class KdbRequestBuilder {
1012

1113
private KdbRequestBuilder (){}
1214

13-
private static final String FUNCTIONTEMPLATE = ("{@[value;`.aqrest.exec;{[x;y] value x}] . (x;y)}");
15+
private static String functionTemplate;
16+
17+
@Value("${function}")
18+
public void setDatabase(String functionTemplate) {
19+
this.functionTemplate = functionTemplate;
20+
}
1421

1522
public static KdbRequest buildKdbRequest(FunctionRequest functionRequest, BasicCredentials basicCredentials){
1623
KdbRequest kdbRequest = new KdbRequest();
1724
kdbRequest.setArguments(buildArgString(functionRequest.getArguments()));
1825
kdbRequest.setFunctionName(functionRequest.getFunction_name());
1926
kdbRequest.setCredentialDictionary(new c.Dict(new String[]{"user"},new String[]{basicCredentials.getUsername()}));
20-
kdbRequest.setFunctionTemplate(FUNCTIONTEMPLATE);
27+
kdbRequest.setFunctionTemplate(functionTemplate);
2128

2229
return kdbRequest;
2330
}

src/test/Scala/SpringKdbLoadTester.sc

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/test/Scala/SpringKdbLoadTester.scala

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/test/java/uk/co/aquaq/kdb/connection/KdbConnectionWrapperTest.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)