Commit 6cdb54970435156281e3cdd74195aa08e0977401
1 parent
720c89f1
Added ConstraintViolationException for saveEdge
Showing
1 changed file
with
16 additions
and
0 deletions
... | ... | @@ -25,6 +25,7 @@ import org.apache.http.HttpHost; |
25 | 25 | import org.apache.http.conn.ssl.DefaultHostnameVerifier; |
26 | 26 | import org.apache.http.impl.client.CloseableHttpClient; |
27 | 27 | import org.apache.http.impl.client.HttpClients; |
28 | +import org.hibernate.exception.ConstraintViolationException; | |
28 | 29 | import org.springframework.beans.factory.annotation.Autowired; |
29 | 30 | import org.springframework.beans.factory.annotation.Value; |
30 | 31 | import org.springframework.cache.Cache; |
... | ... | @@ -172,6 +173,21 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic |
172 | 173 | public Edge saveEdge(Edge edge) { |
173 | 174 | log.trace("Executing saveEdge [{}]", edge); |
174 | 175 | edgeValidator.validate(edge, Edge::getTenantId); |
176 | + Edge savedEdge; | |
177 | + if (!sqlDatabaseUsed) { | |
178 | + savedEdge = edgeDao.save(edge.getTenantId(), edge); | |
179 | + } else { | |
180 | + try { | |
181 | + savedEdge = edgeDao.save(edge.getTenantId(), edge); | |
182 | + } catch (Exception t) { | |
183 | + ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); | |
184 | + if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("edge_name_unq_key")) { | |
185 | + throw new DataValidationException("Edge with such name already exists!"); | |
186 | + } else { | |
187 | + throw t; | |
188 | + } | |
189 | + } | |
190 | + } | |
175 | 191 | return edgeDao.save(edge.getTenantId(), edge); |
176 | 192 | } |
177 | 193 | ... | ... |