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

minor: fixed error message in sample batch import when code is not unique

SVN: 16541
parent f4b76692
No related branches found
No related tags found
No related merge requests found
...@@ -178,23 +178,8 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa ...@@ -178,23 +178,8 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa
internalCreateSample(sample, hibernateTemplate, internalCreateSample(sample, hibernateTemplate,
new ClassValidator<SamplePE>(SamplePE.class), true); new ClassValidator<SamplePE>(SamplePE.class), true);
try
{ flushWithSqlExceptionHandling(hibernateTemplate);
hibernateTemplate.flush();
} catch (UncategorizedSQLException e)
{
// need to deal with exception thrown by trigger checking code uniqueness
final SQLException sqlExceptionOrNull =
ExceptionUtils.tryGetThrowableOfClass(e, SQLException.class);
if (sqlExceptionOrNull != null && sqlExceptionOrNull.getNextException() != null)
{
throw new DataIntegrityViolationException(sqlExceptionOrNull.getNextException()
.getMessage());
} else
{
throw e;
}
}
} }
public List<SamplePE> listSamplesWithPropertiesByExperiment(final ExperimentPE experiment) public List<SamplePE> listSamplesWithPropertiesByExperiment(final ExperimentPE experiment)
...@@ -474,7 +459,9 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa ...@@ -474,7 +459,9 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa
{ {
operationLog.info(String.format("ADD: %d samples.", samples.size())); operationLog.info(String.format("ADD: %d samples.", samples.size()));
} }
hibernateTemplate.flush();
// TODO 2010-06-16, Piotr Buczek: is memory usage increasing without clear of session?
flushWithSqlExceptionHandling(getHibernateTemplate());
} }
public final void updateSample(final SamplePE sample) throws DataAccessException public final void updateSample(final SamplePE sample) throws DataAccessException
...@@ -482,9 +469,9 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa ...@@ -482,9 +469,9 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa
assert sample != null : "Unspecified sample"; assert sample != null : "Unspecified sample";
validatePE(sample); validatePE(sample);
final HibernateTemplate hibernateTemplate = getHibernateTemplate(); getHibernateTemplate().flush();
flushWithSqlExceptionHandling(getHibernateTemplate());
hibernateTemplate.flush();
if (operationLog.isInfoEnabled()) if (operationLog.isInfoEnabled())
{ {
operationLog.info("UPDATE: sample '" + sample + "'."); operationLog.info("UPDATE: sample '" + sample + "'.");
...@@ -507,4 +494,26 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa ...@@ -507,4 +494,26 @@ public class SampleDAO extends AbstractGenericEntityDAO<SamplePE> implements ISa
return list; return list;
} }
private static void flushWithSqlExceptionHandling(HibernateTemplate hibernateTemplate)
throws DataAccessException
{
try
{
hibernateTemplate.flush();
} catch (UncategorizedSQLException e)
{
// need to deal with exception thrown by trigger checking code uniqueness
final SQLException sqlExceptionOrNull =
ExceptionUtils.tryGetThrowableOfClass(e, SQLException.class);
if (sqlExceptionOrNull != null && sqlExceptionOrNull.getNextException() != null)
{
throw new DataIntegrityViolationException(sqlExceptionOrNull.getNextException()
.getMessage());
} else
{
throw e;
}
}
}
} }
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