Project

General

Profile

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

    
11
import java.sql.SQLException;
12
import java.util.List;
13

    
14
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
15
import eu.etaxonomy.cdm.database.ICdmDataSource;
16

    
17
/**
18
 * Base class for a {@link ISchemaUpdaterStep schema update step} which supports automated handling
19
 * of auditing tables.
20
 *
21
 * @see CdmUpdater
22
 * @see ISchemaUpdater
23
 *
24
 * @author a.mueller
25
 *
26
 * @param <T>
27
 */
28
public abstract class AuditedSchemaUpdaterStepBase extends SchemaUpdaterStepBase {
29

    
30
	protected String tableName;
31
	protected boolean includeAudTable;
32
	protected boolean isAuditing;
33

    
34
//    protected AuditedSchemaUpdaterStepBase(String stepName, boolean includedAudTable) {
35
//        super(null, stepName);
36
//        this.includeAudTable = includedAudTable;
37
//    }
38
//
39
//    protected AuditedSchemaUpdaterStepBase(String stepName, String tableName, boolean includedAudTable) {
40
//        super(null, stepName);
41
//        this.includeAudTable = includedAudTable;
42
//        this.tableName = tableName;
43
//    }
44

    
45

    
46
    protected AuditedSchemaUpdaterStepBase(List<ISchemaUpdaterStep> stepList, String stepName, boolean includedAudTable) {
47
        super(stepList, stepName);
48
        this.includeAudTable = includedAudTable;
49
    }
50

    
51
    protected AuditedSchemaUpdaterStepBase(List<? extends ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includedAudTable) {
52
        super(stepList, stepName);
53
        this.includeAudTable = includedAudTable;
54
        this.tableName = tableName;
55
    }
56

    
57
    @Override
58
    public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
59
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
60
        isAuditing = false;
61
		invokeOnTable(caseType.transformTo(tableName), datasource, monitor, caseType, result);
62
		if (includeAudTable){
63
			String aud = "_AUD";
64
			isAuditing = true;
65
			invokeOnTable(caseType.transformTo(tableName + aud), datasource, monitor, caseType, result);
66
		}
67
		return;
68
	}
69

    
70
	/**
71
	 * Invoke the update on the given table of name tableName.
72
	 * @param tableName the tableName, already in the correct case
73
	 * @param datasource the data source
74
	 * @param monitor the monitor
75
	 * @param caseType the caseType (in case other tables are also affected
76
	 * @param result
77
	 * @return
78
	 */
79
	protected abstract void invokeOnTable(String tableName, ICdmDataSource datasource,
80
	        IProgressMonitor monitor, CaseType caseType, SchemaUpdateResult result);
81

    
82
}
(2-2/41)