/** * 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 new {@link NativeEbeanQuery} encapsulating the query annotated on the given {@link EbeanQueryMethod}. * * @param method must not be {@literal null}. * @param ebeanServer must not be {@literal null}. * @param queryString must not be {@literal null} or empty. * @param evaluationContextProvider */ public NativeEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString, EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) { super(method, ebeanServer, queryString, evaluationContextProvider, parser); Parameters<?, ?> parameters = method.getParameters(); boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter(); boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable") || queryString.contains("#sort"); if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) { throw new InvalidEbeanQueryMethodException( "Cannot use native queries with dynamic sorting and/or pagination in method " + method); } }
/** * 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)); } }
/** * Creates a new {@link NativeEbeanUpdate} encapsulating the query annotated on the given {@link EbeanQueryMethod}. * * @param method must not be {@literal null}. * @param ebeanServer must not be {@literal null}. * @param queryString must not be {@literal null} or empty. * @param evaluationContextProvider */ public NativeEbeanUpdate(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString, EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) { super(method, ebeanServer, queryString, evaluationContextProvider, parser); Parameters<?, ?> parameters = method.getParameters(); boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter(); boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable") || queryString.contains("#sort"); if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) { throw new InvalidEbeanQueryMethodException( "Cannot use native queries with dynamic sorting and/or pagination in method " + method); } }
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)); } }
@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, EvaluationContextProvider.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); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { QueryLookupStrategy queryLookupStrategy = GenericQueryLookupStrategy.create(entityManager , sqlSessionTemplate , key , extractor , evaluationContextProvider) ; return queryLookupStrategy ; }
public GenericQueryLookupStrategy(EntityManager entityManager, SqlSessionTemplate sqlSessionTemplate , Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) { this.jpaQueryLookupStrategy = JpaQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider); this.extractor = extractor; this.entityManager = entityManager; this.sqlSessionTemplate = sqlSessionTemplate ; }
/** * Creates a new {@link AbstractStringBasedEbeanQuery} from the given {@link EbeanQueryMethod}, {@link io.ebean.EbeanServer} and * query {@link String}. * * @param method must not be {@literal null}. * @param ebeanServer must not be {@literal null}. * @param queryString must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @param parser must not be {@literal null}. */ public AbstractStringBasedEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString, EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) { super(method, ebeanServer); Assert.hasText(queryString, "Query string must not be null or empty!"); Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!"); Assert.notNull(parser, "Parser must not be null or empty!"); this.evaluationContextProvider = evaluationContextProvider; this.query = new ExpressionBasedStringQuery(queryString, method.getEntityInformation(), parser); this.parser = parser; }
/** * Creates a new {@link SpelExpressionStringQueryParameterBinder}. * * @param parameters must not be {@literal null} * @param values must not be {@literal null} * @param query must not be {@literal null} * @param evaluationContextProvider must not be {@literal null} * @param parser must not be {@literal null} */ public SpelExpressionStringQueryParameterBinder(DefaultParameters parameters, Object[] values, StringQuery query, EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) { super(parameters, values, query); Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); Assert.notNull(parser, "SpelExpressionParser must not be null!"); this.evaluationContextProvider = evaluationContextProvider; this.query = query; this.parser = parser; }
public TemplateQueryLookupStrategy(EntityManager entityManager, Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) { this.jpaQueryLookupStrategy = JpaQueryLookupStrategy .create(entityManager, key, extractor, evaluationContextProvider); this.extractor = extractor; this.entityManager = entityManager; }
/** * Creates a new {@link VaultPartTreeQuery} for the given {@link QueryMethod}, * {@link EvaluationContextProvider}, {@link KeyValueOperations} and query creator * type. * * @param queryMethod must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @param keyValueOperations must not be {@literal null}. * @param queryCreator must not be {@literal null}. */ @SuppressWarnings("unchecked") public VaultPartTreeQuery(QueryMethod queryMethod, EvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) { super(queryMethod, evaluationContextProvider, keyValueOperations, new VaultQueryCreatorFactory( (MappingContext) keyValueOperations.getMappingContext())); }
@Override public QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { QueryLookupStrategy parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider); return new AggregateQueryLookupStrategy(parentQueryLookupStrategy); }
/** {@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()))); } }; }
/** * Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider}, * {@link KeyValueOperations} using the given {@link QueryCreatorFactory} producing the {@link AbstractQueryCreator} * in charge of altering the query. * * @param queryMethod must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @param keyValueOperations must not be {@literal null}. * @param queryCreatorFactory must not be {@literal null}. * @since 2.0 */ public KeyValuePartTreeQuery(QueryMethod queryMethod, EvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations, QueryCreatorFactory queryCreatorFactory) { Assert.notNull(queryMethod, "Query method must not be null!"); Assert.notNull(evaluationContextProvider, "EvaluationContextprovider must not be null!"); Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!"); Assert.notNull(queryCreatorFactory, "QueryCreatorFactory type must not be null!"); this.queryMethod = queryMethod; this.keyValueOperations = keyValueOperations; this.evaluationContextProvider = evaluationContextProvider; this.queryCreatorFactory = queryCreatorFactory; }
/** * @param key * @param evaluationContextProvider * @param keyValueOperations * @param queryCreator * @since 1.1 */ public KeyValueQueryLookupStrategy(@Nullable Key key, EvaluationContextProvider 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; }
@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 DocumentDbQueryLookupStrategy(DocumentDbOperations operations, EvaluationContextProvider provider) { this.dbOperations = operations; }
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()); }
@Override public void setEvaluationContextProvider(EvaluationContextProvider evaluationContextProvider) { super.setEvaluationContextProvider(evaluationContextProvider); snowdropRepositoryFactory.setEvaluationContextProvider(evaluationContextProvider); }
@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); }
public ObjectifyQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.ofNullable(EbeanQueryLookupStrategy.create(ebeanServer, key, evaluationContextProvider)); }
private DeclaredQueryLookupStrategy(SqlSessionTemplate sqlSessionTemplate, EvaluationContextProvider evaluationContextProvider) { this.sqlSessionTemplate = sqlSessionTemplate; this.evaluationContextProvider = evaluationContextProvider; }
public SimpleMybatisQuery(SqlSessionTemplate sqlSessionTemplate, MybatisQueryMethod method, Query query, EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) { super(sqlSessionTemplate, method); }
@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); }
@Bean public EvaluationContextProvider evaluationContextProvider() { return new ExtensionAwareEvaluationContextProvider(); }
@Override protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return new AclQueryLookupStrategy(key, evaluationContextProvider); }
public AclQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { this.key = key; this.evaluationContextProvider = evaluationContextProvider; }
@Override protected QueryLookupStrategy getQueryLookupStrategy(final Key key, final EvaluationContextProvider evaluationContextProvider) { return new MyBatisQueryLookupStrategy(mapperProvider, key); }
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) { return Optional.<QueryLookupStrategy> of(new GqQueryLookupStrategy(emf)); }