jQAssistant / extended-objects

eXtended Objects - Lightweight and flexible datastore mapping of Java domain objects
Apache License 2.0
22 stars 7 forks source link

ListProxy Lists are not sortable #160

Open Restage opened 9 years ago

Restage commented 9 years ago

ListProxy Lists returned by fetching nodes via a node's relationship property are not sortable by calling Collection.sort(). That's because the set() method in the ListProxy is not yet implemented. Is this on purpose or just an incomplete implementation at this point in time? Personally I would prefer to sort the list in my application logic rather then querying the nodes in a specific order.

Small Example Code:

List<IEvent> eventNodes = matchdayNode.getEvents();
eventNodes.sort(new EventComparator());
DirkMahler commented 9 years ago

This behavior is on purpose - the returned List directly delegates to an iterator provided by the datastore (i.e. Neo4j). This allows large results to be returned. If you need ordering you shoudl consider creating an active property with a cypher query e.g.:

@Label("MatchDay")
public interface MatchDay {

  List<Event> getEvents();

  @ResultOf
  @Cypher("match (m:MatchDay)-[:HAS_EVENT]->(e:Event) where id(m)={this} return e order by e.date") 
  Result<Event> getOrderedEvents();