/** * Get the factory instance for the operations. * * @param operationsMapping the reference to the template. * @param indexManager the reference to the {@link IndexManager}. * @return the factory instance. */ protected CouchbaseRepositoryFactory getFactoryInstance(final RepositoryOperationsMapping operationsMapping, IndexManager indexManager) { return new CouchbaseRepositoryFactory(operationsMapping, indexManager); }
/** * Create a new factory. * * @param couchbaseOperationsMapping the template for the underlying actions. */ public CouchbaseRepositoryFactory(final RepositoryOperationsMapping couchbaseOperationsMapping, final IndexManager indexManager) { Assert.notNull(couchbaseOperationsMapping, "RepositoryOperationsMapping must not be null!"); Assert.notNull(indexManager, "IndexManager must not be null!"); 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 SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. * * 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) { CouchbaseOperations 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()); SimpleCouchbaseRepository 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 SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. 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) { CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(repositoryMetadata.getRepositoryInterface(), repositoryMetadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); if (isN1qlAvailable) { return getN1qlBaseClass(repositoryMetadata); } return getSimpleBaseClass(repositoryMetadata); }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. * * 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) { CouchbaseOperations 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()); SimpleCouchbaseRepository 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 SimpleCouchbaseRepository} and {@link N1qlCouchbaseRepository}. 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) { CouchbaseOperations 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 operationsMapping the reference to the template. * @param indexManager the reference to the {@link IndexManager}. * @return the factory instance. */ protected CouchbaseRepositoryFactory getFactoryInstance(final RepositoryOperationsMapping operationsMapping, IndexManager indexManager) { return new CouchbaseRepositoryFactory(operationsMapping, indexManager); }
/** * Create a new factory. * * @param couchbaseOperationsMapping the template for the underlying actions. */ public CouchbaseRepositoryFactory(final RepositoryOperationsMapping couchbaseOperationsMapping, final IndexManager indexManager) { Assert.notNull(couchbaseOperationsMapping, "RepositoryOperationsMapping must not be null!"); Assert.notNull(indexManager, "IndexManager must not be null!"); 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) { CouchbaseOperations couchbaseOperations = getDependencyInstance(couchbaseOperationsBean, CouchbaseOperations.class); RepositoryOperationsMapping couchbaseOperationsMapping = new RepositoryOperationsMapping(couchbaseOperations); IndexManager indexManager = new IndexManager(); return create(() -> new CouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager), repositoryType); }
@Override protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) { CouchbaseOperations couchbaseOperations = getDependencyInstance(couchbaseOperationsBean, CouchbaseOperations.class); RepositoryOperationsMapping couchbaseOperationsMapping = new RepositoryOperationsMapping(couchbaseOperations); IndexManager indexManager = new IndexManager(); return create(() -> new CouchbaseRepositoryFactory(couchbaseOperationsMapping, indexManager), repositoryType); }