org.springframework.data.repository.query.RepositoryQuery Java Examples
The following examples show how to use
org.springframework.data.repository.query.RepositoryQuery.
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: 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 #2
Source File: MybatisQueryCreationListener.java From spring-data-mybatis with Apache License 2.0 | 6 votes |
@Override public void onCreation(RepositoryQuery query) { if (query instanceof PartTreeMybatisQuery) { new MybatisPartTreeMapperBuilder(configuration, mappingContext.getPersistentEntity( query.getQueryMethod().getEntityInformation().getJavaType()), (PartTreeMybatisQuery) query).build(); } else if (query instanceof SimpleMybatisQuery) { new MybatisSimpleQueryMapperBuilder(configuration, mappingContext.getPersistentEntity( query.getQueryMethod().getEntityInformation().getJavaType()), (SimpleMybatisQuery) query).build(); } }
Example #3
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 #4
Source File: AclJpaQuery.java From strategy-spring-security-acl with Apache License 2.0 | 6 votes |
private void installAclProxy(RepositoryQuery query) { CriteriaQuery<?> criteriaQuery = criteriaQuery(); if (criteriaQuery == null) { logger.warn("Unable to install ACL Jpa Specification for method '" + method + "' and query: " + query + " ; query methods with Pageable/Sort are not (yet) supported"); return; } this.cachedCriteriaQuery = criteriaQuery; this.root = root(cachedCriteriaQuery); try { this.aclPredicateTargetSource = installAclPredicateTargetSource(); } catch (Exception e) { logger.warn( "Unable to install ACL Jpa Specification for method '" + method + "' and query: " + query + " : " + getStackTrace(e)); } }
Example #5
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 #6
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 #7
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 #8
Source File: RepositoryQueryTest.java From sdn-rx with Apache License 2.0 | 6 votes |
@Test void shouldSelectStringBasedNeo4jQueryForNamedQuery() { final String namedQueryName = "TestEntity.findAllByANamedQuery"; when(namedQueries.hasQuery(namedQueryName)).thenReturn(true); when(namedQueries.getQuery(namedQueryName)).thenReturn("MATCH (n) RETURN n"); final Neo4jQueryLookupStrategy lookupStrategy = new Neo4jQueryLookupStrategy(mock(Neo4jOperations.class), mock( Neo4jMappingContext.class), QueryMethodEvaluationContextProvider.DEFAULT); RepositoryQuery query = lookupStrategy .resolveQuery(queryMethod("findAllByANamedQuery"), TEST_REPOSITORY_METADATA, PROJECTION_FACTORY, namedQueries); assertThat(query).isInstanceOf(StringBasedNeo4jQuery.class); }
Example #9
Source File: KeyValueRepositoryFactory.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
/** * @param key * @param evaluationContextProvider * @param keyValueOperations * @param queryCreator * @since 1.1 */ public KeyValueQueryLookupStrategy(@Nullable Key key, QueryMethodEvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) { Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!"); Assert.notNull(queryCreator, "Query creator type must not be null!"); Assert.notNull(repositoryQueryType, "RepositoryQueryType type must not be null!"); this.evaluationContextProvider = evaluationContextProvider; this.keyValueOperations = keyValueOperations; this.queryCreator = queryCreator; this.repositoryQueryType = repositoryQueryType; }
Example #10
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 #11
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 #12
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 #13
Source File: AggregateQueryProvider2Test.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class}) public void testCreateAggregateQuery(String methodName) throws Exception { NonReactiveAggregateQuerySupportingRepositoryFactory factory = new NonReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations, queryExecutor); Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider); assertTrue(lookupStrategy.isPresent(), "Expecting non null lookupStrategy"); Method method = TestAggregateRepository22.class.getMethod(methodName); RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class); ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory(); RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null); assertNotNull(query); Object object = query.execute(new Object[0]); assertNull(object); }
Example #14
Source File: ReactiveAggregateQueryProviderTest.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class}) public void testCreateAggregateQuery(String methodName) throws Exception { ReactiveAggregateQuerySupportingRepositoryFactory factory = new ReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations, queryExecutor); Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider); Assert.isTrue(lookupStrategy.isPresent(), "Lookup strategy must not be null"); Method method = ReactiveTestAggregateRepository22.class.getMethod(methodName); RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(ReactiveTestAggregateRepository22.class); ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory(); RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null); assertNotNull(query); Object object = query.execute(new Object[0]); assertNull(object); }
Example #15
Source File: KeyValueRepositoryFactoryBeanUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
@Test // DATAKV-123 @SuppressWarnings("unchecked") public void createsRepositoryFactory() { Class<? extends AbstractQueryCreator<?, ?>> creatorType = (Class<? extends AbstractQueryCreator<?, ?>>) mock( AbstractQueryCreator.class).getClass(); Class<? extends RepositoryQuery> queryType = mock(KeyValuePartTreeQuery.class).getClass(); factoryBean.setQueryCreator(creatorType); factoryBean.setKeyValueOperations(mock(KeyValueOperations.class)); factoryBean.setQueryType(queryType); assertThat(factoryBean.createRepositoryFactory()).isNotNull(); }
Example #16
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 #17
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 #18
Source File: KeyValueRepositoryFactory.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
/** * Creates a new {@link KeyValueRepositoryFactory} for the given {@link KeyValueOperations} and * {@link AbstractQueryCreator}-type. * * @param keyValueOperations must not be {@literal null}. * @param queryCreator must not be {@literal null}. * @param repositoryQueryType must not be {@literal null}. * @since 1.1 */ public KeyValueRepositoryFactory(KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) { Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!"); Assert.notNull(queryCreator, "Query creator type must not be null!"); Assert.notNull(repositoryQueryType, "RepositoryQueryType type must not be null!"); this.queryCreator = queryCreator; this.keyValueOperations = keyValueOperations; this.context = keyValueOperations.getMappingContext(); this.repositoryQueryType = repositoryQueryType; }
Example #19
Source File: AclJpaQuery.java From strategy-spring-security-acl with Apache License 2.0 | 5 votes |
public AclJpaQuery(Method method, RepositoryQuery query, Class<?> domainType, EntityManager em, JpaSpecProvider<Object> jpaSpecProvider) { this.method = method; this.query = query; this.domainType = domainType; this.em = em; this.jpaSpecProvider = jpaSpecProvider; installAclProxy(query); }
Example #20
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 #21
Source File: AclJpaRepositoryFactoryBean.java From strategy-spring-security-acl with Apache License 2.0 | 5 votes |
private RepositoryQuery wrapQuery(Method method, RepositoryMetadata metadata, RepositoryQuery query) { if (method.getDeclaredAnnotation(NoAcl.class) != null) { // no acl applied here return query; } if (query instanceof PartTreeJpaQuery) { query = new AclJpaQuery(method, query, metadata.getDomainType(), em, jpaSpecProvider); } else { logger.warn( "Unsupported query type for method '{}' > ACL Jpa Specification not installed: {}", method, query.getClass()); } return query; }
Example #22
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 #23
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 #24
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 #25
Source File: MyTitleRepositoryFactoryBean.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
@Override protected MyTitleRepositoryFactory createRepositoryFactory(KeyValueOperations operations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) { return new MyTitleRepositoryFactory(operations, queryCreator, hazelcastInstance); }
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: RepositoryQueryTest.java From sdn-rx with Apache License 2.0 | 5 votes |
@Test void shouldSelectStringBasedNeo4jQuery() { final Neo4jQueryLookupStrategy lookupStrategy = new Neo4jQueryLookupStrategy(mock(Neo4jOperations.class), mock( Neo4jMappingContext.class), QueryMethodEvaluationContextProvider.DEFAULT); RepositoryQuery query = lookupStrategy .resolveQuery(queryMethod("annotatedQueryWithValidTemplate"), TEST_REPOSITORY_METADATA, PROJECTION_FACTORY, namedQueries); assertThat(query).isInstanceOf(StringBasedNeo4jQuery.class); }
Example #28
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 #29
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 #30
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() ); }