separate Amplification and AmplificationResult.java #4541
[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 * 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
34 /**
35 * Constructor
36 * @param stepName
37 */
38 protected AuditedSchemaUpdaterStepBase(String stepName) {
39 super(stepName);
40 }
41
42 @Override
43 public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
44 boolean result = true;
45 isAuditing = false;
46 result &= invokeOnTable(caseType.transformTo(tableName), datasource, monitor, caseType);
47 if (includeAudTable){
48 String aud = "_AUD";
49 isAuditing = true;
50 result &= invokeOnTable(caseType.transformTo(tableName + aud), datasource, monitor, caseType);
51 }
52 return (result == true )? 0 : null;
53 }
54
55 /**
56 * Invoke the update on the given table of name tableName.
57 * @param tableName the tableName, already in the correct case
58 * @param datasource the data source
59 * @param monitor the monitor
60 * @param caseType the caseType (in case other tables are also affected
61 * @return
62 */
63 protected abstract boolean invokeOnTable(String tableName, ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType);
64
65 }