DATACASS-533 - Export composable repositories via CDI.
We now export composable repositories through our CDI extension. Repositories can now be customized either by a single custom implementation (as it was before) and by providing fragment interfaces along their fragment implementation. This change aligns CDI support with the existing RepositoryFactory support we provide within a Spring application context.
This commit is contained in:
@@ -59,19 +59,14 @@ public class CassandraRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class, java.util.Optional)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
|
||||
Optional<Object> customImplementation) {
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
|
||||
CassandraOperations cassandraOperations = getDependencyInstance(cassandraOperationsBean, CassandraOperations.class);
|
||||
|
||||
CassandraRepositoryFactory factory = new CassandraRepositoryFactory(cassandraOperations);
|
||||
|
||||
return customImplementation //
|
||||
.map(o -> factory.getRepository(repositoryType, o)) //
|
||||
.orElseGet(() -> factory.getRepository(repositoryType));
|
||||
return create(() -> new CassandraRepositoryFactory(cassandraOperations), repositoryType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,13 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.cassandra.repository.cdi;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
interface SamplePersonRepositoryCustom {
|
||||
interface SamplePersonFragment {
|
||||
|
||||
int returnOne();
|
||||
}
|
||||
@@ -13,13 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.cassandra.repository.cdi;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class SamplePersonRepositoryImpl implements SamplePersonRepositoryCustom {
|
||||
class SamplePersonFragmentImpl implements SamplePersonFragment {
|
||||
|
||||
@Override
|
||||
public int returnOne() {
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.cassandra.repository.cdi;
|
||||
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
@@ -22,6 +21,6 @@ import org.springframework.data.repository.Repository;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface SamplePersonRepository extends Repository<Person, Long>, SamplePersonRepositoryCustom {
|
||||
public interface SamplePersonRepository extends Repository<Person, Long>, SamplePersonFragment {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user