Skip to content

Commit

Permalink
Reformat code & optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Oct 4, 2024
1 parent b3d253d commit b6fce28
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 87 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/polypheny/jdbc/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,21 @@ PreparedStatementSignature prepareIndexedStatement( PrepareStatementRequest msg,
return completeSynchronously( req, timeout ).getPreparedStatementSignature();
}


public PreparedStatementSignature prepareNamedStatement( PrepareStatementRequest msg, int timeout ) throws PrismInterfaceServiceException {
Request.Builder req = newMessage();
req.setPrepareIndexedStatementRequest( msg );
return completeSynchronously( req, timeout ).getPreparedStatementSignature();
}



StatementResult executeIndexedStatement( ExecuteIndexedStatementRequest msg, int timeout ) throws PrismInterfaceServiceException {
Request.Builder req = newMessage();
req.setExecuteIndexedStatementRequest( msg );
return completeSynchronously( req, timeout ).getStatementResult();
}


public StatementResult executeNamedStatement( ExecuteNamedStatementRequest msg, int timeout ) throws PrismInterfaceServiceException {
Request.Builder req = newMessage();
req.setExecuteNamedStatementRequest( msg );
Expand Down Expand Up @@ -471,4 +472,5 @@ CloseResultResponse closeResult( CloseResultRequest msg, int timeout ) throws Pr
req.setCloseResultRequest( msg );
return completeSynchronously( req, timeout ).getCloseResultResponse();
}

}
32 changes: 20 additions & 12 deletions src/main/java/org/polypheny/jdbc/multimodel/GraphResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.polypheny.jdbc.multimodel;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
Expand All @@ -41,29 +40,30 @@ public class GraphResult extends Result implements Iterable<PolyGraphElement> {
private final List<PolyGraphElement> elements;



public GraphResult( Frame frame, PolyStatement polyStatement ) {
super( ResultType.GRAPH );
this.polyStatement= polyStatement;
this.polyStatement = polyStatement;
this.isFullyFetched = frame.getIsLast();
this.elements = new ArrayList<>();
addGraphElements(frame.getGraphFrame());
addGraphElements( frame.getGraphFrame() );
}


private void addGraphElements( GraphFrame graphFrame ) {
if (graphFrame.getNodesCount() > 0) {
graphFrame.getNodesList().forEach( n -> elements.add( new PolyNode(n) ) );
if ( graphFrame.getNodesCount() > 0 ) {
graphFrame.getNodesList().forEach( n -> elements.add( new PolyNode( n ) ) );
return;
}
if (graphFrame.getEdgesCount() > 0) {
graphFrame.getEdgesList().forEach( n -> elements.add( new PolyEdge(n) ) );
if ( graphFrame.getEdgesCount() > 0 ) {
graphFrame.getEdgesList().forEach( n -> elements.add( new PolyEdge( n ) ) );
return;
}
if (graphFrame.getPathsCount() > 0) {
graphFrame.getPathsList().forEach( n -> elements.add( new PolyPath(n) ) );
if ( graphFrame.getPathsCount() > 0 ) {
graphFrame.getPathsList().forEach( n -> elements.add( new PolyPath( n ) ) );
}
}


private void fetchMore() throws PrismInterfaceServiceException {
int id = polyStatement.getStatementId();
int timeout = getPolyphenyConnection().getTimeout();
Expand All @@ -78,6 +78,7 @@ private void fetchMore() throws PrismInterfaceServiceException {
addGraphElements( frame.getGraphFrame() );
}


private PolyConnection getPolyphenyConnection() {
return polyStatement.getConnection();
}
Expand All @@ -87,12 +88,18 @@ private PrismInterfaceClient getPrismInterfaceClient() {
return getPolyphenyConnection().getPrismInterfaceClient();
}


@Override
public Iterator<PolyGraphElement> iterator() {return new GraphElementIterator();}
public Iterator<PolyGraphElement> iterator() {
return new GraphElementIterator();
}


class GraphElementIterator implements Iterator<PolyGraphElement> {

int index = -1;


@Override
public boolean hasNext() {
if ( index + 1 >= elements.size() ) {
Expand All @@ -108,15 +115,16 @@ public boolean hasNext() {
return index + 1 < elements.size();
}


@Override
public PolyGraphElement next() {
if ( !hasNext() ) {
throw new NoSuchElementException( "There are no more graph elements" );
}
return elements.get( ++index );
}
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@Getter
public class RelationalColumnMetadata {

private final int columnIndex;
private final boolean isNullable;
private final int length;
Expand All @@ -31,6 +32,7 @@ public class RelationalColumnMetadata {
private final String protocolTypeName;
private final int scale;


public RelationalColumnMetadata( ColumnMeta columnMeta ) {
this.columnIndex = columnMeta.getColumnIndex();
this.isNullable = columnMeta.getIsNullable();
Expand All @@ -41,4 +43,5 @@ public RelationalColumnMetadata( ColumnMeta columnMeta ) {
this.protocolTypeName = columnMeta.getTypeMeta().getProtoValueType().name();
this.scale = columnMeta.getScale();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Getter;
import org.polypheny.jdbc.PrismInterfaceErrors;
import org.polypheny.jdbc.PrismInterfaceServiceException;
import org.polypheny.prism.ColumnMeta;

public class RelationalMetadata {

private List<RelationalColumnMetadata> columnMetas;
private Map<String, Integer> columnIndexes;

Expand All @@ -35,6 +35,7 @@ public RelationalMetadata( List<ColumnMeta> columnMetadata ) {

}


public RelationalColumnMetadata getColumnMeta( int columnIndex ) throws PrismInterfaceServiceException {
try {
return columnMetas.get( columnIndex );
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/polypheny/jdbc/types/PolyEdge.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PolyEdge extends PolyGraphElement {
private final String target;
private final EdgeDirection direction;


public PolyEdge( ProtoEdge protoEdge ) {
super();
this.id = protoEdge.getId();
Expand All @@ -43,6 +44,7 @@ public PolyEdge( ProtoEdge protoEdge ) {
this.direction = EdgeDirection.valueOf( protoEdge.getDirection().name() );
}


enum EdgeDirection {
LEFT_TO_RIGHT,
RIGHT_TO_LEFT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PolyGraphElement extends HashMap<String, TypedValue> {
protected String name;
protected List<String> labels;


public <T> T unwrap( Class<T> aClass ) throws PrismInterfaceServiceException {
if ( aClass.isInstance( this ) ) {
return aClass.cast( this );
Expand Down
43 changes: 0 additions & 43 deletions src/main/java/org/polypheny/jdbc/types/TypedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -1467,47 +1467,4 @@ private static PolyInterval getInterval( ProtoInterval interval ) {
return new PolyInterval( interval.getMonths(), interval.getMilliseconds() );
}


@Override
public String toString() {
if ( isSerialized ) {
deserialize();
}
switch ( valueCase ) {
case BOOLEAN:
return "" + booleanValue;
case INTEGER:
return "" + integerValue;
case LONG:
return "" + bigintValue;
case BIG_DECIMAL:
return "" + bigDecimalValue;
case FLOAT:
return "" + floatValue;
case DOUBLE:
return "" + doubleValue;
case DATE:
return "" + dateValue;
case TIME:
return "" + timeValue;
case TIMESTAMP:
return "" + timestampValue;
case INTERVAL:
return "" + otherValue;
case STRING:
return varcharValue;
case BINARY:
return "BINARY";
case NULL:
return "NULL";
case LIST:
return "LIST";
case FILE:
return "FILE";
case DOCUMENT:
return "DOCUMENT";
}
return "";
}

}
10 changes: 5 additions & 5 deletions src/main/java/org/polypheny/jdbc/utils/ProtoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public static List<ProtoValue> serializeParameterList( List<TypedValue> values )
}


public static Map<String, ProtoValue> serializeParameterMap(Map<String, TypedValue> values) {
return values.entrySet().stream().collect(Collectors.toMap(
public static Map<String, ProtoValue> serializeParameterMap( Map<String, TypedValue> values ) {
return values.entrySet().stream().collect( Collectors.toMap(
Entry::getKey,
value -> {
try {
return value.getValue().serialize();
} catch (Exception e) {
throw new RuntimeException("Serialization failed", e);
} catch ( Exception e ) {
throw new RuntimeException( "Serialization failed", e );
}
}
));
) );
}

}
2 changes: 1 addition & 1 deletion src/test/java/org/polypheny/jdbc/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void testMetaDataGetProceduresNotStrict() throws SQLException {

@Test
@Disabled
// This test fails due to syntax definitions missing for some of the functions on the server side (operator registry).
// This test fails due to syntax definitions missing for some of the functions on the server side (operator registry).
void testMetaDataGetFunctionsNotStrict() throws SQLException {
try ( Connection con = DriverManager.getConnection( "jdbc:polypheny://127.0.0.1:20590?strict=false", "pa", "" ) ) {
DatabaseMetaData meta = con.getMetaData();
Expand Down
39 changes: 20 additions & 19 deletions src/test/java/org/polypheny/jdbc/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,47 @@ public class Demo {
private static String namespace = "public";
private static Connection con;

public static void main(String[] args) {

public static void main( String[] args ) {
try {
con = DriverManager.getConnection("jdbc:polypheny://127.0.0.1:20590?strict=false", "pa", "");
if (!con.isWrapperFor(PolyConnection.class)) {
System.out.println("Driver must support unwrapping to PolyConnection");
con = DriverManager.getConnection( "jdbc:polypheny://127.0.0.1:20590?strict=false", "pa", "" );
if ( !con.isWrapperFor( PolyConnection.class ) ) {
System.out.println( "Driver must support unwrapping to PolyConnection" );
return;
}
Scanner scanner = new Scanner(System.in);
Scanner scanner = new Scanner( System.in );

while (true) {
while ( true ) {
printPrompt();
String input = scanner.nextLine();

if (input.startsWith("lng ")) {
language = input.substring(4).trim();
System.out.println("Language set to " + language);
} else if (input.startsWith("ns ")) {
namespace = input.substring(3).trim();
System.out.println("Namespace set to " + namespace);
} else if (input.equals("exit")) {
if ( input.startsWith( "lng " ) ) {
language = input.substring( 4 ).trim();
System.out.println( "Language set to " + language );
} else if ( input.startsWith( "ns " ) ) {
namespace = input.substring( 3 ).trim();
System.out.println( "Namespace set to " + namespace );
} else if ( input.equals( "exit" ) ) {
break;
} else {
if (language == null || namespace == null) {
System.out.println("Please set both language and namespace before executing a statement.");
if ( language == null || namespace == null ) {
System.out.println( "Please set both language and namespace before executing a statement." );
continue;
}
String statement = input.trim();
executeStatement(namespace, language, statement);
executeStatement( namespace, language, statement );
}
}

scanner.close();
} catch (Exception e) {
} catch ( Exception e ) {
e.printStackTrace();
} finally {
try {
if (con != null && !con.isClosed()) {
if ( con != null && !con.isClosed() ) {
con.close();
}
} catch (Exception e) {
} catch ( Exception e ) {
e.printStackTrace();
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/org/polypheny/jdbc/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.polypheny.jdbc.multimodel.Result.ResultType;
import org.polypheny.jdbc.types.PolyDocument;
import org.polypheny.jdbc.types.PolyGraphElement;
import org.polypheny.jdbc.types.PolyNode;

public class QueryTest {

Expand Down Expand Up @@ -117,6 +116,7 @@ public void mqlDataRetrievalTest() {
}
}


@Test
public void simpleCypherNodesTest() {
try ( Connection connection = TestHelper.getConnection() ) {
Expand All @@ -128,8 +128,8 @@ public void simpleCypherNodesTest() {
assertEquals( ResultType.GRAPH, result.getResultType() );
GraphResult graphResult = result.unwrap( GraphResult.class );
for ( PolyGraphElement element : graphResult ) {
element.get("name");
element.get("year_joined");
element.get( "name" );
element.get( "year_joined" );
element.getLabels();
element.getId();
}
Expand All @@ -138,6 +138,7 @@ public void simpleCypherNodesTest() {
}
}


@Test
public void simpleCypherPropertyTest() {
try ( Connection connection = TestHelper.getConnection() ) {
Expand All @@ -151,11 +152,12 @@ public void simpleCypherPropertyTest() {
assertEquals( ResultType.RELATIONAL, result.getResultType() );
RelationalResult relationalResult = result.unwrap( RelationalResult.class );
for ( PolyRow row : relationalResult ) {
row.get(0);
row.get("c.name");
row.get( 0 );
row.get( "c.name" );
}
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
}

}
Loading

0 comments on commit b6fce28

Please sign in to comment.