Search in sources :

Example 1 with UnitOfWork

use of org.polymap.model2.runtime.UnitOfWork in project polymap4-core by Polymap4.

the class StyleRepository method newFeatureStyle.

public FeatureStyle newFeatureStyle() {
    UnitOfWork uow = repo.newUnitOfWork();
    FeatureStyle result = uow.createEntity(FeatureStyle.class, null, FeatureStyle.defaults(this, uow));
    return result;
}
Also used : UnitOfWork(org.polymap.model2.runtime.UnitOfWork)

Example 2 with UnitOfWork

use of org.polymap.model2.runtime.UnitOfWork in project polymap4-core by Polymap4.

the class StyleRepository method featureStyle.

public Optional<FeatureStyle> featureStyle(String id) {
    UnitOfWork uow = repo.newUnitOfWork();
    FeatureStyle result = uow.entity(FeatureStyle.class, id);
    if (result != null) {
        result.uow = uow;
        result.repo = this;
    }
    return Optional.ofNullable(result);
}
Also used : UnitOfWork(org.polymap.model2.runtime.UnitOfWork)

Example 3 with UnitOfWork

use of org.polymap.model2.runtime.UnitOfWork in project polymap4-core by Polymap4.

the class ProjectNode method findUserSettings.

/**
 */
protected <N extends ProjectNode, U extends UserSettings> U findUserSettings(Class<U> userSettingsType, Association<N> backAssoc) {
    String username = SecurityContext.instance().getUser().getName();
    // give every instance its own UnitOfWork; so modifications can be
    // AutoCommit without interfering with the main UnitOfWork
    EntityRepository repo = context.getRepository();
    UnitOfWork uow = repo.newUnitOfWork();
    U template = Expressions.template(userSettingsType, repo);
    ResultSet<U> rs = uow.query(userSettingsType).where(and(is(backAssoc, (N) ProjectNode.this), eq(template.username, username))).maxResults(2).execute();
    assert rs.size() >= 0 || rs.size() <= 1 : "Illegal result set size: " + rs.size();
    // not found
    if (rs.size() == 0) {
        U result = uow.createEntity(userSettingsType, null, (U proto) -> {
            ProjectNode localNode = uow.entity(ProjectNode.this);
            ((Association) backAssoc.info().get(proto)).set(localNode);
            proto.username.set(username);
            return proto;
        });
        uow.commit();
        return uow.entity(result);
    } else // found
    {
        return rs.stream().findAny().get();
    }
}
Also used : UnitOfWork(org.polymap.model2.runtime.UnitOfWork) Association(org.polymap.model2.Association) EntityRepository(org.polymap.model2.runtime.EntityRepository)

Aggregations

UnitOfWork (org.polymap.model2.runtime.UnitOfWork)3 Association (org.polymap.model2.Association)1 EntityRepository (org.polymap.model2.runtime.EntityRepository)1