Created
August 21, 2018 06:57
-
-
Save paulwellnerbou/1c4732e532de6b464ed726339691ab1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.wellnerbou.solr; | |
import org.springframework.data.solr.core.mapping.SimpleSolrMappingContext; | |
import org.springframework.data.solr.repository.query.SolrEntityInformation; | |
import org.springframework.data.solr.repository.support.SolrEntityInformationCreatorImpl; | |
public class CollectionAwareEntityInformationFacade<T, ID> implements SolrEntityInformation<T, ID> { | |
private SolrEntityInformation<T, ID> solrEntityInformation; | |
private String collectionName; | |
public CollectionAwareEntityInformationFacade(final Class<T> type, final String collectionName) { | |
this(createWrappendSolrEntityInformation(type), collectionName); | |
} | |
public CollectionAwareEntityInformationFacade(final SolrEntityInformation<T, ID> solrEntityInformation, final String collectionName) { | |
this.solrEntityInformation = solrEntityInformation; | |
this.collectionName = collectionName; | |
} | |
/** | |
* Copied from {@link org.springframework.data.solr.repository.support.SimpleSolrRepository}. | |
*/ | |
private static SolrEntityInformation createWrappendSolrEntityInformation(final Class type) { | |
return new SolrEntityInformationCreatorImpl(new SimpleSolrMappingContext()).getEntityInformation(type); | |
} | |
@Override | |
public String getIdAttribute() { | |
return solrEntityInformation.getIdAttribute(); | |
} | |
@Override | |
public String getCollectionName() { | |
return collectionName; | |
} | |
@Override | |
public boolean isNew(final T entity) { | |
return solrEntityInformation.isNew(entity); | |
} | |
@Override | |
public ID getId(final T entity) { | |
return solrEntityInformation.getId(entity); | |
} | |
@Override | |
public Class<ID> getIdType() { | |
return solrEntityInformation.getIdType(); | |
} | |
@Override | |
public Class<T> getJavaType() { | |
return solrEntityInformation.getJavaType(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment