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:08:07 +0200 |
commit | 7fc7eec87bc2c56543e9e4ce6a2d66c5f94442b5 (patch) | |
tree | dfa656ecc05e5b3b80595a02889bef9fb98032ac /sonar-server | |
parent | 05be0dff7b176e4f5236da44098ea4c24ec750b7 (diff) | |
download | sonarqube-7fc7eec87bc2c56543e9e4ce6a2d66c5f94442b5.tar.gz sonarqube-7fc7eec87bc2c56543e9e4ce6a2d66c5f94442b5.zip |
Improve exception handling in BaseDao
Diffstat (limited to 'sonar-server')
-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); } } |