minor
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / update / AuditedSchemaUpdaterStepBase.java
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 * @author a.mueller
18 *
19 * @param <T>
20 */
21 public abstract class AuditedSchemaUpdaterStepBase<T extends AuditedSchemaUpdaterStepBase<T>> extends SchemaUpdaterStepBase<T> implements ISchemaUpdaterStep {
22
23 protected String tableName;
24 protected boolean includeAudTable;
25 protected boolean isAuditing;
26
27
28 /**
29 * Constructor
30 * @param stepName
31 */
32 protected AuditedSchemaUpdaterStepBase(String stepName) {
33 super(stepName);
34 }
35
36 @Override
37 public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
38 boolean result = true;
39 isAuditing = false;
40 result &= invokeOnTable(caseType.transformTo(tableName), datasource, monitor, caseType);
41 if (includeAudTable){
42 String aud = "_AUD";
43 isAuditing = true;
44 result &= invokeOnTable(caseType.transformTo(tableName + aud), datasource, monitor, caseType);
45 }
46 return (result == true )? 0 : null;
47 }
48
49 /**
50 * Invoke the update on the given table of name tableName.
51 * @param tableName the tableName, already in the correct case
52 * @param datasource the data source
53 * @param monitor the monitor
54 * @param caseType the caseType (in case other tables are also affected
55 * @return
56 */
57 protected abstract boolean invokeOnTable(String tableName, ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType);
58
59 }