org.springframework.data.repository.core.RepositoryMetadata Java Examples
The following examples show how to use
org.springframework.data.repository.core.RepositoryMetadata.
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: MybatisQueryMethod.java From spring-data-mybatis with Apache License 2.0 | 6 votes |
/** * Creates a new {@link QueryMethod} from the given parameters. Looks up the correct * query to use for following invocations of the method given. * @param method must not be {@literal null}. * @param metadata must not be {@literal null}. * @param factory must not be {@literal null}. */ public MybatisQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { super(method, metadata, factory); Assert.notNull(method, "Method must not be null!"); this.method = method; Assert.isTrue(!(isModifyingQuery() && getParameters().hasSpecialParameter()), String.format("Modifying method must not contain %s!", Parameters.TYPES)); this.metadata = metadata; String namespace = getAnnotationValue("namespace", String.class); String statementName = getAnnotationValue("statement", String.class); this.namespace = StringUtils.hasText(namespace) ? namespace : metadata.getRepositoryInterface().getName(); this.statementName = StringUtils.hasText(statementName) ? statementName : (method.getName() + UUID.randomUUID().toString().replace("-", "")); }
Example #2
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 #3
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 #4
Source File: DefaultRepositoryFactory.java From gazpachoquest with GNU General Public License v3.0 | 6 votes |
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository( final RepositoryMetadata metadata, final EntityManager entityManager) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); if (isQueryDslExecutor(repositoryInterface)) { return new QueryDslJpaRepository(entityInformation, entityManager); } else { return new GenericRepositoryImpl(entityInformation, entityManager, namedQueryUtil); // custom } }
Example #5
Source File: ExpressionBasedStringQuery.java From ignite with Apache License 2.0 | 6 votes |
/** * @param qry, the query expression potentially containing a SpEL expression. Must not be {@literal null}.} * @param metadata the {@link RepositoryMetadata} for the given entity. Must not be {@literal null}. * @param parser Must not be {@literal null}. * @return rendered query */ private static String renderQueryIfExpressionOrReturnQuery(String qry, RepositoryMetadata metadata, SpelExpressionParser parser) { Assert.notNull(qry, "query must not be null!"); Assert.notNull(metadata, "metadata must not be null!"); Assert.notNull(parser, "parser must not be null!"); if (!containsExpression(qry)) return qry; StandardEvaluationContext evalCtx = new StandardEvaluationContext(); evalCtx.setVariable(ENTITY_NAME, metadata.getDomainType().getSimpleName()); qry = potentiallyQuoteExpressionsParameter(qry); Expression expr = parser.parseExpression(qry, ParserContext.TEMPLATE_EXPRESSION); String result = expr.getValue(evalCtx, String.class); if (result == null) return qry; return potentiallyUnquoteParameterExpressions(result); }
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: SpelQueryEngineUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception { List<Class<?>> types = new ArrayList<>(args.length); for (Object arg : args) { types.add(arg.getClass()); } Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()])); RepositoryMetadata metadata = mock(RepositoryMetadata.class); doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method); PartTree partTree = new PartTree(method.getName(), method.getReturnType()); SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor( new QueryMethod(method, metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args)); return new SpelCriteria(creator.createQuery().getCriteria(), SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().withRootObject(args).build()); }
Example #8
Source File: SimpleDbQueryMethodWithSelectAndWhereClauseTest.java From spring-data-simpledb with MIT License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private SimpleDbQueryMethod prepareQueryMethodToTest(String methodName, Class<?> entityClass) throws Exception { RepositoryMetadata repositoryMetadata = Mockito.mock(RepositoryMetadata.class); when(repositoryMetadata.getDomainType()).thenReturn((Class) entityClass); Method testMethod = AnnotatedQueryRepository.class.getMethod(methodName); when(repositoryMetadata.getReturnedDomainClass(testMethod)).thenReturn((Class) entityClass); SimpleDbDomain simpleDbDomain = new SimpleDbDomain(); return new SimpleDbQueryMethod(testMethod, repositoryMetadata, simpleDbDomain); }
Example #9
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 #10
Source File: JooqJpaRepositoryFactory.java From blog-examples with Apache License 2.0 | 5 votes |
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (JooqQueryExecutor.class.isAssignableFrom(metadata.getRepositoryInterface())) { return JooqJpaRepository.class; } else { return SimpleJpaRepository.class; } }
Example #11
Source File: DynamoDBQueryMethod.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
public DynamoDBQueryMethod(Method method, RepositoryMetadata metadata) { super(method, metadata); this.method = method; this.scanEnabledForRepository = metadata.getRepositoryInterface().isAnnotationPresent(EnableScan.class); this.scanCountEnabledForRepository = metadata.getRepositoryInterface().isAnnotationPresent(EnableScanCount.class); }
Example #12
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 #13
Source File: CrateRepositoryFactory.java From spring-data-crate with Apache License 2.0 | 5 votes |
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (isQueryDslRepository(metadata.getRepositoryInterface())) { throw new IllegalArgumentException("QueryDsl Support has not been implemented yet."); } return SimpleCrateRepository.class; }
Example #14
Source File: MybatisRepositoryQuery.java From genericdao with Artistic License 2.0 | 5 votes |
public MybatisRepositoryQuery(SqlSessionTemplate sqlSessionTemplate , Method method, RepositoryMetadata repositoryMetadata){ this.sqlSessionTemplate = sqlSessionTemplate ; this.method = method ; this.repositoryMetadata = repositoryMetadata ; log.info("{}的领域类{}",repositoryMetadata.getRepositoryInterface().getName() , repositoryMetadata.getDomainType() ); if(!mybatisMapperMap.containsKey(getMapperKey())){ Object mapper = sqlSessionTemplate.getMapper(repositoryMetadata.getRepositoryInterface()) ; mybatisMapperMap.put(getMapperKey() , mapper) ; } }
Example #15
Source File: SolrRepositoryFactory.java From dubbox with Apache License 2.0 | 5 votes |
private SolrOperations selectSolrOperations(RepositoryMetadata metadata) { SolrOperations ops = templateHolder.getSolrOperations(metadata.getDomainType()); if (ops == null) { ops = solrOperations; } return ops; }
Example #16
Source File: ArchitecturallyEvidentType.java From moduliths with Apache License 2.0 | 5 votes |
@Override public boolean isAggregateRoot() { return isEntity() && beanTypes.that(SpringDataTypes.isSpringDataRepository()).stream() // .map(JavaClass::reflect) // .map(AbstractRepositoryMetadata::getMetadata) // .map(RepositoryMetadata::getDomainType) // .anyMatch(it -> getType().isAssignableTo(it)); }
Example #17
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 #18
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 #19
Source File: SimpleDbIndexByQueryMethodBindedTest.java From spring-data-simpledb with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private SimpleDbQueryMethod prepareQueryMethodToTest(String methodName, Class<?> entityClass) throws Exception { RepositoryMetadata repositoryMetadata = Mockito.mock(RepositoryMetadata.class); when(repositoryMetadata.getDomainType()).thenReturn((Class) entityClass); Method testMethod = AnnotatedQueryRepository.class.getMethod(methodName); when(repositoryMetadata.getReturnedDomainClass(testMethod)).thenReturn((Class) entityClass); SimpleDbDomain simpleDbDomain = new SimpleDbDomain(); return new SimpleDbQueryMethod(testMethod, repositoryMetadata, simpleDbDomain); }
Example #20
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 #21
Source File: AbstractSpringAuditableRepositoryAspect.java From javers with Apache License 2.0 | 5 votes |
protected void onDelete(JoinPoint pjp) { getRepositoryInterface(pjp).ifPresent( i -> { RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(i); for (Object deletedObject : AspectUtil.collectArguments(pjp)) { handleDelete(metadata, deletedObject); } }); }
Example #22
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 #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: ReactiveAggregateMongoQuery.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
/** * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}. * * @param method must not be {@literal null}. * @param projectionFactory - the projection factory */ @Autowired public ReactiveAggregateMongoQuery(Method method, RepositoryMetadata metadata, ReactiveMongoOperations mongoOperations, ProjectionFactory projectionFactory, MongoQueryExecutor queryExecutor) { super(new ReactiveMongoQueryMethod(method, metadata, projectionFactory, mongoOperations.getConverter().getMappingContext()), mongoOperations, new SpelExpressionParser(), CONTEXT_PROVIDER); this.mongoOperations = mongoOperations; this.method = method; this.queryExecutor = queryExecutor; }
Example #25
Source File: NonReactiveAggregateMongoQuery.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
/** * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}. * * @param method must not be {@literal null}. * @param projectionFactory - the projection factory */ @Autowired public NonReactiveAggregateMongoQuery(Method method, RepositoryMetadata metadata, MongoOperations mongoOperations, ProjectionFactory projectionFactory, MongoQueryExecutor queryExecutor) { super(new MongoQueryMethod(method, metadata, projectionFactory, mongoOperations.getConverter().getMappingContext()), mongoOperations, new SpelExpressionParser(), CONTEXT_PROVIDER); this.mongoOperations = mongoOperations; this.method = method; this.queryExecutor = queryExecutor; }
Example #26
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 { 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); }
Example #27
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 #28
Source File: SimpleDbQueryMethodWithSelectClauseTest.java From spring-data-simpledb with MIT License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private SimpleDbQueryMethod prepareQueryMethodToTest(String methodName, Class<?> entityClass) throws Exception { RepositoryMetadata repositoryMetadata = Mockito.mock(RepositoryMetadata.class); when(repositoryMetadata.getDomainType()).thenReturn((Class) entityClass); Method testMethod = AnnotatedQueryRepository.class.getMethod(methodName); when(repositoryMetadata.getReturnedDomainClass(testMethod)).thenReturn((Class) entityClass); SimpleDbDomain simpleDbDomain = new SimpleDbDomain(); return new SimpleDbQueryMethod(testMethod, repositoryMetadata, simpleDbDomain); }
Example #29
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 #30
Source File: SimpleBaseRepositoryFactoryBean.java From es with Apache License 2.0 | 5 votes |
protected Object getTargetRepository(RepositoryMetadata metadata) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (isBaseRepository(repositoryInterface)) { JpaEntityInformation<M, ID> entityInformation = getEntityInformation((Class<M>) metadata.getDomainType()); SimpleBaseRepository repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager); SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface, SearchableQuery.class); if (searchableQuery != null) { String countAllQL = searchableQuery.countAllQuery(); if (!StringUtils.isEmpty(countAllQL)) { repository.setCountAllQL(countAllQL); } String findAllQL = searchableQuery.findAllQuery(); if (!StringUtils.isEmpty(findAllQL)) { repository.setFindAllQL(findAllQL); } Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass(); if (callbackClass != null && callbackClass != SearchCallback.class) { repository.setSearchCallback(BeanUtils.instantiate(callbackClass)); } repository.setJoins(searchableQuery.joins()); } return repository; } return super.getTargetRepository(metadata); }