Skip to content
Snippets Groups Projects
Commit 510d0fbd authored by felmer's avatar felmer
Browse files

SP-406, BIS-279: Locks added

SVN: 27822
parent 24099d95
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
......@@ -352,6 +353,14 @@ public abstract class AbstractDAO extends HibernateDaoSupport
});
}
protected void lockEntity(Object entityOrNull)
{
if (entityOrNull != null)
{
getHibernateTemplate().lock(entityOrNull, LockMode.PESSIMISTIC_WRITE);
}
}
/**
* Callback interface for Hibernate code requiring a {@link org.hibernate.StatelessSession}. To
* be used with {@link HibernateTemplate}'s execution methods, often as anonymous classes within
......
......@@ -639,6 +639,7 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple
}
final HibernateTemplate template = getHibernateTemplate();
lockRelatedEntities(dataset);
template.save(dataset);
template.flush();
scheduleDynamicPropertiesEvaluation(Collections.singletonList(dataset));
......@@ -649,6 +650,13 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple
}
}
private void lockRelatedEntities(DataPE data)
{
lockEntity(data.getExperiment());
lockEntity(data.tryGetSample());
lockEntity(data.getContainer());
}
@Override
public void updateDataSet(DataPE data, PersonPE modifier)
{
......@@ -691,6 +699,7 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple
}
hibernateTemplate.evict(loaded);
}
lockRelatedEntities(data);
hibernateTemplate.update(data);
hibernateTemplate.flush();
scheduleDynamicPropertiesEvaluation(Collections.singletonList(data));
......
......@@ -387,6 +387,8 @@ public class ExperimentDAO extends AbstractGenericEntityWithPropertiesDAO<Experi
public void createOrUpdateExperiment(ExperimentPE experiment, PersonPE modifier)
{
HibernateTemplate template = getHibernateTemplate();
lockEntity(experiment.getProject());
internalCreateOrUpdateExperiment(experiment, modifier, template);
template.flush();
......
......@@ -86,8 +86,10 @@ public class SampleDAO extends AbstractGenericEntityWithPropertiesDAO<SamplePE>
{
sample.setModificationDate(new Date());
}
// sample.setModifier(modifier);
// sample.setModificationDate(new Date());
lockEntity(sample.getDatabaseInstance());
lockEntity(sample.getSpace());
lockEntity(sample.getExperiment());
lockEntity(sample.getContainer());
hibernateTemplate.saveOrUpdate(sample);
if (doLog && operationLog.isInfoEnabled())
{
......
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