org.springframework.data.repository.query.EvaluationContextProvider Java Examples

The following examples show how to use org.springframework.data.repository.query.EvaluationContextProvider. 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: TemplateQueryParameterBinderFactory.java    From spring-data-jpa-extra with Apache License 2.0 6 votes vote down vote up
public static ParameterBinder createQueryAwareBinder(JpaParameters parameters, DeclaredQuery query,
                                                     ExpressionParser parser, EvaluationContextProvider evaluationContextProvider) {

    Assert.notNull(parameters, "JpaParameters must not be null!");
    Assert.notNull(query, "StringQuery must not be null!");
    Assert.notNull(parser, "ExpressionParser must not be null!");
    Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");

    List<StringQuery.ParameterBinding> bindings = query.getParameterBindings();
    QueryParameterSetterFactory expressionSetterFactory = TemplateBasedQueryParameterSetterFactory.parsingTemplate(parser,
            evaluationContextProvider, parameters);
    QueryParameterSetterFactory basicSetterFactory = TemplateBasedQueryParameterSetterFactory.basic(parameters);

    return new ParameterBinder(parameters, createSetters(bindings, query, expressionSetterFactory, basicSetterFactory),
            !query.usesPaging());
}
 
Example #2
Source File: TemplateBasedQueryParameterSetterFactory.java    From spring-data-jpa-extra with Apache License 2.0 5 votes vote down vote up
TemplateBasedQueryParameterSetterFactory(ExpressionParser parser,
                                         EvaluationContextProvider evaluationContextProvider, Parameters<?, ?> parameters) {
    Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
    Assert.notNull(parser, "ExpressionParser must not be null!");
    Assert.notNull(parameters, "Parameters must not be null!");

    this.evaluationContextProvider = evaluationContextProvider;
    this.parser = parser;
    this.parameters = parameters;
}
 
Example #3
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(final QueryLookupStrategy.Key key,
    EvaluationContextProvider evaluationContextProvider) {
    return Optional.of((mtd, metadata, factory, namedQueries) -> {
        final Query annotation = mtd.getAnnotation(Query.class);
        final Ignite ignite = repoToIgnite.get(metadata.getRepositoryInterface());

        if (annotation != null && (StringUtils.hasText(annotation.value()) || annotation.textQuery() || annotation
            .dynamicQuery())) {

            String qryStr = annotation.value();

            boolean annotatedIgniteQuery = !annotation.dynamicQuery() && (StringUtils.hasText(qryStr) || annotation
                .textQuery());

            IgniteQuery query = annotatedIgniteQuery ? new IgniteQuery(qryStr,
                !annotation.textQuery() && (isFieldQuery(qryStr) || annotation.forceFieldsQuery()),
                annotation.textQuery(), false, IgniteQueryGenerator.getOptions(mtd)) : null;

            if (key != QueryLookupStrategy.Key.CREATE) {
                return new IgniteRepositoryQuery(ignite, metadata, query, mtd, factory,
                    getRepositoryCache(metadata.getRepositoryInterface()),
                    annotatedIgniteQuery ? DynamicQueryConfig.fromQueryAnnotation(annotation) : null,
                    evaluationContextProvider);
            }
        }

        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.springdata20.repository"
                + ".config.Query annotation.");
        }

        return new IgniteRepositoryQuery(ignite, metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd,
            factory, getRepositoryCache(metadata.getRepositoryInterface()),
            DynamicQueryConfig.fromQueryAnnotation(annotation), evaluationContextProvider);
    });
}
 
Example #4
Source File: SpelEvaluator.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param evaluationCtxProvider Evaluation context provider.
 * @param parameters            Parameters.
 * @param extractor             Extractor.
 */
public SpelEvaluator(EvaluationContextProvider evaluationCtxProvider,
    Parameters<?, ?> parameters,
    SpelExtractor extractor) {
    this.evaluationCtxProvider = evaluationCtxProvider;
    this.parameters = parameters;
    this.extractor = extractor;
}
 
Example #5
Source File: AggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Override
public QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                  EvaluationContextProvider evaluationContextProvider) {

  QueryLookupStrategy parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider);
  return new AggregateQueryLookupStrategy(parentQueryLookupStrategy);
}
 
Example #6
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@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 #7
Source File: GenericQueryLookupStrategy.java    From genericdao with Artistic License 2.0 5 votes vote down vote up
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 ;
}
 
Example #8
Source File: GenericJpaRepositoryFactory.java    From genericdao with Artistic License 2.0 5 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) {
	QueryLookupStrategy queryLookupStrategy = GenericQueryLookupStrategy.create(entityManager ,
			sqlSessionTemplate , key , extractor , evaluationContextProvider) ;

	return queryLookupStrategy  ;
}
 
Example #9
Source File: CrateRepositoryFactory.java    From spring-data-crate with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) {
    return new CrateQueryLookupStrategy();
}
 
Example #10
Source File: IgniteRepositoryQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Ignite repository query.
 *
 * @param ignite                               the ignite
 * @param metadata                             Metadata.
 * @param staticQuery                          Query.
 * @param mtd                                  Method.
 * @param factory                              Factory.
 * @param cache                                Cache.
 * @param staticQueryConfiguration             the query configuration
 * @param queryMethodEvaluationContextProvider the query method evaluation context provider
 */
public IgniteRepositoryQuery(Ignite ignite,
    RepositoryMetadata metadata,
    @Nullable IgniteQuery staticQuery,
    Method mtd,
    ProjectionFactory factory,
    IgniteCache cache,
    @Nullable DynamicQueryConfig staticQueryConfiguration,
    EvaluationContextProvider queryMethodEvaluationContextProvider) {
    this.metadata = metadata;
    this.mtd = mtd;
    this.factory = factory;
    type = metadata.getDomainType();

    this.cache = cache;
    this.ignite = ignite;

    this.staticQueryConfiguration = staticQueryConfiguration;
    this.staticQuery = staticQuery;

    if (this.staticQuery != null)
        staticReturnStgy = calcReturnType(mtd, this.staticQuery.isFieldQuery());
    else
        staticReturnStgy = null;

    expressionParser = new SpelExpressionParser();
    this.queryMethodEvaluationContextProvider = queryMethodEvaluationContextProvider;

    qMethod = getQueryMethod();

    // control projection
    hasDynamicProjection = getQueryMethod().getParameters().hasDynamicProjection();
    hasProjection = hasDynamicProjection || getQueryMethod().getResultProcessor().getReturnedType()
        .isProjecting();

    dynamicProjectionIndex = qMethod.getParameters().getDynamicProjectionIndex();

    returnedDomainClass = getQueryMethod().getReturnedObjectType();

    dynamicQueryConfigurationIndex = getDynamicQueryConfigurationIndex(qMethod);

    // ensure dynamic query configuration param exists if dynamicQuery = true
    if (dynamicQueryConfigurationIndex == -1 && this.staticQuery == null) {
        throw new IllegalStateException(
            "When passing dynamicQuery = true via org.apache.ignite.springdata.repository.config.Query "
                + "annotation, you must provide a non null method parameter of type DynamicQueryConfig");
    }
    // ensure domain class is registered on marshaller to transform row to entity
    registerClassOnMarshaller(((IgniteEx)ignite).context(), type);
}
 
Example #11
Source File: GenericQueryLookupStrategy.java    From genericdao with Artistic License 2.0 4 votes vote down vote up
public static QueryLookupStrategy create(EntityManager entityManager, SqlSessionTemplate sqlSessionTemplate  ,
                                         Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) {
    return new GenericQueryLookupStrategy(entityManager , sqlSessionTemplate ,
            key , extractor , evaluationContextProvider);
}
 
Example #12
Source File: AclJpaRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 4 votes vote down vote up
public AclQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
  this.key = key;
  this.evaluationContextProvider = evaluationContextProvider;
}
 
Example #13
Source File: AclJpaRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(Key key,
    EvaluationContextProvider evaluationContextProvider) {
  return new AclQueryLookupStrategy(key, evaluationContextProvider);
}
 
Example #14
Source File: AggregateTestConfiguration.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
@Bean
public EvaluationContextProvider evaluationContextProvider() {
  return new ExtensionAwareEvaluationContextProvider();
}
 
Example #15
Source File: TemplateQueryLookupStrategy.java    From spring-data-jpa-extra with Apache License 2.0 4 votes vote down vote up
public static QueryLookupStrategy create(EntityManager entityManager, Key key, QueryExtractor extractor,
                                         EvaluationContextProvider evaluationContextProvider) {
    return new TemplateQueryLookupStrategy(entityManager, key, extractor, evaluationContextProvider);
}
 
Example #16
Source File: TemplateQueryLookupStrategy.java    From spring-data-jpa-extra with Apache License 2.0 4 votes vote down vote up
public TemplateQueryLookupStrategy(EntityManager entityManager, Key key, QueryExtractor extractor,
                                   EvaluationContextProvider evaluationContextProvider) {
    this.jpaQueryLookupStrategy = JpaQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider);
    this.extractor = extractor;
    this.entityManager = entityManager;
}
 
Example #17
Source File: GenericJpaRepositoryFactory.java    From spring-data-jpa-extra with Apache License 2.0 4 votes vote down vote up
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
                                                               EvaluationContextProvider evaluationContextProvider) {
    return Optional.of(TemplateQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider));
}
 
Example #18
Source File: TemplateBasedQueryParameterSetterFactory.java    From spring-data-jpa-extra with Apache License 2.0 4 votes vote down vote up
public static QueryParameterSetterFactory parsingTemplate(ExpressionParser parser, EvaluationContextProvider evaluationContextProvider, JpaParameters parameters) {
    return null;
}
 
Example #19
Source File: SpelQueryContext.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link EvaluatingSpelQueryContext} for the given {@link EvaluationContextProvider}, parameter
 * name source and replacement source.
 *
 * @param evaluationCtxProvider must not be {@literal null}.
 * @param paramNameSrc          must not be {@literal null}.
 * @param replacementSrc        must not be {@literal null}.
 */
private EvaluatingSpelQueryContext(EvaluationContextProvider evaluationCtxProvider,
    BiFunction<Integer, String, String> paramNameSrc, BiFunction<String, String, String> replacementSrc) {
    super(paramNameSrc, replacementSrc);

    evaluationContextProvider = evaluationCtxProvider;
}
 
Example #20
Source File: SpelQueryContext.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Createsa {@link EvaluatingSpelQueryContext} from the current one and the given {@link
 * EvaluationContextProvider}*.
 *
 * @param provider must not be {@literal null}.
 * @return Evaluating Spel QueryContext
 */
public EvaluatingSpelQueryContext withEvaluationContextProvider(EvaluationContextProvider provider) {
    Assert.notNull(provider, "EvaluationContextProvider must not be null!");

    return new EvaluatingSpelQueryContext(provider, paramNameSrc, replacementSrc);
}