Skip to content

Commit 2f72df6

Browse files
committing changes to open source
1 parent 0284f05 commit 2f72df6

5 files changed

Lines changed: 27 additions & 21 deletions

File tree

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.slf4j.LoggerFactory;
88
import org.springframework.stereotype.Component;
99
import uk.co.aquaq.kdb.request.KdbRequest;
10+
1011
import java.io.IOException;
1112
import java.net.UnknownHostException;
1213

@@ -15,7 +16,6 @@
1516
public class KdbConnectionWrapper {
1617

1718
private static final Logger logger = LoggerFactory.getLogger(KdbConnectionWrapper.class);
18-
private c connectionToKdb;
1919
@Value("${kdb.host}")
2020
private String hostname;
2121
@Value("${kdb.port}")
@@ -25,9 +25,9 @@ public class KdbConnectionWrapper {
2525
@Value("${kdb.password}")
2626
private String password;
2727

28-
private void open(){
28+
private c open(){
2929
try {
30-
connectionToKdb = new c(hostname, port, getCredentials());
30+
return new c(hostname, port, getCredentials());
3131
} catch (UnknownHostException unknownHostException) {
3232
String message = String.format("Unable to contact KDB host %s. Original message: %s", hostname, unknownHostException.getMessage());
3333
logger.error(message);
@@ -43,43 +43,38 @@ private String getCredentials() {
4343
return (username != null ? username : "") + ':' + (password != null ? password : "");
4444
}
4545

46-
private void close() throws IOException{
47-
if (connectionToKdb != null) {
48-
connectionToKdb.close();
49-
connectionToKdb = null;
50-
}
51-
}
46+
5247

5348
public void executeAsyncQuery(String query) throws IOException {
49+
c connectionToKdb=open();
5450
try {
5551
connectionToKdb.ks(query);
5652
}
5753
finally {
58-
close();
54+
connectionToKdb.close();
55+
5956
}
6057
}
6158

6259
public Object executeDeferredSyncFunction(KdbRequest kdbRequest) throws c.KException , IOException{
60+
c connectionToKdb=open();
6361
try {
64-
open();
6562
connectionToKdb.ks(kdbRequest.getFunctionTemplate(),
6663
new Object[]{kdbRequest.getFunctionName().toCharArray(),
6764
kdbRequest.getArguments().toCharArray()},
6865
kdbRequest.getCredentialDictionary());
69-
Object response=connectionToKdb.k();
70-
logger.warn(kdbRequest.hashCode()+"response:"+response.toString());
71-
return response;
66+
return connectionToKdb.k();
7267
}finally {
73-
close();
68+
connectionToKdb.close();
7469
}
7570
}
7671

7772
public Object syncQuery(String query) throws IOException, c.KException {
73+
c connectionToKdb=open();
7874
try {
79-
open();
8075
return c.td(connectionToKdb.k(query));
8176
}finally {
82-
close();
77+
connectionToKdb.close();
8378
}
8479
}
8580
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private KdbRequestBuilder (){}
1515
private static String functionTemplate;
1616

1717
@Value("${function}")
18-
public void setDatabase(String functionTemplate) {
18+
public void setFunctionTemplate(String functionTemplate) {
1919
this.functionTemplate = functionTemplate;
2020
}
2121

src/main/java/uk/co/aquaq/kdb/security/SecurityConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
3333
auth.inMemoryAuthentication()
3434
.withUser(user).password(password).authorities("ROLE_USER");
3535
}
36-
3736
@Override
3837
protected void configure(HttpSecurity http) throws Exception {
3938
http.cors()

src/main/java/uk/co/aquaq/kdb/service/KdbService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ public class KdbService {
2626

2727
public Object executeFunction(FunctionRequest functionRequest, BasicCredentials credentialValues){
2828
KdbRequest kdbRequest= KdbRequestBuilder.buildKdbRequest(functionRequest,credentialValues);
29+
List<Map<String,String>> results = null;
2930
try {
30-
return kdbConnector.executeDeferredSyncFunction(kdbRequest);
31+
Object functionResult= kdbConnector.executeDeferredSyncFunction(kdbRequest);
32+
if(functionResult instanceof c.Flip){
33+
c.Flip flip= (c.Flip)kdbConnector.executeDeferredSyncFunction(kdbRequest);
34+
FlipConverter flipConverter = new FlipConverter();
35+
results= flipConverter.convertFlipToRecordList(flip);
36+
return results;
37+
}
38+
else{
39+
return functionResult;
40+
}
3141
} catch (Exception exception) {
32-
logger.warn(exception.getMessage());
42+
logger.warn( exception.getMessage());
3343
}
3444
return null;
3545
}

src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ kdb.host=localhost
1414
kdb.port=6007
1515
kdb.username=admin
1616
kdb.password=admin
17+
function={@[value;`.aqrest.exec;{[x;y] value x}] . (x;y)}
18+
1719
server.port=8080
1820
freeform.query.mode.enabled=false
1921
basic.authentication.user=user

0 commit comments

Comments
 (0)