Revision 14028
branches/v10/extensions/extOracleSpatial/src/com/iver/cit/gvsig/jdbc_spatial/DlgConnection.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 26-oct-2005 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
package com.iver.cit.gvsig.jdbc_spatial; |
|
45 |
|
|
46 |
import java.awt.BorderLayout; |
|
47 |
import java.awt.event.ActionListener; |
|
48 |
import java.util.ArrayList; |
|
49 |
import java.util.HashMap; |
|
50 |
|
|
51 |
import javax.swing.JButton; |
|
52 |
import javax.swing.JDialog; |
|
53 |
import javax.swing.JOptionPane; |
|
54 |
import javax.swing.JPanel; |
|
55 |
|
|
56 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
|
57 |
|
|
58 |
import com.iver.andami.PluginServices; |
|
59 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
61 |
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionPanel; |
|
62 |
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings; |
|
63 |
import com.iver.utiles.NotExistInXMLEntity; |
|
64 |
import com.iver.utiles.XMLEntity; |
|
65 |
import java.awt.Dimension; |
|
66 |
|
|
67 |
public class DlgConnection extends JDialog { |
|
68 |
|
|
69 |
private JPanel jContentPane = null; |
|
70 |
private ConnectionPanel jConnPanel = null; |
|
71 |
private JButton jBtnOK = null; |
|
72 |
private JPanel jPanel1 = null; |
|
73 |
private JButton jBtnCancel = null; |
|
74 |
private ConnectionSettings connSettings = null; |
|
75 |
|
|
76 |
/** |
|
77 |
* This is the default constructor |
|
78 |
*/ |
|
79 |
public DlgConnection() { |
|
80 |
super(); |
|
81 |
initialize(); |
|
82 |
} |
|
83 |
|
|
84 |
private void setPreferences() |
|
85 |
{ |
|
86 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML(); |
|
87 |
|
|
88 |
if (xml == null) { |
|
89 |
xml = new XMLEntity(); |
|
90 |
} |
|
91 |
|
|
92 |
if (!xml.contains("jdbc-connections")) { |
|
93 |
String[] servers = new String[0]; |
|
94 |
xml.putProperty("jdbc-connections", servers); |
|
95 |
} |
|
96 |
|
|
97 |
try { |
|
98 |
String[] servers = xml.getStringArrayProperty("jdbc-connections"); |
|
99 |
HashMap settings = new HashMap(); |
|
100 |
for (int i = 0; i < servers.length; i++) { |
|
101 |
ConnectionSettings cs = new ConnectionSettings(); |
|
102 |
cs.setFromString(servers[i]); |
|
103 |
settings.put(cs.getName(), cs); |
|
104 |
} |
|
105 |
getJConnPanel().setSettings(settings); |
|
106 |
} catch (NotExistInXMLEntity e) { |
|
107 |
} |
|
108 |
|
|
109 |
} |
|
110 |
/** |
|
111 |
* This method initializes this |
|
112 |
* |
|
113 |
* @return void |
|
114 |
*/ |
|
115 |
private void initialize() { |
|
116 |
this.setSize(360, 367); |
|
117 |
this.setTitle(PluginServices.getText(this, "database_connection")); |
|
118 |
this.setContentPane(getJContentPane()); |
|
119 |
setPreferences(); |
|
120 |
jConnPanel.setDrivers(getDriverNames()); |
|
121 |
} |
|
122 |
|
|
123 |
private String[] getDriverNames(){ |
|
124 |
Class[] classes = new Class[] { VectorialJDBCDriver.class }; |
|
125 |
|
|
126 |
ArrayList ret = new ArrayList(); |
|
127 |
String[] driverNames = LayerFactory.getDM().getDriverNames(); |
|
128 |
|
|
129 |
for (int i = 0; i < driverNames.length; i++) { |
|
130 |
boolean is = false; |
|
131 |
|
|
132 |
for (int j = 0; j < classes.length; j++) { |
|
133 |
if (LayerFactory.getDM().isA(driverNames[i], classes[j])) { |
|
134 |
ret.add(driverNames[i]); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
return (String[]) ret.toArray(new String[0]); |
|
140 |
|
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* This method initializes jContentPane |
|
145 |
* |
|
146 |
* @return javax.swing.JPanel |
|
147 |
*/ |
|
148 |
private JPanel getJContentPane() { |
|
149 |
if (jContentPane == null) { |
|
150 |
jContentPane = new JPanel(); |
|
151 |
jContentPane.setLayout(new BorderLayout()); |
|
152 |
jContentPane.add(getJConnPanel(), java.awt.BorderLayout.CENTER); |
|
153 |
jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH); |
|
154 |
|
|
155 |
} |
|
156 |
return jContentPane; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* This method initializes jPanel |
|
161 |
* |
|
162 |
* @return javax.swing.JPanel |
|
163 |
*/ |
|
164 |
private ConnectionPanel getJConnPanel() { |
|
165 |
if (jConnPanel == null) { |
|
166 |
jConnPanel = new ConnectionPanel(); |
|
167 |
} |
|
168 |
return jConnPanel; |
|
169 |
} |
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
/** |
|
174 |
* This method initializes jPanel1 |
|
175 |
* |
|
176 |
* @return javax.swing.JPanel |
|
177 |
*/ |
|
178 |
private JPanel getJPanel1() { |
|
179 |
if (jPanel1 == null) { |
|
180 |
ActionListener okAction = new java.awt.event.ActionListener() { |
|
181 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
182 |
if (!jConnPanel.done()) { |
|
183 |
JOptionPane.showMessageDialog(DlgConnection.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE); |
|
184 |
return; |
|
185 |
} |
|
186 |
jConnPanel.saveConnectionSettings(); |
|
187 |
connSettings = jConnPanel.getConnectionSettings(); |
|
188 |
dispose(); |
|
189 |
} |
|
190 |
}; |
|
191 |
|
|
192 |
ActionListener cancelAction = new java.awt.event.ActionListener() { |
|
193 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
194 |
connSettings = null; |
|
195 |
dispose(); |
|
196 |
} |
|
197 |
}; |
|
198 |
jPanel1 = new AcceptCancelPanel(okAction, cancelAction); |
|
199 |
|
|
200 |
|
|
201 |
} |
|
202 |
return jPanel1; |
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
public ConnectionSettings getConnSettings() { |
|
207 |
return connSettings; |
|
208 |
} |
|
209 |
|
|
210 |
} // @jve:decl-index=0:visual-constraint="10,10" |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/ExtJDBC_Spatial.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package es.prodevelop.cit.gvsig.jdbc_spatial; |
|
44 |
|
|
45 |
import com.iver.andami.PluginServices; |
|
46 |
import com.iver.andami.plugins.Extension; |
|
47 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
48 |
|
|
49 |
import com.iver.cit.gvsig.About; |
|
50 |
import com.iver.cit.gvsig.AddLayer; |
|
51 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
52 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
54 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
55 |
import com.iver.cit.gvsig.jdbc_spatial.loaders.PostgisLayerBuilder; |
|
56 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
57 |
|
|
58 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
|
59 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
|
60 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
61 |
|
|
62 |
import es.prodevelop.cit.gvsig.fmap.layers.FLayerJDBCVectorial; |
|
63 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.WizardJDBC; |
|
64 |
|
|
65 |
import org.apache.log4j.Logger; |
|
66 |
|
|
67 |
import java.security.KeyException; |
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* This extension adds the export-to-oracle button. |
|
72 |
* |
|
73 |
* @author jldominguez |
|
74 |
* |
|
75 |
*/ |
|
76 |
public class ExtJDBC_Spatial extends Extension { |
|
77 |
private static Logger logger = Logger.getLogger(ExtJDBC_Spatial.class.getName()); |
|
78 |
|
|
79 |
public void initialize() { |
|
80 |
|
|
81 |
// about |
|
82 |
java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html"); |
|
83 |
About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class); |
|
84 |
claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl); |
|
85 |
|
|
86 |
System.out.println("A?ado WizardJDBC."); |
|
87 |
AddLayer.addWizard(WizardJDBC.class); |
|
88 |
|
|
89 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
90 |
|
|
91 |
extensionPoints.add("CatalogLayers", "POSTGIS", new PostgisLayerBuilder()); |
|
92 |
extensionPoints.add("Layers", FLayerJDBCVectorial.class.getName(), |
|
93 |
FLayerJDBCVectorial.class); |
|
94 |
|
|
95 |
try { |
|
96 |
((ExtensionPoint) extensionPoints.get("Layers")).addAlias(FLayerJDBCVectorial.class.getName(), |
|
97 |
"JDBCVectorial"); |
|
98 |
} |
|
99 |
catch (KeyException e) { |
|
100 |
// TODO Auto-generated catch block |
|
101 |
e.printStackTrace(); |
|
102 |
} |
|
103 |
|
|
104 |
OraEpsgTableLoader loader = new OraEpsgTableLoader(); |
|
105 |
if (!loader.createOracleEpsgTable()) { |
|
106 |
logger.error("Unable to create ORA_EPSG datasource!"); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
public void execute(String actionCommand) { |
|
111 |
if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) { |
|
112 |
FLyrVect lyrv = null; |
|
113 |
MapContext mx = null; |
|
114 |
|
|
115 |
try { |
|
116 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
117 |
|
|
118 |
if (w instanceof View) { |
|
119 |
View v = (View) w; |
|
120 |
MapControl mc = v.getMapControl(); |
|
121 |
mx = mc.getMapContext(); |
|
122 |
|
|
123 |
FLayer[] lyrs = mx.getLayers().getActives(); |
|
124 |
|
|
125 |
if (lyrs.length == 1) { |
|
126 |
FLayer lyr = lyrs[0]; |
|
127 |
|
|
128 |
if (lyr instanceof FLyrVect) { |
|
129 |
lyrv = (FLyrVect) lyr; |
|
130 |
|
|
131 |
ExportToOracle export = new ExportToOracle(); |
|
132 |
export.toOracle(mx, lyrv); |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
catch (Exception ex) { |
|
138 |
System.err.println( |
|
139 |
"Unexpected error while getting active vect layer: " + |
|
140 |
ex.getMessage()); |
|
141 |
System.err.println("Nothing done."); |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
public boolean isEnabled() { |
|
147 |
return isVisible(); |
|
148 |
|
|
149 |
// return true; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Is visible when there is one vector layer selected |
|
154 |
*/ |
|
155 |
public boolean isVisible() { |
|
156 |
// return true; |
|
157 |
try { |
|
158 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
159 |
|
|
160 |
if (w instanceof View) { |
|
161 |
View v = (View) w; |
|
162 |
MapControl mc = v.getMapControl(); |
|
163 |
MapContext mx = mc.getMapContext(); |
|
164 |
FLayer[] lyrs = mx.getLayers().getActives(); |
|
165 |
|
|
166 |
if (lyrs.length == 1) { |
|
167 |
FLayer lyr = lyrs[0]; |
|
168 |
|
|
169 |
if ((lyr instanceof FLyrVect) && (true)) { |
|
170 |
return true; |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
catch (Exception ex) { |
|
176 |
return false; |
|
177 |
} |
|
178 |
|
|
179 |
return false; |
|
180 |
} |
|
181 |
|
|
182 |
private java.net.URL createResourceUrl(String path) { |
|
183 |
return getClass().getClassLoader().getResource(path); |
|
184 |
} |
|
185 |
} |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/SingleJDBCConnectionExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package es.prodevelop.cit.gvsig.jdbc_spatial; |
|
44 |
|
|
45 |
import com.iver.andami.PluginServices; |
|
46 |
import com.iver.andami.plugins.Extension; |
|
47 |
|
|
48 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.ConnectionWithParams; |
|
49 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.SingleJDBCConnectionManager; |
|
50 |
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings; |
|
51 |
|
|
52 |
import com.iver.utiles.NotExistInXMLEntity; |
|
53 |
import com.iver.utiles.XMLEntity; |
|
54 |
|
|
55 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.JDBConnectionManagerDialog; |
|
56 |
|
|
57 |
import org.apache.log4j.Logger; |
|
58 |
|
|
59 |
import java.sql.SQLException; |
|
60 |
|
|
61 |
import java.util.ArrayList; |
|
62 |
|
|
63 |
import javax.swing.JOptionPane; |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* This extension allows the user to access the single connection manager dialog |
|
68 |
* |
|
69 |
* @see com.iver.cit.gvsig.fmap.drivers.jdbc.utils.SingleJDBCConnectionManager |
|
70 |
* |
|
71 |
* @author jldominguez |
|
72 |
* |
|
73 |
*/ |
|
74 |
public class SingleJDBCConnectionExtension extends Extension { |
|
75 |
private static Logger logger = Logger.getLogger(SingleJDBCConnectionExtension.class.getName()); |
|
76 |
|
|
77 |
/** |
|
78 |
* This method simply loads the connections stored in gvSIG's persistence file |
|
79 |
* as closed connections |
|
80 |
*/ |
|
81 |
public void initialize() { |
|
82 |
loadPersistenceConnections(); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* The only command available is the one to open the connection manager |
|
87 |
* dialog ("GESTOR_JDBC") |
|
88 |
*/ |
|
89 |
public void execute(String actionCommand) { |
|
90 |
if (actionCommand.compareToIgnoreCase("GESTOR_JDBC") == 0) { |
|
91 |
JDBConnectionManagerDialog dlg = new JDBConnectionManagerDialog(); |
|
92 |
dlg.showDialog(); |
|
93 |
saveAllToPersistence(); |
|
94 |
|
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
public boolean isEnabled() { |
|
100 |
return true; |
|
101 |
} |
|
102 |
|
|
103 |
public boolean isVisible() { |
|
104 |
return true; |
|
105 |
} |
|
106 |
|
|
107 |
private void saveAllToPersistence() { |
|
108 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML(); |
|
109 |
xml.remove("jdbc-connections"); |
|
110 |
|
|
111 |
ConnectionWithParams[] all = SingleJDBCConnectionManager.instance() |
|
112 |
.getAllConnections(); |
|
113 |
|
|
114 |
if (all == null) { |
|
115 |
return; |
|
116 |
} |
|
117 |
|
|
118 |
for (int i = 0; i < all.length; i++) { |
|
119 |
addToPersistence(all[i]); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
private void addToPersistence(ConnectionWithParams cwp) { |
|
124 |
if (cwp == null) { |
|
125 |
return; |
|
126 |
} |
|
127 |
|
|
128 |
ConnectionSettings _cs = new ConnectionSettings(); |
|
129 |
|
|
130 |
_cs.setHost(cwp.getHost()); |
|
131 |
_cs.setPort(cwp.getPort()); |
|
132 |
_cs.setDb(cwp.getDb()); |
|
133 |
_cs.setDriver(cwp.getDrvName()); |
|
134 |
_cs.setUser(cwp.getUser()); |
|
135 |
_cs.setName(cwp.getName()); |
|
136 |
|
|
137 |
String newstr = _cs.toString(); |
|
138 |
|
|
139 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML(); |
|
140 |
|
|
141 |
String[] old = null; |
|
142 |
|
|
143 |
if (xml.contains("jdbc-connections")) { |
|
144 |
old = xml.getStringArrayProperty("jdbc-connections"); |
|
145 |
} |
|
146 |
|
|
147 |
ArrayList oldl = stringArrayToArrayList(old); |
|
148 |
oldl.add(newstr); |
|
149 |
|
|
150 |
String[] newarr = (String[]) oldl.toArray(new String[0]); |
|
151 |
|
|
152 |
xml.remove("jdbc-connections"); |
|
153 |
xml.putProperty("jdbc-connections", newarr); |
|
154 |
PluginServices.getPluginServices(this).setPersistentXML(xml); |
|
155 |
} |
|
156 |
|
|
157 |
private ArrayList stringArrayToArrayList(String[] arr) { |
|
158 |
ArrayList resp = new ArrayList(); |
|
159 |
|
|
160 |
if ((arr != null) && (arr.length > 0)) { |
|
161 |
for (int i = 0; i < arr.length; i++) { |
|
162 |
resp.add(arr[i]); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
return resp; |
|
167 |
} |
|
168 |
|
|
169 |
private void loadPersistenceConnections() { |
|
170 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML(); |
|
171 |
|
|
172 |
if (xml == null) { |
|
173 |
xml = new XMLEntity(); |
|
174 |
} |
|
175 |
|
|
176 |
if (!xml.contains("jdbc-connections")) { |
|
177 |
String[] servers = new String[0]; |
|
178 |
xml.putProperty("jdbc-connections", servers); |
|
179 |
} |
|
180 |
|
|
181 |
// add drivers to connection manager |
|
182 |
String[] servers = null; |
|
183 |
|
|
184 |
try { |
|
185 |
servers = xml.getStringArrayProperty("jdbc-connections"); |
|
186 |
} |
|
187 |
catch (NotExistInXMLEntity e) { |
|
188 |
System.err.println( |
|
189 |
"Error while getting projects jdbc-connections: " + |
|
190 |
e.getMessage()); |
|
191 |
|
|
192 |
return; |
|
193 |
} |
|
194 |
|
|
195 |
for (int i = 0; i < servers.length; i++) { |
|
196 |
ConnectionSettings cs = new ConnectionSettings(); |
|
197 |
boolean params_ok = true; |
|
198 |
try { |
|
199 |
cs.setFromString(servers[i]); |
|
200 |
} catch (Exception ex) { |
|
201 |
logger.error("Found misconfigured connection: " + servers[i]); |
|
202 |
params_ok = false; |
|
203 |
} |
|
204 |
if (params_ok) addDisconnected(cs); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
private void addDisconnected(ConnectionSettings _cs) { |
|
209 |
try { |
|
210 |
SingleJDBCConnectionManager.instance() |
|
211 |
.getConnection(_cs.getDriver(), |
|
212 |
_cs.getUser(), null, _cs.getName(), _cs.getHost(), |
|
213 |
_cs.getPort(), _cs.getDb(), false); |
|
214 |
} |
|
215 |
catch (SQLException e) { |
|
216 |
System.err.println("While getting connection: " + e.getMessage()); |
|
217 |
showConnectionErrorMessage(e.getMessage()); |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
private void showConnectionErrorMessage(String _msg) { |
|
222 |
String msg = (_msg.length() > 300) ? "" : (": " + _msg); |
|
223 |
String title = PluginServices.getText(this, "connection_error"); |
|
224 |
JOptionPane.showMessageDialog(null, title + msg, title, |
|
225 |
JOptionPane.ERROR_MESSAGE); |
|
226 |
} |
|
227 |
|
|
228 |
public void terminate() { |
|
229 |
SingleJDBCConnectionManager.instance().closeAllBeforeTerminate(); |
|
230 |
} |
|
231 |
} |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/ExportOracleExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package es.prodevelop.cit.gvsig.jdbc_spatial; |
|
44 |
|
|
45 |
import java.security.KeyException; |
|
46 |
|
|
47 |
import org.apache.log4j.Logger; |
|
48 |
|
|
49 |
import com.iver.andami.PluginServices; |
|
50 |
import com.iver.andami.plugins.Extension; |
|
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
52 |
import com.iver.cit.gvsig.About; |
|
53 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
56 |
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB; |
|
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
58 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
59 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
|
60 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
|
61 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* This extension adds the export-to-oracle button. |
|
66 |
* |
|
67 |
* @author jldominguez |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class ExportOracleExtension extends Extension { |
|
71 |
private static Logger logger = Logger.getLogger(ExportOracleExtension.class.getName()); |
|
72 |
|
|
73 |
public void initialize() { |
|
74 |
|
|
75 |
// about |
|
76 |
java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html"); |
|
77 |
About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class); |
|
78 |
claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl); |
|
79 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
80 |
try { |
|
81 |
((ExtensionPoint)extensionPoints.get("Layers")).addAlias(FLayerVectorialDB.class.getName(), "VectorialDB"); |
|
82 |
} catch (KeyException e) { |
|
83 |
// TODO Auto-generated catch block |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
// System.out.println("A?ado WizardVectorialDB."); |
|
87 |
// AddLayer.addWizard(WizardVectorialDB.class); |
|
88 |
// |
|
89 |
// ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
90 |
// |
|
91 |
//// extensionPoints.add("CatalogLayers", "POSTGIS", new PostgisLayerBuilder()); |
|
92 |
// extensionPoints.add("Layers", FLayerJDBCVectorial.class.getName(), |
|
93 |
// FLayerJDBCVectorial.class); |
|
94 |
|
|
95 |
// try { |
|
96 |
// ((ExtensionPoint) extensionPoints.get("Layers")).addAlias(FLayerJDBCVectorial.class.getName(), |
|
97 |
// "JDBCVectorial"); |
|
98 |
// } |
|
99 |
// catch (KeyException e) { |
|
100 |
// // TODO Auto-generated catch block |
|
101 |
// e.printStackTrace(); |
|
102 |
// } |
|
103 |
|
|
104 |
OraEpsgTableLoader loader = new OraEpsgTableLoader(); |
|
105 |
if (!loader.createOracleEpsgTable()) { |
|
106 |
logger.error("Unable to create ORA_EPSG datasource!"); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
public void execute(String actionCommand) { |
|
111 |
if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) { |
|
112 |
FLyrVect lyrv = null; |
|
113 |
MapContext mx = null; |
|
114 |
|
|
115 |
try { |
|
116 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
117 |
|
|
118 |
if (w instanceof View) { |
|
119 |
View v = (View) w; |
|
120 |
MapControl mc = v.getMapControl(); |
|
121 |
mx = mc.getMapContext(); |
|
122 |
|
|
123 |
FLayer[] lyrs = mx.getLayers().getActives(); |
|
124 |
|
|
125 |
if (lyrs.length == 1) { |
|
126 |
FLayer lyr = lyrs[0]; |
|
127 |
|
|
128 |
if (lyr instanceof FLyrVect) { |
|
129 |
lyrv = (FLyrVect) lyr; |
|
130 |
|
|
131 |
ExportToOracle export = new ExportToOracle(); |
|
132 |
export.toOracle(mx, lyrv); |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
catch (Exception ex) { |
|
138 |
System.err.println( |
|
139 |
"Unexpected error while getting active vect layer: " + |
|
140 |
ex.getMessage()); |
|
141 |
System.err.println("Nothing done."); |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
public boolean isEnabled() { |
|
147 |
return isVisible(); |
|
148 |
|
|
149 |
// return true; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Is visible when there is one vector layer selected |
|
154 |
*/ |
|
155 |
public boolean isVisible() { |
|
156 |
// return true; |
|
157 |
try { |
|
158 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
159 |
|
|
160 |
if (w instanceof View) { |
|
161 |
View v = (View) w; |
|
162 |
MapControl mc = v.getMapControl(); |
|
163 |
MapContext mx = mc.getMapContext(); |
|
164 |
FLayer[] lyrs = mx.getLayers().getActives(); |
|
165 |
|
|
166 |
if (lyrs.length == 1) { |
|
167 |
FLayer lyr = lyrs[0]; |
|
168 |
|
|
169 |
if ((lyr instanceof FLyrVect) && (true)) { |
|
170 |
return true; |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
catch (Exception ex) { |
|
176 |
return false; |
|
177 |
} |
|
178 |
|
|
179 |
return false; |
|
180 |
} |
|
181 |
|
|
182 |
private java.net.URL createResourceUrl(String path) { |
|
183 |
return getClass().getClassLoader().getResource(path); |
|
184 |
} |
|
185 |
} |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/ExportToOracle.java | ||
---|---|---|
51 | 51 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
52 | 52 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
53 | 53 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
54 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.ConnectionWithParams;
|
|
55 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.SingleJDBCConnectionManager;
|
|
54 |
import com.iver.cit.gvsig.fmap.drivers.IConnection;
|
|
55 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
|
|
56 | 56 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
57 | 57 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
58 | 58 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
59 | 59 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
60 | 60 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
61 | 61 |
|
62 |
import com.iver.utiles.PostProcessSupport; |
|
63 | 62 |
|
64 | 63 |
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver; |
65 | 64 |
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialWriter; |
66 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.JDBConnectionParamsDialog; |
|
67 | 65 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.OracleConnectionChooserPanel; |
68 | 66 |
|
69 | 67 |
import java.awt.Component; |
70 |
import java.sql.Connection; |
|
71 |
import java.sql.SQLException; |
|
72 | 68 |
import java.sql.Types; |
73 | 69 |
|
74 | 70 |
import javax.swing.JOptionPane; |
... | ... | |
89 | 85 |
boolean valid_name = false; |
90 | 86 |
|
91 | 87 |
while (!valid_name) { |
92 |
tableName = JOptionPane.showInputDialog(PluginServices.getText( |
|
88 |
tableName = JOptionPane.showInputDialog(((Component)PluginServices.getMainFrame()),PluginServices.getText(
|
|
93 | 89 |
this, "intro_tablename")); |
94 | 90 |
valid_name = ((tableName == null) || |
95 | 91 |
((tableName.length() <= (OracleSpatialDriver.MAX_ID_LENGTH - |
... | ... | |
133 | 129 |
return; |
134 | 130 |
} |
135 | 131 |
|
136 |
Connection conex = cwp.getConnection(); |
|
132 |
IConnection conex = cwp.getConnection();
|
|
137 | 133 |
|
138 | 134 |
DBLayerDefinition dbLayerDef = new DBLayerDefinition(); |
139 | 135 |
dbLayerDef.setCatalogName(cwp.getDb()); |
... | ... | |
212 | 208 |
writer.setGeoCS(geo_cs); |
213 | 209 |
|
214 | 210 |
OracleSpatialDriver oDriver = new OracleSpatialDriver(); |
215 |
|
|
211 |
|
|
216 | 212 |
oDriver.setDestProjection(strSRID); |
217 | 213 |
|
218 | 214 |
DBLayerDefinition driver_ldef = cloneDBLyrDef(dbLayerDef); |
... | ... | |
225 | 221 |
writer.setDriver(oDriver); |
226 | 222 |
|
227 | 223 |
Object[] params = new Object[2]; |
228 |
params[0] = (java.sql.Connection) conex;
|
|
224 |
params[0] = (IConnection) conex;
|
|
229 | 225 |
params[1] = driver_ldef; |
230 | 226 |
|
231 | 227 |
/* |
... | ... | |
336 | 332 |
|
337 | 333 |
return resp; |
338 | 334 |
} |
339 |
|
|
340 |
|
|
341 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
342 | 338 |
} |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialDriver.java | ||
---|---|---|
71 | 71 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
72 | 72 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
73 | 73 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
74 |
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC; |
|
75 |
import com.iver.cit.gvsig.fmap.drivers.DBException; |
|
74 | 76 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
75 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver;
|
|
77 |
import com.iver.cit.gvsig.fmap.drivers.DefaultJDBCDriver;
|
|
76 | 78 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
77 | 79 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
80 |
import com.iver.cit.gvsig.fmap.drivers.IConnection; |
|
78 | 81 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
82 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams; |
|
83 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager; |
|
79 | 84 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
80 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.ConnectionWithParams; |
|
81 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.SingleJDBCConnectionManager; |
|
82 | 85 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
83 | 86 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
84 | 87 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
... | ... | |
162 | 165 |
* @author jldominguez |
163 | 166 |
* |
164 | 167 |
*/ |
165 |
public class OracleSpatialDriver extends DefaultDBDriver
|
|
168 |
public class OracleSpatialDriver extends DefaultJDBCDriver
|
|
166 | 169 |
implements IDelayedDriver, ICanReproject, IWriteable { |
167 | 170 |
private static Logger logger = Logger.getLogger(OracleSpatialDriver.class.getName()); |
168 | 171 |
private static int FETCH_SIZE = 15000; |
169 | 172 |
|
170 |
// constants
|
|
173 |
// constants |
|
171 | 174 |
public static final int GEODETIC_FULLEXTENT_SAMPLE_SIZE = 50; |
172 | 175 |
public static final String GEODETIC_SRID = "8307"; |
173 | 176 |
public static final String ASSUMED_ORACLE_SRID = "8307"; |
... | ... | |
180 | 183 |
public static final String ORACLE_EPSG_FILE_NAME = "ORA_EPSG.DBF"; |
181 | 184 |
public static final String DEFAULT_GEO_FIELD = "GEOMETRY"; |
182 | 185 |
// public static final String DEFAULT_GEO_FIELD = "MERGEDGEOMETRY"; |
183 |
|
|
186 |
|
|
184 | 187 |
public static final String ORACLE_ID_FIELD = "ROWID"; |
185 | 188 |
public static final String DEFAULT_ID_FIELD = "GID"; |
186 | 189 |
public static final String ORACLE_GEO_SCHEMA = "MDSYS"; |
... | ... | |
193 | 196 |
private static final long ID_MIN_DELAY = 1000; |
194 | 197 |
|
195 | 198 |
public static final String ORACLE_JAR_FILE_NAME = "oracle.jdbc.driver.OracleDriver"; |
196 |
|
|
199 |
|
|
197 | 200 |
static { |
198 | 201 |
try { |
199 | 202 |
Class.forName(ORACLE_JAR_FILE_NAME); |
... | ... | |
221 | 224 |
private int[] pkOneBasedIndexes; |
222 | 225 |
private String[] fieldNames; |
223 | 226 |
private String not_restricted_sql = ""; |
224 |
|
|
227 |
|
|
225 | 228 |
private Rectangle2D workingAreaInViewsCS = null; |
226 | 229 |
private Rectangle2D workingAreaInTablesCS = null; |
227 | 230 |
private STRUCT workingAreaInTablesCSStruct = null; |
... | ... | |
259 | 262 |
drvAtts = new DriverAttributes(); |
260 | 263 |
drvAtts.setLoadedInMemory(false); |
261 | 264 |
} |
262 |
|
|
265 |
|
|
263 | 266 |
public String getWhereClause() { |
264 | 267 |
return lyrDef.getWhereClause(); |
265 | 268 |
} |
266 |
|
|
267 | 269 |
|
270 |
|
|
268 | 271 |
/** |
269 | 272 |
* This method is called when the user creates a new oracle |
270 | 273 |
* table from a vectorial layer |
... | ... | |
273 | 276 |
* <tt>DBLayerDefinition</tt> |
274 | 277 |
*/ |
275 | 278 |
public void setData(Object[] params) { |
276 |
setData((Connection) params[0], (DBLayerDefinition) params[1]); |
|
279 |
setData((IConnection) params[0], (DBLayerDefinition) params[1]);
|
|
277 | 280 |
} |
278 | 281 |
|
279 | 282 |
private void adjustLyrDef() throws SQLException { |
... | ... | |
308 | 311 |
/** |
309 | 312 |
* Standard initializing method. |
310 | 313 |
*/ |
311 |
public void setData(Connection _conn, DBLayerDefinition lyrDef) { |
|
314 |
public void setData(IConnection _conn, DBLayerDefinition lyrDef) {
|
|
312 | 315 |
conn = _conn; |
313 | 316 |
|
314 | 317 |
// This metadata is required to store layer in GVP |
315 | 318 |
// without problems: |
316 | 319 |
ConnectionWithParams _cwp = |
317 |
SingleJDBCConnectionManager.instance().findConnection(conn);
|
|
320 |
SingleVectorialDBConnectionManager.instance().findConnection(conn);
|
|
318 | 321 |
host = _cwp.getHost(); |
319 | 322 |
port = _cwp.getPort(); |
320 | 323 |
dbName = _cwp.getDb(); |
... | ... | |
334 | 337 |
cleanWhereClause(); |
335 | 338 |
loadSdoMetadata(); |
336 | 339 |
oneRowMetadata(); |
337 |
|
|
340 |
|
|
338 | 341 |
setDestProjection(lyrDef.getSRID_EPSG()); |
339 |
|
|
342 |
|
|
340 | 343 |
IProjection viewProj = CRSFactory.getCRS("EPSG:" + destProj); |
341 | 344 |
IProjection tableProj = CRSFactory.getCRS("EPSG:" + epsgSRID); |
342 | 345 |
ICoordTrans reprojecter = viewProj.getCT(tableProj); |
... | ... | |
363 | 366 |
} |
364 | 367 |
|
365 | 368 |
private void getMetadata() { |
366 |
|
|
369 |
|
|
367 | 370 |
long id_load_start = System.currentTimeMillis(); |
368 | 371 |
setIdRowTable(); |
369 | 372 |
long id_load_end = System.currentTimeMillis(); |
370 |
|
|
373 |
|
|
371 | 374 |
long delay = id_load_end - id_load_start; |
372 | 375 |
if (delay < ID_MIN_DELAY) { |
373 | 376 |
logger.info("Ids thread delayed by: " + (ID_MIN_DELAY - delay) + " ms."); |
... | ... | |
397 | 400 |
getTableName() + " c"; |
398 | 401 |
|
399 | 402 |
// SDO_ELEM_INFO |
400 |
Statement _st = conn.createStatement();
|
|
403 |
Statement _st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
|
401 | 404 |
ResultSet _rs = _st.executeQuery(qry); |
402 | 405 |
|
403 | 406 |
ArrayList types = new ArrayList(); |
... | ... | |
526 | 529 |
|
527 | 530 |
private void loadSdoMetadata() { |
528 | 531 |
try { |
529 |
Statement _st = conn.createStatement();
|
|
532 |
Statement _st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
|
530 | 533 |
String[] tokens = getTableName().split("\\u002E", 2); |
531 | 534 |
String qry; |
532 | 535 |
if (tokens.length > 1) |
533 | 536 |
{ |
534 | 537 |
qry = "select * from " + ORACLE_GEOMETADATA_VIEW + |
535 |
" where OWNER = '" + tokens[0] + "' AND TABLE_NAME = '" +
|
|
538 |
" where OWNER = '" + tokens[0] + "' AND TABLE_NAME = '" + |
|
536 | 539 |
tokens[1] + "'"; |
537 | 540 |
} |
538 | 541 |
else |
... | ... | |
557 | 560 |
tableHasSrid = false; |
558 | 561 |
} |
559 | 562 |
full_Extent = getFullExtentFromCurrentRecord(_rs); |
560 |
|
|
561 |
hasRealiableExtent = realiableExtent(full_Extent, isGeogCS);
|
|
562 |
|
|
563 |
|
|
564 |
hasRealiableExtent = realiableExtent(full_Extent, isGeogCS); |
|
565 |
|
|
563 | 566 |
if (!hasRealiableExtent) { |
564 | 567 |
full_Extent = getFastEstimatedGeodeticExtent( |
565 | 568 |
getTableName(), geoColName, conn, 20, 10); |
... | ... | |
619 | 622 |
String _sql = "select " + getStandardSelectExpression() + ", c." + |
620 | 623 |
geoColName + " from " + getTableName() + " c "; |
621 | 624 |
|
622 |
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
|
625 |
st = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
|
623 | 626 |
ResultSet.CONCUR_READ_ONLY); |
624 | 627 |
|
625 | 628 |
ResultSet _rs = st.executeQuery(_sql + " where (rownum = 1)"); |
... | ... | |
635 | 638 |
// ----------------------- |
636 | 639 |
_rs = st.executeQuery(not_restricted_sql + " where (rownum = 1)"); |
637 | 640 |
metaData = _rs.getMetaData(); |
638 |
|
|
639 |
userName = conn.getMetaData().getUserName();
|
|
640 |
|
|
641 |
|
|
642 |
userName = ((ConnectionJDBC)conn).getConnection().getMetaData().getUserName();
|
|
643 |
|
|
641 | 644 |
// geoColInd = _rs.findColumn(geoColName); |
642 | 645 |
oneBasedGeoColInd = metaData.getColumnCount() + 1; |
643 | 646 |
|
644 |
DatabaseMetaData dbmd = conn.getMetaData();
|
|
647 |
DatabaseMetaData dbmd = ((ConnectionJDBC)conn).getConnection().getMetaData();
|
|
645 | 648 |
pkOneBasedIndexes = getPKIndexes(dbmd, _rs); |
646 | 649 |
|
647 | 650 |
int cnt = metaData.getColumnCount(); |
... | ... | |
655 | 658 |
|
656 | 659 |
adjustLyrDef(); |
657 | 660 |
|
658 |
_rs.close(); // st no debe cerrarse ya que las llamadas a metadata lo encesitan
|
|
661 |
_rs.close(); // st no debe cerrarse ya que las llamadas a metadata lo encesitan |
|
659 | 662 |
} |
660 | 663 |
catch (SQLException se) { |
661 | 664 |
logger.error("While getting metadata. " + se.getMessage()); |
... | ... | |
664 | 667 |
|
665 | 668 |
private int getShapeTypeOfStruct(STRUCT sample) throws SQLException { |
666 | 669 |
int code = ((NUMBER) sample.getOracleAttributes()[0]).intValue() % 10; |
667 |
|
|
670 |
|
|
668 | 671 |
switch (code) { |
669 | 672 |
case 1: |
670 | 673 |
return FShape.POINT; |
... | ... | |
775 | 778 |
throws DriverException { |
776 | 779 |
if (isNotAvailableYet) { |
777 | 780 |
return null; |
778 |
}
|
|
781 |
} |
|
779 | 782 |
|
780 | 783 |
singleCachedFeatureRowNum = -1; |
781 | 784 |
|
... | ... | |
836 | 839 |
" where rowid = ?"; |
837 | 840 |
|
838 | 841 |
try { |
839 |
java.sql.PreparedStatement ps = conn.prepareStatement(_sql);
|
|
842 |
java.sql.PreparedStatement ps = ((ConnectionJDBC)conn).getConnection().prepareStatement(_sql);
|
|
840 | 843 |
ps.setObject(1, r_id); |
841 | 844 |
|
842 | 845 |
// Statement stmnt = conn.createStatement(); |
... | ... | |
892 | 895 |
logger.debug("SQL para leer ids: " + _sql); |
893 | 896 |
Statement st = null; |
894 | 897 |
|
895 |
|
|
896 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
|
|
898 |
|
|
899 |
st = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
|
|
897 | 900 |
ResultSet.CONCUR_READ_ONLY); |
898 |
|
|
901 |
|
|
899 | 902 |
st.setFetchSize(FETCH_SIZE); |
900 | 903 |
logger.info("FETCH_SIZE = " + FETCH_SIZE); |
901 |
|
|
904 |
|
|
902 | 905 |
ResultSet _r = null; |
903 | 906 |
_r = st.executeQuery(_sql); |
904 | 907 |
|
... | ... | |
1162 | 1165 |
|
1163 | 1166 |
return res; |
1164 | 1167 |
} |
1165 |
|
|
1168 |
|
|
1166 | 1169 |
public Value[] getAttributesUsingMainMetadata(ResultSet rs) { |
1167 | 1170 |
Value[] res = null; |
1168 | 1171 |
|
... | ... | |
1235 | 1238 |
|
1236 | 1239 |
return res; |
1237 | 1240 |
} |
1238 |
|
|
1239 | 1241 |
|
1242 |
|
|
1240 | 1243 |
public String getFieldName(int fieldId) |
1241 | 1244 |
throws com.hardcode.gdbms.engine.data.driver.DriverException { |
1242 | 1245 |
return fieldNames[fieldId]; |
... | ... | |
1279 | 1282 |
String rnq = getSearchId(); |
1280 | 1283 |
ROWID _id = (ROWID) rowToId.get(new Integer((int) rowIndex)); |
1281 | 1284 |
|
1282 |
ps = conn.prepareStatement(rnq);
|
|
1285 |
ps = ((ConnectionJDBC)conn).getConnection().prepareStatement(rnq);
|
|
1283 | 1286 |
ps.setObject(1, _id); |
1284 | 1287 |
|
1285 | 1288 |
ps.execute(); |
... | ... | |
1401 | 1404 |
|
1402 | 1405 |
private IGeometry getFMapGeometryCollection(Datum[] the_data, int dim) { |
1403 | 1406 |
// int __srid) { |
1404 |
|
|
1407 |
|
|
1405 | 1408 |
NUMBER _srid = new NUMBER(0); |
1406 | 1409 |
NUMBER main_type = new NUMBER((dim * 1000) + |
1407 | 1410 |
OracleSpatialUtils.getStructType(the_data)); |
1408 |
|
|
1409 | 1411 |
|
1412 |
|
|
1410 | 1413 |
Datum[] all_info_array = null; |
1411 | 1414 |
Object[] elems_info_aray = null; |
1412 | 1415 |
Datum[] all_ords = null; |
... | ... | |
1417 | 1420 |
all_info_array = ((ARRAY) the_data[3]).getOracleArray(); |
1418 | 1421 |
elems_info_aray = groupByElement(all_info_array); |
1419 | 1422 |
all_ords = ((ARRAY) the_data[4]).getOracleArray(); |
1420 |
|
|
1423 |
|
|
1421 | 1424 |
ords_of_groups = getOrdOfGroups(all_ords, elems_info_aray); |
1422 | 1425 |
_elems_info_aray = new Object[elems_info_aray.length]; |
1423 | 1426 |
} |
... | ... | |
1445 | 1448 |
|
1446 | 1449 |
gtype = new NUMBER((dim * 1000) + |
1447 | 1450 |
(item_info_array[1].intValue() % 1000)); |
1448 |
|
|
1451 |
|
|
1449 | 1452 |
if (tableHasSrid) { |
1450 | 1453 |
_srid = new NUMBER(Integer.parseInt(oracleSRID)); |
1451 | 1454 |
} |
... | ... | |
1456 | 1459 |
|
1457 | 1460 |
// if it's the first geometry, the type is the collection's main type (no?) - no |
1458 | 1461 |
// if (i == 0) gtype = main_type; |
1459 |
|
|
1462 |
|
|
1460 | 1463 |
STRUCT itemst = null; |
1461 | 1464 |
|
1462 | 1465 |
if (tableHasSrid) { |
1463 |
|
|
1466 |
|
|
1464 | 1467 |
itemst = OracleSpatialUtils.createStruct(gtype, _srid, |
1465 |
item_info_array, item_ords, conn);
|
|
1468 |
item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection());
|
|
1466 | 1469 |
} |
1467 | 1470 |
else { |
1468 | 1471 |
itemst = OracleSpatialUtils.createStruct(gtype, null, |
1469 |
item_info_array, item_ords, conn);
|
|
1472 |
item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection());
|
|
1470 | 1473 |
} |
1471 | 1474 |
|
1472 | 1475 |
geoms[i] = getFMapGeometry(itemst, true); |
... | ... | |
1483 | 1486 |
* @return the IGeometry |
1484 | 1487 |
*/ |
1485 | 1488 |
public IGeometry getFMapGeometry(STRUCT st, boolean force_not_collection) { |
1486 |
|
|
1489 |
|
|
1487 | 1490 |
if (st == null) { |
1488 | 1491 |
return new FNullGeometry(); |
1489 | 1492 |
} |
1490 |
|
|
1493 |
|
|
1491 | 1494 |
Datum[] the_data = null; |
1492 | 1495 |
|
1493 | 1496 |
try { |
... | ... | |
1895 | 1898 |
} |
1896 | 1899 |
|
1897 | 1900 |
if (size == 2) { |
1898 |
return ((info[1] % 1000) != (info[4] % 1000)) &&
|
|
1901 |
return ((info[1] % 1000) != (info[4] % 1000)) && |
|
1899 | 1902 |
( ! ((info[1] == 1005) && (info[4] == 2)) ); |
1900 | 1903 |
} |
1901 | 1904 |
|
... | ... | |
2324 | 2327 |
getLyrDef().setWhereClause(""); |
2325 | 2328 |
emptyWhereClause = true; |
2326 | 2329 |
} |
2327 |
|
|
2330 |
|
|
2328 | 2331 |
private String getValidViewConstructor( |
2329 | 2332 |
STRUCT _st, |
2330 | 2333 |
String ora_srid, |
2331 | 2334 |
boolean _hassrid, |
2332 | 2335 |
boolean _isgeocs) { |
2333 |
|
|
2336 |
|
|
2334 | 2337 |
String sdo = getSdoConstructor(_st, _hassrid, _isgeocs); |
2335 | 2338 |
String resp = ""; |
2336 | 2339 |
if ((_hassrid) && (_isgeocs)) { |
... | ... | |
2338 | 2341 |
} else { |
2339 | 2342 |
resp = sdo; |
2340 | 2343 |
} |
2341 |
|
|
2344 |
|
|
2342 | 2345 |
return resp; |
2343 | 2346 |
} |
2344 | 2347 |
|
... | ... | |
2353 | 2356 |
resp = "select " + getStandardSelectExpression() + ", c." + |
2354 | 2357 |
geoColName + " from " + getTableName() + " c where "; |
2355 | 2358 |
if (idsLoadWhere.length() > 0) { |
2356 |
resp = resp + " (" + idsLoadWhere + ") AND ";
|
|
2359 |
resp = resp + " (" + idsLoadWhere + ") AND "; |
|
2357 | 2360 |
} |
2358 | 2361 |
resp = resp + "(" + vport + ")"; |
2359 | 2362 |
} |
... | ... | |
2361 | 2364 |
resp = "select " + getStandardSelectExpression() + ", c." + |
2362 | 2365 |
geoColName + " from " + getTableName() + " c where "; |
2363 | 2366 |
if (idsLoadWhere.length() > 0) { |
2364 |
resp = resp + " (" + idsLoadWhere + ") AND ";
|
|
2367 |
resp = resp + " (" + idsLoadWhere + ") AND "; |
|
2365 | 2368 |
} |
2366 | 2369 |
resp = resp + "(" + "sdo_relate(" + geoColName + ", " + viewsdo + |
2367 | 2370 |
", 'mask=anyinteract querytype=window') = 'TRUE')"; |
2368 | 2371 |
} |
2369 |
|
|
2372 |
|
|
2370 | 2373 |
// return "select " + getStandardSelectExpression() + ", c." + |
2371 | 2374 |
// geoColName + " from " + getTableName() + " c"; |
2372 | 2375 |
return resp; |
... | ... | |
2431 | 2434 |
} |
2432 | 2435 |
|
2433 | 2436 |
private static STRUCT rectangleToStruct(Rectangle2D r, boolean hasSrid, |
2434 |
boolean isView, boolean _isGeogCS, String _oracleSRID, Connection __conn) { |
|
2437 |
boolean isView, boolean _isGeogCS, String _oracleSRID, IConnection __conn) {
|
|
2435 | 2438 |
Point2D c1 = new Point2D.Double(r.getMinX(), r.getMinY()); |
2436 | 2439 |
Point2D c2 = new Point2D.Double(r.getMaxX(), r.getMaxY()); |
2437 | 2440 |
|
... | ... | |
2477 | 2480 |
|
2478 | 2481 |
// StructDescriptor dsc = StructDescriptor.createDescriptor("STRUCT", conn); |
2479 | 2482 |
StructDescriptor dsc = StructDescriptor.createDescriptor("MDSYS.SDO_GEOMETRY", |
2480 |
__conn);
|
|
2483 |
((ConnectionJDBC)__conn).getConnection());
|
|
2481 | 2484 |
|
2482 |
resp = new STRUCT(dsc, __conn, new_obj);
|
|
2485 |
resp = new STRUCT(dsc,((ConnectionJDBC)__conn).getConnection(), new_obj);
|
|
2483 | 2486 |
} |
2484 | 2487 |
catch (Exception ex) { |
2485 | 2488 |
logger.error("Error while creating rect struct: " + |
... | ... | |
2510 | 2513 |
Object[] _resp = new Object[2]; |
2511 | 2514 |
|
2512 | 2515 |
try { |
2513 |
_stmnt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
|
|
2516 |
_stmnt = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
|
|
2514 | 2517 |
ResultSet.CONCUR_READ_ONLY); |
2515 | 2518 |
_stmnt.setFetchDirection(ResultSet.FETCH_FORWARD); |
2516 | 2519 |
_stmnt.setFetchSize(FETCH_SIZE); |
... | ... | |
2574 | 2577 |
|
2575 | 2578 |
return resp; |
2576 | 2579 |
} |
2577 |
|
|
2580 |
|
|
2578 | 2581 |
private String getIdsQueryWhereClause(boolean with_where) { |
2579 | 2582 |
String resp = ""; |
2580 |
|
|
2583 |
|
|
2581 | 2584 |
String _where = ""; |
2582 | 2585 |
if (with_where) _where = " where "; |
2583 | 2586 |
|
... | ... | |
2609 | 2612 |
public String getIdAndElemInfoFullResulltSetQuery() { |
2610 | 2613 |
String resp = "select rowid, c." + geoColName + ".SDO_ELEM_INFO from " + |
2611 | 2614 |
getTableName() + " c"; |
2612 |
|
|
2615 |
|
|
2613 | 2616 |
resp = resp + getIdsQueryWhereClause(true); |
2614 | 2617 |
return resp; |
2615 | 2618 |
} |
... | ... | |
2795 | 2798 |
|
2796 | 2799 |
return resp; |
2797 | 2800 |
} |
2798 |
|
|
2801 |
|
|
2799 | 2802 |
private static String getDerivedNAme(String tname, String suffix) { |
2800 |
|
|
2801 |
int ind = tname.lastIndexOf(".");
|
|
2803 |
|
|
2804 |
int ind = tname.lastIndexOf("."); |
|
2802 | 2805 |
if (ind == -1) { |
2803 |
|
|
2806 |
|
|
2804 | 2807 |
int l = Math.min(28, tname.length()); |
2805 | 2808 |
return tname.substring(0, l) + "_" + suffix; |
2806 | 2809 |
|
2807 | 2810 |
} else { |
2808 |
|
|
2811 |
|
|
2809 | 2812 |
String pre = tname.substring(0, ind); |
2810 | 2813 |
String post = tname.substring(ind + 1, tname.length()); |
2811 | 2814 |
int lpost = Math.min(24, post.length()); |
2812 | 2815 |
int lpre = Math.min(3, pre.length()); |
2813 | 2816 |
return pre.substring(0, lpre) + "_" + post.substring(0, lpost) + "_" + suffix; |
2814 | 2817 |
} |
2815 |
|
|
2818 |
|
|
2816 | 2819 |
} |
2817 | 2820 |
|
2818 | 2821 |
public static String getIndexCreationSql(DBLayerDefinition dbLayerDef) { |
... | ... | |
2825 | 2828 |
} |
2826 | 2829 |
|
2827 | 2830 |
public static String getRemoveMetadataSql(DBLayerDefinition dbLayerDef) { |
2828 |
|
|
2831 |
|
|
2829 | 2832 |
String tname = dbLayerDef.getTableName(); |
2830 | 2833 |
int ind = tname.lastIndexOf("."); |
2831 | 2834 |
if (ind != -1) { |
... | ... | |
2833 | 2836 |
tname = tname.substring(ind + 1, tname.length()); |
2834 | 2837 |
return "DELETE FROM " + ORACLE_GEOMETADATA_VIEW + |
2835 | 2838 |
" WHERE TABLE_NAME = '" + tname + "' AND OWNER = '" + schema + "'"; |
2836 |
|
|
2839 |
|
|
2837 | 2840 |
} else{ |
2838 | 2841 |
return "DELETE FROM " + ORACLE_GEOMETADATA_VIEW + |
2839 | 2842 |
" WHERE TABLE_NAME = '" + tname + "'"; |
... | ... | |
3004 | 3007 |
} |
3005 | 3008 |
|
3006 | 3009 |
private static boolean isUserEditableType(int ftype, String item_name, String geo_name) { |
3007 |
|
|
3010 |
|
|
3008 | 3011 |
if (item_name.compareToIgnoreCase(geo_name) == 0) { |
3009 | 3012 |
return true; |
3010 | 3013 |
} |
3011 |
|
|
3014 |
|
|
3012 | 3015 |
if ((ftype == Types.BINARY) |
3013 | 3016 |
|| (ftype == Types.ARRAY) |
3014 | 3017 |
|| (ftype == Types.BLOB) |
... | ... | |
3453 | 3456 |
try { |
3454 | 3457 |
destProjOracle = epsgSridToOracleSrid(destProj); |
3455 | 3458 |
isDestGeogCS = getIsGCS(destProjOracle, true); |
3456 |
|
|
3459 |
|
|
3457 | 3460 |
} catch (Exception e) { |
3458 | 3461 |
logger.error("Unknown EPSG code: " + destProj); |
3459 | 3462 |
destProjOracle = oracleSRID; |
3460 | 3463 |
isDestGeogCS = false; |
3461 | 3464 |
} |
3462 |
|
|
3465 |
|
|
3463 | 3466 |
} |
3464 |
|
|
3467 |
|
|
3465 | 3468 |
public String getDestProjectionOracleCode() { |
3466 | 3469 |
return destProjOracle; |
3467 | 3470 |
} |
3468 |
|
|
3471 |
|
|
3469 | 3472 |
public boolean getIsDestProjectionGeog() { |
3470 | 3473 |
return isDestGeogCS; |
3471 | 3474 |
} |
3472 |
|
|
3475 |
|
|
3473 | 3476 |
public String getTableProjectionOracleCode() { |
3474 | 3477 |
return oracleSRID; |
3475 | 3478 |
} |
... | ... | |
3558 | 3561 |
Rectangle2D resp = null; |
3559 | 3562 |
|
3560 | 3563 |
try { |
3561 |
Statement st = conn.createStatement();
|
|
3564 |
Statement st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
|
3562 | 3565 |
ResultSet rs = st.executeQuery(_qry); |
3563 | 3566 |
|
3564 | 3567 |
if (rs.next()) { |
... | ... | |
3657 | 3660 |
/** |
3658 | 3661 |
* Does what it says, reverses the order of the Coordinates in the linestring. |
3659 | 3662 |
* @param ls The ls to reverse. |
3660 |
* @param gf a GeometryFactory object
|
|
3663 |
* @param gf a GeometryFactory object |
|
3661 | 3664 |
* @return A new ls with the reversed Coordinates. |
3662 | 3665 |
* |
3663 | 3666 |
*/ |
... | ... | |
3722 | 3725 |
* @return the generated STRUCT |
3723 | 3726 |
*/ |
3724 | 3727 |
public static STRUCT iGeometryToSTRUCT(IGeometry ig, int _forced_type, |
3725 |
Connection _conn, String _o_srid, boolean withSrid, boolean agu_bien, |
|
3728 |
IConnection _conn, String _o_srid, boolean withSrid, boolean agu_bien,
|
|
3726 | 3729 |
boolean _isGeoCS) { |
3727 | 3730 |
if (ig instanceof FGeometryCollection) { |
3728 | 3731 |
FGeometryCollection coll = (FGeometryCollection) ig; |
... | ... | |
3743 | 3746 |
|
3744 | 3747 |
public STRUCT shapeToStruct(Shape shp, int force_type, boolean hasSrid, |
3745 | 3748 |
boolean agu_bien, boolean isView) { |
3746 |
|
|
3747 |
if (shp == null) return null;
|
|
3749 |
|
|
3750 |
if (shp == null) return null; |
|
3748 | 3751 |
return shapeToStruct(shp, force_type, conn, oracleSRID, hasSrid, |
3749 | 3752 |
agu_bien, isView, isGeogCS); |
3750 | 3753 |
} |
3751 | 3754 |
|
3752 | 3755 |
public static STRUCT shapeToStruct(Shape shp, int forced_type, |
3753 |
Connection _conn, String o_srid, boolean hasSrid, boolean agu_bien, |
Also available in: Unified diff