-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch pulls out Java code in separate standalone .java files.
- Loading branch information
Showing
6 changed files
with
82 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.sql.*; | ||
|
||
public class TestConnection { | ||
public static Connection getConnection() { | ||
Class.forName("org.postgresql.Driver"); | ||
|
||
String DB_URL = "jdbc:postgresql://"; | ||
DB_URL += System.getenv("PGHOST") + ":" + System.getenv("PGPORT"); | ||
DB_URL += "/?ssl=true"; | ||
DB_URL += "&sslcert=" + System.getenv("PGSSLCERT"); | ||
DB_URL += "&sslkey=key.pk8"; | ||
DB_URL += "&sslrootcert=/certs/ca.crt"; | ||
DB_URL += "&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory"; | ||
return DriverManager.getConnection(DB_URL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.sql.*; | ||
|
||
public class TestStatements { | ||
public static void runTests(Connection conn) throws Exception { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT 1, 2 > ?, ?::int, ?::string, ?::string, ?::string, ?::string, ?::string"); | ||
stmt.setInt(1, 3); | ||
stmt.setInt(2, 3); | ||
stmt.setBoolean(3, true); | ||
stmt.setLong(4, -4L); | ||
stmt.setFloat(5, 5.31f); | ||
stmt.setDouble(6, -6.21d); | ||
stmt.setShort(7, (short)7); | ||
|
||
ResultSet rs = stmt.executeQuery(); | ||
rs.next(); | ||
int a = rs.getInt(1); | ||
boolean b = rs.getBoolean(2); | ||
int c = rs.getInt(3); | ||
String d = rs.getString(4); | ||
String e = rs.getString(5); | ||
String f = rs.getString(6); | ||
String g = rs.getString(7); | ||
String h = rs.getString(8); | ||
if (a != 1 || b != false || c != 3 || !d.equals("true") || !e.equals("-4") || !f.startsWith("5.3") || !g.startsWith("-6.2") || !h.equals("7")) { | ||
throw new Exception("unexpected: round-trip of constants via SELECT does not preserve their value"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import java.sql.*; | ||
|
||
public class TestStatements { | ||
public static void runTests(Connection conn) throws Exception { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT 1, 2 > ?, ?::int"); | ||
stmt.setInt(1, 3); | ||
stmt.setString(2, "a"); // invalid because wrong type | ||
|
||
ResultSet rs = stmt.executeQuery(); | ||
rs.next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import java.sql.*; | ||
|
||
public class main { | ||
public static void main(String[] args) throws Exception { | ||
Connection conn = TestConnection.getConnection(); | ||
TestStatements.runTests(conn) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
set -uex | ||
|
||
cd acceptance/java/ | ||
|
||
# See: https://basildoncoder.com/blog/postgresql-jdbc-client-certificates.html | ||
openssl pkcs8 -topk8 -inform PEM -outform DER -in /certs/node.client.key -out key.pk8 -nocrypt | ||
|
||
export PATH=$PATH:/usr/lib/jvm/java-1.7-openjdk/bin | ||
|
||
cp -f "$1" TestConnection.java | ||
cp -f "$2" TestStatements.java | ||
|
||
javac main.java TestConnection.java TestStatements.java | ||
java -cp /postgres.jar:. main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters