Skip to content

Commit

Permalink
Merge pull request #28 from ydb-platform/develop
Browse files Browse the repository at this point in the history
Update to new version of Java SDK
  • Loading branch information
alex268 authored Mar 28, 2024
2 parents 35ce0d2 + 59b6bc6 commit 952de6e
Show file tree
Hide file tree
Showing 27 changed files with 992 additions and 177 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
- develop
pull_request:
type: [opened, reopened, edited]
type: [opened, reopened, edited, synchronize]

jobs:
build:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Checkout YDB Java SDK
if: ${{ env.NEED_SDK }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-sdk
ref: develop
Expand All @@ -61,7 +61,7 @@ jobs:

- name: Checkout YDB YC Auth Provider
if: ${{ env.NEED_SDK }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-yc
ref: develop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.auth.AuthProvider;
import tech.ydb.auth.TokenAuthProvider;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -25,23 +24,20 @@ public static void main(String[] args) {
// Access token credentials
AuthProvider authProvider = new TokenAuthProvider(accessToken);

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {
try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions auth/anonymous_credentials/src/main/java/tech/ydb/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.auth.AuthProvider;
import tech.ydb.auth.NopAuthProvider;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -22,24 +21,20 @@ public static void main(String[] args) {
// Anonymous credentials
AuthProvider authProvider = NopAuthProvider.INSTANCE;

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {

try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions auth/environ/src/main/java/tech/ydb/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.auth.AuthProvider;
import tech.ydb.auth.iam.CloudAuthHelper;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -22,24 +21,20 @@ public static void main(String[] args) {
// Construct authProvider from environment variables
AuthProvider authProvider = CloudAuthHelper.getAuthProviderFromEnviron();

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {

try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions auth/metadata_credentials/src/main/java/tech/ydb/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.auth.AuthProvider;
import tech.ydb.auth.iam.CloudAuthHelper;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -23,24 +22,20 @@ public static void main(String[] args) {
// Use metadata credentials
AuthProvider authProvider = CloudAuthHelper.getMetadataAuthProvider();

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {

try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.auth.AuthProvider;
import tech.ydb.auth.iam.CloudAuthHelper;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -23,24 +22,20 @@ public static void main(String[] args) {

AuthProvider authProvider = CloudAuthHelper.getServiceAccountFileAuthProvider(saKeyFile);

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {

try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions auth/static_credentials/src/main/java/tech/ydb/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

package tech.ydb.example;

import java.util.concurrent.CompletableFuture;

import tech.ydb.core.Result;
import tech.ydb.core.auth.StaticCredentials;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
import tech.ydb.table.query.DataQueryResult;
import tech.ydb.table.result.ResultSetReader;
import tech.ydb.table.transaction.TxControl;

Expand All @@ -29,23 +27,20 @@ public static void main(String[] args) {
// Use credentials auth provider with username and password
StaticCredentials authProvider = new StaticCredentials(username, password);

try ( GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider) // Or this method could not be called at all
try (GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build()) {
try ( TableClient tableClient = TableClient
.newClient(transport)
.build()) {
try (TableClient tableClient = TableClient.newClient(transport).build()) {
SessionRetryContext retryCtx = SessionRetryContext.create(tableClient).build();

retryCtx.supplyResult(session -> {
ResultSetReader rsReader = session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
.join().getValue().getResultSet(0);
DataQueryResult dataQueryResult = retryCtx.supplyResult(
session -> session.executeDataQuery("SELECT 1;", TxControl.serializableRw())
).join().getValue();

rsReader.next();
ResultSetReader rsReader = dataQueryResult.getResultSet(0);
while (rsReader.next()) {
System.out.println(rsReader.getColumn(0).getInt32());

return CompletableFuture.completedFuture(Result.success(Boolean.TRUE));
}).join();
}
}
}
}
Expand Down
34 changes: 29 additions & 5 deletions basic_example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<name>YDB Basic Example</name>
<description>Simple example of usage Java SDK for YDB</description>

<properties>
<junit5.version>5.10.1</junit5.version>
</properties>

<dependencies>
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-table</artifactId>
</dependency>
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-topic</artifactId>
</dependency>
<dependency>
<groupId>tech.ydb.auth</groupId>
<artifactId>yc-auth-provider</artifactId>
Expand All @@ -30,6 +30,19 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<dependency>
<groupId>tech.ydb.test</groupId>
<artifactId>ydb-junit5-support</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -52,7 +65,18 @@
<mainClass>tech.ydb.example.App</mainClass>
</manifest>
</archive>
</configuration>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
<YDB_ANONYMOUS_CREDENTIALS>1</YDB_ANONYMOUS_CREDENTIALS>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Loading

0 comments on commit 952de6e

Please sign in to comment.