Skip to content

Commit 409e0f7

Browse files
committed
$fk : isComposite() and isExplicit() added
1 parent 6b90104 commit 409e0f7

File tree

1 file changed

+24
-130
lines changed

1 file changed

+24
-130
lines changed

src/main/java/org/telosys/tools/generator/context/ForeignKeyInContext.java

Lines changed: 24 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,16 @@
5353
public class ForeignKeyInContext {
5454

5555
private final String fkName ;
56-
// private final String tableName ; // removed in v 3.4.0
5756
private final String originEntityName ; // v 3.4.0
58-
// private final String targetTableName ; // removed in v 3.4.0
5957
private final String referencedEntityName ; // v 3.4.0
60-
// private final List<ForeignKeyColumnInContext> fkColumns ; // removed in v 3.4.0
6158
private final List<ForeignKeyAttributeInContext> fkAttributes ; // new in v 3.4.0
6259

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-
6760
private final ModelInContext modelInContext ; // v 3.4.0
6861

6962
private final EnvInContext env ; // ver 3.4.0
7063

64+
private final boolean explicitFK; // ver 4.1.0
65+
7166
//-------------------------------------------------------------------------------------
7267
public ForeignKeyInContext(ForeignKey foreignKey, ModelInContext modelInContext, EnvInContext env ) {
7368
if ( foreignKey == null ) {
@@ -80,31 +75,16 @@ public ForeignKeyInContext(ForeignKey foreignKey, ModelInContext modelInContext,
8075
this.env = env ;
8176

8277
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
8578

8679
this.originEntityName = foreignKey.getOriginEntityName();
8780
this.referencedEntityName = foreignKey.getReferencedEntityName();
8881

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
10482
this.fkAttributes = new LinkedList<>() ;
10583
for ( ForeignKeyAttribute fkAttribute : foreignKey.getAttributes() ) {
10684
fkAttributes.add( new ForeignKeyAttributeInContext(foreignKey, fkAttribute, modelInContext) );
10785
}
86+
87+
this.explicitFK = foreignKey.isExplicit();
10888
}
10989

11090
//-------------------------------------------------------------------------------------
@@ -128,14 +108,26 @@ public String getSqlName() {
128108
}
129109

130110
//-------------------------------------------------------------------------------------
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+
139131
//-------------------------------------------------------------------------------------
140132
// ORIGIN ENTITY
141133
//-------------------------------------------------------------------------------------
@@ -199,31 +191,6 @@ public String getSqlReferencedTableName() {
199191
return getReferencedEntity().getSqlTableName();
200192
}
201193

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-
227194
//-------------------------------------------------------------------------------------
228195
// ATTRIBUTES ( COLUMNS )
229196
//-------------------------------------------------------------------------------------
@@ -243,13 +210,6 @@ public List<ForeignKeyAttributeInContext> getAttributes() {
243210
}
244211

245212
//-------------------------------------------------------------------------------------
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-
// }
253213
@VelocityMethod(
254214
text={
255215
"Returns the number of attributes composing the foreign key"
@@ -274,12 +234,6 @@ public int getAttributesCount() {
274234
@VelocityReturnType("List<String>")
275235
public List<String> getSqlOriginColumns() throws GeneratorException {
276236
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-
// }
283237
for ( ForeignKeyAttributeInContext fkAttrib : fkAttributes ) {
284238
String sqlColumnName = fkAttrib.getOriginAttribute().getSqlColumnName();
285239
list.add(sqlColumnName);
@@ -314,12 +268,6 @@ public String getSqlOriginColumnsAsString() throws GeneratorException {
314268
@VelocityReturnType("List<String>")
315269
public List<String> getSqlReferencedColumns() throws GeneratorException {
316270
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-
// }
323271
for ( ForeignKeyAttributeInContext fkAttrib : fkAttributes ) {
324272
String sqlColumnName = fkAttrib.getReferencedAttribute().getSqlColumnName();
325273
list.add(sqlColumnName);
@@ -336,58 +284,4 @@ public String getSqlReferencedColumnsAsString() throws GeneratorException {
336284
return ListUtil.join(getSqlReferencedColumns(), ",");
337285
}
338286

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-
// }
393287
}

0 commit comments

Comments
 (0)