53
53
public class ForeignKeyInContext {
54
54
55
55
private final String fkName ;
56
- // private final String tableName ; // removed in v 3.4.0
57
56
private final String originEntityName ; // v 3.4.0
58
- // private final String targetTableName ; // removed in v 3.4.0
59
57
private final String referencedEntityName ; // v 3.4.0
60
- // private final List<ForeignKeyColumnInContext> fkColumns ; // removed in v 3.4.0
61
58
private final List <ForeignKeyAttributeInContext > fkAttributes ; // new in v 3.4.0
62
59
63
- // private int updateRuleCode = 0 ; // removed in v 3.4.0
64
- // private int deleteRuleCode = 0 ; // removed in v 3.4.0
65
- // private int deferrableCode = 0 ; // removed in v 3.4.0
66
-
67
60
private final ModelInContext modelInContext ; // v 3.4.0
68
61
69
62
private final EnvInContext env ; // ver 3.4.0
70
63
64
+ private final boolean explicitFK ; // ver 4.1.0
65
+
71
66
//-------------------------------------------------------------------------------------
72
67
public ForeignKeyInContext (ForeignKey foreignKey , ModelInContext modelInContext , EnvInContext env ) {
73
68
if ( foreignKey == null ) {
@@ -80,31 +75,16 @@ public ForeignKeyInContext(ForeignKey foreignKey, ModelInContext modelInContext,
80
75
this .env = env ;
81
76
82
77
this .fkName = foreignKey .getName () ;
83
- // this.tableName = foreignKey.getTableName() ; // removed in v 3.4.0
84
- // this.targetTableName = foreignKey.getReferencedTableName(); // removed in v 3.4.0
85
78
86
79
this .originEntityName = foreignKey .getOriginEntityName ();
87
80
this .referencedEntityName = foreignKey .getReferencedEntityName ();
88
81
89
- // this.updateRuleCode = 0 ; // removed in v 3.4.0
90
- // this.deleteRuleCode = 0 ; // removed in v 3.4.0
91
- // this.deferrableCode = 0 ; // removed in v 3.4.0
92
- // this.fkColumns = new LinkedList<>() ;
93
-
94
- //--- V 3.0.0
95
- // //--- ON UPDATE, ON DELETE and DEFERRABLE (stored in each column in meta-data, keep the last one)
96
- // this.updateRuleCode = foreignKey.getUpdateRuleCode() ;
97
- // this.deleteRuleCode = foreignKey.getDeleteRuleCode() ;
98
- // this.deferrableCode = foreignKey.getDeferrableCode() ;
99
-
100
- // for ( ForeignKeyColumn metadataFKColumn : foreignKey.getColumns() ) {
101
- // fkColumns.add( new ForeignKeyColumnInContext(metadataFKColumn) );
102
- // }
103
- // v 3.4.0
104
82
this .fkAttributes = new LinkedList <>() ;
105
83
for ( ForeignKeyAttribute fkAttribute : foreignKey .getAttributes () ) {
106
84
fkAttributes .add ( new ForeignKeyAttributeInContext (foreignKey , fkAttribute , modelInContext ) );
107
85
}
86
+
87
+ this .explicitFK = foreignKey .isExplicit ();
108
88
}
109
89
110
90
//-------------------------------------------------------------------------------------
@@ -128,14 +108,26 @@ public String getSqlName() {
128
108
}
129
109
130
110
//-------------------------------------------------------------------------------------
131
- // @VelocityMethod(
132
- // text={
133
- // "Returns the name of the table holding the foreign key"
134
- // })
135
- // public String getTableName() { // removed in v 3.4.0
136
- // return this.tableName ;
137
- // }
138
-
111
+ @ VelocityMethod (
112
+ text ={ "Returns true if the Foreign Key is explicit (defined with name)." ,
113
+ "Returns false for an implicit Foreign Key." },
114
+ example = "#if ( $fk.isExplicit() )" ,
115
+ since = "4.1.0"
116
+ )
117
+ public boolean isExplicit () {
118
+ return this .explicitFK ;
119
+ }
120
+
121
+ //-------------------------------------------------------------------------------------
122
+ @ VelocityMethod (
123
+ text ={ "Returns true if the Foreign Key is composite (has more than 1 attribute)" },
124
+ example = "#if ( $fk.isComposite() )" ,
125
+ since = "4.1.0"
126
+ )
127
+ public boolean isComposite () {
128
+ return fkAttributes .size () > 1 ;
129
+ }
130
+
139
131
//-------------------------------------------------------------------------------------
140
132
// ORIGIN ENTITY
141
133
//-------------------------------------------------------------------------------------
@@ -199,31 +191,6 @@ public String getSqlReferencedTableName() {
199
191
return getReferencedEntity ().getSqlTableName ();
200
192
}
201
193
202
- //-------------------------------------------------------------------------------------
203
- // @VelocityMethod(
204
- // text={
205
- // "Returns the name of the referenced table (the table referenced by the foreign key)"
206
- // })
207
- // public String getReferencedTableName() { // removed in v 3.4.0
208
- // return this.targetTableName ;
209
- // }
210
-
211
- //-------------------------------------------------------------------------------------
212
- // @VelocityMethod(
213
- // text={
214
- // "Returns all the columns composing the Foreign Key",
215
- // "(sorted in the original database order)"
216
- // },
217
- // example= {
218
- // "#foreach( $fkcol in $fk.columns ) ",
219
- // "...",
220
- // "#end"
221
- // })
222
- // @VelocityReturnType("List of 'Foreign Key Column' objects ( List of '$fkcol' )")
223
- // public List<ForeignKeyColumnInContext> getColumns() { // removed in v 3.4.0
224
- // return this.fkColumns ;
225
- // }
226
-
227
194
//-------------------------------------------------------------------------------------
228
195
// ATTRIBUTES ( COLUMNS )
229
196
//-------------------------------------------------------------------------------------
@@ -243,13 +210,6 @@ public List<ForeignKeyAttributeInContext> getAttributes() {
243
210
}
244
211
245
212
//-------------------------------------------------------------------------------------
246
- // @VelocityMethod(
247
- // text={
248
- // "Returns the number of columns composing the foreign key"
249
- // })
250
- // public int getColumnsCount() {
251
- // return this.fkColumns.size() ;
252
- // }
253
213
@ VelocityMethod (
254
214
text ={
255
215
"Returns the number of attributes composing the foreign key"
@@ -274,12 +234,6 @@ public int getAttributesCount() {
274
234
@ VelocityReturnType ("List<String>" )
275
235
public List <String > getSqlOriginColumns () throws GeneratorException {
276
236
List <String > list = new LinkedList <>();
277
- // SqlInContext sql = this.env.getSql();
278
- // if ( fkColumns != null ) {
279
- // for ( ForeignKeyColumnInContext col : fkColumns ) {
280
- // list.add(sql.convertToColumnName(col.getColumnName()));
281
- // }
282
- // }
283
237
for ( ForeignKeyAttributeInContext fkAttrib : fkAttributes ) {
284
238
String sqlColumnName = fkAttrib .getOriginAttribute ().getSqlColumnName ();
285
239
list .add (sqlColumnName );
@@ -314,12 +268,6 @@ public String getSqlOriginColumnsAsString() throws GeneratorException {
314
268
@ VelocityReturnType ("List<String>" )
315
269
public List <String > getSqlReferencedColumns () throws GeneratorException {
316
270
List <String > list = new LinkedList <>();
317
- // SqlInContext sql = this.env.getSql();
318
- // if ( fkColumns != null ) {
319
- // for ( ForeignKeyColumnInContext col : fkColumns ) {
320
- // list.add( sql.convertToColumnName(col.getReferencedColumnName()) );
321
- // }
322
- // }
323
271
for ( ForeignKeyAttributeInContext fkAttrib : fkAttributes ) {
324
272
String sqlColumnName = fkAttrib .getReferencedAttribute ().getSqlColumnName ();
325
273
list .add (sqlColumnName );
@@ -336,58 +284,4 @@ public String getSqlReferencedColumnsAsString() throws GeneratorException {
336
284
return ListUtil .join (getSqlReferencedColumns (), "," );
337
285
}
338
286
339
-
340
-
341
-
342
- //-------------------------------------------------------------------------------------
343
- //-------------------------------------------------------------------------------------
344
- // @VelocityMethod(
345
- // text={
346
- // "Returns the 'DEFERRABILITY' status ( 'NOT DEFERRABLE', 'INITIALLY IMMEDIATE', 'INITIALLY DEFERRED' ) "
347
- // })
348
- // public String getDeferrable() {
349
- // return MetadataUtil.getForeignKeyDeferrability(deferrableCode).toUpperCase();
350
- // }
351
- // //-------------------------------------------------------------------------------------
352
- // @VelocityMethod(
353
- // text={
354
- // "Returns the 'DEFERRABILITY' status code ( MetaData Code : 5,6,7 ) "
355
- // })
356
- // public int getDeferrableCode() {
357
- // return deferrableCode;
358
- // }
359
- //
360
- // //-------------------------------------------------------------------------------------
361
- // @VelocityMethod(
362
- // text={
363
- // "Returns the 'ON DELETE' rule ( 'NO ACTION', 'RESTRICT', 'SET NULL', 'SET DEFAULT', 'CASCADE' ) "
364
- // })
365
- // public String getDeleteRule() {
366
- // return MetadataUtil.getForeignKeyDeleteRule(deleteRuleCode).toUpperCase();
367
- // }
368
- // //-------------------------------------------------------------------------------------
369
- // @VelocityMethod(
370
- // text={
371
- // "Returns the 'ON DELETE' rule code ( MetaData Code : 0,1,2,3,4 ) "
372
- // })
373
- // public int getDeleteRuleCode() {
374
- // return deleteRuleCode;
375
- // }
376
- //
377
- // //-------------------------------------------------------------------------------------
378
- // @VelocityMethod(
379
- // text={
380
- // "Returns the 'ON UPDATE' rule ( 'NO ACTION', 'RESTRICT', 'SET NULL', 'SET DEFAULT', 'CASCADE' ) "
381
- // })
382
- // public String getUpdateRule() {
383
- // return MetadataUtil.getForeignKeyUpdateRule(updateRuleCode).toUpperCase();
384
- // }
385
- // //-------------------------------------------------------------------------------------
386
- // @VelocityMethod(
387
- // text={
388
- // "Returns the 'ON UPDATE' rule code ( MetaData Code : 0,1,2,3,4 ) "
389
- // })
390
- // public int getUpdateRuleCode() {
391
- // return updateRuleCode;
392
- // }
393
287
}
0 commit comments