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-model/src/main/java/eu/etaxonomy/cdm/model/media/ExternalLink.java
71 71
     * The {@link ExternalLinkType type} of this link.
72 72
     */
73 73
    @XmlAttribute(name ="ExternalLinkType")
74
    @Column(name="linkType")
74
    @Column(name="linkType", length=10)
75 75
    @NotNull
76 76
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
77 77
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.media.ExternalLinkType")}
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
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_49/SchemaUpdater_47_49.java
21 21
import eu.etaxonomy.cdm.database.update.ColumnTypeChanger;
22 22
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
23 23
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
24
import eu.etaxonomy.cdm.database.update.MnTableCreator;
24 25
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
25 26
import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
27
import eu.etaxonomy.cdm.database.update.TableCreator;
26 28
import eu.etaxonomy.cdm.database.update.TableNameChanger;
27 29
import eu.etaxonomy.cdm.database.update.TermRepresentationUpdater;
28 30
import eu.etaxonomy.cdm.database.update.v41_47.SchemaUpdater_41_47;
......
214 216
        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
215 217
        stepList.add(step);
216 218

  
219
        //#6588
220
        stepName = "Add ExternalLink table";
221
        tableName = "ExternalLink";
222
        String[] columnNames = new String[]{"linkType","uri","size"};
223
        String[] referencedTables = new String[]{null, null, null};
224
        String[] columnTypes = new String[]{"string_10","clob","int"};
225
        step = TableCreator.NewVersionableInstance(stepName, tableName,
226
                columnNames, columnTypes, referencedTables, INCLUDE_AUDIT);
227
        stepList.add(step);
228

  
229
        //add i18n description
230
        stepName= "Add i18n description to ExternalLink";
231
        String firstTableName = "ExternalLink";
232
        String attributeName = "description";
233
        step = MnTableCreator.NewDescriptionInstance(stepName, firstTableName, null, attributeName, INCLUDE_AUDIT);
234
        stepList.add(step);
217 235

  
218 236

  
219 237
//        //7276  Make User.emailAddress a unique field

Also available in: Unified diff