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 | 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 | 41492 | jjdelcerro | import java.util.logging.Level; |
29 | import javax.swing.DefaultListModel; |
||
30 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
31 | import org.gvsig.exportto.ExporttoService; |
||
32 | 41486 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel; |
33 | 41638 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.GeometryIndexPanel; |
34 | 41598 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.IdentifiersOptionsPanel; |
35 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel; |
36 | 41638 | jjdelcerro | 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 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel; |
40 | import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel; |
||
41 | 41598 | jjdelcerro | import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
42 | 40435 | jjdelcerro | import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
43 | 41492 | jjdelcerro | 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 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
49 | 41127 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureType; |
50 | 41492 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
51 | 41486 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
52 | 40435 | jjdelcerro | import org.gvsig.tools.service.spi.AbstractProvider; |
53 | import org.gvsig.tools.service.spi.ProviderServices; |
||
54 | 41486 | jjdelcerro | import org.slf4j.Logger; |
55 | import org.slf4j.LoggerFactory; |
||
56 | 40435 | jjdelcerro | |
57 | /**
|
||
58 | * Exporto provider which gets Exporto from a file.
|
||
59 | 41492 | jjdelcerro | *
|
60 | 40435 | jjdelcerro | * @author gvSIG Team
|
61 | * @version $Id$
|
||
62 | */
|
||
63 | 41492 | jjdelcerro | public class BaseExporttoJDBCProvider extends AbstractProvider |
64 | 41598 | jjdelcerro | implements ExporttoJDBCOptions, ExporttoSwingProvider {
|
65 | 41492 | jjdelcerro | |
66 | 41127 | jldominguez | private static Logger logger = LoggerFactory.getLogger( |
67 | 41492 | jjdelcerro | BaseExporttoJDBCProvider.class); |
68 | 40435 | jjdelcerro | |
69 | 41486 | jjdelcerro | protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>(); |
70 | 40435 | jjdelcerro | |
71 | 41486 | jjdelcerro | protected FeatureStore sourceStore;
|
72 | 40435 | jjdelcerro | protected IProjection projection;
|
73 | 41486 | jjdelcerro | private final JDBCConnectionPanel connectionPanel; |
74 | private final SelectPkPanel selectPkPanel; |
||
75 | private final SelectTableNamePanel selectTableNamePanel; |
||
76 | private final CheckGeometriesPanel checkGeometriesPanel; |
||
77 | 41598 | jjdelcerro | private final IdentifiersOptionsPanel identifiersOptionsPanel; |
78 | 41638 | jjdelcerro | |
79 | private final GeometryIndexPanel geometryIndexPanel; |
||
80 | private final UpdateTableStatisticsPanel updateTableStatistics; |
||
81 | private final PermissionsPanel permissionsPanel; |
||
82 | private final PostCreatingStatementPanel postCreatingStatementPanel; |
||
83 | 40435 | jjdelcerro | |
84 | 41492 | jjdelcerro | private String storeName = null; |
85 | 41638 | jjdelcerro | |
86 | 41492 | jjdelcerro | public BaseExporttoJDBCProvider(ProviderServices providerServices,
|
87 | FeatureStore sourceStore, IProjection projection) { |
||
88 | 40435 | jjdelcerro | super(providerServices);
|
89 | 41486 | jjdelcerro | this.sourceStore = sourceStore;
|
90 | 40435 | jjdelcerro | this.projection = projection;
|
91 | |||
92 | 41127 | jldominguez | FeatureType ftype = null;
|
93 | try {
|
||
94 | 41486 | jjdelcerro | ftype = sourceStore.getDefaultFeatureType(); |
95 | 41127 | jldominguez | } catch (Exception exc) { |
96 | 41486 | jjdelcerro | logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc);
|
97 | 41492 | jjdelcerro | |
98 | 41127 | jldominguez | } |
99 | 41486 | jjdelcerro | this.connectionPanel = new JDBCConnectionPanel(this); |
100 | this.selectTableNamePanel = new SelectTableNamePanel(this); |
||
101 | 41488 | jjdelcerro | this.selectPkPanel = new SelectPkPanel(this); |
102 | 41486 | jjdelcerro | this.checkGeometriesPanel = new CheckGeometriesPanel(this); |
103 | 41598 | jjdelcerro | this.identifiersOptionsPanel = new IdentifiersOptionsPanel(this); |
104 | 41638 | jjdelcerro | |
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 | 41486 | jjdelcerro | |
110 | 41598 | jjdelcerro | this.panels.add(this.identifiersOptionsPanel); |
111 | 41486 | jjdelcerro | this.panels.add(this.connectionPanel); |
112 | this.panels.add(this.selectTableNamePanel); |
||
113 | this.panels.add(this.selectPkPanel); |
||
114 | 41638 | jjdelcerro | this.panels.add(this.geometryIndexPanel); |
115 | 41486 | jjdelcerro | this.panels.add(this.checkGeometriesPanel); |
116 | 41638 | jjdelcerro | |
117 | this.panels.add(this.permissionsPanel); |
||
118 | this.panels.add(this.updateTableStatistics); |
||
119 | this.panels.add(this.postCreatingStatementPanel); |
||
120 | |||
121 | 40435 | jjdelcerro | } |
122 | |||
123 | public int getPanelCount() { |
||
124 | 41486 | jjdelcerro | return this.panels.size(); |
125 | 40435 | jjdelcerro | } |
126 | |||
127 | public ExporttoSwingProviderPanel getPanelAt(int index) { |
||
128 | 41486 | jjdelcerro | return this.panels.get(index); |
129 | 40435 | jjdelcerro | } |
130 | |||
131 | 41488 | jjdelcerro | public FeatureStore getSource() {
|
132 | return this.sourceStore; |
||
133 | } |
||
134 | 41492 | jjdelcerro | |
135 | 40435 | jjdelcerro | public ExporttoService createExporttoService() {
|
136 | 41486 | jjdelcerro | JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
|
137 | explorerParameters.setSchema(this.getSchema());
|
||
138 | 41598 | jjdelcerro | return new ExporrtoJDBCService(this); |
139 | 41486 | jjdelcerro | } |
140 | 40435 | jjdelcerro | |
141 | 41598 | jjdelcerro | public boolean getTranslateIdentifiersToLowerCase() { |
142 | return this.identifiersOptionsPanel.getTranslateToLowerCase(); |
||
143 | } |
||
144 | |||
145 | public boolean getRemoveSpacesInIdentifiers() { |
||
146 | return this.identifiersOptionsPanel.getRemoveSpacesInTableName(); |
||
147 | } |
||
148 | |||
149 | 41486 | jjdelcerro | public JDBCServerExplorerParameters getExplorerParameters() {
|
150 | return this.connectionPanel.getServerExplorerParameters(); |
||
151 | } |
||
152 | 41492 | jjdelcerro | |
153 | 41486 | jjdelcerro | public String getSchema() { |
154 | return this.selectTableNamePanel.getSchema(); |
||
155 | } |
||
156 | 40435 | jjdelcerro | |
157 | 41486 | jjdelcerro | public String getTableName() { |
158 | return this.selectTableNamePanel.getTableName(); |
||
159 | } |
||
160 | 40435 | jjdelcerro | |
161 | 41486 | jjdelcerro | public boolean canCreatetable() { |
162 | return this.selectTableNamePanel.canCreateTable(); |
||
163 | 40435 | jjdelcerro | } |
164 | |||
165 | 41486 | jjdelcerro | public String getPrimaryKey() { |
166 | return this.selectPkPanel.getPrimaryKeyName(); |
||
167 | } |
||
168 | 40435 | jjdelcerro | |
169 | 41486 | jjdelcerro | public int getGeometryChecks() { |
170 | return this.checkGeometriesPanel.getGeometryChecks(); |
||
171 | } |
||
172 | |||
173 | public int getGeometryChecksAction() { |
||
174 | return this.checkGeometriesPanel.getGeometryChecksAction(); |
||
175 | } |
||
176 | 41492 | jjdelcerro | |
177 | 41488 | jjdelcerro | public boolean getTryToFixGeometry() { |
178 | return this.checkGeometriesPanel.getTryToFixGeometry(); |
||
179 | } |
||
180 | 41492 | jjdelcerro | |
181 | 41486 | jjdelcerro | public String getExplorerName() { |
182 | return this.connectionPanel.getServerExplorerParameters().getExplorerName(); |
||
183 | } |
||
184 | 41492 | jjdelcerro | |
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 | 41598 | jjdelcerro | public IProjection getTargetProjection() {
|
207 | return this.projection; |
||
208 | } |
||
209 | |||
210 | 41638 | jjdelcerro | 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 | 41598 | jjdelcerro | |
254 | 40435 | jjdelcerro | } |