Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.jdbc / src / main / java / org / gvsig / exportto / swing / prov / jdbc / BaseExporttoJDBCProvider.java @ 43020

History | View | Annotate | Download (9.08 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.exportto.swing.prov.jdbc;
25

    
26
import java.util.ArrayList;
27
import java.util.List;
28
import org.cresques.cts.IProjection;
29
import org.gvsig.exportto.ExporttoService;
30
import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel;
31
import org.gvsig.exportto.swing.prov.jdbc.panel.GeometryIndexPanel;
32
import org.gvsig.exportto.swing.prov.jdbc.panel.IdentifiersOptionsPanel;
33
import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel;
34
import org.gvsig.exportto.swing.prov.jdbc.panel.UpdateTableStatisticsPanel;
35
import org.gvsig.exportto.swing.prov.jdbc.panel.PermissionsPanel;
36
import org.gvsig.exportto.swing.prov.jdbc.panel.PostCreatingStatementPanel;
37
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel;
38
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel;
39
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider;
40
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
41
import org.gvsig.fmap.dal.DALLocator;
42
import org.gvsig.fmap.dal.DataManager;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.feature.FeatureType;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
46
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
47
import org.gvsig.tools.service.spi.AbstractProvider;
48
import org.gvsig.tools.service.spi.ProviderServices;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
51

    
52
/**
53
 * Exporto provider which gets Exporto from a file.
54
 *
55
 * @author gvSIG Team
56
 * @version $Id$
57
 */
58
public class BaseExporttoJDBCProvider extends AbstractProvider
59
        implements ExporttoJDBCOptions, ExporttoSwingProvider {
60

    
61
    private static Logger logger = LoggerFactory.getLogger(
62
            BaseExporttoJDBCProvider.class);
63

    
64
    protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>();
65

    
66
    protected FeatureStore sourceStore;
67
    protected IProjection projection;
68
    private final JDBCConnectionPanel connectionPanel;
69
    private final SelectPkPanel selectPkPanel;
70
    private final SelectTableNamePanel selectTableNamePanel;
71
    private final CheckGeometriesPanel checkGeometriesPanel;
72
    private final IdentifiersOptionsPanel identifiersOptionsPanel;
73

    
74
    private final GeometryIndexPanel geometryIndexPanel;
75
    private final UpdateTableStatisticsPanel updateTableStatistics;
76
    private final PermissionsPanel permissionsPanel;
77
    private final PostCreatingStatementPanel postCreatingStatementPanel;
78

    
79
    private String storeName = null;
80

    
81
    public BaseExporttoJDBCProvider(ProviderServices providerServices,
82
            FeatureStore sourceStore, IProjection projection) {
83
        super(providerServices);
84
        this.sourceStore = sourceStore;
85
        this.projection = projection;
86

    
87
        FeatureType ftype = null;
88
        try {
89
            ftype = sourceStore.getDefaultFeatureType();
90
        } catch (Exception exc) {
91
            logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc);
92

    
93
        }
94
        this.connectionPanel = new JDBCConnectionPanel(this);
95
        this.selectTableNamePanel = new SelectTableNamePanel(this);
96
        this.selectPkPanel = new SelectPkPanel(this);
97
        this.checkGeometriesPanel = new CheckGeometriesPanel(this);
98
        this.identifiersOptionsPanel = new IdentifiersOptionsPanel(this);
99

    
100
        this.geometryIndexPanel = new GeometryIndexPanel(this);
101
        this.updateTableStatistics = new UpdateTableStatisticsPanel(this);
102
        this.permissionsPanel = new PermissionsPanel(this);
103
        this.postCreatingStatementPanel = new PostCreatingStatementPanel(this);
104

    
105
        this.panels.add(this.identifiersOptionsPanel);
106
        this.panels.add(this.connectionPanel);
107
        this.panels.add(this.selectTableNamePanel);
108
        this.panels.add(this.selectPkPanel);
109
        this.panels.add(this.geometryIndexPanel);
110
        this.panels.add(this.checkGeometriesPanel);
111

    
112
        this.panels.add(this.permissionsPanel);
113
        this.panels.add(this.updateTableStatistics);
114
        this.panels.add(this.postCreatingStatementPanel);
115

    
116
    }
117

    
118

    
119

    
120
    public int getPanelCount() {
121
        return this.panels.size();
122
    }
123

    
124
    public ExporttoSwingProviderPanel getPanelAt(int index) {
125
        return this.panels.get(index);
126
    }
127

    
128
    public FeatureStore getSource() {
129
        return this.sourceStore;
130
    }
131

    
132
    public ExporttoService createExporttoService() {
133
        JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
134
        explorerParameters.setSchema(this.getSchema());
135
        return new ExporrtoJDBCService(this);
136
    }
137

    
138
    public boolean getTranslateIdentifiersToLowerCase() {
139
        return this.identifiersOptionsPanel.getTranslateToLowerCase();
140
    }
141

    
142
    public boolean getRemoveSpacesInIdentifiers() {
143
        return this.identifiersOptionsPanel.getRemoveSpacesInTableName();
144
    }
145

    
146
    public JDBCServerExplorerParameters getExplorerParameters() {
147
        return this.connectionPanel.getServerExplorerParameters();
148
    }
149

    
150
    public String getSchema() {
151
        return this.selectTableNamePanel.getSchema();
152
    }
153

    
154
    public String getTableName() {
155
        return this.selectTableNamePanel.getTableName();
156
    }
157

    
158
    public boolean canCreatetable() {
159
        return this.selectTableNamePanel.canCreateTable();
160
    }
161

    
162
    public String getPrimaryKey() {
163
        return this.selectPkPanel.getPrimaryKeyName();
164
    }
165

    
166
    public int getGeometryChecks() {
167
        return this.checkGeometriesPanel.getGeometryChecks();
168
    }
169

    
170
    public int getGeometryChecksAction() {
171
        return this.checkGeometriesPanel.getGeometryChecksAction();
172
    }
173

    
174
    public boolean getTryToFixGeometry() {
175
        return this.checkGeometriesPanel.getTryToFixGeometry();
176
    }
177

    
178
    public String getExplorerName() {
179
        return this.connectionPanel.getServerExplorerParameters().getExplorerName();
180
    }
181

    
182
    public String getStoreName() {
183
        if ( this.storeName == null ) {
184
            try {
185
                JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
186
                if ( explorerParameters == null ) {
187
                    return null;
188
                }
189
                DataManager dataManager = DALLocator.getDataManager();
190

    
191
                JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer(
192
                        explorerParameters.getExplorerName(),
193
                        explorerParameters
194
                );
195
                this.storeName = explorer.getStoreName();
196
            } catch (Exception ex) {
197
                return null;
198
            }
199
        }
200
        return this.storeName;
201
    }
202

    
203
    public IProjection getTargetProjection() {
204
        return this.projection;
205
    }
206

    
207
    public String getSelectRole() {
208
        return this.permissionsPanel.getSelectRole();
209
    }
210

    
211
    public String getInsertRole() {
212
        return this.permissionsPanel.getInsertRole();
213
    }
214

    
215
    public String getUpdateRole() {
216
        return this.permissionsPanel.getUpdateRole();
217
    }
218

    
219
    public String getDeleteRole() {
220
        return this.permissionsPanel.getDeleteRole();
221
    }
222

    
223
    public String getTruncateRole() {
224
        return this.permissionsPanel.getTruncateRole();
225
    }
226

    
227
    public String getReferenceRole() {
228
        return this.permissionsPanel.getReferenceRole();
229
    }
230

    
231
    public String getTriggerRole() {
232
        return this.permissionsPanel.getTriggerRole();
233
    }
234

    
235
    public String getAllRole() {
236
        return this.permissionsPanel.getAllRole();
237
    }
238

    
239
    public String getPostCreatingStatement() {
240
        return this.postCreatingStatementPanel.getPostCreatingStatement();
241
    }
242

    
243
    public boolean getCreateIndexInGeometryRow() {
244
        return this.geometryIndexPanel.getCreateIndexInGeometryRow();
245
    }
246

    
247
    public boolean getUpdateTableStatistics() {
248
        return this.updateTableStatistics.getUpdateTableStatistics();
249
    }
250

    
251
    /**
252
     * Sets the target projection to which should be exported
253
     * @param targetProjection
254
     */
255
    public void setTargetProjection(IProjection targetProjection){
256
        this.projection=targetProjection;
257
    }
258

    
259
    /**
260
     * Informs if it needs to ask for a target projection,
261
     * or if it is not needed or provided through its own wizard panel.
262
     * @return
263
     */
264
    public boolean needsPanelTargetProjection(){
265
        return true;
266
    }
267

    
268
}