diff --git a/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java b/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java index 8633e59fe34..9db145b8572 100644 --- a/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java +++ b/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java @@ -133,7 +133,7 @@ public int addEntry(String path, int parentPathId) throws SQLException, Registry } } } catch (SQLException e) { - if (e instanceof SQLIntegrityConstraintViolationException) { + if (e instanceof SQLIntegrityConstraintViolationException || "23505".equals(e.getSQLState())) { if (log.isDebugEnabled()) { log.debug("Failed to insert due to already exist in database : " + path); } diff --git a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java index c3cdd390534..ddef661cd26 100644 --- a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java +++ b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java @@ -204,12 +204,13 @@ public void test4CustomQueryResultsOrderForComments() throws RegistryException { try { registry.addComment("/test/comments/r1x", new Comment("commentXX1 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("commentXX2 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("commentXX3 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("a new test comment")); + Thread.sleep(2000); } catch (InterruptedException e) { throw new RegistryException("Error adding comments to resource", e); } @@ -264,12 +265,18 @@ public void test4CustomQueryResultsOrderForComments() throws RegistryException { Resource r2 = registry.newResource(); r2.setContent("r2 content"); registry.put("/test/comments/r2", r2); - - registry.addComment("/test/comments/r2", new Comment("commentXX1 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("commentXX2 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("commentXX3 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("a new test comment")); - + try { + registry.addComment("/test/comments/r2", new Comment("commentXX1 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("commentXX2 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("commentXX3 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("a new test comment")); + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RegistryException("Sleep Thread Interrupted", e); + } comQuery = configSystemRegistry.newResource(); sql = "SELECT REG_COMMENT_ID FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC " + "WHERE C.REG_COMMENT_TEXT LIKE ? AND C.REG_ID=RC.REG_COMMENT_ID " +