Skip to content

Commit

Permalink
Fix typo and reduce duplication in QueryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Apr 4, 2024
1 parent 2880782 commit f81a8e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RelationalResult extends Result implements Iterable<PolyRow> {


public RelationalResult( Frame frame, PolyStatement polyStatement ) throws PrismInterfaceServiceException {
super( ResultType.DOCUMENT );
super( ResultType.RELATIONAL );
this.polyStatement = polyStatement;
this.isFullyFetched = frame.getIsLast();
this.rows = new ArrayList<>();
Expand Down
42 changes: 24 additions & 18 deletions src/test/java/org/polypheny/jdbc/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
public class QueryTest {

private static final String MQL_LANGUAGE_NAME = "mongo";
private static final String TEST_DATA = "db.test.insertOne({name: \"John Doe\", age: 20, subjects: [\"Math\", \"Physics\", \"Chemistry\"], address: {street: \"123 Main St\", city: \"Anytown\", state: \"CA\", postalCode: \"12345\"}, graduationYear: 2023});";
private static final String TEST_QUERY = "db.emps.find({});";


@Test
public void thisOneWorks() throws ClassNotFoundException, SQLException {
private Connection getConnection() throws ClassNotFoundException, SQLException {
final String DB_URL = "jdbc:polypheny://localhost:20590";
final String USER = "pa";
final String PASS = "";

Class.forName( "org.polypheny.jdbc.PolyphenyDriver" );

return DriverManager.getConnection( DB_URL, USER, PASS );
}


@Test
public void thisOneWorks() throws ClassNotFoundException, SQLException {
try (
Connection connection = DriverManager.getConnection( DB_URL, USER, PASS );
Connection connection = getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery( "SELECT * FROM emps" )
) {
Expand All @@ -45,15 +49,23 @@ public void thisOneWorks() throws ClassNotFoundException, SQLException {


@Test
public void simpleMqlTest() throws ClassNotFoundException {

final String DB_URL = "jdbc:polypheny://localhost:20590";
final String USER = "pa";
final String PASS = "";
public void simpleRelationalTest() throws ClassNotFoundException {
try ( Connection connection = getConnection() ) {
if ( !connection.isWrapperFor( PolyConnection.class ) ) {
fail( "Driver must support unwrapping to PolyphenyConnection" );
}
PolyStatement polyStatement = connection.unwrap( PolyConnection.class ).createProtoStatement();
Result result = polyStatement.execute( "public", "sql", "SELECT* FROM emps" );
assertEquals( ResultType.RELATIONAL, result.getResultType() );
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
}

Class.forName( "org.polypheny.jdbc.PolyphenyDriver" );

try ( Connection connection = DriverManager.getConnection( DB_URL, USER, PASS ) ) {
@Test
public void simpleMqlTest() throws ClassNotFoundException {
try ( Connection connection = getConnection() ) {
if ( !connection.isWrapperFor( PolyConnection.class ) ) {
fail( "Driver must support unwrapping to PolyphenyConnection" );
}
Expand All @@ -68,13 +80,7 @@ public void simpleMqlTest() throws ClassNotFoundException {

@Test
public void mqlDataRetrievalTest() throws ClassNotFoundException {
final String DB_URL = "jdbc:polypheny://localhost:20590";
final String USER = "pa";
final String PASS = "";

Class.forName( "org.polypheny.jdbc.PolyphenyDriver" );

try ( Connection connection = DriverManager.getConnection( DB_URL, USER, PASS ) ) {
try ( Connection connection = getConnection() ) {
if ( !connection.isWrapperFor( PolyConnection.class ) ) {
fail( "Driver must support unwrapping to PolyphenyConnection" );
}
Expand Down

0 comments on commit f81a8e9

Please sign in to comment.