Skip to content

Commit

Permalink
Refactored Spring Data REST Invokers integration
Browse files Browse the repository at this point in the history
  • Loading branch information
max-dev committed Sep 3, 2014
1 parent de42007 commit e4e58fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
import org.springframework.data.rest.core.invoke.DynamicRepositoryInvokerFactory;
import org.lightadmin.core.persistence.repository.invoker.DynamicRepositoryInvokerFactory;
import org.springframework.data.rest.core.invoke.RepositoryInvokerFactory;
import org.springframework.data.rest.core.support.DomainObjectMerger;
import org.springframework.data.rest.webmvc.RepositoryRestController;
Expand Down Expand Up @@ -93,7 +93,9 @@ public DomainObjectMerger domainObjectMerger() throws Exception {

@Bean
public RepositoryInvokerFactory repositoryInvokerFactory() {
return new DynamicRepositoryInvokerFactory(repositories(), defaultConversionService());
RepositoryInvokerFactory repositoryInvokerFactory = super.repositoryInvokerFactory();

return new DynamicRepositoryInvokerFactory(repositories(), repositoryInvokerFactory);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.core.invoke;
package org.lightadmin.core.persistence.repository.invoker;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.rest.core.invoke.RepositoryInvoker;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.core.invoke;
package org.lightadmin.core.persistence.repository.invoker;

import org.lightadmin.core.persistence.repository.DynamicJpaRepository;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.invoke.RepositoryInvoker;
import org.springframework.data.rest.core.invoke.RepositoryInvokerFactory;
import org.springframework.util.Assert;

import java.util.Map;
Expand All @@ -27,38 +29,19 @@

public class DynamicRepositoryInvokerFactory implements RepositoryInvokerFactory {

private final RepositoryInvokerFactory delegate;
private final Repositories repositories;
private final ConversionService conversionService;
private final Map<Class<?>, RepositoryInvoker> invokers;

public DynamicRepositoryInvokerFactory(Repositories repositories, ConversionService conversionService) {
Assert.notNull(repositories, "Repositories must not be null!");
Assert.notNull(conversionService, "ConversionService must not be null!");

public DynamicRepositoryInvokerFactory(Repositories repositories, RepositoryInvokerFactory repositoryInvokerFactory) {
this.repositories = repositories;
this.conversionService = conversionService;
this.invokers = newHashMap();
}

@SuppressWarnings("unchecked")
private RepositoryInvoker prepareInvokers(Class<?> domainType) {
DynamicJpaRepository repository = (DynamicJpaRepository) repositories.getRepositoryFor(domainType);
RepositoryInformation information = repositories.getRepositoryInformationFor(domainType);

return new DynamicRepositoryInvokerWrapper(repository, information, conversionService);
this.delegate = repositoryInvokerFactory;
}

@Override
public RepositoryInvoker getInvokerFor(Class<?> domainType) {
RepositoryInvoker invoker = invokers.get(domainType);
DynamicJpaRepository dynamicJpaRepository = (DynamicJpaRepository) repositories.getRepositoryFor(domainType);
RepositoryInvoker repositoryInvoker = delegate.getInvokerFor(domainType);

if (invoker != null) {
return invoker;
}

invoker = prepareInvokers(domainType);
invokers.put(domainType, invoker);

return invoker;
}
return new DynamicRepositoryInvokerWrapper(dynamicJpaRepository, repositoryInvoker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.core.invoke;
package org.lightadmin.core.persistence.repository.invoker;

import org.lightadmin.core.persistence.repository.DynamicJpaRepository;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.rest.core.invoke.RepositoryInvoker;

import java.io.Serializable;
import java.lang.reflect.Method;
Expand All @@ -31,12 +30,12 @@
@SuppressWarnings("unchecked")
public class DynamicRepositoryInvokerWrapper implements DynamicRepositoryInvoker {

private DynamicJpaRepository<?, ?> repository;
private RepositoryInvoker repositoryInvoker;
private final DynamicJpaRepository<?, ?> repository;
private final RepositoryInvoker repositoryInvoker;

public DynamicRepositoryInvokerWrapper(DynamicJpaRepository<Object, Serializable> repository, RepositoryInformation information, ConversionService conversionService) {
this.repository = repository;
this.repositoryInvoker = new PagingAndSortingRepositoryInvoker(repository, information, conversionService);
public DynamicRepositoryInvokerWrapper(DynamicJpaRepository dynamicRepository, RepositoryInvoker repositoryInvoker) {
this.repository = dynamicRepository;
this.repositoryInvoker = repositoryInvoker;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.rest.core.invoke.DynamicRepositoryInvoker;
import org.lightadmin.core.persistence.repository.invoker.DynamicRepositoryInvoker;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.rest.webmvc.RootResourceInformation;
Expand Down

0 comments on commit e4e58fa

Please sign in to comment.