@@ -56,6 +56,9 @@ public static class EntityTable {
56
56
private Set <EntityColumn > entityClassPKColumns ;
57
57
//字段名和属性名的映射
58
58
private Map <String , String > aliasMap ;
59
+ //useGenerator包含多列的时候需要用到
60
+ private List <String > keyProperties ;
61
+ private List <String > keyColumns ;
59
62
60
63
public void setTable (Table table ) {
61
64
this .name = table .name ();
@@ -96,12 +99,45 @@ public Set<EntityColumn> getEntityClassPKColumns() {
96
99
public Map <String , String > getAliasMap () {
97
100
return aliasMap ;
98
101
}
102
+
103
+ public String [] getKeyProperties () {
104
+ if (keyProperties != null && keyProperties .size () > 0 ) {
105
+ return keyProperties .toArray (new String []{});
106
+ }
107
+ return new String []{};
108
+ }
109
+
110
+ public void setKeyProperties (String keyProperty ) {
111
+ if (this .keyProperties == null ) {
112
+ this .keyProperties = new ArrayList <String >();
113
+ this .keyProperties .add (keyProperty );
114
+ } else {
115
+ this .keyProperties .add (keyProperty );
116
+ }
117
+ }
118
+
119
+ public String [] getKeyColumns () {
120
+ if (keyColumns != null && keyColumns .size () > 0 ) {
121
+ return keyColumns .toArray (new String []{});
122
+ }
123
+ return new String []{};
124
+ }
125
+
126
+ public void setKeyColumns (String keyColumn ) {
127
+ if (this .keyColumns == null ) {
128
+ this .keyColumns = new ArrayList <String >();
129
+ this .keyColumns .add (keyColumn );
130
+ } else {
131
+ this .keyColumns .add (keyColumn );
132
+ }
133
+ }
99
134
}
100
135
101
136
/**
102
137
* 实体字段对应数据库列的信息
103
138
*/
104
139
public static class EntityColumn {
140
+ private EntityTable table ;
105
141
private String property ;
106
142
private String column ;
107
143
private Class <?> javaType ;
@@ -110,9 +146,23 @@ public static class EntityColumn {
110
146
private boolean uuid = false ;
111
147
private boolean identity = false ;
112
148
private String generator ;
113
- private String keyProperties ;//useGenerator包含多列的时候需要用到
114
149
private String orderBy ;
115
150
151
+ public EntityColumn () {
152
+ }
153
+
154
+ public EntityColumn (EntityTable table ) {
155
+ this .table = table ;
156
+ }
157
+
158
+ public EntityTable getTable () {
159
+ return table ;
160
+ }
161
+
162
+ public void setTable (EntityTable table ) {
163
+ this .table = table ;
164
+ }
165
+
116
166
public String getProperty () {
117
167
return property ;
118
168
}
@@ -177,14 +227,6 @@ public void setGenerator(String generator) {
177
227
this .generator = generator ;
178
228
}
179
229
180
- public String getKeyProperties () {
181
- return keyProperties ;
182
- }
183
-
184
- public void setKeyProperties (String keyProperties ) {
185
- this .keyProperties = keyProperties ;
186
- }
187
-
188
230
public String getOrderBy () {
189
231
return orderBy ;
190
232
}
@@ -398,7 +440,7 @@ public static synchronized void initEntityNameMap(Class<?> entityClass) {
398
440
if (field .isAnnotationPresent (Transient .class )) {
399
441
continue ;
400
442
}
401
- EntityColumn entityColumn = new EntityColumn ();
443
+ EntityColumn entityColumn = new EntityColumn (entityTable );
402
444
if (field .isAnnotationPresent (Id .class )) {
403
445
entityColumn .setId (true );
404
446
}
@@ -436,6 +478,8 @@ public static synchronized void initEntityNameMap(Class<?> entityClass) {
436
478
} else if (generatedValue .generator ().equals ("JDBC" )) {
437
479
entityColumn .setIdentity (true );
438
480
entityColumn .setGenerator ("JDBC" );
481
+ entityTable .setKeyProperties (entityColumn .getProperty ());
482
+ entityTable .setKeyColumns (entityColumn .getColumn ());
439
483
} else {
440
484
//允许通过generator来设置获取id的sql,例如mysql=CALL IDENTITY(),hsqldb=SELECT SCOPE_IDENTITY()
441
485
//允许通过拦截器参数设置公共的generator
0 commit comments