Bug 515387 - Leverage Java 8 to provide simpler Session-related APIs for very common use cases
Summary: Leverage Java 8 to provide simpler Session-related APIs for very common use c...
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Core (show other bugs)
Version: 4.1.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-04-18 10:29 EDT by Pierre-Charles David CLA
Modified: 2017-04-20 04:53 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre-Charles David CLA 2017-04-18 10:29:09 EDT
With Java 8, there are some new language features like default methods, lambdas, static methods in interfaces, etc. that could be used to provide easier to use APIs for client code, in particular for Session related APIs.

Two "sore points", which correspond to very common use cases but which are either non obvious or cumbersome:

* Given an EObject, how to I obtain the corresponding Sirius Session? It's easy enough if you know about EObjectQuery, but discovering its existence is really not obivous. Proposal: define a static method directly in the Session interface which calls EObjectQuery. By being defined directly on Session, it will appear among the first candidates in code completion.

Instead of:

   Session s = new EObjectQuery(obj).getSession();
   if (s != null) {
     doSomething();
   }

we'd have:

  Session.of(obj).ifPresent(s -> doSomehting());

* Given a Session, how do I execute some code which will modify my model? The current solution is really combersome:

  session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
         @Override
         protected void doExecute() {
             doSomething();
         }
     });

We could provide a helper method directly on Session (with a default implem) to reduce that to:

   session.execute(() -> doSomething());

Instead of a single method, we could provide several for common use cases:
* exclusive read-only access;
* read-write access;
* read-write access, with the possibility to get a summary of the actual changes.
Comment 1 Eclipse Genie CLA 2017-04-18 10:47:59 EDT
New Gerrit change created: https://git.eclipse.org/r/95188
Comment 2 Pierre-Charles David CLA 2017-04-19 03:24:05 EDT
* DRAFT for Session.of(): https://git.eclipse.org/r/95188
* DRAFT for Session.execute() helpers: https://git.eclipse.org/r/#/c/95188/