@Override protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { RepositoryFragments fragments = RepositoryFragments.empty(); boolean isQueryDslRepository = QUERY_DSL_PRESENT && QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface()); if (isQueryDslRepository) { if (metadata.isReactiveRepository()) { throw new InvalidDataAccessApiUsageException( "Cannot combine Querydsl and reactive repository support in a single interface"); } MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType(), metadata); fragments = fragments.append(RepositoryFragment.implemented( getTargetRepositoryViaReflection(QuerydslMongoPredicateExecutor.class, entityInformation, operations))); } return fragments; }
public void afterPropertiesSet() { this.factory = createRepositoryFactory(); this.factory.setQueryLookupStrategyKey(queryLookupStrategyKey); this.factory.setNamedQueries(namedQueries); this.factory.setEvaluationContextProvider( evaluationContextProvider.orElseGet(() -> QueryMethodEvaluationContextProvider.DEFAULT)); this.factory.setBeanClassLoader(classLoader); this.factory.setBeanFactory(beanFactory); if (publisher != null) { this.factory.addRepositoryProxyPostProcessor(new EventPublishingRepositoryProxyPostProcessor(publisher)); } repositoryBaseClass.ifPresent(this.factory::setRepositoryBaseClass); RepositoryFragments customImplementationFragment = customImplementation // .map(RepositoryFragments::just) // .orElseGet(RepositoryFragments::empty); RepositoryFragments repositoryFragmentsToUse = this.repositoryFragments // .orElseGet(RepositoryFragments::empty) // .append(customImplementationFragment); this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); // Make sure the aggregate root type is present in the MappingContext (e.g. for auditing) this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType())); this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); if (!lazyInit) { this.repository.get(); } }
@Override protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { RepositoryComposition.RepositoryFragments fragments = RepositoryComposition.RepositoryFragments.empty(); boolean isQueryDslRepository = QUERY_DSL_PRESENT && QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface()); if (isQueryDslRepository) { if (metadata.isReactiveRepository()) { throw new InvalidDataAccessApiUsageException( "Cannot combine Querydsl and reactive repository support in a single interface"); } JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); Object querydslFragment = getTargetRepositoryViaReflection(QuerydslJpaPredicateExecutor.class, entityInformation, entityManager, entityPathResolver, crudMethodMetadataPostProcessor.getCrudMethodMetadata()); fragments = fragments.append(RepositoryFragment.implemented(querydslFragment)); } return fragments; }
private static RepositoryFragments concat(Stream<RepositoryFragment<?>> left, Stream<RepositoryFragment<?>> right) { return from(Stream.concat(left, right).collect(Collectors.toList())); }
private RepositoryFragments getRepositoryFragments(Class<T> repositoryType, CdiRepositoryConfiguration cdiRepositoryConfiguration) { Optional<Bean<?>> customImplementationBean = getCustomImplementationBean(repositoryType, cdiRepositoryConfiguration); Optional<Object> customImplementation = customImplementationBean.map(this::getDependencyInstance); List<RepositoryFragment<?>> repositoryFragments = findRepositoryFragments(repositoryType, cdiRepositoryConfiguration); RepositoryFragments customImplementationFragment = customImplementation // .map(RepositoryFragments::just) // .orElseGet(RepositoryFragments::empty); return RepositoryFragments.from(repositoryFragments) // .append(customImplementationFragment); }
/** * Returns a repository instance for the given interface backed by an instance providing implementation logic for * custom logic. * * @param repositoryInterface must not be {@literal null}. * @param customImplementation must not be {@literal null}. * @return * @deprecated since 2.0. Use {@link RepositoryFragments} with {@link #getRepository(Class, RepositoryFragments)} to * compose repositories backed by custom implementations. */ @Deprecated public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) { return getRepository(repositoryInterface, RepositoryFragments.just(customImplementation)); }
/** * Create a {@link RepositoryComposition} from {@link RepositoryFragment fragments} with * {@link MethodLookups#direct()) method lookup. * * @param fragments must not be {@literal null}. * @return the {@link RepositoryComposition} from {@link RepositoryFragment fragments}. */ public static RepositoryComposition of(List<RepositoryFragment<?>> fragments) { return new RepositoryComposition(RepositoryFragments.from(fragments), MethodLookups.direct(), PASSTHRU_ARG_CONVERTER); }
@Override protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { Object fragmentImplementation = getTargetRepositoryViaReflection( // EnversRevisionRepositoryImpl.class, // getEntityInformation(metadata.getDomainType()), // revisionEntityInformation, // entityManager // ); return RepositoryFragments // .just(fragmentImplementation) // .append(super.getRepositoryFragments(metadata)); } }
/** * Returns a repository instance for the given interface. * * @param repositoryInterface must not be {@literal null}. * @return */ public <T> T getRepository(Class<T> repositoryInterface) { return getRepository(repositoryInterface, RepositoryFragments.empty()); }
/** * Creates {@link RepositoryFragments} based on {@link RepositoryMetadata} to add repository-specific extensions. * * @param metadata * @return */ protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { return RepositoryFragments.empty(); }
public RepositoryInformation getRepositoryInformation() { RepositoryFragments fragments = customImplementation.map(RepositoryFragments::just)// .orElse(RepositoryFragments.empty()); return factory.getRepositoryInformation(repositoryMetadata, fragments); }
/** * Create a new {@link RepositoryComposition} retaining current configuration and append {@link RepositoryFragment} to * the new composition. The resulting composition contains the appended {@link RepositoryFragment} as last element. * * @param fragment must not be {@literal null}. * @return the new {@link RepositoryComposition}. */ public RepositoryComposition append(RepositoryFragment<?> fragment) { return new RepositoryComposition(fragments.append(fragment), methodLookup, argumentConverter); }
/** * Create new {@link RepositoryFragments} from the current content appending {@link RepositoryFragment}. * * @param fragment must not be {@literal null} * @return the new {@link RepositoryFragments} containing all existing fragments and the given * {@link RepositoryFragment} as last element. */ public RepositoryFragments append(RepositoryFragment<?> fragment) { Assert.notNull(fragment, "RepositoryFragment must not be null!"); return concat(stream(), Stream.of(fragment)); }
/** * Create a new {@link RepositoryComposition} retaining current configuration and append {@link RepositoryFragments} * to the new composition. The resulting composition contains the appended {@link RepositoryFragments} as last * element. * * @param fragments must not be {@literal null}. * @return the new {@link RepositoryComposition}. */ public RepositoryComposition append(RepositoryFragments fragments) { return new RepositoryComposition(this.fragments.append(fragments), methodLookup, argumentConverter); }
/** * Create {@link RepositoryFragments} from a {@link List} of {@link RepositoryFragment fragments}. * * @param fragments must not be {@literal null}. * @return the {@link RepositoryFragments} for {@code implementations}. */ public static RepositoryFragments from(List<RepositoryFragment<?>> fragments) { Assert.notNull(fragments, "RepositoryFragments must not be null!"); return new RepositoryFragments(new ArrayList<>(fragments)); }
/** * Create {@link RepositoryFragments} from {@link RepositoryFragments fragments}. * * @param fragments must not be {@literal null}. * @return the {@link RepositoryFragments} for {@code implementations}. */ public static RepositoryFragments of(RepositoryFragment<?>... fragments) { Assert.notNull(fragments, "RepositoryFragments must not be null!"); Assert.noNullElements(fragments, "RepositoryFragments must not contain null elements!"); return new RepositoryFragments(Arrays.asList(fragments)); }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void afterPropertiesSet() { List<RepositoryFragment<?>> fragments = (List) fragmentBeanNames.stream() // .map(it -> beanFactory.getBean(it, RepositoryFragment.class)) // .collect(Collectors.toList()); this.repositoryFragments = RepositoryFragments.from(fragments); }
/** * Create new {@link RepositoryFragments} from the current content appending {@link RepositoryFragments}. * * @param fragments must not be {@literal null} * @return the new {@link RepositoryFragments} containing all existing fragments and the given * {@link RepositoryFragments} as last elements. */ public RepositoryFragments append(RepositoryFragments fragments) { Assert.notNull(fragments, "RepositoryFragments must not be null!"); return concat(stream(), fragments.stream()); }
/** * Create a {@link RepositoryComposition} for just a single {@code implementation} with {@link MethodLookups#direct()) * method lookup. * * @param implementation must not be {@literal null}. * @return the {@link RepositoryComposition} for a single {@code implementation}. */ public static RepositoryComposition just(Object implementation) { return new RepositoryComposition(RepositoryFragments.just(implementation), MethodLookups.direct(), PASSTHRU_ARG_CONVERTER); }
/** * Create {@link RepositoryFragments} from just implementation objects. * * @param implementations must not be {@literal null}. * @return the {@link RepositoryFragments} for {@code implementations}. */ public static RepositoryFragments just(Object... implementations) { Assert.notNull(implementations, "Implementations must not be null!"); Assert.noNullElements(implementations, "Implementations must not contain null elements!"); return new RepositoryFragments( Arrays.stream(implementations).map(RepositoryFragment::implemented).collect(Collectors.toList())); }