View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    * Copyright (C) Andrew Wilcox <andrewbwilcox@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.extract.csv;
23  
24  import java.io.BufferedWriter;
25  import java.io.IOException;
26  
27  import org.jumpmind.symmetric.extract.DataExtractorContext;
28  import org.jumpmind.symmetric.model.Data;
29  import org.jumpmind.symmetric.model.Node;
30  import org.jumpmind.symmetric.model.Trigger;
31  import org.jumpmind.symmetric.service.IConfigurationService;
32  import org.jumpmind.symmetric.service.IDataExtractorService;
33  import org.jumpmind.symmetric.service.INodeService;
34  
35  class StreamReloadDataCommand extends AbstractStreamDataCommand {
36  
37      private IDataExtractorService dataExtractorService;
38  
39      private IConfigurationService configurationService;
40  
41      private INodeService nodeService;
42  
43      public void execute(BufferedWriter out, Data data, DataExtractorContext context) throws IOException {
44          Trigger trigger = configurationService.getTriggerById(data.getAudit().getTriggerId());
45          // The initial_load_select can be overridden
46          if (data.getRowData() != null) {
47              trigger.setInitialLoadSelect(data.getRowData());
48          }
49          Node node = nodeService.findNode(context.getBatch().getNodeId());
50          dataExtractorService.extractInitialLoadWithinBatchFor(node, trigger, out,
51                  context);
52          out.flush();
53      }
54  
55      public void setDataExtractorService(IDataExtractorService dataExtractorService) {
56          this.dataExtractorService = dataExtractorService;
57      }
58  
59      public void setConfigurationService(IConfigurationService configurationService) {
60          this.configurationService = configurationService;
61      }
62  
63      public void setNodeService(INodeService nodeService) {
64          this.nodeService = nodeService;
65      }
66  
67  }