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

Query builders refactoring / rewrite #2973

Merged
merged 6 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<!-- files="DefaultBeanContext.java|BeanDefinitionWriter.java|DefaultHttpClient.java"/> -->

<suppress checks="MissingJavadocType" files=".*doc-examples.*" />
<suppress checks="FileLength" files=".*AbstractSqlLikeQueryBuilder.*" />
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.micronaut.data.cosmos.operations;

import io.micronaut.core.annotation.Internal;
import io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder;
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder;
import io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2;
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder2;
import io.micronaut.data.model.runtime.PreparedQuery;
import io.micronaut.data.model.runtime.QueryParameterBinding;
import io.micronaut.data.model.runtime.StoredQuery;
Expand Down Expand Up @@ -47,16 +47,16 @@ public CosmosSqlPreparedQuery(PreparedQuery<E, R> preparedQuery) {
@Override
public void prepare(E entity) {
if (isExpandableQuery()) {
SqlQueryBuilder queryBuilder = sqlStoredQuery.getQueryBuilder();
SqlQueryBuilder2 queryBuilder = sqlStoredQuery.getQueryBuilder();
StringBuilder q = new StringBuilder(sqlStoredQuery.getExpandableQueryParts()[0]);
int queryParamIndex = 1;
int inx = 1;
for (QueryParameterBinding parameter : sqlStoredQuery.getQueryBindings()) {
AbstractSqlLikeQueryBuilder.Placeholder placeholder = queryBuilder.formatParameter(inx++);
AbstractSqlLikeQueryBuilder2.Placeholder placeholder = queryBuilder.formatParameter(inx++);
if (!parameter.isExpandable()) {
q.append(placeholder.getName());
q.append(placeholder.name());
} else {
appendExpandedParameter(q, parameter, placeholder.getName());
appendExpandedParameter(q, parameter, placeholder.name());
}
q.append(sqlStoredQuery.getExpandableQueryParts()[queryParamIndex++]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.micronaut.data.cosmos.operations;

import io.micronaut.core.annotation.Internal;
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder;
import io.micronaut.data.model.query.builder.sql.SqlQueryBuilder2;
import io.micronaut.data.model.runtime.RuntimePersistentEntity;
import io.micronaut.data.model.runtime.StoredQuery;
import io.micronaut.data.runtime.operations.internal.sql.DefaultSqlStoredQuery;
Expand All @@ -41,7 +41,7 @@ final class CosmosSqlStoredQuery<E, R> extends DefaultSqlStoredQuery<E, R> {
* @param queryBuilder The query builder
* @param update The update statement. In this case list of properties to update via API.
*/
public CosmosSqlStoredQuery(StoredQuery<E, R> storedQuery, RuntimePersistentEntity<E> runtimePersistentEntity, SqlQueryBuilder queryBuilder,
public CosmosSqlStoredQuery(StoredQuery<E, R> storedQuery, RuntimePersistentEntity<E> runtimePersistentEntity, SqlQueryBuilder2 queryBuilder,
String update) {
super(storedQuery, runtimePersistentEntity, queryBuilder);
this.update = update;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import io.micronaut.data.cosmos.common.CosmosEntity;
import io.micronaut.data.cosmos.common.CosmosUtils;
import io.micronaut.data.cosmos.config.CosmosDatabaseConfiguration;
import io.micronaut.data.document.model.query.builder.CosmosSqlQueryBuilder;
import io.micronaut.data.document.model.query.builder.CosmosSqlQueryBuilder2;
import io.micronaut.data.event.EntityEventListener;
import io.micronaut.data.exceptions.EmptyResultException;
import io.micronaut.data.exceptions.NonUniqueResultException;
Expand Down Expand Up @@ -136,7 +136,7 @@ public final class DefaultReactiveCosmosRepositoryOperations extends AbstractRep

private final CosmosSerde cosmosSerde;
private final CosmosAsyncDatabase cosmosAsyncDatabase;
private CosmosSqlQueryBuilder defaultCosmosSqlQueryBuilder;
private CosmosSqlQueryBuilder2 defaultCosmosSqlQueryBuilder;
private final CosmosDiagnosticsProcessor cosmosDiagnosticsProcessor;
private final boolean queryMetricsEnabled;

Expand Down Expand Up @@ -176,7 +176,7 @@ public <E, R> PreparedQuery<E, R> decorate(PreparedQuery<E, R> preparedQuery) {
@Override
public <E, R> StoredQuery<E, R> decorate(MethodInvocationContext<?, ?> context, StoredQuery<E, R> storedQuery) {
if (defaultCosmosSqlQueryBuilder == null) {
defaultCosmosSqlQueryBuilder = new CosmosSqlQueryBuilder(context.getAnnotationMetadata());
defaultCosmosSqlQueryBuilder = new CosmosSqlQueryBuilder2(context.getAnnotationMetadata());
}
String update = null;
if (storedQuery instanceof QueryResultStoredQuery<E, R> queryResultStoredQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.micronaut.data.azure
import groovy.transform.CompileStatic
import io.micronaut.annotation.processing.test.AbstractTypeElementSpec
import io.micronaut.context.ApplicationContext
import io.micronaut.core.annotation.AnnotationMetadata
import io.micronaut.core.annotation.NonNull
import io.micronaut.data.azure.entities.CosmosBook
import io.micronaut.data.azure.entities.Family
Expand Down Expand Up @@ -151,8 +152,8 @@ interface MyRepository {
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.registered = TRUE) ORDER BY family_.registeredDate DESC,family_.lastName ASC',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.registered = TRUE)',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.registered = TRUE AND family_.registered = TRUE)',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.lastName IN (@p1))',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.lastName NOT IN (@p1))',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.lastName IN (@p1,@p2,@p3))',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (family_.lastName NOT IN (@p1,@p2,@p3))',
'SELECT DISTINCT VALUE family_ FROM family family_ WHERE (ARRAY_CONTAINS(family_.tags,@p1,true))'
]
}
Expand Down Expand Up @@ -303,7 +304,7 @@ interface MyRepository {
}

private static String getQuery(PersistentEntityCriteriaQuery<Object> query) {
return ((QueryResultPersistentEntityCriteriaQuery) query).buildQuery(queryBuilder).getQuery()
return ((QueryResultPersistentEntityCriteriaQuery) query).buildQuery(AnnotationMetadata.EMPTY_METADATA, queryBuilder).getQuery()
}

@CompileStatic
Expand Down
2 changes: 2 additions & 0 deletions data-document-model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ dependencies {
api mn.micronaut.aop
api projects.micronautDataModel
api mnSerde.micronaut.serde.api

compileOnly(libs.managed.jakarta.persistence.api)
}
Loading
Loading