Search in sources :

Example 11 with SoftDelete

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

the class EntityRestoreServiceBean method restoreEntities.

@Override
public void restoreEntities(Collection<Entity> entities) {
    for (Entity entity : entities) {
        if (!(entity instanceof SoftDelete))
            continue;
        String storeName = metadata.getTools().getStoreName(metadata.getClassNN(entity.getClass()));
        if (storeName == null) {
            log.warn("Unable to restore entity {}: cannot determine data store", entity);
            continue;
        }
        Transaction tx = persistence.createTransaction(storeName);
        try {
            persistence.getEntityManager(storeName).setSoftDeletion(false);
            restoreEntity(entity, storeName);
            tx.commit();
        } finally {
            tx.end();
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) Transaction(com.haulmont.cuba.core.Transaction)

Aggregations

SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetaClass (com.haulmont.chile.core.model.MetaClass)5 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 EntityManager (com.haulmont.cuba.core.EntityManager)3 Range (com.haulmont.chile.core.model.Range)2 Query (com.haulmont.cuba.core.Query)2 OnDelete (com.haulmont.cuba.core.entity.annotation.OnDelete)2 OnDeleteInverse (com.haulmont.cuba.core.entity.annotation.OnDeleteInverse)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)2 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)2 java.util (java.util)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 Session (org.eclipse.persistence.sessions.Session)2 Pair (com.haulmont.bali.datastruct.Pair)1 QueryRunner (com.haulmont.bali.db.QueryRunner)1