Example usage for org.springframework.data.repository.support Repositories getEntityInformationFor

List of usage examples for org.springframework.data.repository.support Repositories getEntityInformationFor

Introduction

In this page you can find the example usage for org.springframework.data.repository.support Repositories getEntityInformationFor.

Prototype

@SuppressWarnings("unchecked")
public <T, S> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) 

Source Link

Document

Returns the EntityInformation for the given domain class.

Usage

From source file:example.springdata.multistore.ApplicationConfigurationTest.java

@Test
public void repositoriesAreAssignedToAppropriateStores() {

    Repositories repositories = new Repositories(context);

    assertThat(repositories.getEntityInformationFor(Customer.class),
            is(instanceOf(JpaEntityInformation.class)));
    assertThat(repositories.getEntityInformationFor(Order.class), is(instanceOf(MongoEntityInformation.class)));
}

From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceAssembler.java

/**
 * @see DATAREST-269 (https://jira.spring.io/browse/DATAREST-269)
 *//*from w  w w  .  j  av a  2  s  .  c o  m*/
@Override
public Link getSelfLinkFor(Object instance) {
    Assert.notNull(instance, "Domain object must not be null!");

    Repositories repositories = repositories(this);

    Class instanceType = instance.getClass();
    PersistentEntity<?, ?> entity = repositories.getPersistentEntity(instanceType);

    if (entity == null) {
        throw new IllegalArgumentException(
                String.format("Cannot create self link for %s! No persistent entity found!", instanceType));
    }

    EntityInformation<Object, Serializable> entityInformation = repositories
            .getEntityInformationFor(instanceType);
    Serializable id = entityInformation.getId(instance);

    if (id == null) {
        return entityLinks(this).linkToCollectionResource(entity.getType()).withSelfRel();
    }

    return entityLinks(this).linkToSingleResource(entity.getType(), id).withSelfRel();
}