Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
405251ce
Commit
405251ce
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-573: delete every single comment sorted by creation date to prevent constraint errors
parent
5fce03dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/core/commons/services/commentAndRating/impl/UserCommentsManagerImpl.java
+34
-9
34 additions, 9 deletions
...rvices/commentAndRating/impl/UserCommentsManagerImpl.java
with
34 additions
and
9 deletions
src/main/java/org/olat/core/commons/services/commentAndRating/impl/UserCommentsManagerImpl.java
+
34
−
9
View file @
405251ce
...
@@ -25,6 +25,9 @@ import java.util.HashSet;
...
@@ -25,6 +25,9 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
org.olat.core.commons.persistence.DB
;
import
org.olat.core.commons.persistence.DB
;
import
org.olat.core.commons.persistence.DBFactory
;
import
org.olat.core.commons.persistence.DBFactory
;
import
org.olat.core.commons.persistence.DBQuery
;
import
org.olat.core.commons.persistence.DBQuery
;
...
@@ -285,22 +288,37 @@ public class UserCommentsManagerImpl extends UserCommentsManager {
...
@@ -285,22 +288,37 @@ public class UserCommentsManagerImpl extends UserCommentsManager {
public
int
deleteAllComments
()
{
public
int
deleteAllComments
()
{
DB
db
=
DBFactory
.
getInstance
();
DB
db
=
DBFactory
.
getInstance
();
// special query when sub path is null
// special query when sub path is null
List
<
UserCommentImpl
>
comments
;
if
(
getOLATResourceableSubPath
()
==
null
)
{
if
(
getOLATResourceableSubPath
()
==
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"delete from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" where resName=:resName and resId=:resId and resSubPath is null"
);
sb
.
append
(
"select comment from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" comment"
)
return
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
())
.
append
(
" where resName=:resName and resId=:resId and resSubPath is null"
)
.
append
(
" order by creationDate desc"
);
comments
=
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
(),
UserCommentImpl
.
class
)
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
executeUpdate
();
.
getResultList
();
}
else
{
}
else
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"delete from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" where resName=:resName and resId=:resId and resSubPath=:resSubPath"
);
sb
.
append
(
"select comment from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" comment"
)
return
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
())
.
append
(
" where resName=:resName and resId=:resId and resSubPath=:resSubPath"
)
.
append
(
" order by creationDate desc"
);
comments
=
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
(),
UserCommentImpl
.
class
)
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
setParameter
(
"resSubPath"
,
getOLATResourceableSubPath
())
.
setParameter
(
"resSubPath"
,
getOLATResourceableSubPath
())
.
executeUpdate
();
.
getResultList
();
}
}
if
(
comments
!=
null
&&
!
comments
.
isEmpty
())
{
for
(
UserCommentImpl
comment:
comments
)
{
db
.
getCurrentEntityManager
().
remove
(
comment
);
}
}
return
comments
==
null
?
0
:
comments
.
size
();
}
}
/**
/**
...
@@ -310,11 +328,18 @@ public class UserCommentsManagerImpl extends UserCommentsManager {
...
@@ -310,11 +328,18 @@ public class UserCommentsManagerImpl extends UserCommentsManager {
public
int
deleteAllCommentsIgnoringSubPath
()
{
public
int
deleteAllCommentsIgnoringSubPath
()
{
DB
db
=
DBFactory
.
getInstance
();
DB
db
=
DBFactory
.
getInstance
();
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"delete from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" where resName=:resName and resId=:resId"
);
sb
.
append
(
"select comment from "
).
append
(
UserCommentImpl
.
class
.
getName
()).
append
(
" comment"
)
return
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
())
.
append
(
" where resName=:resName and resId=:resId"
)
.
append
(
" order by creationDate desc"
);
List
<
UserCommentImpl
>
comments
=
db
.
getCurrentEntityManager
().
createQuery
(
sb
.
toString
(),
UserCommentImpl
.
class
)
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resName"
,
getOLATResourceable
().
getResourceableTypeName
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
setParameter
(
"resId"
,
getOLATResourceable
().
getResourceableId
())
.
executeUpdate
();
.
getResultList
();
for
(
UserCommentImpl
comment:
comments
)
{
db
.
getCurrentEntityManager
().
remove
(
comment
);
}
return
comments
.
size
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment