@@ -60,6 +60,34 @@ protected String getNamespace() {
60
60
return entityInformation .getJavaType ().getName ();
61
61
}
62
62
63
+ @ Override
64
+ public <S extends T > S insert (S entity ) {
65
+ entityInformation .setCreatedDate (entity );
66
+ entityInformation .setCreatedBy (entity );
67
+
68
+ if (entityInformation .hasVersion ()) {
69
+ entityInformation .setVersion (entity , 0 );
70
+ }
71
+
72
+
73
+ insert (STATEMENT_INSERT , entity );
74
+ return entity ;
75
+ }
76
+
77
+ @ Override
78
+ public <S extends T > S update (S entity ) {
79
+ entityInformation .setLastModifiedDate (entity );
80
+ entityInformation .setLastModifiedBy (entity );
81
+
82
+ int row = update (STATEMENT_UPDATE , entity );
83
+ if (row == 0 ) {
84
+ throw new MybatisNoHintException ("update effect 0 row, maybe version control lock occurred." );
85
+ }
86
+ if (entityInformation .hasVersion ()) {
87
+ entityInformation .increaseVersion (entity );
88
+ }
89
+ return entity ;
90
+ }
63
91
64
92
@ Override
65
93
@ Transactional
@@ -69,28 +97,11 @@ public <S extends T> S save(S entity) {
69
97
if (entityInformation .isNew (entity )) {
70
98
// insert
71
99
72
- entityInformation .setCreatedDate (entity );
73
- entityInformation .setCreatedBy (entity );
74
-
75
- if (entityInformation .hasVersion ()) {
76
- entityInformation .setVersion (entity , 0 );
77
- }
78
-
79
-
80
- insert (STATEMENT_INSERT , entity );
100
+ insert (entity );
81
101
} else {
82
102
// update
83
103
84
- entityInformation .setLastModifiedDate (entity );
85
- entityInformation .setLastModifiedBy (entity );
86
-
87
- int row = update (STATEMENT_UPDATE , entity );
88
- if (row == 0 ) {
89
- throw new MybatisNoHintException ("update effect 0 row, maybe version control lock occurred." );
90
- }
91
- if (entityInformation .hasVersion ()) {
92
- entityInformation .increaseVersion (entity );
93
- }
104
+ update (entity );
94
105
}
95
106
96
107
return entity ;
0 commit comments