@@ -813,7 +813,7 @@ class NotificationService {
813
813
}
814
814
}
815
815
816
- @Transactional
816
+
817
817
def addAlertForUser (User user , Long queryId ) {
818
818
log. debug(' add my alert : ' + queryId + ' for user : ' + user)
819
819
def notificationInstance = new Notification ()
@@ -823,25 +823,28 @@ class NotificationService {
823
823
def exists = Notification . findByQueryAndUser(notificationInstance. query, notificationInstance. user)
824
824
if (! exists) {
825
825
log. info(" Adding alert for user: " + notificationInstance. user + " , query id: " + queryId)
826
- if (! notificationInstance. save(validate : true , flush : true )) {
827
- notificationInstance. errors. allErrors. each {
828
- log. error(it)
826
+ Notification . withTransaction {
827
+ if (! notificationInstance. save(validate : true , flush : true )) {
828
+ notificationInstance. errors. allErrors. each {
829
+ log. error(it)
830
+ }
829
831
}
830
832
}
831
833
} else {
832
834
log. info(" NOT Adding alert for user: " + notificationInstance. user + " , query id: " + queryId + " , already exists..." )
833
835
}
834
836
}
835
837
836
- @Transactional
837
- def deleteAlertForUser (User user , Long queryId ) {
838
+ def deleteAlertForUser (User user , Long queryId ) {
838
839
log. debug(' Deleting my alert : ' + queryId + ' for user : ' + user)
839
840
def query = Query . findById(queryId)
840
841
841
842
def notificationInstance = Notification . findByUserAndQuery(user, query)
842
843
if (notificationInstance) {
843
844
log. debug(' Deleting my notification : ' + queryId)
844
- notificationInstance. each { it. delete(flush : true ) }
845
+ Notification . withTransaction {
846
+ notificationInstance. each { it. delete(flush : true ) }
847
+ }
845
848
} else {
846
849
log. error(' *** Unable to find my notification - no delete : ' + queryId)
847
850
}
@@ -906,17 +909,21 @@ class NotificationService {
906
909
QueryResult qr = QueryResult . findByQueryAndFrequency(query, oldFrequency)
907
910
if (qr) {
908
911
qr. frequency = user. frequency
909
- if (! qr. save(validate : true , flush : true )) {
910
- qr. errors. allErrors. each {
911
- log. error(it)
912
+ QueryResult . withTransaction {
913
+ if (! qr. save(validate : true , flush : true )) {
914
+ qr. errors. allErrors. each {
915
+ log. error(it)
916
+ }
912
917
}
913
918
}
914
919
}
915
920
}
916
921
917
- if (! user. save(validate : true , flush : true )) {
918
- user. errors. allErrors. each {
919
- log. error(it)
922
+ User . withTransaction {
923
+ if (! user. save(validate : true , flush : true )) {
924
+ user. errors. allErrors. each {
925
+ log. error(it)
926
+ }
920
927
}
921
928
}
922
929
}
0 commit comments