svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extOracleSpatial / src / org / gvsig / fmap / dal / store / oraclespatial / OracleSpatialServerExplorer.java @ 29563
History | View | Annotate | Download (7.04 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.dal.store.oraclespatial; |
32 |
|
33 |
import java.sql.Connection; |
34 |
import java.sql.SQLException; |
35 |
import java.sql.Statement; |
36 |
import java.util.ArrayList; |
37 |
import java.util.List; |
38 |
|
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
40 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
43 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
44 |
import org.gvsig.fmap.dal.exception.RemoveException; |
45 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCHelper; |
47 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
48 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
49 |
import org.gvsig.fmap.dal.store.jdbc.TransactionalAction; |
50 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
51 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
/**
|
56 |
* @author vsanjaime
|
57 |
*
|
58 |
*/
|
59 |
public class OracleSpatialServerExplorer extends JDBCServerExplorer { |
60 |
final static private Logger logger = LoggerFactory |
61 |
.getLogger(OracleSpatialServerExplorer.class); |
62 |
|
63 |
public static final String NAME = "OracleSpatialExplorer"; |
64 |
|
65 |
|
66 |
public OracleSpatialServerExplorer(
|
67 |
OracleSpatialServerExplorerParameters parameters, |
68 |
DataServerExplorerProviderServices services) |
69 |
throws InitializeException {
|
70 |
super(parameters, services);
|
71 |
} |
72 |
|
73 |
private OracleSpatialServerExplorerParameters getOracleSpatialParameters() {
|
74 |
return (OracleSpatialServerExplorerParameters) getParameters();
|
75 |
} |
76 |
|
77 |
|
78 |
protected JDBCHelper createHelper() throws InitializeException { |
79 |
return new OracleSpatialHelper(this, getOracleSpatialParameters()); |
80 |
} |
81 |
|
82 |
|
83 |
protected String getStoreName() { |
84 |
return OracleSpatialStoreProvider.NAME;
|
85 |
} |
86 |
|
87 |
public String getName() { |
88 |
return NAME;
|
89 |
} |
90 |
|
91 |
protected JDBCStoreParameters createStoreParams()
|
92 |
throws InitializeException, ProviderNotRegisteredException {
|
93 |
OracleSpatialStoreParameters orgParams = (OracleSpatialStoreParameters) super
|
94 |
.createStoreParams(); |
95 |
|
96 |
orgParams.setUseSSL(getOracleSpatialParameters().getUseSSL()); |
97 |
|
98 |
return orgParams;
|
99 |
} |
100 |
|
101 |
|
102 |
// ****************************
|
103 |
|
104 |
|
105 |
public boolean canAdd() { |
106 |
return true; |
107 |
} |
108 |
|
109 |
protected void checkIsMine(DataStoreParameters dsp) { |
110 |
if (!(dsp instanceof OracleSpatialStoreParameters)) { |
111 |
// FIXME Excpetion ???
|
112 |
throw new IllegalArgumentException( |
113 |
"not instance of OracleSpatialStoreParameters");
|
114 |
} |
115 |
super.checkIsMine(dsp);
|
116 |
|
117 |
OracleSpatialStoreParameters orap = (OracleSpatialStoreParameters) dsp; |
118 |
if (orap.getUseSSL().booleanValue() != getOracleSpatialParameters()
|
119 |
.getUseSSL()) { |
120 |
throw new IllegalArgumentException("worng explorer: Host"); |
121 |
} |
122 |
} |
123 |
|
124 |
public void remove(DataStoreParameters dsp) throws RemoveException { |
125 |
final OracleSpatialStoreParameters osParams =(OracleSpatialStoreParameters) dsp;
|
126 |
|
127 |
TransactionalAction action = new TransactionalAction() {
|
128 |
public boolean continueTransactionAllowed() { |
129 |
return false; |
130 |
} |
131 |
public Object action(Connection conn) throws DataException { |
132 |
|
133 |
|
134 |
Statement st;
|
135 |
try{
|
136 |
st = conn.createStatement(); |
137 |
} catch (SQLException e) { |
138 |
throw new JDBCSQLException(e); |
139 |
} |
140 |
|
141 |
String sqlDrop = "Drop table " |
142 |
+ osParams.tableID(); |
143 |
|
144 |
StringBuilder strb = new StringBuilder(); |
145 |
strb.append("Delete from GEOMETRY_COLUMNS where f_table_schema = ");
|
146 |
if (osParams.getSchema() == null || osParams.getSchema().length() == 0) { |
147 |
strb.append("current_schema() ");
|
148 |
} else {
|
149 |
strb.append('\'');
|
150 |
strb.append(osParams.getSchema()); |
151 |
strb.append("' ");
|
152 |
} |
153 |
strb.append("and f_table_name = '");
|
154 |
strb.append(osParams.getTable()); |
155 |
strb.append('\'');
|
156 |
|
157 |
String sqlDeleteFromGeometry_column = strb.toString();
|
158 |
try{
|
159 |
try{
|
160 |
st.execute(sqlDrop); |
161 |
} catch (SQLException e) { |
162 |
throw new JDBCExecuteSQLException(sqlDrop, e); |
163 |
} |
164 |
|
165 |
try {
|
166 |
st.execute(sqlDeleteFromGeometry_column); |
167 |
} catch (SQLException e) { |
168 |
throw new JDBCExecuteSQLException( |
169 |
sqlDeleteFromGeometry_column, e); |
170 |
} |
171 |
|
172 |
} finally{
|
173 |
try{ st.close(); } catch (SQLException e) {}; |
174 |
} |
175 |
return null; |
176 |
} |
177 |
}; |
178 |
try {
|
179 |
this.helper.doConnectionAction(action);
|
180 |
} catch (Exception e) { |
181 |
throw new RemoveException(this.getName(), e); |
182 |
} |
183 |
} |
184 |
|
185 |
public NewDataStoreParameters getAddParameters() throws DataException { |
186 |
OracleSpatialServerExplorerParameters parameters = getOracleSpatialParameters(); |
187 |
OracleSpatialNewStoreParameters params = new OracleSpatialNewStoreParameters();
|
188 |
params.setHost(parameters.getHost()); |
189 |
params.setPort(parameters.getPort()); |
190 |
params.setDBName(parameters.getDBName()); |
191 |
params.setUser(parameters.getUser()); |
192 |
params.setPassword(parameters.getPassword()); |
193 |
params.setCatalog(parameters.getCatalog()); |
194 |
params.setSchema(parameters.getSchema()); |
195 |
params.setJDBCDriverClassName(parameters.getJDBCDriverClassName()); |
196 |
params.setUrl(parameters.getUrl()); |
197 |
params.setUseSSL(parameters.getUseSSL()); |
198 |
|
199 |
|
200 |
params.setDefaultFeatureType(this.getServerExplorerProviderServices()
|
201 |
.createNewFeatureType()); |
202 |
|
203 |
|
204 |
return params;
|
205 |
} |
206 |
|
207 |
|
208 |
|
209 |
// ***********************
|
210 |
// ***********************
|
211 |
|
212 |
|
213 |
public boolean hasGeometrySupport() { |
214 |
return true; |
215 |
} |
216 |
|
217 |
protected OracleSpatialHelper getOSHelper() {
|
218 |
return (OracleSpatialHelper) getHelper();
|
219 |
} |
220 |
|
221 |
|
222 |
protected List getSQLForList(int mode, boolean showInformationDBTables) { |
223 |
List list = new ArrayList(1); |
224 |
StringBuffer sqlBuf = new StringBuffer(); |
225 |
sqlBuf |
226 |
.append("SELECT null as TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, false as ISVIEW ");
|
227 |
sqlBuf.append(" FROM INFORMATION_SCHEMA.TABLES ");
|
228 |
sqlBuf.append(" xxWHERExx ");
|
229 |
sqlBuf.append(" union ");
|
230 |
sqlBuf |
231 |
.append("SELECT null as TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, true as ISVIEW ");
|
232 |
sqlBuf.append(" FROM INFORMATION_SCHEMA.VIEWS ");
|
233 |
sqlBuf.append(" xxWHERExx ");
|
234 |
|
235 |
if (showInformationDBTables) {
|
236 |
list.add(sqlBuf.toString().replaceAll("xxWHERExx", "")); |
237 |
} else {
|
238 |
list |
239 |
.add(sqlBuf |
240 |
.toString() |
241 |
.replaceAll("xxWHERExx",
|
242 |
"WHERE TABLE_SCHEMA NOT IN ('information_schema','pg_catalog')"));
|
243 |
|
244 |
} |
245 |
return list;
|
246 |
|
247 |
|
248 |
} |
249 |
} |