Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Cskefu
Commits
64f897ff
Commit
64f897ff
authored
5 years ago
by
mukaiu
Browse files
Options
Download
Email Patches
Plain Diff
#325 fix sync es data transaction
parent
70ad4148
springboot2.x
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
contact-center/app/src/main/java/com/chatopera/cc/aspect/SyncDatabaseAspect.java
+2
-1
...main/java/com/chatopera/cc/aspect/SyncDatabaseAspect.java
contact-center/app/src/main/java/com/chatopera/cc/model/EntCustomer.java
+4
-0
...app/src/main/java/com/chatopera/cc/model/EntCustomer.java
contact-center/app/src/main/java/com/chatopera/cc/persistence/hibernate/BaseService.java
+26
-11
...a/com/chatopera/cc/persistence/hibernate/BaseService.java
with
32 additions
and
12 deletions
+32
-12
contact-center/app/src/main/java/com/chatopera/cc/aspect/SyncDatabaseAspect.java
+
2
-
1
View file @
64f897ff
...
...
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.persistence.RollbackException
;
import
java.util.List
;
@Aspect
...
...
@@ -70,7 +71,7 @@ public class SyncDatabaseAspect {
try
{
// 更新时,执行此代码,但是新建时会报错
dbDataRes
.
saveOrUpdate
(
data
);
}
catch
(
StaleState
Exception
ex
)
{
}
catch
(
Rollback
Exception
ex
)
{
// 报错的情况下,执行此代码
dbDataRes
.
save
(
data
);
}
...
...
This diff is collapsed.
Click to expand it.
contact-center/app/src/main/java/com/chatopera/cc/model/EntCustomer.java
+
4
-
0
View file @
64f897ff
...
...
@@ -20,6 +20,8 @@ package com.chatopera.cc.model;
import
com.chatopera.cc.basic.MainUtils
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.springframework.data.elasticsearch.annotations.Document
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldType
;
import
javax.persistence.*
;
import
java.util.Date
;
...
...
@@ -37,6 +39,7 @@ public class EntCustomer extends ESBean implements java.io.Serializable {
private
String
id
=
MainUtils
.
getUUID
();
@Field
(
type
=
FieldType
.
Text
,
fielddata
=
true
)
private
String
name
;
private
String
etype
;
private
String
ekind
;
...
...
@@ -89,6 +92,7 @@ public class EntCustomer extends ESBean implements java.io.Serializable {
private
String
processid
;
private
String
description
;
@Field
(
type
=
FieldType
.
Text
,
fielddata
=
true
)
private
String
creater
;
private
String
username
;
private
String
updateuser
;
...
...
This diff is collapsed.
Click to expand it.
contact-center/app/src/main/java/com/chatopera/cc/persistence/hibernate/BaseService.java
+
26
-
11
View file @
64f897ff
...
...
@@ -46,14 +46,17 @@ public class BaseService<T> {
*/
public
void
saveOrUpdateAll
(
final
List
<
Object
>
ts
)
{
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
for
(
final
Object
t
:
ts
)
{
session
.
saveOrUpdate
(
t
);
}
tx
.
commit
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
if
(
ex
!=
null
)
{
tx
.
rollback
();
}
throw
ex
;
}
finally
{
session
.
close
();
}
...
...
@@ -61,12 +64,15 @@ public class BaseService<T> {
public
void
saveOrUpdate
(
final
Object
t
)
{
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
session
.
saveOrUpdate
(
t
);
tx
.
commit
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
if
(
ex
!=
null
)
{
tx
.
rollback
();
}
throw
ex
;
}
finally
{
session
.
close
();
}
...
...
@@ -74,12 +80,15 @@ public class BaseService<T> {
public
void
save
(
final
Object
t
)
{
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
session
.
save
(
t
);
tx
.
commit
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
if
(
ex
!=
null
)
{
tx
.
rollback
();
}
throw
ex
;
}
finally
{
session
.
close
();
}
...
...
@@ -92,14 +101,17 @@ public class BaseService<T> {
*/
public
void
deleteAll
(
final
List
<
Object
>
objects
)
{
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
for
(
final
Object
t
:
objects
)
{
session
.
delete
(
session
.
merge
(
t
));
}
tx
.
commit
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
if
(
ex
!=
null
)
{
tx
.
rollback
();
}
throw
ex
;
}
finally
{
session
.
close
();
}
...
...
@@ -107,12 +119,15 @@ public class BaseService<T> {
public
void
delete
(
final
Object
object
)
{
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
session
.
delete
(
session
.
merge
(
object
));
tx
.
commit
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
if
(
ex
!=
null
)
{
tx
.
rollback
();
}
throw
ex
;
}
finally
{
session
.
close
();
}
...
...
@@ -122,8 +137,8 @@ public class BaseService<T> {
public
List
<
T
>
list
(
final
String
bean
)
{
List
<
T
>
dataList
=
null
;
Session
session
=
hibernateFactory
.
openSession
();
Transaction
tx
=
session
.
beginTransaction
();
try
{
Transaction
tx
=
session
.
beginTransaction
();
dataList
=
session
.
createCriteria
(
Class
.
forName
(
bean
)).
list
();
tx
.
commit
();
}
catch
(
Exception
ex
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help