@Override protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Optional<Object> customImplementation) { RxJavaCouchbaseOperations reactiveCouchbaseOperations = getDependencyInstance(reactiveCouchbaseOperationsBean, RxJavaCouchbaseOperations.class); ReactiveRepositoryOperationsMapping reactiveCouchbaseOperationsMapping = new ReactiveRepositoryOperationsMapping(reactiveCouchbaseOperations); IndexManager indexManager = new IndexManager(); ReactiveCouchbaseRepositoryFactory factory = new ReactiveCouchbaseRepositoryFactory(reactiveCouchbaseOperationsMapping, indexManager); return customImplementation.map(o -> factory.getRepository(repositoryType, o)) .orElseGet(() -> factory.getRepository(repositoryType)); }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleReactiveCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
/** * Returns the base class for the repository being constructed. Two categories of repositories can be produced by * this factory: {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. This method checks if N1QL * is available to choose between the two, but the actual concrete class is determined respectively by * {@link #getSimpleBaseClass(RepositoryMetadata)} and {@link #getN1qlBaseClass(RepositoryMetadata)}. * * Override these methods if you want to change the base class for all your repositories. * * @param repositoryMetadata metadata for the repository. * * @return the base class. */ @Override protected final Class<?> getRepositoryBaseClass(final RepositoryMetadata repositoryMetadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(repositoryMetadata.getRepositoryInterface(), repositoryMetadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); if (isN1qlAvailable) { return getN1qlBaseClass(repositoryMetadata); } return getSimpleBaseClass(repositoryMetadata); }
/** * Get the factory instance for the operations. * * @param couchbaseOperationsMapping the reference to the template. * @param indexManager the reference to the {@link IndexManager}. * @return the factory instance. */ protected ReactiveCouchbaseRepositoryFactory getFactoryInstance(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping, IndexManager indexManager) { return new ReactiveCouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager); }
/** * Create a new factory. * * @param couchbaseOperationsMapping the template for the underlying actions. */ public ReactiveCouchbaseRepositoryFactory(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping, final IndexManager indexManager) { Assert.notNull(couchbaseOperationsMapping); Assert.notNull(indexManager); this.couchbaseOperationsMapping = couchbaseOperationsMapping; this.indexManager = indexManager; mappingContext = this.couchbaseOperationsMapping.getMappingContext(); viewPostProcessor = ViewPostProcessor.INSTANCE; addRepositoryProxyPostProcessor(viewPostProcessor); }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleReactiveCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
/** * Returns the base class for the repository being constructed. Two categories of repositories can be produced by * this factory: {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. This method checks if N1QL * is available to choose between the two, but the actual concrete class is determined respectively by * {@link #getSimpleBaseClass(RepositoryMetadata)} and {@link #getN1qlBaseClass(RepositoryMetadata)}. * * Override these methods if you want to change the base class for all your repositories. * * @param repositoryMetadata metadata for the repository. * * @return the base class. */ @Override protected final Class<?> getRepositoryBaseClass(final RepositoryMetadata repositoryMetadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(repositoryMetadata.getRepositoryInterface(), repositoryMetadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); if (isN1qlAvailable) { return getN1qlBaseClass(repositoryMetadata); } return getSimpleBaseClass(repositoryMetadata); }
/** * Get the factory instance for the operations. * * @param couchbaseOperationsMapping the reference to the template. * @param indexManager the reference to the {@link IndexManager}. * @return the factory instance. */ protected ReactiveCouchbaseRepositoryFactory getFactoryInstance(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping, IndexManager indexManager) { return new ReactiveCouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager); }
/** * Create a new factory. * * @param couchbaseOperationsMapping the template for the underlying actions. */ public ReactiveCouchbaseRepositoryFactory(final ReactiveRepositoryOperationsMapping couchbaseOperationsMapping, final IndexManager indexManager) { Assert.notNull(couchbaseOperationsMapping); Assert.notNull(indexManager); this.couchbaseOperationsMapping = couchbaseOperationsMapping; this.indexManager = indexManager; mappingContext = this.couchbaseOperationsMapping.getMappingContext(); viewPostProcessor = ViewPostProcessor.INSTANCE; addRepositoryProxyPostProcessor(viewPostProcessor); }
@Override protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Optional<Object> customImplementation) { RxJavaCouchbaseOperations reactiveCouchbaseOperations = getDependencyInstance(reactiveCouchbaseOperationsBean, RxJavaCouchbaseOperations.class); ReactiveRepositoryOperationsMapping reactiveCouchbaseOperationsMapping = new ReactiveRepositoryOperationsMapping(reactiveCouchbaseOperations); IndexManager indexManager = new IndexManager(); ReactiveCouchbaseRepositoryFactory factory = new ReactiveCouchbaseRepositoryFactory(reactiveCouchbaseOperationsMapping, indexManager); return customImplementation.map(o -> factory.getRepository(repositoryType, o)) .orElseGet(() -> factory.getRepository(repositoryType)); }