Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.