diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-04 18:18:15 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-04 19:19:26 +0200 |
commit | 927dfe6ef05795bdbf402c2e52907b55ea105e4d (patch) | |
tree | ef208fce1ecda010c42c522daf36f1641f1f09a5 /sonar-server/src/main/java/org | |
parent | 972e4d53dfad4692574b70e1bc495c76a2c177d3 (diff) | |
download | sonarqube-927dfe6ef05795bdbf402c2e52907b55ea105e4d.tar.gz sonarqube-927dfe6ef05795bdbf402c2e52907b55ea105e4d.zip |
Improve exception handling in BaseDao
Diffstat (limited to 'sonar-server/src/main/java/org')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/db/BaseDao.java | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index 10cedfdfcc3..d79460478a0 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -33,6 +33,7 @@ import org.sonar.server.search.action.KeyIndexAction; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.io.Serializable; import java.util.Collection; import java.util.Date; @@ -181,10 +182,14 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple } private void update(DbSession session, E item, Date now) { - item.setUpdatedAt(now); - doUpdate(session, item); - if (hasIndex()) { - session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); + try { + item.setUpdatedAt(now); + doUpdate(session, item); + if (hasIndex()) { + session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); + } + } catch (Exception e) { + throw new IllegalStateException("Fail to update item in db: " + item, e); } } @@ -218,9 +223,13 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple item.setCreatedAt(now); } item.setUpdatedAt(now); - doInsert(session, item); - if (hasIndex()) { - session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); + try { + doInsert(session, item); + if (hasIndex()) { + session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); + } + } catch (Exception e) { + throw new IllegalStateException("Fail to insert item in db: " + item, e.getCause()); } } @@ -247,9 +256,13 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple @Override public final void deleteByKey(DbSession session, K key) { Preconditions.checkNotNull(key, "Missing key"); - doDeleteByKey(session, key); - if (hasIndex()) { - session.enqueue(new KeyIndexAction<K>(getIndexType(), IndexAction.Method.DELETE, key)); + try { + doDeleteByKey(session, key); + if (hasIndex()) { + session.enqueue(new KeyIndexAction<K>(getIndexType(), IndexAction.Method.DELETE, key)); + } + } catch (Exception e) { + throw new IllegalStateException("Fail to delete item from db: " + key, e); } } |