Skip to content
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

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

lavrukov
Copy link
Contributor

@lavrukov lavrukov commented Dec 4, 2024

No description provided.

@lavrukov lavrukov force-pushed the table-refactoring-rem-find branch 3 times, most recently from fe00e12 to b8abd43 Compare December 4, 2024 09:07
@lavrukov lavrukov force-pushed the table-refactoring-rem-find branch from b8abd43 to e6fd1d3 Compare December 4, 2024 09:08
@lavrukov lavrukov requested review from g-sg-v and nvamelichev and removed request for g-sg-v December 4, 2024 09:09
Copy link
Collaborator

@nvamelichev nvamelichev left a 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

@@ -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);
Copy link
Collaborator

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);
Copy link
Collaborator

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());
Copy link
Collaborator

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

Copy link
Contributor Author

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 :)

@@ -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));
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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?

@lavrukov lavrukov merged commit 0bee8ca into main Dec 4, 2024
1 check passed
@lavrukov lavrukov deleted the table-refactoring-rem-find branch December 4, 2024 20:50
nvamelichev pushed a commit that referenced this pull request Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants