Enhancement #7654

DB client CollectionSupportImpl returns lists that don't implement List#listIterator methods

Added by Tuukka Lehtonen about 1 month ago. Updated about 1 month ago.

Status:ClosedStart date:2017-11-30
Priority:4Due date:2017-11-30
Assignee:Tuukka Lehtonen% Done:

100%

Category:-Spent time:-
Target version:2017-27
Release notes:Improved implementations of collections returned by DB CollectionSupport interface to be more interoperable with other collection implementations. Also fixes lots of bugs in the implemented functions, such as an reversed iteration order problem in the List<Resource> implementation.
Tags: db, client, 1.31.0
Story points-
Velocity based estimate-
ReleaseSimantics 1.31.0Release relationshipAuto

Description

The problem with this is that if you compare these lists returned by CollectionSupportImpl against e.g. an ArrayList, the comparison is not supported:

org.simantics.db.exception.DatabaseException: java.lang.UnsupportedOperationException: Not implemented
    at org.simantics.db.impl.query.CacheEntryBase.checkAndThrow(CacheEntryBase.java:123)
    at org.simantics.db.impl.query.ReadEntry.get(ReadEntry.java:154)
    at org.simantics.db.impl.query.QueryProcessor.performForEach(QueryProcessor.java:1034)
    at org.simantics.db.impl.query.QueryProcessor.queryRead(QueryProcessor.java:865)
    at org.simantics.db.impl.graph.ReadGraphImpl.syncRequest(ReadGraphImpl.java:2027)
    at org.simantics.db.impl.graph.ReadGraphImpl.syncRequest(ReadGraphImpl.java:2014)
    at org.simantics.db.layer0.adapter.impl.EntityInstances.findRec(EntityInstances.java:154)
    at org.simantics.db.layer0.adapter.impl.EntityInstances.find(EntityInstances.java:183)
    at org.simantics.db.layer0.adapter.impl.EntityInstances.find(EntityInstances.java:56)
    at fi.vtt.simantics.apros.profile.InstancesWithUniqueName.perform(InstancesWithUniqueName.java:30)
    at fi.vtt.simantics.apros.profile.InstancesWithUniqueName.perform(InstancesWithUniqueName.java:1)
    at org.simantics.db.impl.query.QueryProcessor.performForEach(QueryProcessor.java:1058)
    at org.simantics.db.impl.query.QueryProcessor.queryRead(QueryProcessor.java:858)
    at org.simantics.db.impl.graph.ReadGraphImpl.syncRequest(ReadGraphImpl.java:2027)
    at org.simantics.db.impl.graph.ReadGraphImpl.syncRequest(ReadGraphImpl.java:2014)
        ...
    at fi.vtt.simantics.procore.internal.SessionImplSocket$1.run(SessionImplSocket.java:457)
    at fi.vtt.simantics.procore.internal.SessionRequestManager$3.run(SessionRequestManager.java:184)
    at org.simantics.db.impl.query.QueryThread.run(QueryThread.java:251)
Caused by: java.lang.UnsupportedOperationException: Not implemented
    at fi.vtt.simantics.procore.internal.CollectionSupportImpl$ResourceList.listIterator(CollectionSupportImpl.java:821)
    at java.util.AbstractList.equals(AbstractList.java:519)
    at org.simantics.db.impl.query.QueryProcessor.compareTo(QueryProcessor.java:2528)
    at org.simantics.db.impl.query.QueryProcessor.update(QueryProcessor.java:2670)
    at org.simantics.db.impl.query.QueryProcessor$7.execute(QueryProcessor.java:2781)
    at gnu.trove.impl.hash.TObjectHash.forEach(TObjectHash.java:135)
    at org.simantics.db.impl.query.QueryProcessor.performDirtyUpdates(QueryProcessor.java:2774)
    at fi.vtt.simantics.procore.internal.State.commitWriteTransaction(State.java:353)
    at fi.vtt.simantics.procore.internal.SessionRequestManager$4.run(SessionRequestManager.java:239)
    ... 1 more

The reciprocal problem is that CollectionSupportImpl.ResourceList#equals does not support comparison against any other type of list than CollectionSupportImpl.ResourceList. Naturally supporting this is much slower than comparing two ResourceLists and this isn't a must have thing.

Another subtle problem I found was injected in platform SVN version r25286 a long time ago:

The order of element iteration was reversed in the iterator returned by ResourceList#iterator() which is not good when it only saves 4 bytes of memory from being allocated per iterator but breaks the API contract.

Associated revisions

Revision ee53d306
Added by Tuukka Lehtonen about 1 month ago

Fixed CollectionSupportImpl.ResourceList iteration order

Implemented CollectionSupportImpl.ResourceList#listIterator methods.

Removed use of the deprecated Callback interface in
org.simantics.db.ResourceMap.

refs #7654

Change-Id: I22ee6da55326bf884b24e63eb2d9ed30fc242771

Revision c1e34071
Added by Tuukka Lehtonen about 1 month ago

Fixed Map & Set equals implementations in CollectionSupportImpl

refs #7654

Change-Id: I9bb10c8b529b705ad8a34a6793a002296a6bea06

History

#1 Updated by Tuukka Lehtonen about 1 month ago

  • Description updated (diff)

#2 Updated by Tuukka Lehtonen about 1 month ago

  • Status changed from New to In Progress
  • Assignee set to Tuukka Lehtonen

#3 Updated by Tuukka Lehtonen about 1 month ago

  • Tags set to 1.31.0, db, client
  • Release set to 56

#4 Updated by Tuukka Lehtonen about 1 month ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100
  • Release notes set to Improved implementations of collections returned by DB CollectionSupport interface to be more interoperable with other collection implementations. Also fixes lots of bugs in the implemented functions, such as an reversed iteration order problem in the List<Resource> implementation.

Also available in: Atom PDF