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 @ 41638
History | View | Annotate | Download (8.94 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 |
public int getPanelCount() { |
124 |
return this.panels.size(); |
125 |
} |
126 |
|
127 |
public ExporttoSwingProviderPanel getPanelAt(int index) { |
128 |
return this.panels.get(index); |
129 |
} |
130 |
|
131 |
public FeatureStore getSource() {
|
132 |
return this.sourceStore; |
133 |
} |
134 |
|
135 |
public ExporttoService createExporttoService() {
|
136 |
JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
|
137 |
explorerParameters.setSchema(this.getSchema());
|
138 |
return new ExporrtoJDBCService(this); |
139 |
} |
140 |
|
141 |
public boolean getTranslateIdentifiersToLowerCase() { |
142 |
return this.identifiersOptionsPanel.getTranslateToLowerCase(); |
143 |
} |
144 |
|
145 |
public boolean getRemoveSpacesInIdentifiers() { |
146 |
return this.identifiersOptionsPanel.getRemoveSpacesInTableName(); |
147 |
} |
148 |
|
149 |
public JDBCServerExplorerParameters getExplorerParameters() {
|
150 |
return this.connectionPanel.getServerExplorerParameters(); |
151 |
} |
152 |
|
153 |
public String getSchema() { |
154 |
return this.selectTableNamePanel.getSchema(); |
155 |
} |
156 |
|
157 |
public String getTableName() { |
158 |
return this.selectTableNamePanel.getTableName(); |
159 |
} |
160 |
|
161 |
public boolean canCreatetable() { |
162 |
return this.selectTableNamePanel.canCreateTable(); |
163 |
} |
164 |
|
165 |
public String getPrimaryKey() { |
166 |
return this.selectPkPanel.getPrimaryKeyName(); |
167 |
} |
168 |
|
169 |
public int getGeometryChecks() { |
170 |
return this.checkGeometriesPanel.getGeometryChecks(); |
171 |
} |
172 |
|
173 |
public int getGeometryChecksAction() { |
174 |
return this.checkGeometriesPanel.getGeometryChecksAction(); |
175 |
} |
176 |
|
177 |
public boolean getTryToFixGeometry() { |
178 |
return this.checkGeometriesPanel.getTryToFixGeometry(); |
179 |
} |
180 |
|
181 |
public String getExplorerName() { |
182 |
return this.connectionPanel.getServerExplorerParameters().getExplorerName(); |
183 |
} |
184 |
|
185 |
public String getStoreName() { |
186 |
if ( this.storeName == null ) { |
187 |
try {
|
188 |
JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
|
189 |
if ( explorerParameters == null ) { |
190 |
return null; |
191 |
} |
192 |
DataManager dataManager = DALLocator.getDataManager(); |
193 |
|
194 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
195 |
explorerParameters.getExplorerName(), |
196 |
explorerParameters |
197 |
); |
198 |
this.storeName = explorer.getStoreName();
|
199 |
} catch (Exception ex) { |
200 |
return null; |
201 |
} |
202 |
} |
203 |
return this.storeName; |
204 |
} |
205 |
|
206 |
public IProjection getTargetProjection() {
|
207 |
return this.projection; |
208 |
} |
209 |
|
210 |
public String getSelectRole() { |
211 |
return this.permissionsPanel.getSelectRole(); |
212 |
} |
213 |
|
214 |
public String getInsertRole() { |
215 |
return this.permissionsPanel.getInsertRole(); |
216 |
} |
217 |
|
218 |
public String getUpdateRole() { |
219 |
return this.permissionsPanel.getUpdateRole(); |
220 |
} |
221 |
|
222 |
public String getDeleteRole() { |
223 |
return this.permissionsPanel.getDeleteRole(); |
224 |
} |
225 |
|
226 |
public String getTruncateRole() { |
227 |
return this.permissionsPanel.getTruncateRole(); |
228 |
} |
229 |
|
230 |
public String getReferenceRole() { |
231 |
return this.permissionsPanel.getReferenceRole(); |
232 |
} |
233 |
|
234 |
public String getTriggerRole() { |
235 |
return this.permissionsPanel.getTriggerRole(); |
236 |
} |
237 |
|
238 |
public String getAllRole() { |
239 |
return this.permissionsPanel.getAllRole(); |
240 |
} |
241 |
|
242 |
public String getPostCreatingStatement() { |
243 |
return this.postCreatingStatementPanel.getPostCreatingStatement(); |
244 |
} |
245 |
|
246 |
public boolean getCreateIndexInGeometryRow() { |
247 |
return this.geometryIndexPanel.getCreateIndexInGeometryRow(); |
248 |
} |
249 |
|
250 |
public boolean getUpdateTableStatistics() { |
251 |
return this.updateTableStatistics.getUpdateTableStatistics(); |
252 |
} |
253 |
|
254 |
} |