Project

General

Profile

« Previous | Next » 

Revision 60454c9a

Added by Andreas Müller almost 6 years ago

ref #6588 update script for ExternalLink

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/MnTableCreator.java
22 22
	private String secondTableAlias;
23 23
    private String secondColumnName;
24 24
	//is the MN table used for a list, if yes, a sortIndex column is needed
25
    //and the and the sortindex column needs to be in the key instead of second table column.
25
    //and the sortindex column needs to be in the key instead of second table column.
26 26
	private boolean isList;
27 27
	private boolean is1toM;
28
	private String sortIndexOrMapkeyColName;
28 29

  
29 30
	public static MnTableCreator NewMnInstance(String stepName, String firstTableName, String secondTableName, boolean includeAudTable, boolean isList, boolean is1toM){
30
		MnTableCreator result = new MnTableCreator(stepName, firstTableName, null, null, secondTableName, null, null, new String[]{}, new String[]{}, null, null, includeAudTable, isList, is1toM, false, false, false);
31
		MnTableCreator result = new MnTableCreator(stepName, firstTableName, null, null,
32
		        secondTableName, null, null, new String[]{}, new String[]{}, null, null,
33
		        includeAudTable, isList, is1toM, false, false, false, null);
31 34
		return result;
32 35
	}
33 36

  
......
50 53
	        boolean includeAudTable, boolean isList, boolean is1toM){
51 54
		MnTableCreator result = new MnTableCreator(stepName, firstTableName, firstTableAlias, null, secondTableName, secondTableAlias, attributeName,
52 55
		        new String[]{}, new String[]{}, null, null,
53
		        includeAudTable, isList, is1toM, false, false, false);
56
		        includeAudTable, isList, is1toM, false, false, false, null);
54 57
		return result;
55 58
	}
59
    public static MnTableCreator NewDescriptionInstance(String stepName, String firstTableName, String firstTableAlias,
60
            String attributeName, boolean includeAudTable){
61
        MnTableCreator result = new MnTableCreator(stepName, firstTableName, firstTableAlias, null, "LanguageString", null, attributeName,
62
                new String[]{}, new String[]{}, null, null,
63
                includeAudTable, true, true, false, false, false, attributeName + "_mapkey_id");
64
        return result;
65
    }
56 66

  
57 67
	   /**
58 68
    *
......
66 76
    * @param secondColumnName The name of the attribute pointing to the second table (this is used for the column name for the
67 77
    *    column pointing to the second table)
68 78
    * @param includeAudTable <code>true</code> if also the Audit (_AUD) table should be created
69
    * @param hasSortIndex by default <code>false</code> but true for {@link Map maps} (or maybe user defined MN-tables)
70
    * @param secondTableInKey should the column that links to the second table also be in the key? This is by default
79
    * @param isList by default <code>false</code> but true for {@link Map maps} (or maybe user defined MN-tables)
80
    * @param is1ToM should the column that links to the second table also be in the key? This is by default
71 81
    * <code>true</code> but for {@link List lists} should be <code>false</code>.
72 82
    * @return
73 83
    */
......
75 85
           boolean includeAudTable, boolean isList, boolean is1toM){
76 86
       MnTableCreator result = new MnTableCreator(stepName, firstTableName, firstTableAlias, firstColumnName, secondTableName, secondTableAlias, secondColumnName,
77 87
               new String[]{}, new String[]{}, null, null,
78
               includeAudTable, isList, is1toM, false, false, false);
88
               includeAudTable, isList, is1toM, false, false, false, null);
79 89
       return result;
80 90
   }
81 91

  
82 92
// ****************************** CONSTRUCTOR *********************************/
83 93

  
84
	protected MnTableCreator(String stepName, String firstTableName, String firstTableAlias, String firstColumnName, String secondTableName, String secondTableAlias, String secondColumnName,
94
	protected MnTableCreator(String stepName, String firstTableName, String firstTableAlias,
95
	        String firstColumnName, String secondTableName, String secondTableAlias, String secondColumnName,
85 96
	        String[] columnNames, String[] columnTypes, List<Object> defaultValues, List<Boolean> isNull,
86 97
	        boolean includeAudTable, boolean isList, boolean is1toM,
87
	        boolean includeCdmBaseAttributes, boolean includeAnnotatableEntity, boolean includeIdentifiableEntity) {
98
	        boolean includeCdmBaseAttributes, boolean includeAnnotatableEntity, boolean includeIdentifiableEntity,
99
	        String description_mapkey_id) {
88 100
		super(stepName, makeAlias(firstTableName, firstTableAlias) + "_" + makeAlias(secondTableName, secondTableAlias),
89 101
		        Arrays.asList(columnNames), Arrays.asList(columnTypes), defaultValues,
90 102
		        isNull,	new ArrayList<>(), includeAudTable,
......
97 109
        this.secondColumnName = (secondColumnName !=  null) ? secondColumnName : this.secondTableAlias;
98 110
        this.isList = isList;
99 111
        this.is1toM = is1toM;
112
        this.sortIndexOrMapkeyColName = (description_mapkey_id == null) ? "sortIndex" : description_mapkey_id;
100 113
		addMyColumns();
101 114
	}
102 115

  
......
117 130
//		secondColAdder.addIndex(tableName+"_"+getSecondIdColumn(), null);
118 131
		this.columnAdders.add(secondColAdder);
119 132
		if (this.isList){
120
			this.columnAdders.add(ColumnAdder.NewIntegerInstance(stepName, tableName, "sortIndex", false, true, null));
133
			this.columnAdders.add(ColumnAdder.NewIntegerInstance(stepName, tableName, this.sortIndexOrMapkeyColName, false, true, null));
121 134
		}
122 135
	}
123 136

  
......
126 139
		String result = "";
127 140
		if (! isAudit){
128 141
			result = getFirstIdColumn() + ",";
129
			result += (isList ? "sortIndex" : getSecondIdColumn());
142
			result += (isList ? sortIndexOrMapkeyColName : getSecondIdColumn());
130 143
		}else{
131 144
			result = "REV, " + primaryKey(false);
132 145
			//for AUDIT also the second table column is in PK

Also available in: Unified diff