Search in sources :

Example 1 with SaveContext

use of io.jmix.core.SaveContext in project jmix-sneferu by mariodavid.

the class DatabaseCleanup method removeAllEntities.

public <T> void removeAllEntities(Class<T> entityClass) {
    SaveContext removeContext = new SaveContext();
    systemAuthenticator.withSystem(() -> {
        dataManager.load(entityClass).all().list().forEach(removeContext::removing);
        dataManager.save(removeContext);
        return null;
    });
}
Also used : SaveContext(io.jmix.core.SaveContext)

Example 2 with SaveContext

use of io.jmix.core.SaveContext in project jmix-sneferu by mariodavid.

the class VisitTestDataCreation method commit.

private int commit(List<Visit> visits) {
    SaveContext saveContext = new SaveContext();
    visits.forEach(dataManager::save);
    dataManager.save(saveContext);
    return visits.size();
}
Also used : SaveContext(io.jmix.core.SaveContext)

Example 3 with SaveContext

use of io.jmix.core.SaveContext in project jmix-docs by Haulmont.

the class CustomerEventListener method emailCustomerTheirNewGrade.

// end::after-commit[]
private void emailCustomerTheirNewGrade(String customerEmail, CustomerGrade grade) {
    SentEmail entity = dataManager.create(SentEmail.class);
    entity.setEmailedTo(customerEmail);
    // tag::save-after-commit[]
    dataManager.save(new SaveContext().saving(entity).setJoinTransaction(false));
// end::save-after-commit[]
}
Also used : SentEmail(dataaccess.ex1.entity.SentEmail) SaveContext(io.jmix.core.SaveContext)

Example 4 with SaveContext

use of io.jmix.core.SaveContext in project jmix by jmix-framework.

the class DynAttrLifecycleListener method entityReload.

@Override
public void entityReload(DataStoreEntityReloadEvent event) {
    LoadContext<?> loadContext = event.getLoadContext();
    SaveContext saveContext = event.getSaveContext();
    Object entity = saveContext.getEntitiesToSave().stream().filter(e -> Objects.equals(EntityValues.getId(e), loadContext.getId())).findFirst().orElse(null);
    DynamicAttributesState state = getExtraState(entity, DynamicAttributesState.class);
    if (state != null) {
        DynamicAttributes dynamicAttributes = state.getDynamicAttributes();
        if (dynamicAttributes != null) {
            loadContext.setHint(DynAttrQueryHints.LOAD_DYN_ATTR, true);
        }
    }
}
Also used : SaveContext(io.jmix.core.SaveContext) DynamicAttributesState(io.jmix.dynattr.DynamicAttributesState) DynamicAttributes(io.jmix.dynattr.DynamicAttributes)

Example 5 with SaveContext

use of io.jmix.core.SaveContext in project jmix by jmix-framework.

the class ImapDataProvider method saveAttachments.

public void saveAttachments(ImapMessage msg, Collection<ImapMessageAttachment> attachments) {
    SaveContext saveContext = new SaveContext();
    FetchPlan fetchPlan = fetchPlanRepository.getFetchPlan(ImapMessageAttachment.class, "imap-msg-attachment-full");
    attachments.forEach(attachment -> {
        attachment.setImapMessage(msg);
        saveContext.saving(attachment, fetchPlan);
    });
    msg.setAttachmentsLoaded(true);
    saveContext.saving(msg, fetchPlanRepository.getFetchPlan(ImapMessage.class, "imap-msg-full"));
    dataManager.save(saveContext);
}
Also used : SaveContext(io.jmix.core.SaveContext) FetchPlan(io.jmix.core.FetchPlan)

Aggregations

SaveContext (io.jmix.core.SaveContext)8 RoleAssignmentEntity (io.jmix.securitydata.entity.RoleAssignmentEntity)2 SentEmail (dataaccess.ex1.entity.SentEmail)1 FetchPlan (io.jmix.core.FetchPlan)1 DynamicAttributes (io.jmix.dynattr.DynamicAttributes)1 DynamicAttributesState (io.jmix.dynattr.DynamicAttributesState)1 RoleGrantedAuthority (io.jmix.security.authentication.RoleGrantedAuthority)1 List (java.util.List)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1