Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwellnerbou/1c4732e532de6b464ed726339691ab1a to your computer and use it in GitHub Desktop.
Save paulwellnerbou/1c4732e532de6b464ed726339691ab1a to your computer and use it in GitHub Desktop.
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