Announcement Announcement Module
No announcement yet.
JDBC and Future/Callable Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDBC and Future/Callable


    I have a system where I currently have a two-step query. The first query performs the where clause filtering and only fetches the row ID's. Once I have those i construct a List<MyObject> containing proxies to the future results and returns this List. Then I schedule a (much slower) query which only fetches the row ID's I retrieved before. I use a rowcallbackHandler and for each row I lookup up the corresponding proxy and 'set' its values with the ones from the row.

    MyProxy implements MyClass
    private int id
    private MyClass value

    public MyProxy(int id){;}

    public int getID(){return id;}

    public String getOtherValue(){waitUntilfetched(); return value.getOtherValue();}

    /* This is called in the RowCallbackhandler */
    public void setValue(){this.value=value; notifyWaiters();}

    This has the advantage that the client knows very fast how many results it can expect but the slow fetch is handled in the background. The first rows can be shown very fast BUT when the user scrolls down the list ht eobject retrieval blocks until the full fetch of the corresponding row is completed.

    Are the other ways of doing ways because I feel like re-inventing the wheel here. Is there a way to work with the executorService and Callables/Futures and Spring/JDBC?