List of usage examples for org.springframework.data.repository.support Repositories getPersistentEntity
public PersistentEntity<?, ?> getPersistentEntity(Class<?> domainClass)
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 a v a2 s . c om*/ @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(); }
From source file:org.lightadmin.core.config.domain.DomainTypeAdministrationConfiguration.java
public DomainTypeAdministrationConfiguration(Repositories repositories, ConfigurationUnits configurationUnits) { Assert.notNull(repositories, "Repositories must not be null!"); Assert.notNull(configurationUnits, "ConfigurationUnits must not be null!"); Class<?> domainType = configurationUnits.getDomainType(); this.repository = (DynamicJpaRepository<?, ? extends Serializable>) repositories .getRepositoryFor(domainType); this.persistentEntity = repositories.getPersistentEntity(domainType); this.configurationUnits = configurationUnits; }