Search in sources :

Example 1 with TransactionalDataManager

use of com.haulmont.cuba.core.TransactionalDataManager in project cuba by cuba-platform.

the class BulkEditorDataServiceBean method loadItemsWithCompositeKey.

@SuppressWarnings("unchecked")
protected List<Entity> loadItemsWithCompositeKey(LoadDescriptor ld) {
    Preconditions.checkNotNull(ld.getMetaClass(), "metaClass is null");
    TransactionalDataManager secureDataManager = txDataManager.secure();
    String storeName = metadataTools.getStoreName(ld.getMetaClass());
    if (storeName == null) {
        storeName = Stores.MAIN;
    }
    List<Entity> items;
    try (Transaction tx = persistence.createTransaction(storeName)) {
        // for composite key we can only load with N queries, since IN operator is not supported for composite keys
        items = ld.getSelectedItems().stream().map(item -> secureDataManager.load(Id.of(item)).view(ld.getView()).softDeletion(false).dynamicAttributes(ld.isLoadDynamicAttributes()).optional()).filter(Optional::isPresent).map(o -> (Entity) o.get()).collect(Collectors.toList());
        tx.commit();
    }
    return items;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Transaction(com.haulmont.cuba.core.Transaction) TransactionalDataManager(com.haulmont.cuba.core.TransactionalDataManager)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)1 TransactionalDataManager (com.haulmont.cuba.core.TransactionalDataManager)1 Entity (com.haulmont.cuba.core.entity.Entity)1