View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Eric Long <erilong@users.sourceforge.net>,
5    *               Chris Henson <chenson42@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 3 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, see
19   * <http://www.gnu.org/licenses/>.
20   */
21  
22  package org.jumpmind.symmetric.load;
23  
24  import java.util.Collection;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.apache.ddlutils.model.Table;
29  
30  public class DataLoaderContext implements IDataLoaderContext {
31  
32      private String version;
33  
34      private String nodeId;
35  
36      private String tableName;
37  
38      private long batchId;
39  
40      private boolean isSkipping;
41  
42      private transient Map<String, TableTemplate> tableTemplateMap;
43  
44      private TableTemplate tableTemplate;
45  
46      private Map<String, Object> contextCache = new HashMap<String, Object>();
47  
48      public DataLoaderContext() {
49          this.tableTemplateMap = new HashMap<String, TableTemplate>();
50      }
51  
52      public TableTemplate getTableTemplate() {
53          return tableTemplate;
54      }
55  
56      public void setTableTemplate(TableTemplate tableTemplate) {
57          this.tableTemplate = tableTemplate;
58          tableTemplateMap.put(getTableName(), tableTemplate);
59      }
60  
61      public int getColumnIndex(String columnName) {
62          String[] columnNames = tableTemplate.getColumnNames();
63          for (int i = 0; i < columnNames.length; i++) {
64              if (columnNames[i].equals(columnName)) {
65                  return i;
66              }
67          }
68          return -1;
69      }
70  
71      public Table[] getAllTablesProcessed() {
72          Collection<TableTemplate> templates = this.tableTemplateMap.values();
73          Table[] tables = new Table[templates.size()];
74          int i = 0;
75          for (TableTemplate table : templates) {
76              tables[i++] = table.getTable();
77          }
78          return tables;
79      }
80  
81      public long getBatchId() {
82          return batchId;
83      }
84  
85      public void setBatchId(long batchId) {
86          this.batchId = batchId;
87          isSkipping = false;
88      }
89  
90      public String getNodeId() {
91          return nodeId;
92      }
93  
94      public void setNodeId(String nodeId) {
95          this.nodeId = nodeId;
96      }
97  
98      public String getTableName() {
99          return tableName;
100     }
101 
102     public void setTableName(String tableName) {
103         this.tableName = tableName;
104         this.tableTemplate = tableTemplateMap.get(tableName);
105     }
106 
107     public String getVersion() {
108         return version;
109     }
110 
111     public void setVersion(String version) {
112         this.version = version;
113     }
114 
115     public boolean isSkipping() {
116         return isSkipping;
117     }
118 
119     public void setSkipping(boolean isSkipping) {
120         this.isSkipping = isSkipping;
121     }
122 
123     public String[] getColumnNames() {
124         return tableTemplate.getColumnNames();
125     }
126 
127     public void setColumnNames(String[] columnNames) {
128         tableTemplate.setColumnNames(columnNames);
129     }
130 
131     public void setOldData(String[] oldData) {
132         tableTemplate.setOldData(oldData);
133     }
134 
135     public String[] getKeyNames() {
136         return tableTemplate.getKeyNames();
137     }
138 
139     public void setKeyNames(String[] keyNames) {
140         tableTemplate.setKeyNames(keyNames);
141     }
142 
143     /***
144      * This is a cache that is available for the lifetime of a batch load. It
145      * can be useful for storing data from the filter for customization
146      * purposes.
147      */
148     public Map<String, Object> getContextCache() {
149         return contextCache;
150     }
151 
152 }