diff --git a/build.gradle b/build.gradle index ce2cdc1ad..2af546e01 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ ext { sdJpaVersion = "1.5.0.BUILD-SNAPSHOT" sdMongoVersion = "1.4.0.BUILD-SNAPSHOT" sdGemfireVersion = "1.3.3.BUILD-SNAPSHOT" - sdNeo4jVersion = "2.3.2.RELEASE" + sdNeo4jVersion = "2.3.3.BUILD-SNAPSHOT" // Libraries jacksonVersion = "2.2.2" @@ -168,14 +168,12 @@ project("spring-data-rest-core") { // JPA testRuntime("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final", optional) - testRuntime("org.springframework:spring-orm:$springVersion", optional) - - } } project("spring-data-rest-webmvc") { + apply plugin: "maven" description = "Spring Data REST MVC components." @@ -209,6 +207,7 @@ project("spring-data-rest-webmvc") { testCompile "org.springframework.data:spring-data-jpa:$sdJpaVersion" testCompile "org.springframework.data:spring-data-mongodb:$sdMongoVersion" testCompile "org.springframework.data:spring-data-gemfire:$sdGemfireVersion" + testCompile "org.springframework.data:spring-data-neo4j:$sdNeo4jVersion" // JODA testCompile "joda-time:joda-time:$jodaVersion" diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/AbstractEntity.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/AbstractEntity.java new file mode 100644 index 000000000..0c5b1bb05 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/AbstractEntity.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.neo4j; + +import org.springframework.data.neo4j.annotation.GraphId; + +public abstract class AbstractEntity { + + @GraphId// + private Long id; + + public Long getId() { + return id; + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (id == null || obj == null || !getClass().equals(obj.getClass())) { + return false; + } + return id.equals(((AbstractEntity) obj).id); + + } + + @Override + public int hashCode() { + return id == null ? 0 : id.hashCode(); + } +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Address.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Address.java new file mode 100644 index 000000000..81c2f275c --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Address.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.neo4j; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Address extends AbstractEntity { + + private String street, city; + private Country country; + + public Address(String street, String city, Country country) { + + this.street = street; + this.city = city; + this.country = country; + } + + public Address() { + + } + + public String getStreet() { + return street; + } + + public String getCity() { + return city; + } + + public Country getCountry() { + return country; + } +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Country.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Country.java new file mode 100644 index 000000000..78f1ace34 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Country.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.neo4j; + +import org.springframework.data.neo4j.annotation.Indexed; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Country extends AbstractEntity { + + @Indexed(unique = true) String code; + String name; + + public Country(String code, String name) { + this.code = code; + this.name = name; + } + + public Country() {} +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Customer.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Customer.java new file mode 100644 index 000000000..c75c765f8 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/Customer.java @@ -0,0 +1,88 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.neo4j; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.springframework.data.neo4j.annotation.Indexed; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; +import org.springframework.util.Assert; + +@NodeEntity +public class Customer extends AbstractEntity { + + private String firstName, lastName; + + @Indexed(unique = true)// + private String emailAddress; + @RelatedTo(type = "ADDRESS")// + private Set
addresses = new HashSet(); + + public Customer(String firstName, String lastName, String emailAddress) { + + Assert.hasText(firstName); + Assert.hasText(lastName); + Assert.hasText(emailAddress); + + this.firstName = firstName; + this.lastName = lastName; + this.emailAddress = emailAddress; + } + + protected Customer() { + + } + + public void add(Address address) { + this.addresses.add(address); + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public Set getAddresses() { + return Collections.unmodifiableSet(addresses); + } + + public boolean hasAddress(Address address) { + return addresses.contains(address); + } + + @Override + public String toString() { + return String.format("%s %s <%s>", firstName, lastName, emailAddress); + } +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/CustomerRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/CustomerRepository.java new file mode 100644 index 000000000..88566d49c --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/neo4j/CustomerRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.neo4j; + +import org.springframework.data.neo4j.repository.GraphRepository; + +public interface CustomerRepository extends GraphRepository