DATAGRAPH-250 Added enforceTargetType flag to @RelatedTo to enable discrimination of clashing relationship types based on end node type
This commit is contained in:
committed by
Michael Hunger
parent
0b8de1bc4b
commit
e2e0e5cab3
@@ -60,4 +60,9 @@ public @interface RelatedTo {
|
||||
* @return target class, required for collection based fields (no generic inferring)
|
||||
*/
|
||||
Class<?> elementClass() default Object.class;
|
||||
|
||||
/**
|
||||
* Used to discriminate between relationships with the same type based on end node type
|
||||
*/
|
||||
boolean enforceTargetType() default false;
|
||||
}
|
||||
|
||||
@@ -47,35 +47,47 @@ public class RelatedToCollectionFieldAccessorFactory implements FieldAccessorFac
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldAccessor forField(final Neo4jPersistentProperty property) {
|
||||
public FieldAccessor forField(final Neo4jPersistentProperty property) {
|
||||
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
|
||||
final Class<?> targetType = relationshipInfo.getTargetType().getType();
|
||||
return new RelatedToCollectionFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, template,property);
|
||||
}
|
||||
return new RelatedToCollectionFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, template, property);
|
||||
}
|
||||
|
||||
public static class RelatedToCollectionFieldAccessor extends RelatedToFieldAccessor {
|
||||
public static class RelatedToCollectionFieldAccessor extends RelatedToFieldAccessor {
|
||||
|
||||
public RelatedToCollectionFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) {
|
||||
super(elementClass, template, direction, type,property);
|
||||
}
|
||||
public RelatedToCollectionFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) {
|
||||
super(elementClass, template, direction, type, property);
|
||||
}
|
||||
|
||||
public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
|
||||
final Node node = checkAndGetNode(entity);
|
||||
public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
|
||||
final Node node = checkAndGetNode(entity);
|
||||
// null should not remove existing relationships but leave them alone
|
||||
if (newVal == null) return null;
|
||||
final Set<Node> targetNodes = createSetOfTargetNodes(newVal);
|
||||
removeMissingRelationships(node, targetNodes);
|
||||
createAddedRelationships(node, targetNodes);
|
||||
return createManagedSet(entity, (Set<?>) newVal, property.obtainMappingPolicy(mappingPolicy));
|
||||
}
|
||||
if (newVal == null) return null;
|
||||
final Set<Node> targetNodes = createSetOfTargetNodes(newVal);
|
||||
removeMissingRelationships(node, targetNodes, property.getTargetType());
|
||||
createAddedRelationships(node, targetNodes);
|
||||
return createManagedSet(entity, (Set<?>) newVal, property.obtainMappingPolicy(mappingPolicy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
|
||||
checkAndGetNode(entity);
|
||||
public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
|
||||
checkAndGetNode(entity);
|
||||
final MappingPolicy currentPolicy = property.obtainMappingPolicy(mappingPolicy);
|
||||
final Set<?> result = createEntitySetFromRelationshipEndNodes(entity, currentPolicy);
|
||||
return doReturn(createManagedSet(entity, result, currentPolicy));
|
||||
}
|
||||
final Set<?> result = property.isTargetTypeEnforced() ?
|
||||
createEntitySetFromRelationshipEndNodesUsingTypeProperty(entity, currentPolicy) :
|
||||
createEntitySetFromRelationshipEndNodes(entity, currentPolicy);
|
||||
|
||||
Set<Object> values = new HashSet<Object>();
|
||||
Class<?> targetType = property.getTargetType();
|
||||
|
||||
for (Object value : result) {
|
||||
if (targetType == null || targetType.isAssignableFrom(value.getClass())) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
return doReturn(createManagedSet(entity, values, currentPolicy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue() {
|
||||
|
||||
@@ -66,11 +66,16 @@ public abstract class RelatedToFieldAccessor implements FieldAccessor {
|
||||
}
|
||||
|
||||
protected void removeMissingRelationships(Node node, Set<Node> targetNodes) {
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(node, targetNodes);
|
||||
removeMissingRelationships( node, targetNodes, null );
|
||||
}
|
||||
|
||||
protected void removeMissingRelationships( Node node, Set<Node> targetNodes, Class targetType ) {
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet( node, targetNodes,
|
||||
targetType );
|
||||
}
|
||||
|
||||
protected void createAddedRelationships(Node node, Set<Node> targetNodes) {
|
||||
relationshipHelper.createAddedRelationships(node, targetNodes);
|
||||
relationshipHelper.createAddedRelationships( node, targetNodes );
|
||||
}
|
||||
|
||||
protected Set<Node> createSetOfTargetNodes(Object newVal) {
|
||||
@@ -78,6 +83,11 @@ public abstract class RelatedToFieldAccessor implements FieldAccessor {
|
||||
}
|
||||
|
||||
protected Set<Object> createEntitySetFromRelationshipEndNodes(Object entity, MappingPolicy mappingPolicy) {
|
||||
return relationshipHelper.createEntitySetFromRelationshipEndNodes(entity, mappingPolicy, relatedType);
|
||||
return relationshipHelper.createEntitySetFromRelationshipEndNodes( entity, mappingPolicy, relatedType );
|
||||
}
|
||||
|
||||
protected Set<Object> createEntitySetFromRelationshipEndNodesUsingTypeProperty( Object entity, MappingPolicy
|
||||
mappingPolicy ) {
|
||||
return relationshipHelper.createEntitySetFromRelationshipEndNodes(entity, mappingPolicy, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.neo4j.mapping.RelationshipInfo;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
|
||||
@@ -35,46 +36,63 @@ public class RelatedToSingleFieldAccessorFactory implements FieldAccessorFactory
|
||||
protected Neo4jTemplate template;
|
||||
|
||||
public RelatedToSingleFieldAccessorFactory(Neo4jTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(final Neo4jPersistentProperty property) {
|
||||
if (!property.isRelationship()) return false;
|
||||
@Override
|
||||
public boolean accept(final Neo4jPersistentProperty property) {
|
||||
if (!property.isRelationship()) return false;
|
||||
return property.getRelationshipInfo().isRelatedTo() && property.getRelationshipInfo().isSingle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldAccessor forField(final Neo4jPersistentProperty property) {
|
||||
@Override
|
||||
public FieldAccessor forField(final Neo4jPersistentProperty property) {
|
||||
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
|
||||
return new RelatedToSingleFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) relationshipInfo.getTargetType().getType(), template,property);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RelatedToSingleFieldAccessor extends RelatedToFieldAccessor {
|
||||
public RelatedToSingleFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> clazz, final Neo4jTemplate template, Neo4jPersistentProperty property) {
|
||||
super(clazz, template, direction, type, property);
|
||||
}
|
||||
public static class RelatedToSingleFieldAccessor extends RelatedToFieldAccessor {
|
||||
public RelatedToSingleFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> clazz, final Neo4jTemplate template, Neo4jPersistentProperty property) {
|
||||
super(clazz, template, direction, type, property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
|
||||
final Node node= checkAndGetNode(entity);
|
||||
if (newVal == null) {
|
||||
removeMissingRelationships(node, Collections.<Node>emptySet());
|
||||
return null;
|
||||
}
|
||||
final Set<Node> target= createSetOfTargetNodes(Collections.singleton(newVal));
|
||||
removeMissingRelationships(node, target);
|
||||
createAddedRelationships(node,target);
|
||||
return newVal;
|
||||
}
|
||||
@Override
|
||||
public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
|
||||
final Node node = checkAndGetNode(entity);
|
||||
if (newVal == null) {
|
||||
removeMissingRelationships(node, Collections.<Node>emptySet());
|
||||
return null;
|
||||
}
|
||||
final Set<Node> target = createSetOfTargetNodes(Collections.singleton(newVal));
|
||||
removeMissingRelationships(node, target, property.getTargetType());
|
||||
createAddedRelationships(node, target);
|
||||
return newVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
|
||||
checkAndGetNode(entity);
|
||||
final Set<Object> result = createEntitySetFromRelationshipEndNodes(entity, property.obtainMappingPolicy(mappingPolicy));
|
||||
final Object singleEntity = result.isEmpty() ? null : result.iterator().next();
|
||||
return doReturn(singleEntity);
|
||||
}
|
||||
@Override
|
||||
public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
|
||||
checkAndGetNode(entity);
|
||||
MappingPolicy currentPolicy = property.obtainMappingPolicy(mappingPolicy);
|
||||
final Set<?> result = property.isTargetTypeEnforced() ?
|
||||
createEntitySetFromRelationshipEndNodesUsingTypeProperty(entity, currentPolicy) :
|
||||
createEntitySetFromRelationshipEndNodes(entity, currentPolicy);
|
||||
|
||||
}
|
||||
if (result.isEmpty()) return doReturn(null);
|
||||
|
||||
Set<Object> values = new HashSet<Object>();
|
||||
Class<?> targetType = property.getTargetType();
|
||||
|
||||
for (Object value : result) {
|
||||
if (targetType == null || targetType.isAssignableFrom(value.getClass())) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (values.size() == 0) return doReturn(null);
|
||||
if (values.size() == 1) return doReturn(values.iterator().next());
|
||||
|
||||
throw new IllegalArgumentException("Cannot obtain single field value for field '" + property.getField().getName() + "'");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class RelatedToViaCollectionFieldAccessorFactory implements FieldAccessor
|
||||
if (newVal == null) return null;
|
||||
|
||||
final Map<Node, Object> endNodeToEntityMapping = loadEndNodeToRelationshipEntityMapping(newVal, startNode);
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet());
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet(), null);
|
||||
persistEntities(endNodeToEntityMapping.values(), relationshipHelper.getRelationshipType());
|
||||
return createManagedSet(entity, (Set<?>) newVal, property.obtainMappingPolicy(mappingPolicy));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class RelatedToViaSingleFieldAccessorFactory implements FieldAccessorFact
|
||||
public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
|
||||
final Node startNode = relationshipHelper.checkAndGetNode(entity);
|
||||
final Map<Node,Object> endNodeToEntityMapping = relationshipEntities.loadEndNodeToRelationshipEntityMapping(startNode, toSet(newVal), relatedType);
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet());
|
||||
relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet(), null);
|
||||
persistEntities(endNodeToEntityMapping.values(), relationshipHelper.getRelationshipType() );
|
||||
return newVal;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.util.Assert;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
* @author mh
|
||||
* @since 28.02.12
|
||||
@@ -67,10 +69,25 @@ public class RelationshipHelper {
|
||||
throw new IllegalStateException("Entity must have a backing Node");
|
||||
}
|
||||
|
||||
protected void removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(Node node, Set<Node> targetNodes) {
|
||||
for (Relationship relationship : node.getRelationships(type, direction)) {
|
||||
if (!targetNodes.remove(relationship.getOtherNode(node)))
|
||||
template.delete(relationship);
|
||||
protected void removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet( Node node,
|
||||
Set<Node> targetNodes,
|
||||
Class targetType ) {
|
||||
for ( Relationship relationship : node.getRelationships( type, direction ) ) {
|
||||
if ( !targetNodes.remove( relationship.getOtherNode( node ) ) ) {
|
||||
if ( targetType != null ) {
|
||||
Object actualTargetType = relationship.getOtherNode( node ).getProperty( "__type__" );
|
||||
|
||||
try {
|
||||
if (! targetType.isAssignableFrom(Class.forName((String) actualTargetType))) {
|
||||
continue;
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException(format("Could not read type '%s' - type does not exist", actualTargetType), e);
|
||||
}
|
||||
}
|
||||
|
||||
template.delete( relationship );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,4 +98,8 @@ public interface Neo4jPersistentProperty extends PersistentProperty<Neo4jPersist
|
||||
boolean hasQuery();
|
||||
|
||||
String getQuery();
|
||||
|
||||
Class<?> getTargetType();
|
||||
|
||||
boolean isTargetTypeEnforced();
|
||||
}
|
||||
|
||||
@@ -167,17 +167,13 @@ public class Neo4jTemplate implements Neo4jOperations {
|
||||
return infrastructure.getTypeRepresentationStrategies().count(getEntityType(entityClass));
|
||||
}
|
||||
|
||||
public <S extends PropertyContainer, T> T createEntityFromStoredType(S state) {
|
||||
notNull(state,"node or relationship");
|
||||
return infrastructure.getEntityPersister().createEntityFromStoredType(state, this);
|
||||
}
|
||||
public <S extends PropertyContainer, T> T createEntityFromStoredType(S state, MappingPolicy mappingPolicy) {
|
||||
notNull(state,"node or relationship");
|
||||
return infrastructure.getEntityPersister().createEntityFromStoredType(state, mappingPolicy, this);
|
||||
}
|
||||
|
||||
public <S extends PropertyContainer, T> T createEntityFromState(S state, Class<T> type, MappingPolicy mappingPolicy) {
|
||||
notNull(state,"node or relationship",type,"entity class");
|
||||
notNull(state,"node or relationship");
|
||||
return infrastructure.getEntityPersister().createEntityFromState(state, type, mappingPolicy, this);
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -382,4 +382,18 @@ class Neo4jPersistentPropertyImpl extends AbstractPersistentProperty<Neo4jPersis
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getTargetType() {
|
||||
if (! isTargetTypeEnforced()) return null;
|
||||
|
||||
if (isCollectionLike()) return getComponentType();
|
||||
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetTypeEnforced() {
|
||||
return getAnnotation( RelatedTo.class ) != null && getAnnotation( RelatedTo.class ).enforceTargetType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.neo4j.helpers.collection.IteratorUtil.first;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"classpath:related-to-via-test-context.xml"})
|
||||
@Transactional
|
||||
public class RelatedToViaTests {
|
||||
public static final String DISTRICT_LINE = "District Line";
|
||||
public static final String CENTRAL_LINE = "Central Line";
|
||||
|
||||
@Autowired
|
||||
private UndergroundRepository tfl;
|
||||
|
||||
@Autowired
|
||||
private CountryRepository countries;
|
||||
|
||||
@Autowired
|
||||
private SuperStateRepository dystopia;
|
||||
|
||||
@Autowired
|
||||
private MetroLineRepository metroLines;
|
||||
|
||||
@Autowired
|
||||
private CityRepository cities;
|
||||
|
||||
@Autowired
|
||||
private PlayerRepository players;
|
||||
|
||||
@Autowired
|
||||
private TeamRepository teams;
|
||||
|
||||
@Autowired
|
||||
private Neo4jTemplate template;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tfl.deleteAll();
|
||||
countries.deleteAll();
|
||||
dystopia.deleteAll();
|
||||
metroLines.deleteAll();
|
||||
cities.deleteAll();
|
||||
players.deleteAll();
|
||||
teams.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapRelationshipAsFirstClassCitizen() throws Exception {
|
||||
TubeStation westHam = tfl.save( new TubeStation( "West Ham" ) );
|
||||
TubeStation stratford = tfl.save( new TubeStation( "Stratford" ) );
|
||||
TubeStation mileEnd = new TubeStation( "Mile End" );
|
||||
mileEnd.connectsTo( westHam, DISTRICT_LINE );
|
||||
mileEnd.connectsTo( stratford, CENTRAL_LINE );
|
||||
|
||||
tfl.save( mileEnd );
|
||||
|
||||
assertThat( first( template.getNode( mileEnd.getId() ).getRelationships() ).getType().name(), is( "route" ) );
|
||||
mileEnd = tfl.findOne( mileEnd.getId() );
|
||||
Line line = first( mileEnd.getLines());
|
||||
assertThat( mileEnd, is( equalTo( line.getOrigin() ) ) );
|
||||
assertThat( asList( DISTRICT_LINE, CENTRAL_LINE ), hasItem( line.getName() ) );
|
||||
assertThat( asList( westHam, stratford ), hasItem( line.getDestination() ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefault() throws Exception {
|
||||
Country france = countries.save( new Country( "République française" ) );
|
||||
Country usa = countries.save( new Country( "United States of America" ) );
|
||||
Country uk = new Country( "United Kingdom of Great Britain and Northern Ireland" );
|
||||
uk.hasCordialRelationsWith( france, "Entente Cordiale" );
|
||||
uk.hasSpecialRelationsWith( usa );
|
||||
|
||||
countries.save( uk );
|
||||
|
||||
assertThat( getRelationshipNames( uk ), is( equalTo( asSet( "cordial", "special" ) ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefaultForCollections() throws Exception {
|
||||
MetroLine m1 = metroLines.save( new MetroLine( "M1 - Vanløse to Vestamager" ) );
|
||||
MetroLine m2 = metroLines.save( new MetroLine( "M2 - Vanløse to Lufthavnen" ) );
|
||||
MetroLine m3 = metroLines.save( new MetroLine( "M3 - Cityringen" ) );
|
||||
MetroLine m4 = metroLines.save( new MetroLine( "M4 - Nørrebro to København H" ) );
|
||||
City copenhagen = new City( "Copenhagen" );
|
||||
copenhagen.has( m1, m2 );
|
||||
copenhagen.plans( m3, m4 );
|
||||
|
||||
cities.save( copenhagen );
|
||||
|
||||
assertThat( getRelationshipNames( copenhagen ), is( equalTo( asSet( "existing", "planned" ) ) ) );
|
||||
assertThat( copenhagen.getCurrentMetroLines(), is( equalTo( asSet( m1, m2 ) ) ) );
|
||||
assertThat( copenhagen.getFutureMetroLines(), is( equalTo( asSet( m3, m4 ) ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipType() throws Exception {
|
||||
SuperState eastasia = dystopia.save( new SuperState( "Eastasia" ) );
|
||||
SuperState eurasia = dystopia.save( new SuperState( "Eurasia" ) );
|
||||
SuperState oceania = new SuperState( "Oceania" );
|
||||
oceania.isAlliedWith( eastasia );
|
||||
|
||||
dystopia.save( oceania );
|
||||
|
||||
assertThat( getFirstRelationshipName( oceania ), is( equalTo( "alliedWith" ) ) );
|
||||
|
||||
oceania = dystopia.findOne( oceania.getId() );
|
||||
oceania.isAtWarWith( eurasia );
|
||||
|
||||
dystopia.save( oceania );
|
||||
|
||||
assertThat( getFirstRelationshipName( oceania ), is( equalTo( "atWarWith" ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipTypeForCollections()
|
||||
throws Exception {
|
||||
Player jordan = players.save( new Player( "Michael Jordan" ) );
|
||||
Player pippen = players.save( new Player( "Scottie Pippen" ) );
|
||||
Team bulls = new Team( "Chicago Bulls" );
|
||||
bulls.add( new PlayerStatus( bulls, jordan ) );
|
||||
bulls.add( new PlayerStatus( bulls, pippen, "substitute" ) );
|
||||
|
||||
teams.save( bulls );
|
||||
|
||||
assertThat( getRelationshipNames( bulls ), is( equalTo( asSet( "starter", "substitute" ) ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldValidateEndNode() throws Exception {
|
||||
TubeStation mileEnd = new TubeStation( "East Ham" );
|
||||
mileEnd.connectsTo( null, DISTRICT_LINE );
|
||||
|
||||
try {
|
||||
tfl.save( mileEnd );
|
||||
|
||||
fail();
|
||||
}
|
||||
catch ( InvalidDataAccessApiUsageException e ) {
|
||||
assertThat( e.getCause().getMessage(), is( equalTo( "End node must not be null (org.springframework.data" +
|
||||
".neo4j.annotation.Line)" ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private String getFirstRelationshipName( IdentifiableEntity entity ) {
|
||||
return first( template.getNode( entity.getId() ).getRelationships() ).getType().name();
|
||||
}
|
||||
|
||||
private Set<String> getRelationshipNames( IdentifiableEntity entity ) {
|
||||
HashSet<String> relationshipNames = new HashSet<String>();
|
||||
|
||||
for ( Relationship relationship : template.getNode( entity.getId() ).getRelationships() ) {
|
||||
relationshipNames.add( relationship.getType().name() );
|
||||
}
|
||||
|
||||
return relationshipNames;
|
||||
}
|
||||
|
||||
private <T> Set<T> asSet( T... ts ) {
|
||||
return new HashSet<T>( asList( ts ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation;
|
||||
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.neo4j.helpers.collection.IteratorUtil.count;
|
||||
|
||||
public class RelationshipDelegates {
|
||||
public static Set<String> getRelationshipNames(Neo4jTemplate template, IdentifiableEntity entity) {
|
||||
HashSet<String> relationshipNames = new HashSet<String>();
|
||||
|
||||
for (Relationship relationship : getRelationships(template, entity)) {
|
||||
relationshipNames.add(relationship.getType().name());
|
||||
}
|
||||
|
||||
return relationshipNames;
|
||||
}
|
||||
|
||||
public static Integer getNumberOfRelationships(Neo4jTemplate template, IdentifiableEntity entity) {
|
||||
return count(getRelationships(template, entity));
|
||||
}
|
||||
|
||||
private static Iterable<Relationship> getRelationships(Neo4jTemplate template, IdentifiableEntity entity) {
|
||||
return template.getNode(entity.getId()).getRelationships();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class SetHelper {
|
||||
public static <T> Set<T> asSet(T... ts) {
|
||||
return new HashSet<T>(asList(ts));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Activity extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Activity() {
|
||||
}
|
||||
|
||||
public Activity( String name ) {
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ActivityRepository extends CRUDRepository<Activity> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Advisor extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Advisor() {
|
||||
}
|
||||
|
||||
public Advisor(String name) {
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface AdvisorRepository extends CRUDRepository<Advisor>{
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public interface Animal {
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface AnimalRepository extends CRUDRepository<Animal> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Apple extends IdentifiableEntity {
|
||||
private String colour;
|
||||
|
||||
public Apple() {
|
||||
}
|
||||
|
||||
public Apple(String colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface AppleRepository extends CRUDRepository<Apple> {
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class AppleStore extends IdentifiableEntity {
|
||||
@RelatedTo(type = "supplies", enforceTargetType = true)
|
||||
private MacBook macBook;
|
||||
|
||||
@RelatedTo(type = "supplies", enforceTargetType = true)
|
||||
private RetinaMacBook retinaMacbook;
|
||||
|
||||
@RelatedTo(type = "supplies", enforceTargetType = true)
|
||||
private Iterable<MacBook> supplies;
|
||||
|
||||
public void suppliesMacBook(MacBook macbook) {
|
||||
this.macBook = macbook;
|
||||
}
|
||||
|
||||
public void suppliesRetinaMacBook(RetinaMacBook retinaMacbook) {
|
||||
this.retinaMacbook = retinaMacbook;
|
||||
}
|
||||
|
||||
public Iterable<MacBook> getSupplies() {
|
||||
return supplies;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface AppleStoreRepository extends CRUDRepository<AppleStore> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class BoardMember extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public BoardMember() {
|
||||
}
|
||||
|
||||
public BoardMember(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface BoardMemberRepository extends CRUDRepository<BoardMember> {
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Book extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
private Book prequel;
|
||||
|
||||
private Set<Book> peers = new HashSet<Book>();
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void follows(Book prequel) {
|
||||
this.prequel = prequel;
|
||||
}
|
||||
|
||||
public void hasTrilogyPeers(Book... books) {
|
||||
peers.addAll(asList(books));
|
||||
}
|
||||
|
||||
public Book getPrequel() {
|
||||
return prequel;
|
||||
}
|
||||
|
||||
public Set<Book> getTrilogyPeers() {
|
||||
return peers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface BookRepository extends CRUDRepository<Book> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class CareerProfile extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(enforceTargetType = true)
|
||||
private Set<Experience> experience = new HashSet<Experience>();
|
||||
|
||||
@RelatedTo(type = "experience", enforceTargetType = true)
|
||||
private Set<Job> jobs = new HashSet<Job>();
|
||||
|
||||
public CareerProfile() {
|
||||
}
|
||||
|
||||
public CareerProfile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addExperience(Experience... experience) {
|
||||
this.experience.addAll(asList(experience));
|
||||
}
|
||||
|
||||
public void addJobs(Job... jobs) {
|
||||
this.jobs.addAll(asList(jobs));
|
||||
}
|
||||
|
||||
public Set<Experience> getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public Set<Job> getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface CareerProfileRepository extends CRUDRepository<CareerProfile> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Carnivore extends IdentifiableEntity implements Animal {
|
||||
private String name;
|
||||
|
||||
public Carnivore() {
|
||||
|
||||
}
|
||||
|
||||
public Carnivore(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Chairman extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Chairman() {
|
||||
}
|
||||
|
||||
public Chairman(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ChairmanRepository extends CRUDRepository<Chairman> {
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class CoffeeMachine extends IdentifiableEntity {
|
||||
@RelatedTo(type = "produces")
|
||||
private DripBrew dripBrew;
|
||||
|
||||
@RelatedTo(type = "produces")
|
||||
private EspressoBasedCoffee espressoBasedCoffee;
|
||||
|
||||
public void produces(DripBrew dripBrew) {
|
||||
this.dripBrew = dripBrew;
|
||||
}
|
||||
|
||||
public void produces(EspressoBasedCoffee espressoBasedCoffee) {
|
||||
this.espressoBasedCoffee = espressoBasedCoffee;
|
||||
}
|
||||
|
||||
public DripBrew getDripBrew() {
|
||||
return dripBrew;
|
||||
}
|
||||
|
||||
public EspressoBasedCoffee getEspressoBasedCoffee() {
|
||||
return espressoBasedCoffee;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface CoffeeMachineRepository extends CRUDRepository<CoffeeMachine> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Course extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Course() {
|
||||
}
|
||||
|
||||
public Course(String name) {
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface CourseRepository extends CRUDRepository<Course> {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class DripBrew extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public DripBrew() {
|
||||
}
|
||||
|
||||
public DripBrew(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface DripBrewRepository extends CRUDRepository<DripBrew> {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class EspressoBasedCoffee extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public EspressoBasedCoffee() {
|
||||
}
|
||||
|
||||
public EspressoBasedCoffee(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface EspressoBasedCoffeeRepository extends CRUDRepository<EspressoBasedCoffee> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Experience extends IdentifiableEntity {
|
||||
private String description;
|
||||
|
||||
public Experience() {
|
||||
}
|
||||
|
||||
public Experience(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ExperienceRepository extends CRUDRepository<Experience> {
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class Friend extends IdentifiableEntity {
|
||||
@RelatedTo(type = "friend", enforceTargetType = true)
|
||||
private Friend friend;
|
||||
|
||||
@RelatedTo(type = "friend", enforceTargetType = true)
|
||||
private Friend bestFriend;
|
||||
|
||||
private String name;
|
||||
|
||||
public Friend() {
|
||||
}
|
||||
|
||||
public Friend(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void isFriendsWith(Friend friend) {
|
||||
this.friend = friend;
|
||||
}
|
||||
|
||||
public void isBestFriendsWith(Friend bestFriend) {
|
||||
this.bestFriend = bestFriend;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface FriendRepository extends CRUDRepository<Friend> {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class FruitBowl extends IdentifiableEntity {
|
||||
@RelatedTo(type = "contains")
|
||||
private Set<Apple> redApples = new HashSet<Apple>();
|
||||
|
||||
@RelatedTo(type = "contains")
|
||||
private Apple greenApple;
|
||||
|
||||
public void addRedApples(Apple... apples) {
|
||||
redApples.addAll(asList(apples));
|
||||
}
|
||||
|
||||
public void setGreenApple(Apple greenApple) {
|
||||
this.greenApple = greenApple;
|
||||
}
|
||||
|
||||
public Set<Apple> getRedApples() {
|
||||
return redApples;
|
||||
}
|
||||
|
||||
public Apple getGreenApple() {
|
||||
return greenApple;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface FruitBowlRepository extends CRUDRepository<FruitBowl> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Herbivore extends IdentifiableEntity implements Animal {
|
||||
private String name;
|
||||
|
||||
public Herbivore() {
|
||||
|
||||
}
|
||||
|
||||
public Herbivore(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Hero extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Hero() {
|
||||
}
|
||||
|
||||
public Hero(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface HeroRepository extends CRUDRepository<Hero> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Human extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Human() {
|
||||
}
|
||||
|
||||
public Human(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface HumanRepository extends CRUDRepository<Human> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Initiative extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "hero", enforceTargetType = true)
|
||||
private Hero leader;
|
||||
|
||||
@RelatedTo(type = "hero", enforceTargetType = true)
|
||||
private Set<Superhero> members = new HashSet<Superhero>();
|
||||
|
||||
public Initiative() {
|
||||
}
|
||||
|
||||
public Initiative(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setLeader(Hero leader) {
|
||||
this.leader = leader;
|
||||
}
|
||||
|
||||
public void add(Superhero... members) {
|
||||
this.members.addAll(asList(members));
|
||||
}
|
||||
|
||||
public Hero getLeader() {
|
||||
return leader;
|
||||
}
|
||||
|
||||
public Set<Superhero> getMembers() {
|
||||
return members;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface InitiativeRepository extends CRUDRepository<Initiative> {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Job extends Experience {
|
||||
public Job() {
|
||||
}
|
||||
|
||||
public Job(String title) {
|
||||
super(title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface JobRepository extends CRUDRepository<Job> {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class MacBook extends IdentifiableEntity{
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface MacBookRepository extends CRUDRepository<MacBook> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class MainHandWeapon extends IdentifiableEntity implements Weapon {
|
||||
private String name;
|
||||
|
||||
public MainHandWeapon() {
|
||||
}
|
||||
|
||||
public MainHandWeapon(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface MainHandWeaponRepository extends CRUDRepository<MainHandWeapon> {
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class MarvelCharacter extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(enforceTargetType=true)
|
||||
private MarvelCharacter favourite;
|
||||
|
||||
@RelatedTo(type = "favourite", enforceTargetType=true)
|
||||
private Activity favouriteActivity;
|
||||
|
||||
public MarvelCharacter() {
|
||||
|
||||
}
|
||||
|
||||
public MarvelCharacter( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void favours( MarvelCharacter marvelCharacter ) {
|
||||
favourite = marvelCharacter;
|
||||
}
|
||||
|
||||
public void loves( Activity activity ) {
|
||||
favouriteActivity = activity;
|
||||
}
|
||||
|
||||
public MarvelCharacter getFavourite() {
|
||||
return favourite;
|
||||
}
|
||||
|
||||
public Activity getFavouriteActivity() {
|
||||
return favouriteActivity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface MarvelCharacterRepository extends CRUDRepository<MarvelCharacter> {
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Mondrian extends IdentifiableEntity {
|
||||
public static short RED = 1;
|
||||
public static short YELLOW = 2;
|
||||
public static short BLUE = 3;
|
||||
|
||||
private String title;
|
||||
|
||||
@RelatedTo(type = "includes", enforceTargetType = true)
|
||||
private Square square;
|
||||
|
||||
@RelatedTo(type = "includes", enforceTargetType = true)
|
||||
private Set<Rectangle> rectangles = new HashSet<Rectangle>();
|
||||
|
||||
@RelatedTo(type = "includes", enforceTargetType = true)
|
||||
private Iterable<Quadrilateral> quadrilaterals;
|
||||
|
||||
public Mondrian() {
|
||||
}
|
||||
|
||||
public Mondrian(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void includes(Square square) {
|
||||
this.square = square;
|
||||
}
|
||||
|
||||
public void includes(Rectangle... rectangles) {
|
||||
this.rectangles.addAll(asList(rectangles));
|
||||
}
|
||||
|
||||
public Square getSquare() {
|
||||
return square;
|
||||
}
|
||||
|
||||
public Set<Rectangle> getRectangles() {
|
||||
return rectangles;
|
||||
}
|
||||
|
||||
public Iterable<Quadrilateral> getQuadrilaterals() {
|
||||
return quadrilaterals;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface MondrianRepository extends CRUDRepository<Mondrian> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class OffHandWeapon extends IdentifiableEntity implements Weapon {
|
||||
private String name;
|
||||
|
||||
public OffHandWeapon() {
|
||||
}
|
||||
|
||||
public OffHandWeapon(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface OffHandWeaponRepository extends CRUDRepository<OffHandWeapon> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Organisation extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "executive", enforceTargetType = true)
|
||||
private Chairman chairman;
|
||||
|
||||
@RelatedTo(type = "executive", enforceTargetType = true)
|
||||
private Set<BoardMember> boardMembers = new HashSet<BoardMember>();
|
||||
|
||||
public Organisation() {
|
||||
}
|
||||
|
||||
public Organisation(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setChairman(Chairman chairman) {
|
||||
this.chairman = chairman;
|
||||
}
|
||||
|
||||
public void add(BoardMember... boardMembers) {
|
||||
this.boardMembers.addAll(asList(boardMembers));
|
||||
}
|
||||
|
||||
public Chairman getChairman() {
|
||||
return chairman;
|
||||
}
|
||||
|
||||
public Set<BoardMember> getBoardMembers() {
|
||||
return boardMembers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface OrganisationRepository extends CRUDRepository<Organisation> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public abstract class Quadrilateral extends IdentifiableEntity{
|
||||
private short colour;
|
||||
|
||||
public Quadrilateral() {
|
||||
}
|
||||
|
||||
public Quadrilateral(short colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Rectangle extends Quadrilateral {
|
||||
public Rectangle() {
|
||||
|
||||
}
|
||||
|
||||
public Rectangle(short colour) {
|
||||
super(colour);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface RectangleRepository extends CRUDRepository<Rectangle> {
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jHelper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.matchers.JUnitMatchers.either;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.neo4j.helpers.collection.IteratorUtil.single;
|
||||
import static org.springframework.data.neo4j.annotation.RelationshipDelegates.getNumberOfRelationships;
|
||||
import static org.springframework.data.neo4j.annotation.RelationshipDelegates.getRelationshipNames;
|
||||
import static org.springframework.data.neo4j.annotation.SetHelper.asSet;
|
||||
import static org.springframework.data.neo4j.annotation.relatedto.Mondrian.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"classpath:related-to-test-context.xml"})
|
||||
@Transactional
|
||||
public class RelatedToTests {
|
||||
@Autowired
|
||||
private BookRepository books;
|
||||
|
||||
@Autowired
|
||||
private TownRepository towns;
|
||||
|
||||
@Autowired
|
||||
private WarchiefRepository warchiefs;
|
||||
|
||||
@Autowired
|
||||
private AdvisorRepository advisors;
|
||||
|
||||
@Autowired
|
||||
private MarvelCharacterRepository marvelCharacters;
|
||||
|
||||
@Autowired
|
||||
private ActivityRepository activities;
|
||||
|
||||
@Autowired
|
||||
private AnimalRepository animals;
|
||||
|
||||
@Autowired
|
||||
private ZooRepository zsl;
|
||||
|
||||
@Autowired
|
||||
private ShopRepository shops;
|
||||
|
||||
@Autowired
|
||||
private RestaurantRepository restaurants;
|
||||
|
||||
@Autowired
|
||||
private ShoppingCenterRepository shoppingCenters;
|
||||
|
||||
@Autowired
|
||||
private MainHandWeaponRepository mainHandWeapons;
|
||||
|
||||
@Autowired
|
||||
private OffHandWeaponRepository offHandWeapons;
|
||||
@Autowired
|
||||
private WorldOfWarcraftCharacterRepository worldOfWarcraftCharacters;
|
||||
|
||||
@Autowired
|
||||
private CourseRepository courses;
|
||||
|
||||
@Autowired
|
||||
private StudentRepository students;
|
||||
|
||||
@Autowired
|
||||
private ExperienceRepository experiences;
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobs;
|
||||
|
||||
@Autowired
|
||||
private CareerProfileRepository linkedin;
|
||||
|
||||
@Autowired
|
||||
private DripBrewRepository dripBrews;
|
||||
|
||||
@Autowired
|
||||
private EspressoBasedCoffeeRepository americanos;
|
||||
|
||||
@Autowired
|
||||
private CoffeeMachineRepository coffeeMachines;
|
||||
|
||||
@Autowired
|
||||
private AppleRepository apples;
|
||||
|
||||
@Autowired
|
||||
private FruitBowlRepository fruitbowls;
|
||||
|
||||
@Autowired
|
||||
private MacBookRepository macBookRepository;
|
||||
|
||||
@Autowired
|
||||
private RetinaMacBookRepository retinaMacBooks;
|
||||
|
||||
@Autowired
|
||||
private AppleStoreRepository appleStores;
|
||||
|
||||
@Autowired
|
||||
private FriendRepository friends;
|
||||
|
||||
@Autowired
|
||||
private ChairmanRepository chairmen;
|
||||
|
||||
@Autowired
|
||||
private BoardMemberRepository boardMembers;
|
||||
|
||||
@Autowired
|
||||
private OrganisationRepository organisations;
|
||||
|
||||
@Autowired
|
||||
private SquareRepository squares;
|
||||
|
||||
@Autowired
|
||||
private RectangleRepository rectangles;
|
||||
|
||||
@Autowired
|
||||
private MondrianRepository mondrians;
|
||||
|
||||
@Autowired
|
||||
private TeamRepository teams;
|
||||
|
||||
@Autowired
|
||||
private HumanRepository humans;
|
||||
|
||||
@Autowired
|
||||
private SuperHumanRepository superHumans;
|
||||
|
||||
@Autowired
|
||||
private SuperheroRepository superheroes;
|
||||
|
||||
@Autowired
|
||||
private HeroRepository heroes;
|
||||
|
||||
@Autowired
|
||||
private InitiativeRepository initiatives;
|
||||
|
||||
@Autowired
|
||||
private Neo4jTemplate template;
|
||||
|
||||
@BeforeTransaction
|
||||
public void before() {
|
||||
Neo4jHelper.cleanDb(template);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapRelationshipEvenWithoutAnnotation() throws Exception {
|
||||
Book theHobbit = books.save(new Book("The Hobbit"));
|
||||
Book theTwoTowers = books.save(new Book("The Two Towers"));
|
||||
Book theReturnOfTheKing = books.save(new Book("The Return of the King"));
|
||||
Book theFellowship = new Book("The Fellowship of the Ring");
|
||||
theFellowship.follows(theHobbit);
|
||||
theFellowship.hasTrilogyPeers(theTwoTowers, theReturnOfTheKing);
|
||||
|
||||
books.save(theFellowship);
|
||||
|
||||
assertThat(getRelationshipNames(template, theFellowship), is(asSet("prequel", "peers")));
|
||||
theFellowship = books.findOne(theFellowship.getId());
|
||||
assertThat(theFellowship.getPrequel(), is(equalTo(theHobbit)));
|
||||
assertThat(theFellowship.getTrilogyPeers(), is(equalTo(asSet(theTwoTowers, theReturnOfTheKing))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRelateNodesUsingFieldNameAsRelationshipType() throws Exception {
|
||||
Town malmo = towns.save(new Town("Malmö"));
|
||||
Town newcastle = new Town("Newcastle");
|
||||
newcastle.isTwinnedWith(malmo);
|
||||
Town gateshead = towns.save(new Town("Gateshead"));
|
||||
Town sunderland = towns.save(new Town("Sunderland"));
|
||||
newcastle.hasNeighbours(gateshead, sunderland);
|
||||
|
||||
towns.save(newcastle);
|
||||
|
||||
assertThat(getRelationshipNames(template, newcastle), is(asSet("twin", "neighbours")));
|
||||
newcastle = towns.findOne(newcastle.getId());
|
||||
assertThat(newcastle.getTwin(), is(equalTo(malmo)));
|
||||
assertThat(newcastle.getNeighbours(), is(equalTo(asSet(gateshead, sunderland))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRelateNodesUsingAnnotationProvidedRelationshipType() throws Exception {
|
||||
Warchief orgrim = warchiefs.save(new Warchief("Orgrim Doomhammer"));
|
||||
Warchief thrall = new Warchief("Thrall, Son of Durotan");
|
||||
thrall.succeeds(orgrim);
|
||||
Advisor garrosh = advisors.save(new Advisor("Garrosh Hellscream"));
|
||||
Advisor rehgar = advisors.save(new Advisor("Rehgar Earthfury"));
|
||||
thrall.hasAdvisors(garrosh, rehgar);
|
||||
|
||||
warchiefs.save(thrall);
|
||||
|
||||
assertThat(getRelationshipNames(template, thrall), is(asSet("succeeds", "is_advised_by")));
|
||||
thrall = warchiefs.findOne(thrall.getId());
|
||||
assertThat(thrall.getMentor(), is(equalTo(orgrim)));
|
||||
assertThat(thrall.getAdvisors(), is(equalTo(asSet(garrosh, rehgar))));
|
||||
}
|
||||
|
||||
/**
|
||||
* stacked entity cache means we do not load the node back polymorphically - should we?
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotDifferentiateByEndNodeClassWhenTargetTypeNotEnforced() throws Exception {
|
||||
DripBrew filteredCoffee = dripBrews.save(new DripBrew("Filtered Coffee"));
|
||||
EspressoBasedCoffee americano = americanos.save(new EspressoBasedCoffee("Americano"));
|
||||
CoffeeMachine coffeeMachine = new CoffeeMachine();
|
||||
coffeeMachine.produces(filteredCoffee);
|
||||
coffeeMachine.produces(americano);
|
||||
|
||||
try {
|
||||
coffeeMachines.save(coffeeMachine);
|
||||
|
||||
fail();
|
||||
} catch (ConverterNotFoundException e) {
|
||||
assertThat(asSet(DripBrew.class.getName(), EspressoBasedCoffee.class.getName()), hasItem(e.getSourceType().getName()));
|
||||
assertThat(asSet(DripBrew.class.getName(), EspressoBasedCoffee.class.getName()), hasItem(e.getTargetType().getName()));
|
||||
assertThat(e.getSourceType().getName(), is(not(equalTo(e.getTargetType().getName()))));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenFields() throws Exception {
|
||||
MarvelCharacter betty = marvelCharacters.save(new MarvelCharacter("Betty Ross"));
|
||||
Activity smashing = activities.save(new Activity("smashing"));
|
||||
MarvelCharacter hulk = new MarvelCharacter("Hulk");
|
||||
hulk.favours(betty);
|
||||
hulk.loves(smashing);
|
||||
|
||||
marvelCharacters.save(hulk);
|
||||
|
||||
assertThat(getRelationshipNames(template, hulk), is(equalTo(asSet("favourite"))));
|
||||
hulk = marvelCharacters.findOne(hulk.getId());
|
||||
assertThat(hulk.getFavourite(), is(equalTo(betty)));
|
||||
assertThat(hulk.getFavouriteActivity(), is(equalTo(smashing)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenCollections() throws Exception {
|
||||
Shop appleStore = shops.save(new Shop("Apple Store"));
|
||||
Shop hAndM = shops.save(new Shop("H&M"));
|
||||
Restaurant wahaca = restaurants.save(new Restaurant("Wahaca"));
|
||||
Restaurant busabaEathai = restaurants.save(new Restaurant("Busaba Eathai"));
|
||||
|
||||
ShoppingCenter westfield = new ShoppingCenter("Westfield - Stratford City");
|
||||
westfield.houses(appleStore, hAndM);
|
||||
westfield.houses(wahaca, busabaEathai);
|
||||
shoppingCenters.save(westfield);
|
||||
|
||||
assertThat(getRelationshipNames(template, westfield), is(equalTo(asSet("houses"))));
|
||||
westfield = shoppingCenters.findOne(westfield.getId());
|
||||
assertThat(westfield.getShops(), is(equalTo(asSet(appleStore, hAndM))));
|
||||
assertThat(westfield.getRestaurants(), is(equalTo(asSet(wahaca, busabaEathai))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenFieldAndCollection() throws Exception {
|
||||
Chairman jacquesRogge = chairmen.save(new Chairman("Jacques Rogge"));
|
||||
BoardMember boardMember1 = boardMembers.save(new BoardMember("Denis Oswald"));
|
||||
BoardMember boardMember2 = boardMembers.save(new BoardMember("René Fasel"));
|
||||
BoardMember boardMember3 = boardMembers.save(new BoardMember("Frank Fredericks"));
|
||||
|
||||
Organisation ioc = new Organisation("THE INTERNATIONAL OLYMPIC COMMITTEE");
|
||||
ioc.setChairman(jacquesRogge);
|
||||
ioc.add(boardMember1, boardMember2, boardMember3);
|
||||
organisations.save(ioc);
|
||||
|
||||
assertThat(getRelationshipNames(template, ioc), is(equalTo(asSet("executive"))));
|
||||
ioc = organisations.findOne(ioc.getId());
|
||||
assertThat(ioc.getChairman(), is(equalTo(jacquesRogge)));
|
||||
assertThat(ioc.getBoardMembers(), is(equalTo(asSet(boardMember1, boardMember2, boardMember3))));
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot distinguish the relationships, so one overwrites the other. It is not even deterministic
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenFields() throws Exception {
|
||||
Friend sam = friends.save(new Friend("Samwise Gamgee"));
|
||||
Friend pippin = friends.save(new Friend("Peregrin Took"));
|
||||
Friend frodo = new Friend("Frodo Baggins");
|
||||
frodo.isFriendsWith(pippin);
|
||||
frodo.isBestFriendsWith(sam);
|
||||
|
||||
friends.save(frodo);
|
||||
|
||||
assertThat(getNumberOfRelationships(template, frodo), is(equalTo(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* "Interesting" semantics - but we have no way of disallowing it
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenCollections() throws Exception {
|
||||
Course probabilityTheory = courses.save(new Course("Probability Theory"));
|
||||
Course geometry = courses.save(new Course("Geometry"));
|
||||
Course statistics = courses.save(new Course("Statistics"));
|
||||
Course calculus = courses.save(new Course("Calculus"));
|
||||
|
||||
Student student = new Student("Ferris Bueller");
|
||||
student.likes(probabilityTheory, geometry);
|
||||
student.isBoredWith(statistics, calculus);
|
||||
students.save(student);
|
||||
|
||||
assertThat(getRelationshipNames(template, student), is(equalTo(asSet("attends"))));
|
||||
student = students.findOne(student.getId());
|
||||
assertThat(student.getFavouriteCourses(), is(either(equalTo(asSet(probabilityTheory, geometry))).or(equalTo(asSet(statistics, calculus)))));
|
||||
assertThat(student.getDislikedCourses(), is(either(equalTo(asSet(probabilityTheory, geometry))).or(equalTo(asSet(statistics, calculus)))));
|
||||
}
|
||||
|
||||
/**
|
||||
* So, because you let your relationship types clash, and
|
||||
* didn't want to distinguish by target type, you get either
|
||||
* only green apples or an exception
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenFieldAndCollection() throws Exception {
|
||||
Apple redApple1 = apples.save(new Apple("red"));
|
||||
Apple redApple2 = apples.save(new Apple("red"));
|
||||
Apple greenApple = apples.save(new Apple("green"));
|
||||
|
||||
FruitBowl fruitBowl = new FruitBowl();
|
||||
fruitBowl.addRedApples(redApple1, redApple2);
|
||||
fruitBowl.setGreenApple(greenApple);
|
||||
try {
|
||||
fruitbowls.save(fruitBowl);
|
||||
|
||||
assertThat(getRelationshipNames(template, fruitBowl), is(equalTo(asSet("contains"))));
|
||||
|
||||
fruitBowl = fruitbowls.findOne(fruitBowl.getId());
|
||||
assertThat(fruitBowl.getRedApples(), is(equalTo(asSet(greenApple))));
|
||||
assertThat(fruitBowl.getGreenApple(), is(equalTo(greenApple)));
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
assertThat(e.getCause().getMessage(), is(equalTo("Cannot obtain single field value for field 'greenApple'")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnFieldsSharingSuperType() throws Exception {
|
||||
MainHandWeapon mainHandWeapon = mainHandWeapons.save(new MainHandWeapon("Warglaive of Azzinoth"));
|
||||
OffHandWeapon offHandWeapon = offHandWeapons.save(new OffHandWeapon("Warglaive of Azzinoth"));
|
||||
WorldOfWarcraftCharacter illidanStormrage = new WorldOfWarcraftCharacter("Illidan Stormrage");
|
||||
illidanStormrage.wields(mainHandWeapon);
|
||||
illidanStormrage.wields(offHandWeapon);
|
||||
|
||||
worldOfWarcraftCharacters.save(illidanStormrage);
|
||||
|
||||
assertThat(getRelationshipNames(template, illidanStormrage), is(equalTo(asSet("wields"))));
|
||||
illidanStormrage = worldOfWarcraftCharacters.findOne(illidanStormrage.getId());
|
||||
assertThat(illidanStormrage.getWeapons(), is(equalTo((Iterable) asSet(mainHandWeapon, offHandWeapon))));
|
||||
assertThat(illidanStormrage.getMainHandWeapon(), is(equalTo(mainHandWeapon)));
|
||||
assertThat(illidanStormrage.getOffHandWeapon(), is(equalTo(offHandWeapon)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnCollectionsSharingSuperType() throws Exception {
|
||||
Herbivore deer = animals.save(new Herbivore("Deer"));
|
||||
Herbivore giraffe = animals.save(new Herbivore("Giraffe"));
|
||||
Carnivore lion = animals.save(new Carnivore("Lion"));
|
||||
Carnivore tiger = animals.save(new Carnivore("Tiger"));
|
||||
|
||||
Zoo zsl = new Zoo("ZSL London Zoo");
|
||||
zsl.exhibits(deer);
|
||||
zsl.exhibits(giraffe);
|
||||
zsl.exhibits(lion);
|
||||
zsl.exhibits(tiger);
|
||||
this.zsl.save(zsl);
|
||||
|
||||
assertThat(getRelationshipNames(template, zsl), is(equalTo(asSet("exhibit"))));
|
||||
zsl = this.zsl.findOne(zsl.getId());
|
||||
assertThat(zsl.getAllAnimals(), is(equalTo((Iterable) asSet(deer, giraffe, lion, tiger))));
|
||||
assertThat(zsl.getHerbivores(), is(equalTo(asSet(deer, giraffe))));
|
||||
assertThat(zsl.getCarnivores(), is(equalTo(asSet(lion, tiger))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnFieldAndCollectionSharingSuperType() throws Exception {
|
||||
Square redSquare = squares.save(new Square(RED));
|
||||
Rectangle yellowRectangle = rectangles.save(new Rectangle(YELLOW));
|
||||
Rectangle blueRectangle = rectangles.save(new Rectangle(BLUE));
|
||||
|
||||
Mondrian mondrian = new Mondrian("Composition with Yellow, Blue and Red");
|
||||
mondrian.includes(redSquare);
|
||||
mondrian.includes(yellowRectangle, blueRectangle);
|
||||
mondrians.save(mondrian);
|
||||
|
||||
assertThat(getRelationshipNames(template, mondrian), is(equalTo(asSet("includes"))));
|
||||
mondrian = mondrians.findOne(mondrian.getId());
|
||||
assertThat(mondrian.getQuadrilaterals(), is(equalTo((Iterable) asSet(redSquare, yellowRectangle, blueRectangle))));
|
||||
assertThat(mondrian.getSquare(), is(equalTo(redSquare)));
|
||||
assertThat(mondrian.getRectangles(), is(equalTo(asSet(yellowRectangle, blueRectangle))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeSubstitutableBetweenFields() throws Exception {
|
||||
MacBook macbook = macBookRepository.save(new MacBook());
|
||||
RetinaMacBook retinaMacbook = retinaMacBooks.save(new RetinaMacBook());
|
||||
AppleStore appleStore = new AppleStore();
|
||||
appleStore.suppliesMacBook(macbook);
|
||||
appleStore.suppliesRetinaMacBook(retinaMacbook);
|
||||
|
||||
try {
|
||||
appleStores.save(appleStore);
|
||||
|
||||
assertThat(getRelationshipNames(template, appleStore), is(equalTo(asSet("supplies"))));
|
||||
appleStore = appleStores.findOne(appleStore.getId());
|
||||
assertThat(single(appleStore.getSupplies()), is(instanceOf(MacBook.class)));
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
assertThat(e.getCause().getMessage(), is(equalTo("Cannot obtain single field value for field 'macBook'")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeSubstitutableBetweenCollections() {
|
||||
Experience college = experiences.save(new Experience("Reed College (calligraphy mainly)"));
|
||||
Experience sabbatical = experiences.save(new Experience("Neem Karoli ashram, found enlightenment"));
|
||||
Job atari = jobs.save(new Job("Technician at Atari"));
|
||||
Job apple = jobs.save(new Job("Co-founder, Chairman and CEO, Apple Inc."));
|
||||
CareerProfile steveJobs = new CareerProfile("Steven Paul Jobs");
|
||||
steveJobs.addExperience(college, sabbatical);
|
||||
steveJobs.addJobs(atari, apple);
|
||||
|
||||
linkedin.save(steveJobs);
|
||||
|
||||
assertThat(getRelationshipNames(template, steveJobs), is(equalTo(asSet("experience"))));
|
||||
steveJobs = linkedin.findOne(steveJobs.getId());
|
||||
assertThat(steveJobs.getExperience(), is(either(equalTo(asSet(college, sabbatical))).or(equalTo(asSet(college, sabbatical, atari, apple)))));
|
||||
assertThat(steveJobs.getJobs(), is(either(equalTo(Collections.<Job>emptySet())).or(equalTo(asSet(atari, apple)))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedAndEndNodeTypeForFieldInheritsFromEndNodeTypeForCollection() throws Exception {
|
||||
Human sam = humans.save(new Human("Samantha Carter"));
|
||||
Human daniel = humans.save(new Human("Daniel Jackson"));
|
||||
Human tealc = humans.save(new Human("Tealc"));
|
||||
SuperHuman jack = superHumans.save(new SuperHuman("Jack O'Neill"));
|
||||
|
||||
Team sg1 = new Team("SG1");
|
||||
sg1.setLeader(jack);
|
||||
sg1.add(sam, daniel, tealc);
|
||||
teams.save(sg1);
|
||||
|
||||
assertThat(getRelationshipNames(template, sg1), is(equalTo(asSet("member"))));
|
||||
assertThat(sg1.getLeader(), is(equalTo(jack)));
|
||||
assertThat(sg1.getMembers(), is(equalTo(asSet(sam, daniel, tealc))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeForCollectionInheritsFromEndNodeTypeForField() throws Exception {
|
||||
Superhero thor = superheroes.save(new Superhero("Thor"));
|
||||
Superhero ironMan = superheroes.save(new Superhero("Iron Man"));
|
||||
Superhero hulk = superheroes.save(new Superhero("Hulk"));
|
||||
Hero nickFury = heroes.save(new Hero("Nick Fury"));
|
||||
|
||||
Initiative avengers = new Initiative("Avengers");
|
||||
avengers.setLeader(nickFury);
|
||||
avengers.add(thor, ironMan, hulk);
|
||||
initiatives.save(avengers);
|
||||
|
||||
assertThat(getRelationshipNames(template, avengers), is(equalTo(asSet("hero"))));
|
||||
avengers = initiatives.findOne(avengers.getId());
|
||||
assertThat(avengers.getLeader(), is(equalTo(nickFury)));
|
||||
assertThat(avengers.getMembers(), is(equalTo(asSet(thor, ironMan, hulk))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Restaurant extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Restaurant() {
|
||||
}
|
||||
|
||||
public Restaurant(String name) {
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface RestaurantRepository extends CRUDRepository<Restaurant> {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class RetinaMacBook extends MacBook {
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface RetinaMacBookRepository extends CRUDRepository<RetinaMacBook> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Shop extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Shop() {
|
||||
}
|
||||
|
||||
public Shop(String name) {
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ShopRepository extends CRUDRepository<Shop> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class ShoppingCenter extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "houses", enforceTargetType = true)
|
||||
private Set<Shop> shops = new HashSet<Shop>();
|
||||
|
||||
@RelatedTo(type = "houses", enforceTargetType = true)
|
||||
private Set<Restaurant> restaurants = new HashSet<Restaurant>();
|
||||
|
||||
public ShoppingCenter() {
|
||||
}
|
||||
|
||||
public ShoppingCenter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void houses(Shop... shops) {
|
||||
this.shops = new HashSet<Shop>(asList(shops));
|
||||
}
|
||||
|
||||
public void houses(Restaurant... restaurants) {
|
||||
this.restaurants.addAll(asList(restaurants));
|
||||
}
|
||||
|
||||
public Set<Shop> getShops() {
|
||||
return shops;
|
||||
}
|
||||
|
||||
public Set<Restaurant> getRestaurants() {
|
||||
return restaurants;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ShoppingCenterRepository extends CRUDRepository<ShoppingCenter> {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Square extends Quadrilateral {
|
||||
public Square() {
|
||||
|
||||
}
|
||||
|
||||
public Square(short colour) {
|
||||
super(colour);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface SquareRepository extends CRUDRepository<Square> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Student extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "attends")
|
||||
private Set<Course> favouriteCourses = new HashSet<Course>();
|
||||
|
||||
@RelatedTo(type = "attends", enforceTargetType = true)
|
||||
private Set<Course> dislikedCourses = new HashSet<Course>();
|
||||
|
||||
public Student() {
|
||||
}
|
||||
|
||||
public Student(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void likes(Course... courses) {
|
||||
favouriteCourses.addAll(asList(courses));
|
||||
}
|
||||
|
||||
public void isBoredWith(Course... courses) {
|
||||
dislikedCourses.addAll(asList(courses));
|
||||
}
|
||||
|
||||
public Set<Course> getFavouriteCourses() {
|
||||
return favouriteCourses;
|
||||
}
|
||||
|
||||
public Set<Course> getDislikedCourses() {
|
||||
return dislikedCourses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface StudentRepository extends CRUDRepository<Student> {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class SuperHuman extends Human {
|
||||
public SuperHuman() {
|
||||
|
||||
}
|
||||
|
||||
public SuperHuman(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface SuperHumanRepository extends CRUDRepository<SuperHuman> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public class Superhero extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
public Superhero() {
|
||||
}
|
||||
|
||||
public Superhero(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface SuperheroRepository extends CRUDRepository<Superhero> {
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Team extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "member", enforceTargetType = true)
|
||||
private SuperHuman leader;
|
||||
|
||||
@RelatedTo(type = "member", enforceTargetType = true)
|
||||
private Set<Human> members = new HashSet<Human>();
|
||||
|
||||
public Team() {
|
||||
}
|
||||
|
||||
public Team(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setLeader(SuperHuman leader) {
|
||||
this.leader = leader;
|
||||
}
|
||||
|
||||
public void add(Human... members) {
|
||||
this.members.addAll(asList(members));
|
||||
}
|
||||
|
||||
public SuperHuman getLeader() {
|
||||
return leader;
|
||||
}
|
||||
|
||||
public Set<Human> getMembers() {
|
||||
return members;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface TeamRepository extends CRUDRepository<Team> {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Town extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo
|
||||
private Town twin;
|
||||
|
||||
@RelatedTo
|
||||
private Set<Town> neighbours = new HashSet<Town>();
|
||||
|
||||
public Town() {
|
||||
|
||||
}
|
||||
|
||||
public Town( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void isTwinnedWith( Town twin ) {
|
||||
this.twin = twin;
|
||||
}
|
||||
|
||||
public Town getTwin() {
|
||||
return twin;
|
||||
}
|
||||
|
||||
public void hasNeighbours(Town... towns) {
|
||||
this.neighbours.addAll(asList(towns));
|
||||
}
|
||||
|
||||
public Set<Town> getNeighbours() {
|
||||
return neighbours;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface TownRepository extends CRUDRepository<Town> {
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@NodeEntity
|
||||
public class Warchief extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "succeeds")
|
||||
private Warchief mentor;
|
||||
|
||||
@RelatedTo(type = "is_advised_by")
|
||||
private Set<Advisor> advisors = new HashSet<Advisor>();
|
||||
|
||||
public Warchief() {
|
||||
|
||||
}
|
||||
|
||||
public Warchief( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void succeeds( Warchief mentor ) {
|
||||
this.mentor = mentor;
|
||||
}
|
||||
|
||||
public Warchief getMentor() {
|
||||
return mentor;
|
||||
}
|
||||
|
||||
public void hasAdvisors(Advisor... advisors) {
|
||||
this.advisors.addAll(asList(advisors));
|
||||
}
|
||||
|
||||
public Set<Advisor> getAdvisors() {
|
||||
return advisors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface WarchiefRepository extends CRUDRepository<Warchief> {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
|
||||
@NodeEntity
|
||||
public interface Weapon {
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class WorldOfWarcraftCharacter extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "wields", enforceTargetType = true)
|
||||
private MainHandWeapon mainHandWeapon;
|
||||
|
||||
@RelatedTo(type = "wields", enforceTargetType = true)
|
||||
private OffHandWeapon offHandWeapon;
|
||||
|
||||
@RelatedTo(type = "wields", enforceTargetType = true)
|
||||
private Iterable<Weapon> weapons;
|
||||
|
||||
public WorldOfWarcraftCharacter() {
|
||||
}
|
||||
|
||||
public WorldOfWarcraftCharacter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void wields(MainHandWeapon mainHandWeapon) {
|
||||
this.mainHandWeapon = mainHandWeapon;
|
||||
}
|
||||
|
||||
public void wields(OffHandWeapon offHandWeapon) {
|
||||
this.offHandWeapon = offHandWeapon;
|
||||
}
|
||||
|
||||
public Iterable<Weapon> getWeapons() {
|
||||
return weapons;
|
||||
}
|
||||
|
||||
public MainHandWeapon getMainHandWeapon() {
|
||||
return mainHandWeapon;
|
||||
}
|
||||
|
||||
public OffHandWeapon getOffHandWeapon() {
|
||||
return offHandWeapon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface WorldOfWarcraftCharacterRepository extends CRUDRepository<WorldOfWarcraftCharacter> {
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
@NodeEntity
|
||||
public class Zoo extends IdentifiableEntity {
|
||||
private String name;
|
||||
|
||||
@RelatedTo(type = "exhibit", enforceTargetType = true)
|
||||
private Iterable<Animal> animals;
|
||||
|
||||
@RelatedTo(type = "exhibit", enforceTargetType = true)
|
||||
private Set<Herbivore> herbivores = new HashSet<Herbivore>();
|
||||
|
||||
@RelatedTo(type = "exhibit", enforceTargetType = true)
|
||||
private Set<Carnivore> carnivores = new HashSet<Carnivore>();
|
||||
|
||||
public Zoo() {
|
||||
|
||||
}
|
||||
|
||||
public Zoo( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void exhibits( Herbivore herbivore ) {
|
||||
herbivores.add(herbivore);
|
||||
}
|
||||
|
||||
public void exhibits( Carnivore carnivore ) {
|
||||
carnivores.add(carnivore);
|
||||
}
|
||||
|
||||
public Iterable<Animal> getAllAnimals() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
public Set<Herbivore> getHerbivores() {
|
||||
return herbivores;
|
||||
}
|
||||
|
||||
public Set<Carnivore> getCarnivores() {
|
||||
return carnivores;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2011 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.neo4j.annotation.relatedto;
|
||||
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
public interface ZooRepository extends CRUDRepository<Zoo> {
|
||||
}
|
||||
@@ -13,11 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.neo4j.annotation;
|
||||
package org.springframework.data.neo4j.annotation.relatedtovia;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.neo4j.annotation.IdentifiableEntity;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedToVia;
|
||||
|
||||
@NodeEntity
|
||||
public class City extends IdentifiableEntity {
|
||||
private String name;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user