-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native query support for reactive repositories (#42)
o. Added support for running native queries on reactive repos. o. Added new unit tests for reactive native queries.
- Loading branch information
1 parent
9614e0c
commit df8bc9f
Showing
7 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...ain/java/com/oracle/nosql/spring/data/repository/query/ReactiveStringBasedNosqlQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*- | ||
* Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Universal Permissive License v 1.0 as shown at | ||
* https://oss.oracle.com/licenses/upl/ | ||
*/ | ||
|
||
package com.oracle.nosql.spring.data.repository.query; | ||
|
||
import com.oracle.nosql.spring.data.core.ReactiveNosqlOperations; | ||
import com.oracle.nosql.spring.data.core.query.NosqlQuery; | ||
import com.oracle.nosql.spring.data.core.query.StringQuery; | ||
import com.oracle.nosql.spring.data.repository.Query; | ||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider; | ||
|
||
import static com.oracle.nosql.spring.data.repository.query.StringBasedNosqlQuery.hasAmbiguousProjectionFlags; | ||
|
||
public class ReactiveStringBasedNosqlQuery extends AbstractReactiveNosqlQuery { | ||
private final String query; | ||
|
||
private final boolean isCountQuery; | ||
private final boolean isExistsQuery; | ||
private final boolean isDeleteQuery; | ||
|
||
public ReactiveStringBasedNosqlQuery(NosqlQueryMethod method, | ||
ReactiveNosqlOperations operations, | ||
QueryMethodEvaluationContextProvider evaluationContextProvider) { | ||
this(method.getAnnotatedQuery(), method, operations, | ||
evaluationContextProvider); | ||
} | ||
|
||
public ReactiveStringBasedNosqlQuery(String query, | ||
NosqlQueryMethod method, | ||
ReactiveNosqlOperations operations, | ||
QueryMethodEvaluationContextProvider evaluationContextProvider) { | ||
super(method, operations); | ||
this.query = query; | ||
if (method.hasAnnotatedQuery()) { | ||
Query queryAnnotation = method.getQueryAnnotation(); | ||
isCountQuery = queryAnnotation.count(); | ||
isExistsQuery = queryAnnotation.exists(); | ||
isDeleteQuery = queryAnnotation.delete(); | ||
if (hasAmbiguousProjectionFlags(isCountQuery, isExistsQuery, | ||
isDeleteQuery)) { | ||
throw new IllegalArgumentException( | ||
String.format("Manually defined query for %s cannot be a " + | ||
"count and exists or delete query at the same time!", | ||
method)); | ||
} | ||
} else { | ||
isCountQuery = false; | ||
isExistsQuery = false; | ||
isDeleteQuery = false; | ||
} | ||
} | ||
|
||
@Override | ||
protected NosqlQuery createQuery(NosqlParameterAccessor accessor) { | ||
return new StringQuery(getQueryMethod(), query, accessor); | ||
} | ||
|
||
@Override | ||
protected boolean isDeleteQuery() { | ||
return isDeleteQuery; | ||
} | ||
|
||
@Override | ||
protected boolean isExistsQuery() { | ||
return isExistsQuery; | ||
} | ||
|
||
@Override | ||
protected boolean isCountQuery() { | ||
return isCountQuery; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters