/** * Creates a {@link QueryLookupStrategy} for the given {@link EntityManager} * and {@link Key}. * * @param em must not be {@literal null}. * @param key may be {@literal null}. * @param extractor must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @return */ public static QueryLookupStrategy create(Key key, EvaluationContextProvider evaluationContextProvider, SqlGenerator generator, NamedParameterJdbcTemplate template, RowMapper rowMapper, TableDescription tableDescription) { Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) { case CREATE: return new CreateQueryLookupStrategy(generator, template, rowMapper, tableDescription); case USE_DECLARED_QUERY: return new DeclaredQueryLookupStrategy(generator, template, rowMapper, tableDescription); case CREATE_IF_NOT_FOUND: return new CreateIfNotFoundQueryLookupStrategy(generator, template, rowMapper, tableDescription); default: throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key)); } }
/** * Creates a {@link QueryLookupStrategy} for the given {@link EbeanServer} and {@link Key}. * * @param ebeanServer must not be {@literal null}. * @param key may be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @return */ public static QueryLookupStrategy create(EbeanServer ebeanServer, Key key, EvaluationContextProvider evaluationContextProvider) { Assert.notNull(ebeanServer, "EbeanServer must not be null!"); Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) { case CREATE: return new CreateQueryLookupStrategy(ebeanServer); case USE_DECLARED_QUERY: return new DeclaredQueryLookupStrategy(ebeanServer, evaluationContextProvider); case CREATE_IF_NOT_FOUND: return new CreateIfNotFoundQueryLookupStrategy(ebeanServer, new CreateQueryLookupStrategy(ebeanServer), new DeclaredQueryLookupStrategy(ebeanServer, evaluationContextProvider)); default: throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key)); } }
public static QueryLookupStrategy create( MybatisMappingContext context, SqlSessionTemplate sqlSessionTemplate, Dialect dialect, Key key, EvaluationContextProvider evaluationContextProvider) { Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) { case CREATE: return new CreateQueryLookupStrategy(context, sqlSessionTemplate, dialect); case USE_DECLARED_QUERY: return new DeclaredQueryLookupStrategy(sqlSessionTemplate, evaluationContextProvider); case CREATE_IF_NOT_FOUND: return new CreateIfNotFoundQueryLookupStrategy( new CreateQueryLookupStrategy(context, sqlSessionTemplate, dialect), new DeclaredQueryLookupStrategy(sqlSessionTemplate, evaluationContextProvider)); default: throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key)); } }
/** * Creates a {@link QueryLookupStrategy} for the given * {@link DynamoDBMapper} and {@link Key}. * * @param dynamoDBOperations * @param key * @return */ public static QueryLookupStrategy create(DynamoDBOperations dynamoDBOperations, Key key) { if (key == null) { return new CreateQueryLookupStrategy(dynamoDBOperations); } switch (key) { case CREATE: return new CreateQueryLookupStrategy(dynamoDBOperations); case USE_DECLARED_QUERY: throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key)); case CREATE_IF_NOT_FOUND: return new CreateIfNotFoundQueryLookupStrategy(dynamoDBOperations); default: throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key)); } }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { QueryLookupStrategy queryLookupStrategy = GenericQueryLookupStrategy.create(entityManager , sqlSessionTemplate , key , extractor , evaluationContextProvider) ; return queryLookupStrategy ; }
@Override public QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { QueryLookupStrategy parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider); return new AggregateQueryLookupStrategy(parentQueryLookupStrategy); }
@Test(dataProvider = "queryMethods", expectedExceptions = {NullPointerException.class, IllegalArgumentException.class}) public void testCreateAggregateQuery(String methodName) throws Exception { AggregateQuerySupportingRepositoryFactory factory = new AggregateQuerySupportingRepositoryFactory(mongoOperations, queryExecutor); QueryLookupStrategy lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider); Method method = TestAggregateRepository22.class.getMethod(methodName); RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class); ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory(); RepositoryQuery query = lookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, null); assertNotNull(query); Object object = query.execute(new Object[0]); assertNull(object); }
/** * @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); }
/** {@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()))); } }; }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return JdbcQueryLookupStrategy.create(key, evaluationContextProvider, generator, template, rowMapper, tableDescription); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return new DocumentDbQueryLookupStrategy(dbOperations, evaluationContextProvider); }
public static QueryLookupStrategy create(EntityManager entityManager, SqlSessionTemplate sqlSessionTemplate , Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) { return new GenericQueryLookupStrategy(entityManager , sqlSessionTemplate , key , extractor , evaluationContextProvider); }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.of(new SnowdropQueryLookupStrategy()); }
public void setQueryLookupStrategyKey(QueryLookupStrategy.Key queryLookupStrategyKey) { this.queryLookupStrategyKey = queryLookupStrategyKey; }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key) { return new MongoQueryLookupStrategy(); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return new JdbcTemplateQueryLookupStrategy(beanFactory, configuration); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return new ObjectifyQueryLookupStrategy(key, evaluationContextProvider); }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.ofNullable(EbeanQueryLookupStrategy.create(ebeanServer, key, evaluationContextProvider)); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return MybatisQueryLookupStrategy.create(mappingContext, sessionTemplate, dialect, key, evaluationContextProvider); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return TemplateQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider); }
public static QueryLookupStrategy create(EntityManager entityManager, Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) { return new TemplateQueryLookupStrategy(entityManager, key, extractor, evaluationContextProvider); }
AggregateQueryLookupStrategy(QueryLookupStrategy parentQueryLookupStrategy) { this.parentQueryLookupStrategy = parentQueryLookupStrategy; }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return new AclQueryLookupStrategy(key, evaluationContextProvider); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(final Key key, final EvaluationContextProvider evaluationContextProvider) { return new MyBatisQueryLookupStrategy(mapperProvider, key); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key) { return new SolrQueryLookupStrategy(); }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.<QueryLookupStrategy> of(new GqQueryLookupStrategy(emf)); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return new CrateQueryLookupStrategy(); }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.of(new KeyValueQueryLookupStrategy(key, evaluationContextProvider, this.keyValueOperations, this.queryCreator, this.repositoryQueryType)); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key) { return DynamoDBQueryLookupStrategy.create(dynamoDBOperations, key); }
public static QueryLookupStrategy create(SimpleDbOperations simpleDbOperations, QueryLookupStrategy.Key key) { // TODO check in Spring data core key switching and their semantics (look in spring-data-jpa) return new SimpleDbQueryLookupStrategy(simpleDbOperations); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) { return SimpleDbQueryLookupStrategy.create(simpleDbOperations, key); }
/** * <P> * Required constructor, capturing arguments for use in {@link #resolveQuery}. * </P> * <P> * Assertions copied from {@link KayValueRepositoryFactory.KeyValueQUeryLookupStrategy} which this class essentially * duplicates. * </P> * * @param key Not used * @param evaluationContextProvider For evaluation of query expressions * @param keyValueOperations Bean to use for Key/Value operations on Hazelcast repos * @param queryCreator Likely to be {@link HazelcastQueryCreator} */ public HazelcastQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) { 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!"); this.evaluationContextProvider = evaluationContextProvider; this.keyValueOperations = keyValueOperations; this.queryCreator = queryCreator; }
/** * <P> * Ensure the mechanism for query evaluation is Hazelcast specific, as the original * {@link KeyValueRepositoryFactory.KeyValueQueryLookStrategy} does not function correctly for Hazelcast. * </P> */ @Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return new HazelcastQueryLookupStrategy(key, evaluationContextProvider, this.keyValueOperations, this.queryCreator); }