-
Notifications
You must be signed in to change notification settings - Fork 24
YDB Java v2 Migration Guide
Alexandr Gorshenin edited this page Nov 21, 2022
·
2 revisions
YDB Java SDK V2 has some major changed compared to YDB Java SDK v1.
This guide contains summary of changes and a set of instructions to apply the to your V1 application.
- https://github.com/ydb-platform/ydb-java-sdk - Main SDK repository
- https://github.com/ydb-platform/ydb-java-examples - Examples and demo apps
- https://github.com/ydb-platform/ydb-java-yc - Authentication provider to connect to Managed YDB instances in Yandex Cloud
Before | After |
<!-- YDB Java SDK v1 -->
<dependency>
<groupId>com.yandex.ydb</groupId>
<artifactId>ydb-sdk-core</artifactId>
<version>1.14.8</version>
</dependency>
<dependency>
<groupId>com.yandex.ydb</groupId>
<artifactId>ydb-sdk-table</artifactId>
<version>1.14.8</version>
</dependency>
<!-- If you want to use Yandex Cloud authentication provider -->
<dependency>
<groupId>com.yandex.ydb</groupId>
<artifactId>ydb-sdk-auth-iam</artifactId>
<version>1.14.8</version>
</dependency> |
<!-- YDB Java SDK v2 -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-core</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-table</artifactId>
<version>2.0.1</version>
</dependency>
<!-- If you want to use Yandex Cloud authentication provider -->
<dependency>
<groupId>tech.ydb.auth</groupId>
<artifactId>yc-auth-provider</artifactId>
<version>2.0.1</version>
</dependency> |
As part of the migration, you can simply run the autocorrect script (be careful if you are using package com.yandex.ydb
for your own classes)
$ find . -type f \( -name '*.java' -or -name '*.xml' -or -name '*.proto' \) -exec sed -i 's#com.yandex.ydb#tech.ydb#g' {} + ;
- The
RpcTransport
class has been removed, useGrpcTransport
instead - The
GrpcTableRpc
class has been removed, no longer needed - The
TableClient::newClient(GrpcTableRpc)
method has been changed toTableClient::newClient(GrpcTransport)
Note that since there is noownTransport
method, you must manually closeGrpcTransport
Before | After |
// Creating of transport
GrpcTransport transport = ...;
// Creating of table client
TableClient tableClient = TableClient
.newClient(GrpcTableRpc.ownTransport(transport))
.build());
...
// We don't need to close transport
// because client owns it and closes it
tableClient.close(); |
// Creating of transport
GrpcTransport transport = ...;
// Creating of table client
TableClient tableClient = TableClient
.newClient(transport)
.build());
...
tableClient.close();
// We must close transport because table
// client uses it but doesn't own it
transport.close(); |
- The
TableClient.Builder::queryCacheSize(int size)
method has been removed, just remove all its calls - Similarly, method
invalidateQueryCache()
has been removed from %%Session%% - In turn, in the
ExecuteDataQuerySettings
class, caching on the server is enabled by default, and there is no need for theenableQueryCache()
method. If you still need to disable caching, you can use thedisableQueryCache()
method
- Method of manually creating a session
TableClient.createSession(CreateSessionSettings)
has been removed - Method of getting a session from a pool has been renamed from
TableClient.getOrCreateSession(Duration)
toTableClient.createSession(Duration)
- In the
Session
class, instead of three methodsclose()
,close(CloseSessionSettings)
andrelease()
, only oneclose()
has been left, which returns the session to pool for further use, and it has been changed to comply with theAutoCloseable
interface - without return value - The
getDisconnectedCount()
method has been removed from theSessionPoolStats
session pool statistics class - the new session pool doesn't store disconnected sessions, but immediately closes them on the server - If for some reason you do not need to use a session pool, you can use the
SimpleTableClient
class, compatible withTableClient
. Its methodcreateSession(Duration)
creates a session on server and methodSession.close()
removes the session from server.
- The
Status
class now contains three members - a code of operation, an optionalissue
list and an optional cost of the requestconsumedRu
- The
Status.expect(String)
method has been renamed toStatus.expectSuccess(String)
- The
UnexpectedResultException
exception instead of storing the code of operation and theissue
list - now containsstatus
. Accordingly, instead of the methodsgetStatusCode()
andgetIssues()
you should usegetStatus().getCode()
andgetStatus().getIssues()
- Similarly, in
Result
, the methodsgetCode()
andtoStatus()
have been replaced with the methodgetStatus()
, and the methodexpect(String)
has been replaced with the methodgetValue()
- The
Result
class hasn't methodcast()
anymore. You can use themap(null)
method to cast one error result to another.
- Some types have been renamed:
String
->Bytes
,Utf8
->Text
,Float32
->Float
,Float64
->Double
- Primitive types have become enum constants instead of static methods
PrimitiveType.uint64() -> PrimitiveType.Uint64
PrimitiveType.timestamp() -> PrimitiveType.Timestamp
PrimitiveType.string() -> PrimitiveType.Bytes
PrimitiveType.utf8() -> PrimitiveType.Text
PrimitiveType.float64() -> PrimitiveType.Double
- Methods of creating values are now prefixed with 'new'
PrimitiveValue.int32(value) -> PrimitiveValue.newInt32(value)
PrimitiveValue.timestamp(value) -> PrimitiveValue.newTimestamp(value)
PrimitiveValue.string(value) -> PrimitiveValue.newBytes(value)
PrimitiveValue.utf8(value) -> PrimitiveValue.newText(value)
PrimitiveValue.float64(value) -> PrimitiveValue.newDouble(value)
Now it works correctly with scaled numbers. When migrating, make sure that you work correctly with values of this type.
The current partitioning settings can be found in TableDescription
obtained from describeTable
We recommend to use the setTimeout
method instead.