Project

General

Profile

Download (2.74 KB) Statistics
| Branch: | Tag: | Revision:
1 7747019c Andreas Müller
/**
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 9692864e Andreas Müller
package eu.etaxonomy.cdm.database.update;
10
11
import java.sql.SQLException;
12 99e01f35 Andreas Müller
import java.util.List;
13 9692864e Andreas Müller
14
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
15
import eu.etaxonomy.cdm.database.ICdmDataSource;
16
17 7747019c Andreas Müller
/**
18 7d7355ba Andreas M��ller
 * Base class for a {@link ISchemaUpdaterStep schema update step} which supports automated handling
19 b121eb12 Andreas Müller
 * of auditing tables.
20 7d7355ba Andreas M��ller
 *
21 b121eb12 Andreas Müller
 * @see CdmUpdater
22
 * @see ISchemaUpdater
23 7d7355ba Andreas M��ller
 *
24 7747019c Andreas Müller
 * @author a.mueller
25
 *
26
 * @param <T>
27
 */
28 2668abef Andreas Müller
public abstract class AuditedSchemaUpdaterStepBase extends SchemaUpdaterStepBase {
29 9692864e Andreas Müller
30
	protected String tableName;
31
	protected boolean includeAudTable;
32
	protected boolean isAuditing;
33
34 99e01f35 Andreas Müller
//    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 7d7355ba Andreas M��ller
        this.includeAudTable = includedAudTable;
49
    }
50
51 99e01f35 Andreas Müller
    protected AuditedSchemaUpdaterStepBase(List<? extends ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includedAudTable) {
52
        super(stepList, stepName);
53 7d7355ba Andreas M��ller
        this.includeAudTable = includedAudTable;
54
        this.tableName = tableName;
55
    }
56 9692864e Andreas Müller
57 ba35e2f8 Andreas Müller
    @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 9692864e Andreas Müller
		if (includeAudTable){
63
			String aud = "_AUD";
64
			isAuditing = true;
65 ba35e2f8 Andreas Müller
			invokeOnTable(caseType.transformTo(tableName + aud), datasource, monitor, caseType, result);
66 9692864e Andreas Müller
		}
67 ba35e2f8 Andreas Müller
		return;
68 9692864e Andreas Müller
	}
69 7d7355ba Andreas M��ller
70 7747019c Andreas Müller
	/**
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 ba35e2f8 Andreas Müller
	 * @param result
77 7747019c Andreas Müller
	 * @return
78
	 */
79 ba35e2f8 Andreas Müller
	protected abstract void invokeOnTable(String tableName, ICdmDataSource datasource,
80
	        IProgressMonitor monitor, CaseType caseType, SchemaUpdateResult result);
81 9692864e Andreas Müller
82
}