Adding a test scenario for @MappedSuperclass, fixed a couple bugs w.r.t. generating links to entities.
This commit is contained in:
@@ -19,8 +19,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class JpaEntityMetadata
|
||||
implements EntityMetadata<JpaAttributeMetadata> {
|
||||
public class JpaEntityMetadata implements EntityMetadata<JpaAttributeMetadata> {
|
||||
|
||||
private Class<?> type;
|
||||
private JpaAttributeMetadata idAttribute;
|
||||
|
||||
@@ -5,14 +5,14 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@Entity
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Person() {
|
||||
|
||||
@@ -425,12 +425,11 @@ public class RepositoryRestController
|
||||
resources.addLink(new SimpleLink(repoMeta.rel() + "." + o.getClass().getSimpleName(),
|
||||
buildUri(baseUri, repository, id.toString())));
|
||||
} else {
|
||||
URI selfUri = buildUri(baseUri, repository, id.toString());
|
||||
MapResource res = createResource(repoMeta.rel(),
|
||||
o,
|
||||
repoMeta.entityMetadata(),
|
||||
buildUri(baseUri, repository, id.toString()));
|
||||
|
||||
URI selfUri = buildUri(baseUri, repository, id.toString());
|
||||
selfUri);
|
||||
res.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
resources.addResource(res);
|
||||
@@ -660,12 +659,11 @@ public class RepositoryRestController
|
||||
URI path = buildUri(baseUri, repository, id);
|
||||
resources.addLink(new SimpleLink(rel, path));
|
||||
} else {
|
||||
URI selfUri = buildUri(baseUri, repository, id);
|
||||
MapResource res = createResource(repoMeta.rel(),
|
||||
obj,
|
||||
repoMeta.entityMetadata(),
|
||||
buildUri(baseUri, repository, id));
|
||||
|
||||
URI selfUri = buildUri(baseUri, repository, id);
|
||||
selfUri);
|
||||
res.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
resources.addResource(res);
|
||||
@@ -731,13 +729,14 @@ public class RepositoryRestController
|
||||
MapResource resource = createResource(repoMeta.rel(),
|
||||
savedEntity,
|
||||
repoMeta.entityMetadata(),
|
||||
buildUri(baseUri, repository, sId));
|
||||
selfUri);
|
||||
resource.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
publishEvent(new BeforeRenderResourceEvent(request, repoMeta, body));
|
||||
|
||||
body = resource;
|
||||
}
|
||||
|
||||
publishEvent(new BeforeRenderResourceEvent(request, repoMeta, body));
|
||||
|
||||
return negotiateResponse(request, HttpStatus.CREATED, headers, body);
|
||||
}
|
||||
|
||||
@@ -792,11 +791,12 @@ public class RepositoryRestController
|
||||
headers.set("ETag", "\"" + version.toString() + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
URI selfUri = buildUri(baseUri, repository, id);
|
||||
MapResource res = createResource(repoMeta.rel(),
|
||||
entity,
|
||||
repoMeta.entityMetadata(),
|
||||
baseUri);
|
||||
URI selfUri = buildUri(baseUri, repository, id);
|
||||
selfUri);
|
||||
res.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
publishEvent(new BeforeRenderResourceEvent(request, repoMeta, res));
|
||||
@@ -882,7 +882,7 @@ public class RepositoryRestController
|
||||
MapResource res = createResource(repoMeta.rel(),
|
||||
savedEntity,
|
||||
repoMeta.entityMetadata(),
|
||||
baseUri);
|
||||
selfUri);
|
||||
res.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
publishEvent(new BeforeRenderResourceEvent(request, repoMeta, body));
|
||||
@@ -1284,12 +1284,11 @@ public class RepositoryRestController
|
||||
return notFoundResponse(request);
|
||||
}
|
||||
|
||||
URI selfUri = buildUri(baseUri, linkedRepoMeta.name(), linkedId);
|
||||
MapResource res = createResource(linkedRepoMeta.rel(),
|
||||
linkedEntity,
|
||||
linkedRepoMeta.entityMetadata(),
|
||||
baseUri);
|
||||
|
||||
URI selfUri = buildUri(baseUri, linkedRepoMeta.name(), linkedId);
|
||||
selfUri);
|
||||
res.addLink(new SimpleLink(SELF, selfUri));
|
||||
|
||||
publishEvent(new BeforeRenderResourcesEvent(request, repoMeta, res));
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.springframework.data.rest.test.webmvc;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class Customer {
|
||||
|
||||
@Id @GeneratedValue private Long id;
|
||||
@OneToOne private Person person;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.springframework.data.rest.test.webmvc;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@Entity
|
||||
public class WebCustomer extends Customer {
|
||||
|
||||
private String username;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.springframework.data.rest.test.webmvc;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public interface WebCustomerRepository extends CrudRepository<WebCustomer, Long> {
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
|
||||
<persistence-unit name="jpa.sample">
|
||||
<class>org.springframework.data.rest.test.webmvc.Address</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.Family</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.Person</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.Profile</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.Address</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.UuidTest</class>
|
||||
<class>org.springframework.data.rest.test.webmvc.WebCustomer</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:spring"/>
|
||||
|
||||
Reference in New Issue
Block a user