Project

General

Profile

Download (4.94 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.database.update;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
18
import eu.etaxonomy.cdm.database.ICdmDataSource;
19

    
20
/**
21
 * Updates the base type of a class.
22
 * E.g. if a class is VersionableEntity it may be upgraded to AnnotatableEntity
23
 * @date 2015-03-20
24
 * @author a.mueller
25
 */
26
public class ClassBaseTypeUpdater extends AuditedSchemaUpdaterStepBase<ClassBaseTypeUpdater> implements ISchemaUpdaterStep {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(TableCreator.class);
29

    
30
	private static final boolean SORT_INDEX = true;
31

    
32
	private final boolean includeIdentifiableEntity;
33
	private final boolean includeAnnotatableEntity;
34
	protected List<ISchemaUpdaterStep> mnTablesStepList = new ArrayList<ISchemaUpdaterStep>();
35
	protected List<ISchemaUpdaterStep> columnAdderStepList = new ArrayList<ISchemaUpdaterStep>();
36

    
37

    
38
	public static final ClassBaseTypeUpdater NewVersionableToAnnotatableInstance(String stepName, String tableName, boolean includeAudTable){
39
		return new ClassBaseTypeUpdater(stepName, tableName, includeAudTable, true, false);
40
	}
41
	public static final ClassBaseTypeUpdater NewAnnotatableToIdentifiableInstance(String stepName, String tableName, boolean includeAudTable){
42
		return new ClassBaseTypeUpdater(stepName, tableName, includeAudTable, false, true);
43
	}
44
	public static final ClassBaseTypeUpdater NewVersionableToIdentifiableInstance(String stepName, String tableName, boolean includeAudTable){
45
		return new ClassBaseTypeUpdater(stepName, tableName, includeAudTable, true, true);
46
	}
47

    
48
	protected ClassBaseTypeUpdater(String stepName, String tableName, boolean includeAudit, boolean includeAnnotatable, boolean includeIdentifiable) {
49
		super(stepName, tableName, includeAudit);
50
		this.includeAnnotatableEntity = includeAnnotatable;
51
		this.includeIdentifiableEntity = includeIdentifiable;
52
		TableCreator.makeMnTables(mnTablesStepList, tableName, includeAnnotatable, includeIdentifiable);
53
		makeColumns();
54
	}
55

    
56

    
57
	private void makeColumns() {
58
		String innerStepName;
59
		String newColumnName;
60
		ColumnAdder adder;
61
		if (this.includeIdentifiableEntity){
62

    
63
			//lsid authority
64
			innerStepName = "-add lsid_authority";
65
			newColumnName = "lsid_authority";
66
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
67
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
68
			this.columnAdderStepList.add(adder);
69

    
70
			//lsid lsid
71
			innerStepName = "-add lsid_lsid";
72
			newColumnName = "lsid_lsid";
73
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
74
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
75
			this.columnAdderStepList.add(adder);
76

    
77
			//lsid namespace
78
			innerStepName = "-add lsid_namespace";
79
			newColumnName = "lsid_namespace";
80
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
81
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
82
			this.columnAdderStepList.add(adder);
83

    
84
			//lsid object
85
			innerStepName = "-add lsid_object";
86
			newColumnName = "lsid_object";
87
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
88
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
89
			this.columnAdderStepList.add(adder);
90

    
91
			//lsid revision
92
			innerStepName = "-add lsid_revision";
93
			newColumnName = "lsid_revision";
94
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
95
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
96
			this.columnAdderStepList.add(adder);
97

    
98
			//protected title cache
99
			innerStepName = "-add protected title cache";
100
			newColumnName = "protectedTitleCache";
101
			adder = ColumnAdder.NewBooleanInstance(innerStepName, tableName, newColumnName,
102
					SchemaUpdaterBase.INCLUDE_AUDIT, false);
103

    
104
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
105
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
106
			this.columnAdderStepList.add(adder);
107

    
108
			//title cache
109
			innerStepName = "-add titleCache";
110
			newColumnName = "titleCache";
111
			adder = ColumnAdder.NewStringInstance(stepName + innerStepName, tableName,
112
					newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
113
			this.columnAdderStepList.add(adder);
114
		}
115
	}
116

    
117
	@Override
118
	protected boolean invokeOnTable(String tableName, ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType)  {
119
		//we only do have inner steps here
120
		return true;
121
	}
122

    
123

    
124
	@Override
125
	public List<ISchemaUpdaterStep> getInnerSteps() {
126
		List<ISchemaUpdaterStep> result = new ArrayList<ISchemaUpdaterStep>
127
					( mnTablesStepList);
128
		result.addAll(columnAdderStepList);
129
		return result;
130
	}
131

    
132
}
(4-4/34)