Community
Participate
Working Groups
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.
New Gerrit change created: https://git.eclipse.org/r/95188
* DRAFT for Session.of(): https://git.eclipse.org/r/95188 * DRAFT for Session.execute() helpers: https://git.eclipse.org/r/#/c/95188/