Project

General

Profile

Download (2.23 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

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

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

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

    
33
    protected AuditedSchemaUpdaterStepBase(String stepName, boolean includedAudTable) {
34
        super(stepName);
35
        this.includeAudTable = includedAudTable;
36
    }
37

    
38
    protected AuditedSchemaUpdaterStepBase(String stepName, String tableName, boolean includedAudTable) {
39
        super(stepName);
40
        this.includeAudTable = includedAudTable;
41
        this.tableName = tableName;
42
    }
43

    
44
	@Override
45
	public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
46
		boolean result = true;
47
		isAuditing = false;
48
		result &= invokeOnTable(caseType.transformTo(tableName), datasource, monitor, caseType);
49
		if (includeAudTable){
50
			String aud = "_AUD";
51
			isAuditing = true;
52
			result &= invokeOnTable(caseType.transformTo(tableName + aud), datasource, monitor, caseType);
53
		}
54
		return (result == true )? 0 : null;
55
	}
56

    
57
	/**
58
	 * Invoke the update on the given table of name tableName.
59
	 * @param tableName the tableName, already in the correct case
60
	 * @param datasource the data source
61
	 * @param monitor the monitor
62
	 * @param caseType the caseType (in case other tables are also affected
63
	 * @return
64
	 */
65
	protected abstract boolean invokeOnTable(String tableName, ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType);
66

    
67
}
(1-1/34)