org.springframework.data.repository.core.NamedQueries Java Examples
The following examples show how to use
org.springframework.data.repository.core.NamedQueries.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveNeo4jQueryLookupStrategy.java From sdn-rx with Apache License 2.0 | 6 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { Neo4jQueryMethod queryMethod = new ReactiveNeo4jQueryMethod(method, metadata, factory); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { return ReactiveStringBasedNeo4jQuery .create(neo4jOperations, mappingContext, evaluationContextProvider, queryMethod, namedQueries.getQuery(namedQueryName)); } else if (queryMethod.hasQueryAnnotation()) { return ReactiveStringBasedNeo4jQuery .create(neo4jOperations, mappingContext, evaluationContextProvider, queryMethod); } else { return ReactivePartTreeNeo4jQuery.create(neo4jOperations, mappingContext, queryMethod); } }
Example #2
Source File: ArangoRepositoryFactory.java From spring-data with Apache License 2.0 | 6 votes |
@Override public RepositoryQuery resolveQuery( final Method method, final RepositoryMetadata metadata, final ProjectionFactory factory, final NamedQueries namedQueries) { final ArangoQueryMethod queryMethod = new ArangoQueryMethod(method, metadata, factory); final String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { final String namedQuery = namedQueries.getQuery(namedQueryName); return new StringBasedArangoQuery(namedQuery, queryMethod, operations); } else if (queryMethod.hasAnnotatedQuery()) { return new StringBasedArangoQuery(queryMethod, operations); } else { return new DerivedArangoQuery(queryMethod, operations); } }
Example #3
Source File: SolrRepositoryFactory.java From dubbox with Apache License 2.0 | 6 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { SolrQueryMethod queryMethod = new SolrQueryMethod(method, metadata, entityInformationCreator); String namedQueryName = queryMethod.getNamedQueryName(); SolrOperations solrOperations = selectSolrOperations(metadata); if (namedQueries.hasQuery(namedQueryName)) { String namedQuery = namedQueries.getQuery(namedQueryName); return new StringBasedSolrQuery(namedQuery, queryMethod, solrOperations); } else if (queryMethod.hasAnnotatedQuery()) { return new StringBasedSolrQuery(queryMethod, solrOperations); } else { return new PartTreeSolrQuery(queryMethod, solrOperations); } }
Example #4
Source File: Neo4jQueryLookupStrategy.java From sdn-rx with Apache License 2.0 | 6 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { Neo4jQueryMethod queryMethod = new Neo4jQueryMethod(method, metadata, factory); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { return StringBasedNeo4jQuery.create(neo4jOperations, mappingContext, evaluationContextProvider, queryMethod, namedQueries.getQuery(namedQueryName)); } else if (queryMethod.hasQueryAnnotation()) { return StringBasedNeo4jQuery.create(neo4jOperations, mappingContext, evaluationContextProvider, queryMethod); } else { return PartTreeNeo4jQuery.create(neo4jOperations, mappingContext, queryMethod); } }
Example #5
Source File: KeyValueRepositoryFactory.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { QueryMethod queryMethod = new QueryMethod(method, metadata, factory); Constructor<? extends KeyValuePartTreeQuery> constructor = (Constructor<? extends KeyValuePartTreeQuery>) ClassUtils .getConstructorIfAvailable(this.repositoryQueryType, QueryMethod.class, QueryMethodEvaluationContextProvider.class, KeyValueOperations.class, Class.class); Assert.state(constructor != null, String.format( "Constructor %s(QueryMethod, EvaluationContextProvider, KeyValueOperations, Class) not available!", ClassUtils.getShortName(this.repositoryQueryType))); return BeanUtils.instantiateClass(constructor, queryMethod, evaluationContextProvider, this.keyValueOperations, this.queryCreator); }
Example #6
Source File: SpannerQueryLookupStrategy.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { SpannerQueryMethod queryMethod = createQueryMethod(method, metadata, factory); Class<?> entityType = getEntityType(queryMethod); boolean isDml = queryMethod.getQueryAnnotation() != null && queryMethod.getQueryAnnotation().dmlStatement(); if (queryMethod.hasAnnotatedQuery()) { Query query = queryMethod.getQueryAnnotation(); return createSqlSpannerQuery(entityType, queryMethod, query.value(), isDml); } else if (namedQueries.hasQuery(queryMethod.getNamedQueryName())) { String sql = namedQueries.getQuery(queryMethod.getNamedQueryName()); return createSqlSpannerQuery(entityType, queryMethod, sql, isDml); } return createPartTreeSpannerQuery(entityType, queryMethod); }
Example #7
Source File: EbeanQueryLookupStrategy.java From spring-data-ebean with Apache License 2.0 | 6 votes |
@Override protected RepositoryQuery resolveQuery(EbeanQueryMethod method, EbeanServer ebeanServer, NamedQueries namedQueries) { RepositoryQuery query = EbeanQueryFactory.INSTANCE.fromQueryAnnotation(method, ebeanServer, evaluationContextProvider); if (null != query) { return query; } String name = method.getNamedQueryName(); if (namedQueries.hasQuery(name)) { return EbeanQueryFactory.INSTANCE.fromMethodWithQueryString(method, ebeanServer, namedQueries.getQuery(name), evaluationContextProvider); } query = NamedEbeanQuery.lookupFrom(method, ebeanServer); if (null != query) { return query; } throw new IllegalStateException( String.format("Did neither find a NamedQuery nor an annotated query for method %s!", method)); }
Example #8
Source File: NonReactiveAggregateQuerySupportingRepositoryFactory.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { if (!isAggregateQueryAnnotated(method)) { return parentQueryLookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, namedQueries); } else { return new NonReactiveAggregateMongoQuery(method, repositoryMetadata, mongoOperations, projectionFactory, queryExecutor); } }
Example #9
Source File: SimpleDbQueryLookupStrategy.java From spring-data-simpledb with MIT License | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { SimpleDbQueryMethod queryMethod; if(SimpleDbQueryMethod.isAnnotatedQuery(method)) { queryMethod = new SimpleDbQueryMethod(method, metadata, simpleDbOperations.getSimpleDb() .getSimpleDbDomain()); } else { queryMethod = new SimpleDbPartTreeQueryMethod(method, metadata, simpleDbOperations.getSimpleDb() .getSimpleDbDomain()); } return SimpleDbRepositoryQuery.fromQueryAnnotation(queryMethod, simpleDbOperations); }
Example #10
Source File: ReactiveAggregateQuerySupportingRepositoryFactory.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { if (!isAggregateQueryAnnotated(method)) { return parentQueryLookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, namedQueries); } else { return new ReactiveAggregateMongoQuery(method, repositoryMetadata, mongoOperations, projectionFactory, queryExecutor); } }
Example #11
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
@Override protected RepositoryQuery resolveQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate, NamedQueries namedQueries) { if (method.isAnnotatedQuery()) { return new SimpleMybatisQuery(method, sqlSessionTemplate); } throw new IllegalStateException(String.format( "Did neither find a NamedQuery nor an annotated query for method %s!", method)); }
Example #12
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
@Override protected RepositoryQuery resolveQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate, NamedQueries namedQueries) { try { return lookupStrategy.resolveQuery(method, sqlSessionTemplate, namedQueries); } catch (IllegalStateException e) { return createStrategy.resolveQuery(method, sqlSessionTemplate, namedQueries); } }
Example #13
Source File: AclJpaRepositoryFactoryBean.java From strategy-spring-security-acl with Apache License 2.0 | 5 votes |
/** * @since Spring data JPA 1.10.0 */ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { QueryLookupStrategy queryLookupStrategy = Factory.super.getQueryLookupStrategy(key, evaluationContextProvider); RepositoryQuery query = queryLookupStrategy.resolveQuery(method, metadata, factory, namedQueries); return wrapQuery(method, metadata, query); }
Example #14
Source File: GenericQueryLookupStrategy.java From genericdao with Artistic License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { if (method.getAnnotation(MybatisQuery.class) != null) { log.info(metadata.getRepositoryInterface().getName()+"."+method.getName()+" 为mybatis方法。 "); return new MybatisRepositoryQuery(sqlSessionTemplate , method , metadata) ; } else { return jpaQueryLookupStrategy.resolveQuery(method, metadata, namedQueries); } }
Example #15
Source File: IgniteRepositoryFactory.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected QueryLookupStrategy getQueryLookupStrategy(final QueryLookupStrategy.Key key, EvaluationContextProvider evaluationCtxProvider) { return new QueryLookupStrategy() { @Override public RepositoryQuery resolveQuery(final Method mtd, final RepositoryMetadata metadata, final ProjectionFactory factory, NamedQueries namedQueries) { final Query annotation = mtd.getAnnotation(Query.class); if (annotation != null) { String qryStr = annotation.value(); if (key != Key.CREATE && StringUtils.hasText(qryStr)) return new IgniteRepositoryQuery(metadata, new IgniteQuery(qryStr, isFieldQuery(qryStr), IgniteQueryGenerator.getOptions(mtd)), mtd, factory, ignite.getOrCreateCache(repoToCache.get(metadata.getRepositoryInterface()))); } if (key == QueryLookupStrategy.Key.USE_DECLARED_QUERY) throw new IllegalStateException("To use QueryLookupStrategy.Key.USE_DECLARED_QUERY, pass " + "a query string via org.apache.ignite.springdata.repository.config.Query annotation."); return new IgniteRepositoryQuery(metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd, factory, ignite.getOrCreateCache(repoToCache.get(metadata.getRepositoryInterface()))); } }; }
Example #16
Source File: HazelcastQueryLookupStrategy.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
/** * <p> * Use {@link HazelcastPartTreeQuery} for resolving queries against Hazelcast repositories. * </P> * * @param Method, the query method * @param RepositoryMetadata, not used * @param ProjectionFactory, not used * @param NamedQueries, not used * @return A mechanism for querying Hazelcast repositories */ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { HazelcastQueryMethod queryMethod = new HazelcastQueryMethod(method, metadata, projectionFactory); if (queryMethod.hasAnnotatedQuery()) { return new StringBasedHazelcastRepositoryQuery(queryMethod, hazelcastInstance); } return new HazelcastPartTreeQuery(queryMethod, evaluationContextProvider, this.keyValueOperations, this.queryCreator); }
Example #17
Source File: DynamoDBQueryLookupStrategy.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@Override protected <T, ID extends Serializable> RepositoryQuery createDynamoDBQuery(Method method, RepositoryMetadata metadata, Class<T> entityClass, Class<ID> idClass, NamedQueries namedQueries) { try { return new PartTreeDynamoDBQuery<T, ID>(dynamoDBOperations, new DynamoDBQueryMethod<T, ID>(method, metadata)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Could not create query metamodel for method %s!", method.toString()), e); } }
Example #18
Source File: FirestoreQueryLookupStrategy.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { // In this method we usually decide if the query method is a PartTree or an annotated // @Query method. // There is no choice in Firestore. We only have PartTree. return new PartTreeFirestoreQuery( new FirestoreQueryMethod(method, repositoryMetadata, projectionFactory), this.firestoreTemplate, this.firestoreTemplate.getMappingContext(), this.firestoreTemplate.getClassMapper() ); }
Example #19
Source File: CosmosRepositoryFactory.java From spring-data-cosmosdb with MIT License | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { final CosmosQueryMethod queryMethod = new CosmosQueryMethod(method, metadata, factory); Assert.notNull(queryMethod, "queryMethod must not be null!"); Assert.notNull(dbOperations, "dbOperations must not be null!"); return new PartTreeCosmosQuery(queryMethod, dbOperations); }
Example #20
Source File: ReactiveCosmosRepositoryFactory.java From spring-data-cosmosdb with MIT License | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { final ReactiveCosmosQueryMethod queryMethod = new ReactiveCosmosQueryMethod(method, metadata, factory); Assert.notNull(queryMethod, "queryMethod must not be null!"); Assert.notNull(cosmosOperations, "dbOperations must not be null!"); return new PartTreeReactiveCosmosQuery(queryMethod, cosmosOperations); }
Example #21
Source File: DatastoreQueryLookupStrategyTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void resolveSqlQueryTest() { String queryName = "fakeNamedQueryName"; String query = "fake query"; when(this.queryMethod.getNamedQueryName()).thenReturn(queryName); Query queryAnnotation = mock(Query.class); when(this.queryMethod.getQueryAnnotation()).thenReturn(queryAnnotation); NamedQueries namedQueries = mock(NamedQueries.class); Parameters parameters = mock(Parameters.class); Mockito.<Parameters>when(this.queryMethod.getParameters()) .thenReturn(parameters); when(parameters.getNumberOfParameters()).thenReturn(1); when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> { Parameter param = mock(Parameter.class); when(param.getName()).thenReturn(Optional.of("tag")); Mockito.<Class>when(param.getType()).thenReturn(Object.class); return param; }); when(namedQueries.hasQuery(eq(queryName))).thenReturn(true); when(namedQueries.getQuery(eq(queryName))).thenReturn(query); this.datastoreQueryLookupStrategy.resolveQuery(null, null, null, namedQueries); verify(this.datastoreQueryLookupStrategy, times(1)).createGqlDatastoreQuery( eq(Object.class), same(this.queryMethod), eq(query)); }
Example #22
Source File: SpannerQueryLookupStrategyTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void resolveSqlQueryTest() { String queryName = "fakeNamedQueryName"; String query = "fake query"; when(this.queryMethod.getNamedQueryName()).thenReturn(queryName); NamedQueries namedQueries = mock(NamedQueries.class); Parameters parameters = mock(Parameters.class); // @formatter:off Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters); // @formatter:off when(parameters.getNumberOfParameters()).thenReturn(1); when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> { Parameter param = mock(Parameter.class); when(param.getName()).thenReturn(Optional.of("tag")); // @formatter:off Mockito.<Class>when(param.getType()).thenReturn(Object.class); // @formatter:on return param; }); when(namedQueries.hasQuery(eq(queryName))).thenReturn(true); when(namedQueries.getQuery(eq(queryName))).thenReturn(query); this.spannerQueryLookupStrategy.resolveQuery(null, null, null, namedQueries); verify(this.spannerQueryLookupStrategy, times(1)).createSqlSpannerQuery( eq(Object.class), same(this.queryMethod), eq(query), eq(false)); }
Example #23
Source File: SpannerQueryLookupStrategyTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void resolvePartTreeQueryTest() { String queryName = "fakeNamedQueryName"; when(this.queryMethod.getNamedQueryName()).thenReturn(queryName); NamedQueries namedQueries = mock(NamedQueries.class); when(namedQueries.hasQuery(any())).thenReturn(false); this.spannerQueryLookupStrategy.resolveQuery(null, null, null, namedQueries); verify(this.spannerQueryLookupStrategy, times(1)) .createPartTreeSpannerQuery(eq(Object.class), same(this.queryMethod)); }
Example #24
Source File: AggregateQuerySupportingRepositoryFactory.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { if (!isAggregateQueryAnnotated(method)) { return parentQueryLookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, namedQueries); } else { return new AggregateMongoQuery(method, repositoryMetadata, mongoOperations, projectionFactory, queryExecutor); } }
Example #25
Source File: EbeanQueryLookupStrategy.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@Override protected RepositoryQuery resolveQuery(EbeanQueryMethod method, EbeanServer ebeanServer, NamedQueries namedQueries) { try { return new PartTreeEbeanQuery(method, ebeanServer); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( String.format("Could not create query metamodel for method %s!", method.toString()), e); } }
Example #26
Source File: EbeanQueryLookupStrategy.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@Override protected RepositoryQuery resolveQuery(EbeanQueryMethod method, EbeanServer ebeanServer, NamedQueries namedQueries) { try { return lookupStrategy.resolveQuery(method, ebeanServer, namedQueries); } catch (IllegalStateException e) { return createStrategy.resolveQuery(method, ebeanServer, namedQueries); } }
Example #27
Source File: TemplateQueryLookupStrategy.java From spring-data-jpa-extra with Apache License 2.0 | 5 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { if (method.getAnnotation(TemplateQuery.class) == null) { return jpaQueryLookupStrategy.resolveQuery(method, metadata, factory, namedQueries); } else { return new FreemarkerTemplateQuery(new JpaQueryMethod(method, metadata, factory, extractor), entityManager); } }
Example #28
Source File: EbeanQueryLookupStrategy.java From spring-data-ebean with Apache License 2.0 | 4 votes |
@Override public final RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { return resolveQuery(new EbeanQueryMethod(method, metadata, factory), ebeanServer, namedQueries); }
Example #29
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 4 votes |
@Override protected RepositoryQuery resolveQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate, NamedQueries namedQueries) { return new PartTreeMybatisQuery(method, sqlSessionTemplate); }
Example #30
Source File: CrateRepositoryFactory.java From spring-data-crate with Apache License 2.0 | 4 votes |
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { //TODO: implement this method return null; }