Skip to content

Commit

Permalink
Add compilation and version retrieval from prism package
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasHafner committed May 5, 2024
1 parent 0c12ae8 commit 0aa4601
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 1,644 deletions.
27 changes: 26 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def protobufVersion = "3.23.4"


dependencies {
implementation 'org.polypheny:prism:1.0'

// https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: protobufVersion

Expand All @@ -65,6 +67,7 @@ dependencies {

// --- Test Compile ---
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.10.2')

// https://mvnrepository.com/artifact/org.mockito/mockito-core
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.11.0'
}
Expand Down Expand Up @@ -119,6 +122,7 @@ jar {
attributes 'Version': project.version
}
}

/*
task sourcesJar(type: Jar, dependsOn: classes) {
classifier "sources"
Expand All @@ -128,6 +132,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
classifier "javadoc"
from javadoc.destinationDir
}*/

shadowJar {
archiveClassifier = ''
mergeServiceFiles() // merge the META-INF/services/java.sql.Driver files
Expand All @@ -138,7 +143,7 @@ shadowJar {
relocate 'com.google', 'org.polypheny.dependency.com.google'
relocate 'javax', 'org.polypheny.dependency.javax'
relocate 'org.checkerframework', 'org.polypheny.dependency.org.checkerframework'
relocate 'org.polypheny.db.protointerface.proto', 'org.polypheny.jdbc.proto' // Prevents Polypheny-DB from using this during tests
relocate 'org.polypheny.prism', 'org.polypheny.jdbc.proto' // Prevents Polypheny-DB from using this during tests
}

assemble.dependsOn shadowJar
Expand Down Expand Up @@ -256,3 +261,23 @@ idea {
}
}
}


task copyProtoFiles {
def subDir = 'org/polypheny/prism'
copy {
configurations.runtimeClasspath.files.each { file ->
if (file.name.startsWith('prism')) {
from zipTree(file).matching { include "$subDir/**" }
into 'src/main/proto'
eachFile { fcp ->
fcp.path = fcp.path.replaceFirst("^$subDir", '')
}
includeEmptyDirs false
}
}
}
}


generateProto.dependsOn copyProtoFiles
20 changes: 9 additions & 11 deletions src/main/java/org/polypheny/jdbc/PrismInterfaceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import org.polypheny.jdbc.properties.PolyphenyConnectionProperties;
import org.polypheny.jdbc.transport.PlainTransport;
import org.polypheny.jdbc.transport.Transport;
import org.polypheny.jdbc.types.TypedValue;
import org.polypheny.jdbc.utils.CallbackQueue;
import org.polypheny.jdbc.utils.ProtoUtils;
import org.polypheny.jdbc.utils.VersionUtil;
import org.polypheny.prism.ClientInfoProperties;
import org.polypheny.prism.ClientInfoPropertiesRequest;
import org.polypheny.prism.CloseResultRequest;
Expand Down Expand Up @@ -66,17 +73,8 @@
import org.polypheny.prism.TableTypesRequest;
import org.polypheny.prism.Type;
import org.polypheny.prism.TypesRequest;
import org.polypheny.jdbc.properties.PolyphenyConnectionProperties;
import org.polypheny.jdbc.transport.PlainTransport;
import org.polypheny.jdbc.transport.Transport;
import org.polypheny.jdbc.types.TypedValue;
import org.polypheny.jdbc.utils.CallbackQueue;
import org.polypheny.jdbc.utils.ProtoUtils;
import org.polypheny.jdbc.utils.VersionUtil;

public class PrismInterfaceClient {
private static final int MAJOR_API_VERSION = 2;
private static final int MINOR_API_VERSION = 0;

private final Transport con;
private final RpcService rpc;
Expand Down Expand Up @@ -114,8 +112,8 @@ public ConnectionResponse register( PolyphenyConnectionProperties connectionProp
Optional.ofNullable( connectionProperties.getUsername() ).ifPresent( requestBuilder::setUsername );
Optional.ofNullable( connectionProperties.getPassword() ).ifPresent( requestBuilder::setPassword );
requestBuilder
.setMajorApiVersion( MAJOR_API_VERSION )
.setMinorApiVersion( MINOR_API_VERSION )
.setMajorApiVersion( VersionUtil.getMAJOR_API_VERSION() )
.setMinorApiVersion( VersionUtil.getMINOR_API_VERSION() )
//.setClientUuid( clientUUID )
.setConnectionProperties( buildConnectionProperties( connectionProperties ) );
ConnectionResponse connectionResponse = rpc.connect( requestBuilder.build(), timeout );
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/polypheny/jdbc/utils/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package org.polypheny.jdbc.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -28,15 +30,37 @@
public class VersionUtil {

private static final String VERSION_FILE = "version.properties";
private static final String API_VERSION_PROPERTIES = "prism-api-version-properties.properties";
private static final Properties properties = new Properties();

@Getter
private static final int MAJOR_API_VERSION;
@Getter
private static final int MINOR_API_VERSION;
@Getter
private static final String API_VERSION_STRING;


static {
try ( InputStream inputStream = VersionUtil.class.getClassLoader().getResourceAsStream( VERSION_FILE ) ) {
properties.load( inputStream );
} catch ( IOException e ) {
log.error( "Error loading version.properties", e );
}

Properties properties = new Properties();
try (InputStream inputStream = VersionUtil.class.getClassLoader().getResourceAsStream(API_VERSION_PROPERTIES)) {
if (inputStream != null) {
properties.load(inputStream);
API_VERSION_STRING = properties.getProperty("version");
MAJOR_API_VERSION = Integer.parseInt(properties.getProperty("majorVersion"));
MINOR_API_VERSION = Integer.parseInt(properties.getProperty("minorVersion"));
} else {
throw new FileNotFoundException("The prism api version properties could not be found.");
}
} catch (IOException e) {
throw new RuntimeException("Error loading API version properties", e);
}
}


Expand Down
66 changes: 0 additions & 66 deletions src/main/proto/connection_requests.proto

This file was deleted.

52 changes: 0 additions & 52 deletions src/main/proto/connection_responses.proto

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/proto/document_frame.proto

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/proto/error.proto

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/proto/graph_frame.proto

This file was deleted.

Loading

0 comments on commit 0aa4601

Please sign in to comment.