Project

General

Profile

Revision 5c05e409

ID5c05e4094cf035b972e361db71b585fadad3e26d
Parent de9aa4e6
Child 58180f0e

Added by Andreas Müller almost 2 years ago

ref #2335 add DTYPE update to DescriptiveDataSet renaming

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/TableNameChanger.java
29 29
	private String oldName;
30 30
	private String newName;
31 31
	private boolean includeAudTable;
32
	private boolean includeDtype;
32 33

  
33 34
	public static final TableNameChanger NewInstance(String stepName, String oldName, String newName, boolean includeAudTable){
34
		return new TableNameChanger(stepName, oldName, newName, includeAudTable);
35
		return new TableNameChanger(stepName, oldName, newName, includeAudTable, false);
35 36
	}
36 37

  
37
	protected TableNameChanger(String stepName, String oldName, String newName, boolean includeAudTable) {
38
	public static final TableNameChanger NewInstance(String stepName, String oldName, String newName, boolean includeAudTable, boolean includeDtype){
39
	    return new TableNameChanger(stepName, oldName, newName, includeAudTable, includeDtype);
40
	}
41

  
42
	protected TableNameChanger(String stepName, String oldName, String newName, boolean includeAudTable, boolean includeDtype) {
38 43
		super(stepName);
39 44
		this.oldName = oldName;
40 45
		this.newName = newName;
41 46
		this.includeAudTable = includeAudTable;
47
		this.includeDtype = includeDtype;
42 48
	}
43 49

  
44 50
    @Override
45 51
    public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
46 52
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
47
		invokeOnTable(caseType.transformTo(oldName), caseType.transformTo(newName),
48
		        datasource, monitor, result);
53
		invokeOnTable(oldName, newName,
54
		        datasource, monitor, result, caseType);
49 55
		updateHibernateSequence(datasource, monitor, newName, oldName); //no result&= as hibernateSequence problems may not lead to a complete fail
50 56
		if (includeAudTable){
51 57
			String aud = "_AUD";
52
			invokeOnTable(caseType.transformTo(oldName + aud), caseType.transformTo(newName + aud),
53
			        datasource, monitor, result);
58
			invokeOnTable(oldName + aud, newName + aud,
59
			        datasource, monitor, result, caseType);
54 60
		}
55 61
		return;
56 62
	}
57 63

  
58 64
	//does not support AuditedSchemaUpdaterStepBase signature
59
	private void invokeOnTable(String oldName, String newName, ICdmDataSource datasource,
60
	        IProgressMonitor monitor, SchemaUpdateResult result) {
61
		DatabaseTypeEnum type = datasource.getDatabaseType();
65
	private void invokeOnTable(String oldNameOrig, String newNameOrig, ICdmDataSource datasource,
66
	        IProgressMonitor monitor, SchemaUpdateResult result, CaseType caseType) {
67
		String oldName = caseType.transformTo(oldNameOrig);
68
		String newName = caseType.transformTo(newNameOrig);
69
        DatabaseTypeEnum type = datasource.getDatabaseType();
62 70
		String updateQuery;
63 71
		if (type.equals(DatabaseTypeEnum.MySQL)){
64 72
			//MySQL allows both syntaxes
......
85 93
			result.addException(e, message, getStepName() + ", TableNameChanger.invokeOnTable");
86 94
			return;
87 95
		}
96
		if(includeDtype){
97
		    updateDtype(datasource, monitor, caseType, newNameOrig, oldNameOrig);
98
		}
88 99
		return;
89 100
	}
90 101

  
......
111 122

  
112 123
	}
113 124

  
125
    private boolean updateDtype(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType, String newNameOrig, String oldNameOrig){
126
        try{
127
            String sql = " UPDATE %s SET dtype = '%s' WHERE dtype = '%s'";
128
            sql =  String.format(sql, caseType.transformTo(newNameOrig), newNameOrig ,oldNameOrig);
129
            datasource.executeUpdate(sql);
130
            return true;
131
        } catch (Exception e) {
132
            String message = "Exception occurred when trying to update DTYPE for table " + this.newName + ": " + e.getMessage();
133
            monitor.warning(message, e);
134
            logger.error(message);
135
            return false;
136
        }
137
    }
138

  
114 139
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_50/SchemaUpdater_47_50.java
150 150
        oldTableName = "WorkingSet_TaxonNode";
151 151
        changeSingleWorkingSetTableName(stepList, oldTableName);
152 152

  
153

  
154

  
153 155
        //#2335 Make DescriptiveDataSet IdentifiableEntity
154 156
        stepName = "Make DescriptiveDataSet IdentifiableEntity";
155 157
        tableName = "DescriptiveDataSet";
......
360 362
    private void changeSingleWorkingSetTableName(List<ISchemaUpdaterStep> stepList, String oldTableName) {
361 363
        String stepName = "Rename " +  oldTableName;
362 364
        String newTableName = oldTableName.replace("WorkingSet", "DescriptiveDataSet");
363
        ISchemaUpdaterStep step = TableNameChanger.NewInstance(stepName, oldTableName, newTableName, INCLUDE_AUDIT);
365
        boolean includeDtype = !oldTableName.contains("_");
366

  
367
        ISchemaUpdaterStep step = TableNameChanger.NewInstance(stepName, oldTableName,
368
                newTableName, INCLUDE_AUDIT, includeDtype);
364 369
        stepList.add(step);
365 370

  
366 371
        if (oldTableName.contains("_")){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)