New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose usage of DataManager.commit in case we want to obtain committed instance by id #469

Closed
haulmont-git opened this Issue Jun 15, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@haulmont-git
Copy link

haulmont-git commented Jun 15, 2017

Example:

Set<Entity> committed = dataManager.commit(new CommitContext()
		.addInstanceToCommit(manager)
		.addInstanceToCommit(mechanic)
		.addInstanceToCommit(procInstance));

ProcInstance committedProcInstance = (ProcInstance) committed.stream()
		.filter(p -> p.equals(procInstance))
		.findFirst()
		.orElseThrow(() -> new RuntimeException("Not found"));

Original issue: https://youtrack.haulmont.com/issue/PL-9274

@knstvk

This comment has been minimized.

Copy link
Member

knstvk commented May 27, 2018

Proposed solution:

public class EntitySet extends ForwardingSet implements Serializable {

    public static EntitySet of(Set<? extends Entity> entities) { }

    public <T extends Entity<K>, K> Optional<T> optional(Class<T> entityClass, K entityId) { }

    public <T extends Entity> Optional<T> optional(T prototype) { }

    public <T extends Entity<K>, K> T get(Class<T> entityClass, K entityId) { }

    public <T extends Entity> T get(T prototype) { }
}
public interface DataManager {
    
    EntitySet commit(CommitContext context);
}    

Usage:

EntitySet committed = dataManager.commit(new CommitContext()
		.addInstanceToCommit(manager)
		.addInstanceToCommit(mechanic)
		.addInstanceToCommit(procInstance));

ProcInstance committedProcInstance = committed.get(procInstance);

ProcInstance committedProcInstance = committed.get(ProcInstance.class, procInstance.getId);

Optional<ProcInstance> committedProcInstance = committed.optional(procInstance);

Optional<ProcInstance> committedProcInstance = committed.optional(ProcInstance.class, procInstance.getId);

All existing code will work without any changes, except if someone implemented DataManager interface and overridden commit(CommitContext) method (it could be done in custom DataSuppliers).

knstvk added a commit that referenced this issue May 31, 2018

@knstvk knstvk modified the milestones: Release 7.0, Release 6.10 May 31, 2018

@knstvk knstvk closed this May 31, 2018

@knstvk knstvk added the state: fixed label May 31, 2018

knstvk added a commit that referenced this issue Jun 28, 2018

Verbose usage of DataManager.commit in case we want to obtain committ…
…ed instance by id #469

Get rid of unchecked warning for old code.

knstvk added a commit that referenced this issue Jun 28, 2018

Verbose usage of DataManager.commit in case we want to obtain committ…
…ed instance by id #469

Get rid of unchecked warning in old code.

@knstvk knstvk removed the ver: 7.0.0 label Jun 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment