-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove static find() method from YqlStatement #102
Conversation
fe00e12
to
b8abd43
Compare
b8abd43
to
e6fd1d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM overall, this PR needs some minor changes
repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java
Outdated
Show resolved
Hide resolved
@@ -888,12 +889,13 @@ public void complexIdLtYsingYqlPredicate() { | |||
|
|||
private void executeQuery(String expectSqlQuery, List<IndexedEntity> expectRows, | |||
Collection<? extends YqlStatementPart<?>> query) { | |||
var statement = YqlStatement.find(IndexedEntity.class, query); | |||
EntitySchema<IndexedEntity> schema = EntitySchema.of(IndexedEntity.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: var schema
is preferable here, I think
@@ -350,6 +352,8 @@ private CompletableFuture<Result<DataQueryResult>> convertEntity(List<Complex> c | |||
} | |||
|
|||
private Params convertId(Id id) { | |||
return YdbConverter.convertToParams(YqlStatement.find(Complex.class).toQueryParameters(id)); | |||
EntitySchema<Complex> schema = EntitySchema.of(Complex.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: var schema
is preferable here, I think
@@ -154,7 +156,9 @@ private <T extends Entity<T>> YdbRepository.Query<?> insert(T p) { | |||
|
|||
@SuppressWarnings("unchecked") | |||
private <T extends Entity<T>> YdbRepository.Query<?> find(T p) { | |||
return new YdbRepository.Query<>(YqlStatement.find((Class<T>) p.getClass()), p.getId()); | |||
EntitySchema<T> schema = EntitySchema.of((Class<T>) p.getClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: var schema
is preferable here, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer var only in new statements. It's little bit more symbols, but more understandable in RO mode, i think :)
repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java
Show resolved
Hide resolved
repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java
Show resolved
Hide resolved
@@ -223,14 +225,17 @@ public T find(Entity.Id<T> id) { | |||
throw new IllegalArgumentException("Cannot use partial id in find method"); | |||
} | |||
return executor.getTransactionLocal().firstLevelCache().get(id, __ -> { | |||
List<T> res = postLoad(executor.execute(YqlStatement.find(type), id)); | |||
var statement = new FindYqlStatement<>(schema, schema); | |||
List<T> res = postLoad(executor.execute(statement, id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: maybe also var res
here?
return res.isEmpty() ? null : res.get(0); | ||
}); | ||
} | ||
|
||
@Override | ||
public <V extends View> V find(Class<V> viewType, Entity.Id<T> id) { | ||
List<V> res = executor.execute(YqlStatement.find(type, viewType), id); | ||
ViewSchema<V> viewSchema = ViewSchema.of(viewType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: maybe also var res
and var viewSchema
here?
@@ -385,15 +391,19 @@ public <V extends View> List<V> find(Class<V> viewType, YqlStatementPart<?> part | |||
} | |||
|
|||
public <V extends View> List<V> find(Class<V> viewType, Collection<? extends YqlStatementPart<?>> parts, boolean distinct) { | |||
return executor.execute(YqlStatement.find(type, viewType, distinct, parts), parts); | |||
ViewSchema<V> viewSchema = ViewSchema.of(viewType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: maybe also var viewSchema
here?
} | ||
|
||
public <ID extends Entity.Id<T>> List<ID> findIds(YqlStatementPart<?> part, YqlStatementPart<?>... otherParts) { | ||
return findIds(toList(part, otherParts)); | ||
} | ||
|
||
private <ID extends Entity.Id<T>> List<ID> findIds(Collection<? extends YqlStatementPart<?>> parts) { | ||
return executor.execute(YqlStatement.findIds(type, parts), parts); | ||
EntityIdSchema<ID> idSchema = EntityIdSchema.ofEntity(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: maybe also var idSchema
here?
@@ -450,7 +460,8 @@ public void delete(Entity.Id<T> id) { | |||
* @param <ID> entity ID type | |||
*/ | |||
public <ID extends Id<T>> void migrate(ID id) { | |||
List<T> foundRaw = executor.execute(YqlStatement.find(type), id); | |||
var statement = new FindYqlStatement<>(schema, schema); | |||
List<T> foundRaw = executor.execute(statement, id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: style: maybe also var foundRaw
here?
repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexander Lavrukov <[email protected]>
No description provided.