Revision 29579 branches/v2_0_0_prep/extensions/extOracleSpatial/src/org/gvsig/fmap/dal/store/oraclespatial/OracleSpatialServerExplorer.java

View differences:

OracleSpatialServerExplorer.java
1 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
*/
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 22

  
23 23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
24
 * AUTHORS (In addition to CIT):
25
 * 2009 IVER T.I   {{Task}}
26
 */
27 27

  
28 28
/**
29 29
 *
......
31 31
package org.gvsig.fmap.dal.store.oraclespatial;
32 32

  
33 33
import java.sql.Connection;
34
import java.sql.ResultSet;
34 35
import java.sql.SQLException;
35 36
import java.sql.Statement;
36 37
import java.util.ArrayList;
38
import java.util.Iterator;
37 39
import java.util.List;
38 40

  
39 41
import org.gvsig.fmap.dal.DataStoreParameters;
......
41 43
import org.gvsig.fmap.dal.exception.DataException;
42 44
import org.gvsig.fmap.dal.exception.InitializeException;
43 45
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
46
import org.gvsig.fmap.dal.exception.ReadException;
44 47
import org.gvsig.fmap.dal.exception.RemoveException;
45 48
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
49
import org.gvsig.fmap.dal.store.jdbc.ConnectionAction;
46 50
import org.gvsig.fmap.dal.store.jdbc.JDBCHelper;
47 51
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
48 52
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
......
54 58

  
55 59
/**
56 60
 * @author vsanjaime
57
 *
61
 * 
58 62
 */
59 63
public class OracleSpatialServerExplorer extends JDBCServerExplorer {
60 64
	final static private Logger logger = LoggerFactory
......
62 66

  
63 67
	public static final String NAME = "OracleSpatialExplorer";
64 68

  
65

  
66 69
	public OracleSpatialServerExplorer(
67 70
			OracleSpatialServerExplorerParameters parameters,
68 71
			DataServerExplorerProviderServices services)
......
74 77
		return (OracleSpatialServerExplorerParameters) getParameters();
75 78
	}
76 79

  
77

  
78 80
	protected JDBCHelper createHelper() throws InitializeException {
79 81
		return new OracleSpatialHelper(this, getOracleSpatialParameters());
80 82
	}
81 83

  
82

  
83 84
	protected String getStoreName() {
84 85
		return OracleSpatialStoreProvider.NAME;
85 86
	}
......
98 99
		return orgParams;
99 100
	}
100 101

  
101

  
102 102
	// ****************************
103 103

  
104

  
105 104
	public boolean canAdd() {
106 105
		return true;
107 106
	}
108 107

  
108
	/**
109
	 * 
110
	 */
109 111
	protected void checkIsMine(DataStoreParameters dsp) {
110 112
		if (!(dsp instanceof OracleSpatialStoreParameters)) {
111 113
			// FIXME Excpetion ???
......
121 123
		}
122 124
	}
123 125

  
126
	/**
127
	 * 
128
	 */
124 129
	public void remove(DataStoreParameters dsp) throws RemoveException {
125
		final OracleSpatialStoreParameters osParams =(OracleSpatialStoreParameters) dsp;
130
		final OracleSpatialStoreParameters osParams = (OracleSpatialStoreParameters) dsp;
126 131

  
127 132
		TransactionalAction action = new TransactionalAction() {
128 133
			public boolean continueTransactionAllowed() {
129 134
				return false;
130 135
			}
136

  
131 137
			public Object action(Connection conn) throws DataException {
132 138

  
133

  
134 139
				Statement st;
135
				try{
140
				try {
136 141
					st = conn.createStatement();
137 142
				} catch (SQLException e) {
138 143
					throw new JDBCSQLException(e);
139 144
				}
140 145

  
141
				String sqlDrop = "Drop table "
142
					+ osParams.tableID();
146
				String sqlDrop = "Drop table " + osParams.tableID();
143 147

  
144 148
				StringBuilder strb = new StringBuilder();
145
				strb.append("Delete from GEOMETRY_COLUMNS where f_table_schema = ");
146
				if (osParams.getSchema() == null || osParams.getSchema().length() ==  0) {
149
				strb
150
						.append("Delete from GEOMETRY_COLUMNS where f_table_schema = ");
151
				if (osParams.getSchema() == null
152
						|| osParams.getSchema().length() == 0) {
147 153
					strb.append("current_schema() ");
148 154
				} else {
149 155
					strb.append('\'');
......
155 161
				strb.append('\'');
156 162

  
157 163
				String sqlDeleteFromGeometry_column = strb.toString();
158
				try{
159
					try{
164
				try {
165
					try {
160 166
						st.execute(sqlDrop);
161 167
					} catch (SQLException e) {
162 168
						throw new JDBCExecuteSQLException(sqlDrop, e);
......
169 175
								sqlDeleteFromGeometry_column, e);
170 176
					}
171 177

  
172
				} finally{
173
					try{ st.close(); } catch (SQLException e) {};
178
				} finally {
179
					try {
180
						st.close();
181
					} catch (SQLException e) {
182
					}
183
					;
174 184
				}
175 185
				return null;
176 186
			}
......
182 192
		}
183 193
	}
184 194

  
195
	/**
196
	 * 
197
	 */
185 198
	public NewDataStoreParameters getAddParameters() throws DataException {
186 199
		OracleSpatialServerExplorerParameters parameters = getOracleSpatialParameters();
187 200
		OracleSpatialNewStoreParameters params = new OracleSpatialNewStoreParameters();
......
196 209
		params.setUrl(parameters.getUrl());
197 210
		params.setUseSSL(parameters.getUseSSL());
198 211

  
199

  
200 212
		params.setDefaultFeatureType(this.getServerExplorerProviderServices()
201 213
				.createNewFeatureType());
202 214

  
203

  
204 215
		return params;
205 216
	}
206 217

  
207

  
208

  
209
	// ***********************
210
	// ***********************
211

  
212

  
218
	/**
219
	 * Geometry support
220
	 */
213 221
	public boolean hasGeometrySupport() {
214 222
		return true;
215 223
	}
216 224

  
225
	/**
226
	 * get helper
227
	 * 
228
	 * @return
229
	 */
217 230
	protected OracleSpatialHelper getOSHelper() {
218 231
		return (OracleSpatialHelper) getHelper();
219 232
	}
220 233

  
234
	/**
235
	 * get sql sentence for list available tables
236
	 */
237
	protected List<String> getSQLForList(int mode,
238
			boolean showInformationDBTables) {
239
		List<String> list = new ArrayList<String>(1);
240
		list.add("SELECT TABLE_NAME FROM USER_SDO_GEOM_METADATA");
221 241

  
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 ");
242
		return list;
234 243

  
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')"));
244
	}
245
	
246
	public List list(final int mode, final boolean showInformationDBTables)
247
	throws DataException {
243 248

  
249
final JDBCStoreParameters orgParams = createStoreParams();
250

  
251
ConnectionAction action = new ConnectionAction() {
252

  
253
	public Object action(Connection conn) throws DataException {
254
		ResultSet rs = null;
255
		Statement st = null;
256
		List sqls = getSQLForList(mode, showInformationDBTables);
257

  
258
		try {
259
			JDBCStoreParameters params;
260

  
261
			List paramList = new ArrayList();
262

  
263
			conn = helper.getConnection();
264
			st = conn.createStatement();
265
			String sql;
266
			Iterator sqlIter = sqls.iterator();
267
			while (sqlIter.hasNext()){
268
				sql = (String) sqlIter.next();
269
				rs = st.executeQuery(sql);
270
				while (rs.next()) {
271
					params = (JDBCStoreParameters) orgParams
272
							.getCopy();
273
					params.setTable(rs.getString(1));
274
					// TODO
275
//					if (rs.getBoolean(4)) {
276
//						param.setIsView(param.IS_VIEW);
277
//					} else {
278
//						param.setIsView(param.NOT_IS_VIEW);
279
//					}
280
					paramList.add(params);
281
				}
282
			}
283

  
284
			return paramList;
285
		} catch (SQLException e) {
286
			throw new JDBCSQLException(e);
287
		} finally {
288
			try {rs.close();} catch (Exception e) {	};
289
			try {st.close();} catch (Exception e) {	};
244 290
		}
245
		return list;
291
	}
246 292

  
293
};
247 294

  
248
	}
295
try {
296
	return (List) helper.doConnectionAction(action);
297
} catch (Exception e) {
298
	throw new ReadException(this.getName(), e);
249 299
}
300
}
301

  
302
	
303

  
304
}

Also available in: Unified diff