ydb-platform / yoj-project

YDB ORM for Java (YOJ) is a lightweight ORM for immutable entities. It has native support for YDB and is battle-tested.
Apache License 2.0
13 stars 12 forks source link

Move YdbRepository start behavior from YdbRepository constructor to separate method #58

Closed lavrukov closed 7 months ago

lavrukov commented 7 months ago

YdbRepository in the constructor establishes a connection to the database, because it is impossible to separate the stages of object initialization and start.

It seems that what is needed here is a factory object which will create a SessionManager and return a Repository

nvamelichev commented 7 months ago

:zany_face: This is an unexpected change in YDB SDK v2, constructing a GrpcTransport immediately establishes a GRPC connection:

    public GrpcTransport build() {
        YdbTransportImpl impl = new YdbTransportImpl(this);
        try {
            impl.init();

We might just add a Guava Suppliers.memoize() for GrpcTransport and SessionManager in YdbRepository to make initialization lazy, as it was in repository-ydb-v1.

nvamelichev commented 7 months ago

:arrow_right: See PR with lazy initialization here: https://github.com/ydb-platform/yoj-project/pull/61

nvamelichev commented 7 months ago

Fixed, the fix will appear in 2.2.11.