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 @ 42676

History | View | Annotate | Download (9.33 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 java.util.logging.Level;
29
import javax.swing.DefaultListModel;
30
import org.cresques.cts.IProjection;
31
import org.gvsig.exportto.ExporttoService;
32
import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel;
33
import org.gvsig.exportto.swing.prov.jdbc.panel.GeometryIndexPanel;
34
import org.gvsig.exportto.swing.prov.jdbc.panel.IdentifiersOptionsPanel;
35
import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel;
36
import org.gvsig.exportto.swing.prov.jdbc.panel.UpdateTableStatisticsPanel;
37
import org.gvsig.exportto.swing.prov.jdbc.panel.PermissionsPanel;
38
import org.gvsig.exportto.swing.prov.jdbc.panel.PostCreatingStatementPanel;
39
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel;
40
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel;
41
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider;
42
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
43
import org.gvsig.fmap.dal.DALLocator;
44
import org.gvsig.fmap.dal.DataManager;
45
import org.gvsig.fmap.dal.exception.InitializeException;
46
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
47
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
48
import org.gvsig.fmap.dal.feature.FeatureStore;
49
import org.gvsig.fmap.dal.feature.FeatureType;
50
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
51
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
52
import org.gvsig.tools.service.spi.AbstractProvider;
53
import org.gvsig.tools.service.spi.ProviderServices;
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56

    
57
/**
58
 * Exporto provider which gets Exporto from a file.
59
 *
60
 * @author gvSIG Team
61
 * @version $Id$
62
 */
63
public class BaseExporttoJDBCProvider extends AbstractProvider
64
        implements ExporttoJDBCOptions, ExporttoSwingProvider {
65

    
66
    private static Logger logger = LoggerFactory.getLogger(
67
            BaseExporttoJDBCProvider.class);
68

    
69
    protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>();
70

    
71
    protected FeatureStore sourceStore;
72
    protected IProjection projection;
73
    private final JDBCConnectionPanel connectionPanel;
74
    private final SelectPkPanel selectPkPanel;
75
    private final SelectTableNamePanel selectTableNamePanel;
76
    private final CheckGeometriesPanel checkGeometriesPanel;
77
    private final IdentifiersOptionsPanel identifiersOptionsPanel;
78

    
79
    private final GeometryIndexPanel geometryIndexPanel;
80
    private final UpdateTableStatisticsPanel updateTableStatistics;
81
    private final PermissionsPanel permissionsPanel;
82
    private final PostCreatingStatementPanel postCreatingStatementPanel;
83

    
84
    private String storeName = null;
85

    
86
    public BaseExporttoJDBCProvider(ProviderServices providerServices,
87
            FeatureStore sourceStore, IProjection projection) {
88
        super(providerServices);
89
        this.sourceStore = sourceStore;
90
        this.projection = projection;
91

    
92
        FeatureType ftype = null;
93
        try {
94
            ftype = sourceStore.getDefaultFeatureType();
95
        } catch (Exception exc) {
96
            logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc);
97

    
98
        }
99
        this.connectionPanel = new JDBCConnectionPanel(this);
100
        this.selectTableNamePanel = new SelectTableNamePanel(this);
101
        this.selectPkPanel = new SelectPkPanel(this);
102
        this.checkGeometriesPanel = new CheckGeometriesPanel(this);
103
        this.identifiersOptionsPanel = new IdentifiersOptionsPanel(this);
104

    
105
        this.geometryIndexPanel = new GeometryIndexPanel(this);
106
        this.updateTableStatistics = new UpdateTableStatisticsPanel(this);
107
        this.permissionsPanel = new PermissionsPanel(this);
108
        this.postCreatingStatementPanel = new PostCreatingStatementPanel(this);
109

    
110
        this.panels.add(this.identifiersOptionsPanel);
111
        this.panels.add(this.connectionPanel);
112
        this.panels.add(this.selectTableNamePanel);
113
        this.panels.add(this.selectPkPanel);
114
        this.panels.add(this.geometryIndexPanel);
115
        this.panels.add(this.checkGeometriesPanel);
116

    
117
        this.panels.add(this.permissionsPanel);
118
        this.panels.add(this.updateTableStatistics);
119
        this.panels.add(this.postCreatingStatementPanel);
120

    
121
    }
122

    
123

    
124

    
125
    public int getPanelCount() {
126
        return this.panels.size();
127
    }
128

    
129
    public ExporttoSwingProviderPanel getPanelAt(int index) {
130
        return this.panels.get(index);
131
    }
132

    
133
    public FeatureStore getSource() {
134
        return this.sourceStore;
135
    }
136

    
137
    public ExporttoService createExporttoService() {
138
        JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
139
        explorerParameters.setSchema(this.getSchema());
140
        return new ExporrtoJDBCService(this);
141
    }
142

    
143
    public boolean getTranslateIdentifiersToLowerCase() {
144
        return this.identifiersOptionsPanel.getTranslateToLowerCase();
145
    }
146

    
147
    public boolean getRemoveSpacesInIdentifiers() {
148
        return this.identifiersOptionsPanel.getRemoveSpacesInTableName();
149
    }
150

    
151
    public JDBCServerExplorerParameters getExplorerParameters() {
152
        return this.connectionPanel.getServerExplorerParameters();
153
    }
154

    
155
    public String getSchema() {
156
        return this.selectTableNamePanel.getSchema();
157
    }
158

    
159
    public String getTableName() {
160
        return this.selectTableNamePanel.getTableName();
161
    }
162

    
163
    public boolean canCreatetable() {
164
        return this.selectTableNamePanel.canCreateTable();
165
    }
166

    
167
    public String getPrimaryKey() {
168
        return this.selectPkPanel.getPrimaryKeyName();
169
    }
170

    
171
    public int getGeometryChecks() {
172
        return this.checkGeometriesPanel.getGeometryChecks();
173
    }
174

    
175
    public int getGeometryChecksAction() {
176
        return this.checkGeometriesPanel.getGeometryChecksAction();
177
    }
178

    
179
    public boolean getTryToFixGeometry() {
180
        return this.checkGeometriesPanel.getTryToFixGeometry();
181
    }
182

    
183
    public String getExplorerName() {
184
        return this.connectionPanel.getServerExplorerParameters().getExplorerName();
185
    }
186

    
187
    public String getStoreName() {
188
        if ( this.storeName == null ) {
189
            try {
190
                JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
191
                if ( explorerParameters == null ) {
192
                    return null;
193
                }
194
                DataManager dataManager = DALLocator.getDataManager();
195

    
196
                JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer(
197
                        explorerParameters.getExplorerName(),
198
                        explorerParameters
199
                );
200
                this.storeName = explorer.getStoreName();
201
            } catch (Exception ex) {
202
                return null;
203
            }
204
        }
205
        return this.storeName;
206
    }
207

    
208
    public IProjection getTargetProjection() {
209
        return this.projection;
210
    }
211

    
212
    public String getSelectRole() {
213
        return this.permissionsPanel.getSelectRole();
214
    }
215

    
216
    public String getInsertRole() {
217
        return this.permissionsPanel.getInsertRole();
218
    }
219

    
220
    public String getUpdateRole() {
221
        return this.permissionsPanel.getUpdateRole();
222
    }
223

    
224
    public String getDeleteRole() {
225
        return this.permissionsPanel.getDeleteRole();
226
    }
227

    
228
    public String getTruncateRole() {
229
        return this.permissionsPanel.getTruncateRole();
230
    }
231

    
232
    public String getReferenceRole() {
233
        return this.permissionsPanel.getReferenceRole();
234
    }
235

    
236
    public String getTriggerRole() {
237
        return this.permissionsPanel.getTriggerRole();
238
    }
239

    
240
    public String getAllRole() {
241
        return this.permissionsPanel.getAllRole();
242
    }
243

    
244
    public String getPostCreatingStatement() {
245
        return this.postCreatingStatementPanel.getPostCreatingStatement();
246
    }
247

    
248
    public boolean getCreateIndexInGeometryRow() {
249
        return this.geometryIndexPanel.getCreateIndexInGeometryRow();
250
    }
251

    
252
    public boolean getUpdateTableStatistics() {
253
        return this.updateTableStatistics.getUpdateTableStatistics();
254
    }
255

    
256
    /**
257
     * Sets the target projection to which should be exported
258
     * @param targetProjection
259
     */
260
    public void setTargetProjection(IProjection targetProjection){
261
        this.projection=targetProjection;
262
    }
263

    
264
    /**
265
     * Informs if it needs to ask for a target projection,
266
     * or if it is not needed or provided through its own wizard panel.
267
     * @return
268
     */
269
    public boolean needsPanelTargetProjection(){
270
        return true;
271
    }
272

    
273
}