TermUpdater_312_313
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / update / SimpleSchemaUpdaterStep.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.database.update;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.common.IProgressMonitor;
18 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
19 import eu.etaxonomy.cdm.database.ICdmDataSource;
20
21 /**
22 * This class represents one step in a schema update.
23 * @author a.mueller
24 * @date 13.09.2010
25 *
26 */
27 public class SimpleSchemaUpdaterStep extends SchemaUpdaterStepBase implements ISchemaUpdaterStep, ITermUpdaterStep{
28 @SuppressWarnings("unused")
29 private static final Logger logger = Logger.getLogger(SimpleSchemaUpdaterStep.class);
30
31 private Map<DatabaseTypeEnum, String> queryMap = new HashMap<DatabaseTypeEnum, String>();
32
33
34 // *************************** FACTORY ********************************/
35
36 public static SimpleSchemaUpdaterStep NewInstance(String stepName, String defaultQuery){
37 return new SimpleSchemaUpdaterStep(stepName, defaultQuery);
38 }
39
40 //************************ CONSTRUCTOR ***********************************/
41 private SimpleSchemaUpdaterStep(String stepName, String defaultQuery){
42 super(stepName);
43 queryMap.put(null, defaultQuery);
44 }
45
46 // *************************** INVOKE *****************************
47
48 /* (non-Javadoc)
49 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase#invoke(eu.etaxonomy.cdm.database.ICdmDataSource, eu.etaxonomy.cdm.common.IProgressMonitor)
50 */
51 public Integer invoke (ICdmDataSource datasource, IProgressMonitor monitor){
52 boolean result = true;
53 String query = queryMap.get(datasource.getDatabaseType());
54 if (query == null){
55 query = queryMap.get(null);
56 }
57 datasource.executeUpdate(query);
58 return (result == true )? 0 : null;
59 }
60
61 //********************************* DELEGATES *********************************/
62
63 public String put(DatabaseTypeEnum dbType, String query) {
64 return queryMap.put(dbType, query);
65 }
66
67
68
69 }