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 @ 43377
History | View | Annotate | Download (9.2 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * This program is distributed in the hope that it will be useful,
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | 41492 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 40435 | jjdelcerro | * GNU General Public License for more details.
|
15 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 41492 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.exportto.swing.prov.jdbc; |
||
25 | |||
26 | 41486 | jjdelcerro | import java.util.ArrayList; |
27 | import java.util.List; |
||
28 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
29 | import org.gvsig.exportto.ExporttoService; |
||
30 | 41486 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel; |
31 | 41638 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.GeometryIndexPanel; |
32 | 41598 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.IdentifiersOptionsPanel; |
33 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel; |
34 | 41638 | jjdelcerro | 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 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel; |
38 | import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel; |
||
39 | 41598 | jjdelcerro | import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
40 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
41 | 41492 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
42 | import org.gvsig.fmap.dal.DataManager; |
||
43 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
44 | 41127 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureType; |
45 | 41492 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
46 | 41486 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
47 | 40435 | jjdelcerro | import org.gvsig.tools.service.spi.AbstractProvider; |
48 | import org.gvsig.tools.service.spi.ProviderServices; |
||
49 | 41486 | jjdelcerro | import org.slf4j.Logger; |
50 | import org.slf4j.LoggerFactory; |
||
51 | 40435 | jjdelcerro | |
52 | /**
|
||
53 | * Exporto provider which gets Exporto from a file.
|
||
54 | 41492 | jjdelcerro | *
|
55 | 40435 | jjdelcerro | * @author gvSIG Team
|
56 | * @version $Id$
|
||
57 | */
|
||
58 | 41492 | jjdelcerro | public class BaseExporttoJDBCProvider extends AbstractProvider |
59 | 41598 | jjdelcerro | implements ExporttoJDBCOptions, ExporttoSwingProvider {
|
60 | 41492 | jjdelcerro | |
61 | 41127 | jldominguez | private static Logger logger = LoggerFactory.getLogger( |
62 | 41492 | jjdelcerro | BaseExporttoJDBCProvider.class); |
63 | 40435 | jjdelcerro | |
64 | 41486 | jjdelcerro | protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>(); |
65 | 40435 | jjdelcerro | |
66 | 41486 | jjdelcerro | protected FeatureStore sourceStore;
|
67 | 40435 | jjdelcerro | protected IProjection projection;
|
68 | 41486 | jjdelcerro | private final JDBCConnectionPanel connectionPanel; |
69 | private final SelectPkPanel selectPkPanel; |
||
70 | private final SelectTableNamePanel selectTableNamePanel; |
||
71 | private final CheckGeometriesPanel checkGeometriesPanel; |
||
72 | 41598 | jjdelcerro | private final IdentifiersOptionsPanel identifiersOptionsPanel; |
73 | 42676 | dmartinezizquierdo | |
74 | 41638 | jjdelcerro | private final GeometryIndexPanel geometryIndexPanel; |
75 | private final UpdateTableStatisticsPanel updateTableStatistics; |
||
76 | private final PermissionsPanel permissionsPanel; |
||
77 | private final PostCreatingStatementPanel postCreatingStatementPanel; |
||
78 | 40435 | jjdelcerro | |
79 | 41492 | jjdelcerro | private String storeName = null; |
80 | 42676 | dmartinezizquierdo | |
81 | 41492 | jjdelcerro | public BaseExporttoJDBCProvider(ProviderServices providerServices,
|
82 | FeatureStore sourceStore, IProjection projection) { |
||
83 | 40435 | jjdelcerro | super(providerServices);
|
84 | 41486 | jjdelcerro | this.sourceStore = sourceStore;
|
85 | 40435 | jjdelcerro | this.projection = projection;
|
86 | |||
87 | 41127 | jldominguez | FeatureType ftype = null;
|
88 | try {
|
||
89 | 41486 | jjdelcerro | ftype = sourceStore.getDefaultFeatureType(); |
90 | 41127 | jldominguez | } catch (Exception exc) { |
91 | 41486 | jjdelcerro | logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc);
|
92 | 41492 | jjdelcerro | |
93 | 41127 | jldominguez | } |
94 | 41486 | jjdelcerro | this.connectionPanel = new JDBCConnectionPanel(this); |
95 | this.selectTableNamePanel = new SelectTableNamePanel(this); |
||
96 | 41488 | jjdelcerro | this.selectPkPanel = new SelectPkPanel(this); |
97 | 41486 | jjdelcerro | this.checkGeometriesPanel = new CheckGeometriesPanel(this); |
98 | 41598 | jjdelcerro | this.identifiersOptionsPanel = new IdentifiersOptionsPanel(this); |
99 | 42676 | dmartinezizquierdo | |
100 | 41638 | jjdelcerro | this.geometryIndexPanel = new GeometryIndexPanel(this); |
101 | this.updateTableStatistics = new UpdateTableStatisticsPanel(this); |
||
102 | this.permissionsPanel = new PermissionsPanel(this); |
||
103 | 42676 | dmartinezizquierdo | this.postCreatingStatementPanel = new PostCreatingStatementPanel(this); |
104 | 41486 | jjdelcerro | |
105 | 41598 | jjdelcerro | this.panels.add(this.identifiersOptionsPanel); |
106 | 41486 | jjdelcerro | this.panels.add(this.connectionPanel); |
107 | this.panels.add(this.selectTableNamePanel); |
||
108 | this.panels.add(this.selectPkPanel); |
||
109 | 42676 | dmartinezizquierdo | this.panels.add(this.geometryIndexPanel); |
110 | 41486 | jjdelcerro | this.panels.add(this.checkGeometriesPanel); |
111 | 42676 | dmartinezizquierdo | |
112 | 41638 | jjdelcerro | this.panels.add(this.permissionsPanel); |
113 | this.panels.add(this.updateTableStatistics); |
||
114 | this.panels.add(this.postCreatingStatementPanel); |
||
115 | 42676 | dmartinezizquierdo | |
116 | 40435 | jjdelcerro | } |
117 | |||
118 | 42676 | dmartinezizquierdo | |
119 | |||
120 | 40435 | jjdelcerro | public int getPanelCount() { |
121 | 41486 | jjdelcerro | return this.panels.size(); |
122 | 40435 | jjdelcerro | } |
123 | |||
124 | public ExporttoSwingProviderPanel getPanelAt(int index) { |
||
125 | 41486 | jjdelcerro | return this.panels.get(index); |
126 | 40435 | jjdelcerro | } |
127 | |||
128 | 41488 | jjdelcerro | public FeatureStore getSource() {
|
129 | return this.sourceStore; |
||
130 | } |
||
131 | 41492 | jjdelcerro | |
132 | 40435 | jjdelcerro | public ExporttoService createExporttoService() {
|
133 | 41486 | jjdelcerro | JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
|
134 | explorerParameters.setSchema(this.getSchema());
|
||
135 | 41598 | jjdelcerro | return new ExporrtoJDBCService(this); |
136 | 41486 | jjdelcerro | } |
137 | 40435 | jjdelcerro | |
138 | 43377 | jjdelcerro | @Override
|
139 | 41598 | jjdelcerro | public boolean getTranslateIdentifiersToLowerCase() { |
140 | return this.identifiersOptionsPanel.getTranslateToLowerCase(); |
||
141 | } |
||
142 | |||
143 | 43377 | jjdelcerro | public boolean getTranslateHyphens() { |
144 | return this.identifiersOptionsPanel.getTranslateHyphens(); |
||
145 | } |
||
146 | |||
147 | 41598 | jjdelcerro | public boolean getRemoveSpacesInIdentifiers() { |
148 | return this.identifiersOptionsPanel.getRemoveSpacesInTableName(); |
||
149 | } |
||
150 | 42676 | dmartinezizquierdo | |
151 | 41486 | jjdelcerro | public JDBCServerExplorerParameters getExplorerParameters() {
|
152 | return this.connectionPanel.getServerExplorerParameters(); |
||
153 | } |
||
154 | 41492 | jjdelcerro | |
155 | 41486 | jjdelcerro | public String getSchema() { |
156 | return this.selectTableNamePanel.getSchema(); |
||
157 | } |
||
158 | 40435 | jjdelcerro | |
159 | 41486 | jjdelcerro | public String getTableName() { |
160 | return this.selectTableNamePanel.getTableName(); |
||
161 | } |
||
162 | 40435 | jjdelcerro | |
163 | 41486 | jjdelcerro | public boolean canCreatetable() { |
164 | return this.selectTableNamePanel.canCreateTable(); |
||
165 | 40435 | jjdelcerro | } |
166 | |||
167 | 41486 | jjdelcerro | public String getPrimaryKey() { |
168 | return this.selectPkPanel.getPrimaryKeyName(); |
||
169 | } |
||
170 | 40435 | jjdelcerro | |
171 | 41486 | jjdelcerro | public int getGeometryChecks() { |
172 | return this.checkGeometriesPanel.getGeometryChecks(); |
||
173 | } |
||
174 | |||
175 | public int getGeometryChecksAction() { |
||
176 | return this.checkGeometriesPanel.getGeometryChecksAction(); |
||
177 | } |
||
178 | 41492 | jjdelcerro | |
179 | 41488 | jjdelcerro | public boolean getTryToFixGeometry() { |
180 | return this.checkGeometriesPanel.getTryToFixGeometry(); |
||
181 | } |
||
182 | 41492 | jjdelcerro | |
183 | 41486 | jjdelcerro | public String getExplorerName() { |
184 | return this.connectionPanel.getServerExplorerParameters().getExplorerName(); |
||
185 | } |
||
186 | 41492 | jjdelcerro | |
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 | 41598 | jjdelcerro | public IProjection getTargetProjection() {
|
209 | return this.projection; |
||
210 | } |
||
211 | |||
212 | 41638 | jjdelcerro | 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 | 42676 | dmartinezizquierdo | |
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 | 40435 | jjdelcerro | } |