Skip to content

Commit 7e9d7dc

Browse files
author
Alex Gaetano Padula
committed
java package finalized and tested for production
1 parent f2c972e commit 7e9d7dc

File tree

3 files changed

+45
-80
lines changed

3 files changed

+45
-80
lines changed

cursusdb.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
/*
2-
* CursusDB
3-
* Java Native Client Package
4-
* ******************************************************************
5-
* Copyright (C) 2023 CursusDB
6-
*
7-
* This program is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or
10-
* (at your option) any later version.
11-
*
12-
* This program is distributed in the hope that it will be useful,
13-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
* GNU General Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Public License
18-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2+
* CursusDB
3+
* Java Native Client Package
4+
* ******************************************************************
5+
* Copyright (C) 2023 CursusDB
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
package cursusdbjava;
21+
package com.cursusdb.java;
2222

2323
import javax.net.SocketFactory;
2424
import javax.net.ssl.SSLSocket;
2525
import javax.net.ssl.SSLSocketFactory;
26-
import java.io.*;
26+
import java.io.DataInputStream;
27+
import java.io.DataOutputStream;
28+
import java.io.IOException;
2729
import java.net.InetSocketAddress;
2830
import java.net.Socket;
2931
import java.util.Base64;
@@ -68,8 +70,6 @@ void Connect() throws IOException {
6870
secureSocket.setEnabledCipherSuites(new String[] { "TLS_AES_128_GCM_SHA256" });
6971
secureSocket.setEnabledProtocols(new String[] { "TLSv1.3" });
7072

71-
// Connect to cluster
72-
secureSocket.connect(new InetSocketAddress("0.0.0.0", port), 1000);
7373

7474
// Setup writer and reader
7575
reader = new DataInputStream(secureSocket.getInputStream());
@@ -78,7 +78,6 @@ void Connect() throws IOException {
7878
// Create new socket
7979
socket = new Socket();
8080

81-
8281
// Connect to cluster
8382
socket.connect(new InetSocketAddress("0.0.0.0", port), 1000);
8483

@@ -87,18 +86,18 @@ void Connect() throws IOException {
8786
writer = new DataOutputStream(socket.getOutputStream());
8887
}
8988

90-
Base64.Encoder base64Encoder = Base64.getEncoder();
91-
String userPassEncoded = base64Encoder.encodeToString((username + "\\0" + password).getBytes());
89+
Base64.Encoder base64Encoder = Base64.getEncoder();
90+
String userPassEncoded = base64Encoder.encodeToString((username + "\\0" + password).getBytes());
9291

93-
writer.writeBytes("Authentication: " + userPassEncoded + "\r\n");
92+
writer.writeBytes("Authentication: " + userPassEncoded + "\r\n");
9493

95-
String clusterResponse = reader.readLine();
94+
String clusterResponse = reader.readLine();
9695

97-
if (clusterResponse.startsWith("0")) {
98-
System.out.println("Connected to cluster.");
99-
} else {
100-
throw new InvalidAuthenticationException("Could not authenticate to cluster");
101-
}
96+
if (clusterResponse.startsWith("0")) {
97+
System.out.println("Connected to cluster.");
98+
} else {
99+
throw new InvalidAuthenticationException("Could not authenticate to cluster");
100+
}
102101

103102
}
104103

readme.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
## CursusDB Java Native Client Package
22
### Quick Start
3-
Add the package
4-
```
5-
package cursusdbjava;
6-
```
73

84
```
9-
// Construct client connection to cluster
10-
// host, port, database user, database user password, tls enabled
11-
CursusDB.Client client = new CursusDB.Client("0.0.0.0",7681, "u", "p", false);
5+
package com.cursusdb.java;
6+
7+
import java.io.IOException;
8+
9+
class Test {
10+
public static void main(String[] args) {
11+
12+
CursusDB.Client client = new CursusDB.Client("0.0.0.0",7681, "db-user-username", "db-user-password", false);
1213
1314
1415
try {
15-
// Connect
16+
1617
client.Connect();
1718
1819
} catch (IOException | CursusDB.Client.InvalidAuthenticationException e) {
1920
throw new RuntimeException(e);
2021
}
2122
2223
try {
23-
// Query database
24-
String response = client.Query("select * from users;");
24+
25+
String response = client.Query("ping;");
2526
2627
System.out.println(response);
2728
@@ -30,10 +31,12 @@ package cursusdbjava;
3031
}
3132
3233
try {
33-
// Close client connection
3434
client.Close();
35-
3635
} catch (IOException e) {
3736
throw new RuntimeException(e);
3837
}
38+
39+
40+
}
41+
}
3942
```

test.java

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

0 commit comments

Comments
 (0)