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
56db6a7a
Commit
56db6a7a
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-634: hardened publisher update to the cost of a query
parent
463c97a5
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/notifications/NotificationsManagerImpl.java
+29
-26
29 additions, 26 deletions
...java/org/olat/notifications/NotificationsManagerImpl.java
with
29 additions
and
26 deletions
src/main/java/org/olat/notifications/NotificationsManagerImpl.java
+
29
−
26
View file @
56db6a7a
...
...
@@ -594,42 +594,45 @@ public class NotificationsManagerImpl extends NotificationsManager implements Us
*/
@Override
public
Publisher
getPublisher
(
SubscriptionContext
subsContext
)
{
return
getPublisher
(
subsContext
.
getResName
(),
subsContext
.
getResId
(),
subsContext
.
getSubidentifier
(),
false
);
}
private
Publisher
getPublisherForUpdate
(
SubscriptionContext
subsContext
)
{
return
getPublisher
(
subsContext
.
getResName
(),
subsContext
.
getResId
(),
subsContext
.
getSubidentifier
(),
true
);
}
@Override
public
List
<
Publisher
>
getAllPublisher
()
{
String
q
=
"select pub from org.olat.notifications.PublisherImpl pub"
;
return
DBFactory
.
getInstance
().
getCurrentEntityManager
().
createQuery
(
q
,
Publisher
.
class
)
.
getResultList
();
}
/**
* return the publisher for the given composite primary key ores +
* subidentifier.
*/
private
Publisher
getPublisher
(
String
resName
,
Long
resId
,
String
subidentifier
,
boolean
forUpdate
)
{
StringBuilder
q
=
new
StringBuilder
();
q
.
append
(
"select pub from "
).
append
(
PublisherImpl
.
class
.
getName
()).
append
(
" pub "
)
.
append
(
" where pub.resName=:resName and pub.resId = :resId and pub.subidentifier = :subidentifier"
);
.
append
(
" where pub.resName=:resName and pub.resId = :resId"
);
if
(
StringHelper
.
containsNonWhitespace
(
subsContext
.
getSubidentifier
()))
{
q
.
append
(
" and pub.subidentifier=:subidentifier"
);
}
else
{
q
.
append
(
" and (pub.subidentifier='' or pub.subidentifier is null)"
);
}
TypedQuery
<
Publisher
>
query
=
DBFactory
.
getInstance
().
getCurrentEntityManager
()
.
createQuery
(
q
.
toString
(),
Publisher
.
class
)
.
setParameter
(
"resName"
,
r
esName
)
.
setParameter
(
"resId"
,
resId
.
longValue
())
.
setParameter
(
"subidentifier"
,
subidentifier
);
if
(
forUpdate
)
{
query
.
set
LockMode
(
LockModeType
.
PESSIMISTIC_WRITE
);
.
setParameter
(
"resName"
,
subsContext
.
getR
esName
()
)
.
setParameter
(
"resId"
,
subsContext
.
getResId
())
;
if
(
StringHelper
.
containsNonWhitespace
(
subsContext
.
getSubidentifier
())
)
{
query
.
set
Parameter
(
"subidentifier"
,
subsContext
.
getSubidentifier
()
);
}
List
<
Publisher
>
res
=
query
.
getResultList
();
if
(
res
.
isEmpty
())
return
null
;
if
(
res
.
size
()
!=
1
)
throw
new
AssertException
(
"only one subscriber per person and publisher!!"
);
return
res
.
get
(
0
);
}
private
Publisher
getPublisherForUpdate
(
SubscriptionContext
subsContext
)
{
Publisher
pub
=
getPublisher
(
subsContext
);
if
(
pub
!=
null
&&
pub
.
getKey
()
!=
null
)
{
//prevent optimistic lock issue
DBFactory
.
getInstance
().
getCurrentEntityManager
().
detach
(
pub
);
pub
=
DBFactory
.
getInstance
().
getCurrentEntityManager
().
find
(
PublisherImpl
.
class
,
pub
.
getKey
(),
LockModeType
.
PESSIMISTIC_WRITE
);
}
return
pub
;
}
@Override
public
List
<
Publisher
>
getAllPublisher
()
{
String
q
=
"select pub from org.olat.notifications.PublisherImpl pub"
;
return
DBFactory
.
getInstance
().
getCurrentEntityManager
().
createQuery
(
q
,
Publisher
.
class
)
.
getResultList
();
}
/**
* @param resName
...
...
@@ -838,7 +841,7 @@ public class NotificationsManagerImpl extends NotificationsManager implements Us
// to make sure: ignore if no subscriptionContext
if
(
subscriptionContext
==
null
)
return
;
Publisher
toUpdate
=
getPublisher
(
subscriptionContext
.
getResName
(),
subscriptionContext
.
getResId
(),
subscriptionContext
.
getSubidentifier
(),
true
);
Publisher
toUpdate
=
getPublisher
ForUpdate
(
subscriptionContext
);
if
(
toUpdate
==
null
)
{
return
;
}
...
...
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