update factory methods for original sources #1549
[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.sql.SQLException;
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
19 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
20 import eu.etaxonomy.cdm.database.ICdmDataSource;
21
22 /**
23 * This class represents one step in a schema update.
24 * @author a.mueller
25 * @date 13.09.2010
26 *
27 */
28 public class SimpleSchemaUpdaterStep extends SchemaUpdaterStepBase<SimpleSchemaUpdaterStep> implements ISchemaUpdaterStep, ITermUpdaterStep{
29 @SuppressWarnings("unused")
30 private static final Logger logger = Logger.getLogger(SimpleSchemaUpdaterStep.class);
31
32 private Map<DatabaseTypeEnum, String> queryMap = new HashMap<DatabaseTypeEnum, String>();
33
34
35 // *************************** FACTORY ********************************/
36
37 public static SimpleSchemaUpdaterStep NewInstance(String stepName, String defaultQuery){
38 return new SimpleSchemaUpdaterStep(stepName, defaultQuery);
39 }
40
41 //************************ CONSTRUCTOR ***********************************/
42 private SimpleSchemaUpdaterStep(String stepName, String defaultQuery){
43 super(stepName);
44 queryMap.put(null, defaultQuery);
45 }
46
47 // *************************** INVOKE *****************************
48
49 /* (non-Javadoc)
50 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase#invoke(eu.etaxonomy.cdm.database.ICdmDataSource, eu.etaxonomy.cdm.common.IProgressMonitor)
51 */
52 public Integer invoke (ICdmDataSource datasource, IProgressMonitor monitor){
53 boolean result = true;
54 String query = queryMap.get(datasource.getDatabaseType());
55 if (query == null){
56 query = queryMap.get(null);
57 }
58 try {
59 datasource.executeUpdate(query);
60 } catch (SQLException e) {
61 logger.error(e);
62 result = false;
63 }
64 return (result == true )? 0 : null;
65 }
66
67 //********************************* DELEGATES *********************************/
68
69 public String put(DatabaseTypeEnum dbType, String query) {
70 return queryMap.put(dbType, query);
71 }
72
73
74
75 }