@Override @SuppressWarnings({"unchecked", "rawtypes"}) protected SimpleJpaRepository<?, ?> getTargetRepository( final RepositoryMetadata metadata, final EntityManager entityManager) { final Class<?> repositoryInterface = metadata.getRepositoryInterface(); final JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); if (isQueryDslSpecificExecutor(repositoryInterface)) { throw new IllegalArgumentException("QueryDSL interface niet toegestaan"); } return isMaxedRepository(repositoryInterface) ? new CustomSimpleMaxedJpaRepository(entityInformation, entityManager) : isQuerycostRepository(repositoryInterface) ? new CustomSimpleQuerycostJpaRepository(entityInformation, entityManager, maxCostsQueryPlan) : new CustomSimpleJpaRepository(entityInformation, entityManager); }
public RepositoryFragments getExtensionFragments(RepositoryMetadata metadata) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); List<RepositoryFragment<?>> result = new ArrayList<>(); Class<?> extensionInterface = getRepositoryExtensionInterface(); for (Class<?> extendedInterface : repositoryInterface.getInterfaces()) { if (extensionInterface.isAssignableFrom(extendedInterface)) { result.add(createExtensionFragment(extendedInterface)); } } if (result.isEmpty()) { return RepositoryFragments.empty(); } else { return RepositoryFragments.from(result); } }
JdbcTemplateQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { super(method, metadata, factory); Query query = method.getAnnotation(Query.class); if (query == null) { this.query = null; } else { this.query = query.value(); } this.singleColumn = method.getAnnotation(SingleColumn.class) != null; Mapper mapperOnMethod = method.getAnnotation(Mapper.class); Mapper mapperOnInterface = metadata.getRepositoryInterface().getAnnotation(Mapper.class); if (mapperOnMethod != null) { this.mapperClass = mapperOnMethod.value(); } else if (mapperOnInterface != null) { this.mapperClass = mapperOnInterface.value(); } else { this.mapperClass = null; } this.method = method; }
@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); } }
/** {@inheritDoc} */ @Override protected RepositoryMetadata getRepositoryMetadata(Class<?> repoItf) { Assert.notNull(repoItf, "Repository interface must be set."); Assert.isAssignable(IgniteRepository.class, repoItf, "Repository must implement IgniteRepository interface."); RepositoryConfig annotation = repoItf.getAnnotation(RepositoryConfig.class); Assert.notNull(annotation, "Set a name of an Apache Ignite cache using @RepositoryConfig annotation to map " + "this repository to the underlying cache."); Assert.hasText(annotation.cacheName(), "Set a name of an Apache Ignite cache using @RepositoryConfig " + "annotation to map this repository to the underlying cache."); repoToCache.put(repoItf, annotation.cacheName()); return super.getRepositoryMetadata(repoItf); }
private ParameterizedType getRichObjectRepositoryType(final RepositoryMetadata metadata, final Type[] repositoryGenericInterfaces) { ParameterizedType repositoryType = null; for (Type repositoryGenericInterface : repositoryGenericInterfaces) { if (repositoryGenericInterface instanceof ParameterizedType) { final Type rawType = ((ParameterizedType) repositoryGenericInterface).getRawType(); if (rawType instanceof Class && RichObjectRepository.class.isAssignableFrom((Class) rawType)) { repositoryType = (ParameterizedType) repositoryGenericInterface; } } } if (repositoryType == null) { throw new RuntimeException("Can't identify RichObjectRepository type from repository meta: " + metadata); } return repositoryType; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) protected Object getTargetRepository(RepositoryMetadata metadata) { SolrOperations operations = this.solrOperations; if (factory != null) { SolrTemplate template = new SolrTemplate(factory); template.setSolrCore(SolrServerUtils.resolveSolrCoreName(metadata.getDomainType())); addSchemaCreationFeaturesIfEnabled(template); template.afterPropertiesSet(); operations = template; } SimpleSolrRepository repository = new SimpleSolrRepository(getEntityInformation(metadata.getDomainType()), operations); repository.setEntityClass(metadata.getDomainType()); this.templateHolder.add(metadata.getDomainType(), operations); return repository; }
@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); }
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(), new StandardEvaluationContext(args)); }
@Override public void handle(RepositoryMetadata repositoryMetadata, Object domainObjectOrId) { Map<String, String> props = commitPropertiesProvider.provide(); String author = authorProvider.provide(); if (isIdClass(repositoryMetadata, domainObjectOrId)) { if (javers.findSnapshots(QueryBuilder.byInstanceId(domainObjectOrId, repositoryMetadata.getDomainType()).build()).size() == 0) { return; } javers.commitShallowDeleteById(author, instanceId(domainObjectOrId, repositoryMetadata.getDomainType()), props); } else if (isDomainClass(repositoryMetadata, domainObjectOrId)) { if (javers.findSnapshots(QueryBuilder.byInstance(domainObjectOrId).build()).size() == 0) { return; } javers.commitShallowDelete(author, domainObjectOrId, props); } else { throw new IllegalArgumentException("Domain object or object id expected"); } }
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { final DocumentDbQueryMethod queryMethod = new DocumentDbQueryMethod(method, metadata, factory); Assert.notNull(queryMethod, "queryMethod must not be null!"); Assert.notNull(dbOperations, "dbOperations must not be null!"); return new PartTreeDocumentDbQuery(queryMethod, dbOperations); }
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) ; } }
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repositoryMetadata, ProjectionFactory projectionFactory, NamedQueries namedQueries) { if (method.getAnnotation(MybatisQuery.class) != null) { log.info(repositoryMetadata.getRepositoryInterface().getName()+"."+method.getName()+" 为mybatis方法。 "); return new MybatisRepositoryQuery(sqlSessionTemplate , method , repositoryMetadata) ; } else { return jpaQueryLookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory,namedQueries); } }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata repositoryMetadata) { boolean isQueryDslRepository = QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryMetadata.getRepositoryInterface()); // return isQueryDslRepository ? QueryDslSpannerRepository.class : SimpleSpannerRepository.class; return SimpleSpannerRepository.class; }
@Override protected final RepositoryMetadata getRepositoryMetadata(Class<?> interfaze) { if (getRepositoryExtensionInterface().isAssignableFrom(interfaze)) { return getRepositoryExtensionMetadata(interfaze); } else { return getMainRepositoryMetadata(interfaze); } }
private Class<?> getExactRepositoryBaseClass(RepositoryMetadata metadata) { if (SnowdropCrudRepository.class.isAssignableFrom(metadata.getRepositoryInterface())) { return SimpleCrudRepository.class; } else { return SimpleRepository.class; } }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (Integer.class.isAssignableFrom(metadata.getIdType()) || Long.class.isAssignableFrom(metadata.getIdType()) || Double.class.isAssignableFrom(metadata.getIdType())) { return getExactRepositoryBaseClass(metadata); } else if (metadata.getIdType() == String.class) { return getExactRepositoryBaseClass(metadata); } else if (metadata.getIdType() == UUID.class) { return getExactRepositoryBaseClass(metadata); } else { throw new IllegalArgumentException("Unsupported ID type " + metadata.getIdType()); } }
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { SnowdropQueryMethod queryMethod = new SnowdropQueryMethod(method, metadata, factory); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { String namedQuery = namedQueries.getQuery(namedQueryName); return new SnowdropStringQuery(queryMethod, snowdropOperations, namedQuery); } else if (queryMethod.hasAnnotatedQuery()) { return new SnowdropStringQuery(queryMethod, snowdropOperations, queryMethod.getAnnotatedQuery()); } return new SnowdropPartQuery(queryMethod, snowdropOperations); }
@Override protected Class<?> getRepositoryBaseClass(final RepositoryMetadata metadata) { if (isMaxedRepository(metadata.getRepositoryInterface())) { return CustomSimpleMaxedJpaRepository.class; } else if (isQuerycostRepository(metadata.getRepositoryInterface())) { return CustomSimpleQuerycostJpaRepository.class; } else { return CustomSimpleJpaRepository.class; } }
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { QueryMethod queryMethod = new QueryMethod(method, metadata, factory); return new ObjectifyRepositoryQuery(queryMethod); }
@Override protected Class<?> getRepositoryBaseClass(final RepositoryMetadata metadata) { // The RepositoryMetadata can be safely ignored, it is used by the // JpaRepositoryFactory // to check for QueryDslJpaRepository's which is out of scope. return RestRepositoryImpl.class; }
/** * Creates a {@link EbeanQueryMethod}. * * @param method must not be {@literal null} * @param metadata must not be {@literal null} */ public EbeanQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { super(method, metadata, factory); Assert.notNull(method, "Method must not be null!"); this.method = method; }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (isQueryDslExecutor(metadata.getRepositoryInterface())) { return QueryDslMybatisRepository.class; } else { return SimpleMybatisRepository.class; } }
@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); } }
/** * 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 AggregateMongoQuery(Method method, RepositoryMetadata metadata, MongoOperations mongoOperations, ProjectionFactory projectionFactory, MongoQueryExecutor queryExecutor) { super(new MongoQueryMethod(method, metadata, projectionFactory, mongoOperations.getConverter().getMappingContext()), mongoOperations); this.mongoOperations = mongoOperations; this.method = method; this.queryExecutor = queryExecutor; }
@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); } }
@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); }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { return isBaseRepository(metadata.getRepositoryInterface()) ? (isTreeRepository(metadata.getRepositoryInterface()) ? TreeRepositoryImpl.class : BaseRepositoryImpl.class) : super.getRepositoryBaseClass(metadata); }
/** * @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); }
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; }
@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); } }
@Override protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository( RepositoryMetadata metadata, EntityManager entityManager) { JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata .getDomainType()); return new GenericRepositoryImpl(entityInformation, entityManager); // custom // implementation }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (isQueryDslExecutor(metadata.getRepositoryInterface())) { return EntityGraphQuerydslRepository.class; } else { return EntityGraphSimpleJpaRepository.class; } }
@SuppressWarnings({ "unchecked" }) protected Object getTargetRepository(RepositoryMetadata metadata) { JpaEntityInformation<T, Serializable> entityInformation = (JpaEntityInformation<T, Serializable>) getEntityInformation(metadata .getDomainType()); return new CalendarDTRepositoryImpl<T, ID>(entityInformation, entityManager); }
@Override protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { if (isQueryDslRepository(metadata.getRepositoryInterface())) { throw new IllegalArgumentException("QueryDsl Support has not been implemented yet."); } return SimpleSolrRepository.class; }
private SolrOperations selectSolrOperations(RepositoryMetadata metadata) { SolrOperations ops = templateHolder.getSolrOperations(metadata.getDomainType()); if (ops == null) { ops = solrOperations; } return ops; }
/** * @param metadata Metadata. * @param qry Query. * @param mtd Method. * @param factory Factory. * @param cache Cache. */ public IgniteRepositoryQuery(RepositoryMetadata metadata, IgniteQuery qry, Method mtd, ProjectionFactory factory, IgniteCache cache) { type = metadata.getDomainType(); this.qry = qry; this.cache = cache; this.metadata = metadata; this.mtd = mtd; this.factory = factory; returnStgy = calcReturnType(mtd, qry.isFieldQuery()); }
/** {@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()))); } }; }