Skip to content
Snippets Groups Projects
Commit c1789759 authored by buczekp's avatar buczekp
Browse files

[LMS-2441] improved speed of revert deletion ~2x (by using stateless session)

SVN: 22408
parent 00646b5d
No related branches found
No related tags found
No related merge requests found
......@@ -22,8 +22,10 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
......@@ -44,6 +46,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
/**
* <i>Data Access Object</i> implementation for {@link IDeletionDAO}.
......@@ -106,7 +109,8 @@ final class DeletionDAO extends AbstractGenericEntityDAO<DeletionPE> implements
super.delete(deletion);
}
private void revertDeletionOfEntities(final DeletionPE deletion, final EntityKind entityKind)
@SuppressWarnings("unused")
private void revertDeletionOfEntitiesOld(final DeletionPE deletion, final EntityKind entityKind)
{
assert deletion != null : "Unspecified deletion";
assert entityKind != null : "Unspecified entity kind";
......@@ -127,6 +131,34 @@ final class DeletionDAO extends AbstractGenericEntityDAO<DeletionPE> implements
operationLog.info(String.format("%s %s(s) reverted", updatedRows, entityKind.name()));
}
private void revertDeletionOfEntities(final DeletionPE deletion, final EntityKind entityKind)
{
assert deletion != null : "Unspecified deletion";
assert entityKind != null : "Unspecified entity kind";
List<TechId> ids =
findTrashedEntityIds(Collections.singletonList(TechId.create(deletion)), entityKind);
int updatedRows = (Integer) executeStatelessAction(new StatelessHibernateCallback()
{
public Object doInStatelessSession(StatelessSession session)
{
String query =
String.format("UPDATE %s SET del_id = NULL WHERE del_id = :dId",
entityKind.getAllTableName());
final SQLQuery sqlQuery = session.createSQLQuery(query);
sqlQuery.setParameter("dId", HibernateUtils.getId(deletion));
return sqlQuery.executeUpdate();
}
});
scheduleDynamicPropertiesEvaluationByIds(TechId.asLongs(ids), entityKind);
operationLog.info(String.format("%s %s(s) reverted", updatedRows, entityKind.name()));
}
public List<TechId> findTrashedSampleIds(final List<TechId> deletionIds)
{
return findTrashedEntityIds(deletionIds, EntityKind.SAMPLE);
......
......@@ -49,21 +49,25 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.TableNames;
*/
public enum EntityKind
{
MATERIAL(TableNames.MATERIALS_TABLE, "material", MaterialPE.class, null, MaterialTypePE.class,
MaterialTypePropertyTypePE.class, MaterialPropertyPE.class),
MATERIAL(TableNames.MATERIALS_TABLE, null, "material", MaterialPE.class, null,
MaterialTypePE.class, MaterialTypePropertyTypePE.class, MaterialPropertyPE.class),
EXPERIMENT(TableNames.EXPERIMENTS_VIEW, "experiment", ExperimentPE.class,
DeletedExperimentPE.class, ExperimentTypePE.class, ExperimentTypePropertyTypePE.class,
ExperimentPropertyPE.class),
EXPERIMENT(TableNames.EXPERIMENTS_VIEW, TableNames.EXPERIMENTS_ALL_TABLE, "experiment",
ExperimentPE.class, DeletedExperimentPE.class, ExperimentTypePE.class,
ExperimentTypePropertyTypePE.class, ExperimentPropertyPE.class),
SAMPLE(TableNames.SAMPLES_VIEW, "sample", SamplePE.class, DeletedSamplePE.class,
SampleTypePE.class, SampleTypePropertyTypePE.class, SamplePropertyPE.class),
SAMPLE(TableNames.SAMPLES_VIEW, TableNames.SAMPLES_ALL_TABLE, "sample", SamplePE.class,
DeletedSamplePE.class, SampleTypePE.class, SampleTypePropertyTypePE.class,
SamplePropertyPE.class),
DATA_SET(TableNames.DATA_VIEW, "dataSet", DataPE.class, DeletedDataPE.class,
DataSetTypePE.class, DataSetTypePropertyTypePE.class, DataSetPropertyPE.class);
DATA_SET(TableNames.DATA_VIEW, TableNames.DATA_ALL_TABLE, "dataSet", DataPE.class,
DeletedDataPE.class, DataSetTypePE.class, DataSetTypePropertyTypePE.class,
DataSetPropertyPE.class);
private final String entityTableName;
private final String allEntitiesTableName;
private final String entityLabel;
private transient final Class<? extends IEntityInformationWithPropertiesHolder> entityClass;
......@@ -76,12 +80,14 @@ public enum EntityKind
private transient final Class<?> propertyClass;
private EntityKind(final String entityTableName, final String entityLabel,
private EntityKind(final String entityTableName, final String allEntitiesTableName,
final String entityLabel,
final Class<? extends IEntityInformationWithPropertiesHolder> entityClass,
final Class<? extends IDeletablePE> deletedEntityClass, final Class<?> typeClass,
final Class<?> assignmentClass, Class<?> propertyClass)
{
this.entityTableName = entityTableName;
this.allEntitiesTableName = allEntitiesTableName;
this.entityLabel = entityLabel;
this.entityClass = entityClass;
this.deletedEntityClass = deletedEntityClass;
......@@ -106,6 +112,11 @@ public enum EntityKind
return entityTableName;
}
public final String getAllTableName()
{
return allEntitiesTableName;
}
public final <T extends EntityTypePE> Class<T> getTypeClass()
{
return cast(typeClass);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment