001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.data.oracle;
018:
019: import java.io.IOException;
020: import java.math.BigDecimal;
021: import java.sql.Connection;
022: import java.sql.ResultSet;
023: import java.sql.SQLException;
024: import java.sql.Statement;
025: import java.sql.Types;
026: import java.util.Arrays;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031: import java.util.Properties;
032:
033: import javax.sql.DataSource;
034:
035: import junit.framework.TestCase;
036:
037: import org.geotools.data.DataStoreFinder;
038: import org.geotools.data.DataUtilities;
039: import org.geotools.data.DefaultQuery;
040: import org.geotools.data.FeatureReader;
041: import org.geotools.data.FeatureSource;
042: import org.geotools.data.FeatureStore;
043: import org.geotools.data.FeatureWriter;
044: import org.geotools.data.Query;
045: import org.geotools.data.Transaction;
046: import org.geotools.data.jdbc.ConnectionPool;
047: import org.geotools.data.jdbc.ConnectionPoolManager;
048: import org.geotools.data.jdbc.JDBCDataStoreConfig;
049: import org.geotools.data.jdbc.datasource.DataSourceUtil;
050: import org.geotools.data.jdbc.fidmapper.MaxIncFIDMapper;
051: import org.geotools.data.jdbc.fidmapper.TypedFIDMapper;
052: import org.geotools.feature.Feature;
053: import org.geotools.feature.FeatureCollection;
054: import org.geotools.feature.FeatureIterator;
055: import org.geotools.feature.FeatureType;
056: import org.geotools.filter.AbstractFilter;
057: import org.geotools.filter.CompareFilter;
058: import org.geotools.filter.Expression;
059: import org.geotools.filter.Filter;
060: import org.geotools.filter.FilterFactory;
061: import org.geotools.filter.FilterFactoryFinder;
062: import org.geotools.filter.GeometryFilter;
063: import org.geotools.filter.LikeFilter;
064: import org.geotools.geometry.jts.ReferencedEnvelope;
065:
066: import com.vividsolutions.jts.geom.Coordinate;
067: import com.vividsolutions.jts.geom.Envelope;
068: import com.vividsolutions.jts.geom.Geometry;
069: import com.vividsolutions.jts.geom.GeometryFactory;
070: import com.vividsolutions.jts.geom.Point;
071: import com.vividsolutions.jts.geom.Polygon;
072:
073: /**
074: * @author geoghegs
075: *
076: * To change the template for this generated type comment go to
077: * Window>Preferences>Java>Code Generation>Code and Comments
078: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/oracle-spatial/src/test/java/org/geotools/data/oracle/OracleDataStoreOnlineTest.java $
079: */
080: public class OracleDataStoreOnlineTest extends TestCase {
081: private FilterFactory filterFactory = FilterFactoryFinder
082: .createFilterFactory();
083: private Properties properties;
084: private GeometryFactory jtsFactory = new GeometryFactory();
085: private String schemaName;
086: private OracleDataStore dstore;
087: private Connection conn;
088:
089: static {
090: DataStoreFinder.scanForPlugins();
091: }
092:
093: /*
094: * @see TestCase#setUp()
095: */
096: protected void setUp() throws Exception {
097: super .setUp();
098: properties = new Properties();
099: properties.load(this .getClass().getResourceAsStream(
100: "remote.properties"));
101: schemaName = properties.getProperty("schema");
102: properties.put("dbtype", "oracle");
103: properties.put("min connections", "1");
104:
105: dstore = (OracleDataStore) DataStoreFinder
106: .getDataStore(properties);
107: conn = dstore.getConnection(Transaction.AUTO_COMMIT);
108: reset();
109: dstore.setFIDMapper("ORA_TEST_POINTS", new TypedFIDMapper(
110: new MaxIncFIDMapper("ORA_TEST_POINTS", "ID",
111: Types.INTEGER), "ORA_TEST_POINTS"));
112: dstore.setFIDMapper("ORA_TEST_LINES", new TypedFIDMapper(
113: new MaxIncFIDMapper("ORA_TEST_LINES", "ID",
114: Types.INTEGER), "ORA_TEST_LINES"));
115: dstore.setFIDMapper("ORA_TEST_POLYGONS", new TypedFIDMapper(
116: new MaxIncFIDMapper("ORA_TEST_POLYGONS", "ID",
117: Types.INTEGER), "ORA_TEST_POLYGONS"));
118: }
119:
120: /*
121: * @see TestCase#tearDown()
122: */
123: protected void tearDown() throws Exception {
124: //reset();
125: if (conn != null)
126: conn.close();
127: if (dstore != null)
128: dstore.dispose();
129: // ConnectionPoolManager manager = ConnectionPoolManager.getInstance();
130: // manager.closeAll();
131: }
132:
133: static boolean first = false;
134:
135: protected void reset() throws Exception {
136: if (conn == null)
137: return;
138: Statement st = conn.createStatement();
139:
140: if (!first) {
141: try {
142: st.execute("DROP TABLE ora_test_points");
143: st
144: .executeUpdate("DELETE FROM user_sdo_geom_metadata WHERE TABLE_NAME='ORA_TEST_POINTS'");
145: } catch (SQLException noPrevRun) {
146: }
147: first = true;
148: }
149: try {
150: final ResultSet rs = st
151: .executeQuery("SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = 'ORA_TEST_POINTS'");
152: if (rs.next()) {
153: try {
154: st.executeUpdate("DELETE FROM ORA_TEST_POINTS");
155: } catch (SQLException fine) {
156: // must be the first time?
157: fine.printStackTrace();
158: }
159: } else {
160: st.execute("CREATE TABLE ORA_TEST_POINTS ("
161: + " NAME VARCHAR2(15),"
162: + " INTVAL NUMBER(12,0)," + ""
163: + " ID NUMBER(3,0) PRIMARY KEY,"
164: + " SHAPE MDSYS.SDO_GEOMETRY )");
165: st
166: .execute("INSERT INTO user_sdo_geom_metadata (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID )"
167: + "VALUES('ORA_TEST_POINTS','SHAPE',"
168: + "MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',0,-20,0.5),MDSYS.SDO_DIM_ELEMENT('Y',0,10,0.5)),"
169: + "4326)");
170:
171: st
172: .execute("CREATE INDEX ORA_TEST_POINTS_SHAPE_IDX "
173: + "ON ORA_TEST_POINTS (SHAPE) INDEXTYPE IS "
174: + "MDSYS.SPATIAL_INDEX PARAMETERS (' SDO_INDX_DIMS=2 LAYER_GTYPE=\"POINT\"') ");
175: }
176: rs.close();
177: } catch (SQLException fine) {
178: fine.printStackTrace();
179: }
180:
181: if (st
182: .executeQuery(
183: "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = 'ORA_TEST_LINES'")
184: .next()) {
185: try {
186: st.execute("DROP TABLE ORA_TEST_LINES");
187: st
188: .executeUpdate("DELETE FROM user_sdo_geom_metadata WHERE TABLE_NAME='ORA_TEST_LINES'");
189: } catch (SQLException noPrevRun) {
190: noPrevRun.printStackTrace();
191: }
192: }
193: try {
194: st.execute("CREATE TABLE ORA_TEST_LINES ("
195: + " name VARCHAR(255),"
196: + " intval NUMBER,"
197: + " id NUMBER PRIMARY KEY,"
198: + " shape MDSYS.SDO_GEOMETRY" + ")");
199: st
200: .execute("INSERT INTO USER_SDO_GEOM_METADATA VALUES ("
201: + " 'ORA_TEST_LINES',"
202: + " 'SHAPE',"
203: + " MDSYS.SDO_DIM_ARRAY("
204: + " MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.005),"
205: + " MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.005)"
206: + " )," + " 82465" + ")");
207: st
208: .execute("create index test_line_index on ORA_TEST_LINES(SHAPE) INDEXTYPE IS MDSYS.SPATIAL_INDEX");
209: } catch (SQLException fine) {
210: fine.printStackTrace();
211: }
212:
213: // + (20,30)
214: //
215: // +(20,10) +(10,10) + (20,10) +(30,10)
216: //
217: st
218: .execute("INSERT INTO ORA_TEST_POINTS VALUES ('point 1',10,1,"
219: + "MDSYS.SDO_GEOMETRY(2001,4326,"
220: + "MDSYS.SDO_POINT_TYPE(10.0, 10.0, NULL),"
221: + "NULL,NULL))");
222: st
223: .execute("INSERT INTO ORA_TEST_POINTS VALUES ('point 2',20,2,"
224: + "MDSYS.SDO_GEOMETRY(2001,4326,"
225: + "MDSYS.SDO_POINT_TYPE(20.0, 10.0, NULL),"
226: + "NULL,NULL))");
227: st
228: .execute("INSERT INTO ORA_TEST_POINTS VALUES ('point 3',30,3,"
229: + "MDSYS.SDO_GEOMETRY(2001,4326,"
230: + "SDO_POINT_TYPE(20.0, 30.0, NULL),"
231: + "NULL,NULL))");
232: st
233: .execute("INSERT INTO ORA_TEST_POINTS VALUES ('point 4',40,4,"
234: + "MDSYS.SDO_GEOMETRY(2001,4326,"
235: + "SDO_POINT_TYPE(30.0, 10.0, NULL),"
236: + "NULL,NULL))");
237: st
238: .execute("INSERT INTO ORA_TEST_POINTS VALUES ('point 5',50,5,"
239: + "MDSYS.SDO_GEOMETRY(2001,4326,"
240: + "SDO_POINT_TYPE(-20.0, 10.0, NULL),"
241: + "NULL,NULL))");
242:
243: // two simple lines
244: st.execute("INSERT INTO ORA_TEST_LINES VALUES ('line1',50,2,"
245: + "MDSYS.SDO_GEOMETRY(2002,82465,NULL,"
246: + "SDO_ELEM_INFO_ARRAY(1,2,1),"
247: + "SDO_ORDINATE_ARRAY(0,0, 10, 10)))");
248:
249: st.execute("INSERT INTO ORA_TEST_LINES VALUES ('line2',100,4,"
250: + "MDSYS.SDO_GEOMETRY(2002,82465,NULL,"
251: + "SDO_ELEM_INFO_ARRAY(1,2,1),"
252: + "SDO_ORDINATE_ARRAY(25,25, 25, 30)))");
253: st.close();
254:
255: }
256:
257: public void testGetFeatureTypes() throws IOException {
258: if (conn == null)
259: return;
260:
261: String[] fts = dstore.getTypeNames();
262: List list = Arrays.asList(fts);
263:
264: System.out.println(list);
265: assertTrue(list.contains("ORA_TEST_POINTS"));
266: }
267:
268: public void testGetSchema() throws Exception {
269: if (conn == null)
270: return;
271: FeatureType ft = dstore.getSchema("ORA_TEST_POINTS");
272: assertNotNull(ft);
273: System.out.println(ft);
274: }
275:
276: public void testGetFeatureReader() throws Exception {
277: if (conn == null)
278: return;
279: FeatureType ft = dstore.getSchema("ORA_TEST_POINTS");
280: Query q = new DefaultQuery("ORA_TEST_POINTS");
281: FeatureReader fr = dstore.getFeatureReader(q,
282: Transaction.AUTO_COMMIT);
283: assertEquals(ft, fr.getFeatureType());
284: int count = 0;
285:
286: while (fr.hasNext()) {
287: fr.next();
288: count++;
289: }
290: assertEquals(5, count);
291:
292: fr.close();
293: }
294:
295: public void testGetFeatureWriter() throws Exception {
296: if (conn == null)
297: return;
298: FeatureWriter writer = dstore.getFeatureWriter(
299: "ORA_TEST_POINTS", Filter.INCLUDE,
300: Transaction.AUTO_COMMIT);
301: assertNotNull(writer);
302:
303: Feature feature = writer.next();
304: System.out.println(feature);
305: feature.setAttribute(0, "Changed Feature");
306: System.out.println(feature);
307: writer.write();
308: writer.close();
309:
310: Query q = new DefaultQuery("ORA_TEST_POINTS");
311: FeatureReader reader = dstore.getFeatureReader(q,
312: Transaction.AUTO_COMMIT);
313: Feature readF = reader.next();
314:
315: assertEquals("Changed Feature", feature.getAttribute(0));
316: assertEquals(feature.getID(), readF.getID());
317: assertEquals(feature.getAttribute(0), readF.getAttribute((0)));
318: assertEquals(feature.getAttribute(1), readF.getAttribute((1)));
319: // assertTrue(feature.getAttribute(2).equals(readF.getAttribute((2)))); JTS doesnt override equals. POS
320:
321: reader.close();
322: }
323:
324: public void testMaxFeatures() throws Exception {
325: if (conn == null)
326: return;
327: DefaultQuery query = new DefaultQuery();
328: query.setTypeName("ORA_TEST_POINTS");
329: query.setMaxFeatures(3);
330: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
331: FeatureCollection fr = fs.getFeatures(query);
332: assertEquals(3, fr.size());
333: }
334:
335: public void testLikeGetFeatures() throws Exception {
336: if (conn == null)
337: return;
338: LikeFilter likeFilter = filterFactory.createLikeFilter();
339: Expression pattern = filterFactory.createLiteralExpression("*");
340: Expression attr = filterFactory.createAttributeExpression(null,
341: "NAME");
342: likeFilter.setPattern(pattern, "*", "?", "\\"); // '*' --> '%'
343: likeFilter.setValue(attr);
344:
345: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
346: FeatureCollection fr = fs.getFeatures(likeFilter);
347: assertEquals(5, fr.size());
348:
349: pattern = filterFactory.createLiteralExpression("*5");
350: likeFilter.setPattern(pattern, "*", "?", "\\");
351: fr = fs.getFeatures(likeFilter);
352: assertEquals(1, fr.size());
353: }
354:
355: public void testAttributeFilter() throws Exception {
356: if (conn == null)
357: return;
358: CompareFilter attributeEquality = filterFactory
359: .createCompareFilter(AbstractFilter.COMPARE_EQUALS);
360: Expression attribute = filterFactory.createAttributeExpression(
361: dstore.getSchema("ORA_TEST_POINTS"), "NAME");
362: Expression literal = filterFactory
363: .createLiteralExpression("point 1");
364: attributeEquality.addLeftValue(attribute);
365: attributeEquality.addRightValue(literal);
366:
367: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
368: FeatureCollection fr = fs.getFeatures(attributeEquality);
369: assertEquals(1, fr.size());
370:
371: FeatureCollection fc = fr;
372: assertEquals(1, fc.size());
373: final FeatureIterator fi = fc.features();
374: Feature f = fi.next();
375: fi.close();
376: assertEquals("point 1", f.getAttribute("NAME"));
377: }
378:
379: public void testBBoxFilter() throws Exception {
380: if (conn == null)
381: return;
382: GeometryFilter filter = filterFactory
383: .createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
384: // had to reduce the envelope a little, Oracle has trobles with bbox that span the whole earth
385: Expression right = filterFactory
386: .createBBoxExpression(new Envelope(-170, 170, -80, 80));
387: Expression left = filterFactory.createAttributeExpression(
388: dstore.getSchema("ORA_TEST_POINTS"), "SHAPE");
389: filter.addLeftGeometry(left);
390: filter.addRightGeometry(right);
391:
392: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
393: FeatureCollection fr = fs.getFeatures(filter);
394: assertEquals(5, fr.size()); // we pass this!
395:
396: // + (20,30)
397: // +----------------------+
398: // +(20,10) +(10,10) | + (20,10) +(30,10) |
399: // +----------------------+
400: right = filterFactory.createBBoxExpression(new Envelope(15, 35,
401: 0, 15));
402: filter.addRightGeometry(right);
403: fr = fs.getFeatures(filter);
404: assertEquals(2, fr.size()); // we have 4!
405:
406: // check a filter built changing operands order works the same
407: filter.addLeftGeometry(right);
408: filter.addRightGeometry(left);
409: fr = fs.getFeatures(filter);
410: assertEquals(2, fr.size()); // we pass this!
411: }
412:
413: public void testDisjointFilter() throws Exception {
414: if (conn == null)
415: return;
416:
417: // + (20,30)
418: // +----------------------+
419: // +(20,10) +(10,10) | + (20,10) +(30,10) |
420: // +----------------------+
421: GeometryFactory gf = new GeometryFactory();
422: Polygon p = gf.createPolygon(gf
423: .createLinearRing(new Coordinate[] {
424: new Coordinate(15, 0), new Coordinate(35, 0),
425: new Coordinate(35, 15), new Coordinate(15, 15),
426: new Coordinate(15, 0) }), null);
427: GeometryFilter filter = filterFactory
428: .createGeometryFilter(AbstractFilter.GEOMETRY_DISJOINT);
429: // had to reduce the envelope a little, Oracle has trobles with bbox that span the whole earth
430: Expression right = filterFactory.createLiteralExpression(p);
431: Expression left = filterFactory.createAttributeExpression(
432: dstore.getSchema("ORA_TEST_POINTS"), "SHAPE");
433: filter.addLeftGeometry(left);
434: filter.addRightGeometry(right);
435:
436: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
437: FeatureCollection fr = fs.getFeatures(filter);
438: assertEquals(3, fr.size()); // we have 4!
439:
440: // check a filter built changing operands order works the same
441: filter.addLeftGeometry(right);
442: filter.addRightGeometry(left);
443: fr = fs.getFeatures(filter);
444: assertEquals(3, fr.size()); // we pass this!
445: }
446:
447: public void testPointGeometryConversion() throws Exception {
448: if (conn == null)
449: return;
450: CompareFilter filter = filterFactory
451: .createCompareFilter(AbstractFilter.COMPARE_EQUALS);
452: Expression left = filterFactory.createAttributeExpression(
453: dstore.getSchema("ORA_TEST_POINTS"), "NAME");
454: Expression right = filterFactory
455: .createLiteralExpression("point 1");
456: filter.addLeftValue(left);
457: filter.addRightValue(right);
458:
459: FeatureSource fs = dstore.getFeatureSource("ORA_TEST_POINTS");
460: FeatureCollection fr = fs.getFeatures(filter);
461: assertEquals(1, fr.size());
462:
463: final FeatureIterator iter = fr.features();
464: Feature feature = (Feature) iter.next();
465: iter.close();
466: Geometry geom = feature.getDefaultGeometry();
467: assertEquals(Point.class.getName(), geom.getClass().getName());
468: Point point = (Point) geom;
469: assertEquals(10.0, point.getX(), 0.001);
470: assertEquals(10.0, point.getY(), 0.001);
471: }
472:
473: public void testAddFeatures() throws Exception {
474: if (conn == null)
475: return;
476: Map fidGen = new HashMap();
477: fidGen.put("ORA_TEST_POINTS",
478: JDBCDataStoreConfig.FID_GEN_MANUAL_INC);
479: JDBCDataStoreConfig config = JDBCDataStoreConfig
480: .createWithSchemaNameAndFIDGenMap(schemaName, fidGen);
481:
482: String name = "add_name";
483: BigDecimal intval = new BigDecimal(70);
484: Point point = jtsFactory
485: .createPoint(new Coordinate(-15.0, -25));
486: Feature feature = dstore.getSchema("ORA_TEST_POINTS").create(
487: new Object[] { name, intval, point });
488:
489: FeatureStore fs = (FeatureStore) dstore
490: .getFeatureSource("ORA_TEST_POINTS");
491: fs.addFeatures(DataUtilities.collection(feature));
492:
493: // Select is directly from the DB
494: Connection conn = dstore.getConnection(Transaction.AUTO_COMMIT);
495: Statement statement = conn.createStatement();
496: ResultSet rs = statement
497: .executeQuery("SELECT * FROM ORA_TEST_POINTS WHERE NAME = 'add_name'");
498:
499: if (rs.next()) {
500: assertEquals(rs.getString("NAME"), name);
501: assertEquals(70, rs.getInt("INTVAL"));
502: } else {
503: fail("Feature was not added correctly");
504: }
505: rs.close();
506: }
507:
508: public void testRemoveFeatures() throws Exception {
509: if (conn == null)
510: return;
511: FeatureStore fs = (FeatureStore) dstore
512: .getFeatureSource("ORA_TEST_POINTS");
513: fs.removeFeatures(Filter.INCLUDE);
514: FeatureCollection fr = fs.getFeatures();
515: assertEquals(0, fr.size());
516: }
517:
518: public void testPropertySelect() throws Exception {
519: if (conn == null)
520: return;
521: DefaultQuery q = new DefaultQuery("ORA_TEST_POINTS",
522: Filter.INCLUDE);
523: q.setPropertyNames(new String[] { "NAME" });
524: FeatureReader fr = dstore.getFeatureReader(q,
525: Transaction.AUTO_COMMIT);
526: Feature f = fr.next();
527: FeatureType ft = f.getFeatureType();
528: assertEquals(1, ft.getAttributeCount());
529: assertEquals("NAME", ft.getAttributeType(0).getName());
530: fr.close();
531: }
532:
533: public void testBoundsWgs84() throws IOException {
534: if (conn == null)
535: return;
536: Envelope extent = dstore.getEnvelope("ORA_TEST_POINTS");
537: assertNotNull(extent);
538: assertTrue(extent instanceof ReferencedEnvelope);
539: ReferencedEnvelope envelope = (ReferencedEnvelope) extent;
540: assertFalse(envelope.isNull());
541:
542: Envelope extent2 = dstore.getFeatureSource("ORA_TEST_POINTS")
543: .getBounds();
544: assertEquals(extent, extent2);
545: }
546:
547: public void testBoundsWgs84Filter() throws Exception {
548: if (conn == null)
549: return;
550:
551: // build a bbox filter
552: GeometryFilter filter = filterFactory
553: .createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
554: // had to reduce the envelope a little, Oracle has trobles with bbox that span the whole earth
555: Expression right = filterFactory
556: .createBBoxExpression(new Envelope(-10, 21, -10, 11));
557: Expression left = filterFactory.createAttributeExpression(
558: dstore.getSchema("ORA_TEST_POINTS"), "SHAPE");
559: filter.addLeftGeometry(left);
560: filter.addRightGeometry(right);
561:
562: Envelope extent = dstore.getFeatureSource("ORA_TEST_POINTS")
563: .getBounds(new DefaultQuery("ORA_TEST_POINTS", filter));
564: assertNotNull(extent);
565: assertTrue(extent instanceof ReferencedEnvelope);
566: ReferencedEnvelope envelope = (ReferencedEnvelope) extent;
567: assertEquals(new Envelope(10, 20, 10, 10), new Envelope(
568: envelope));
569: }
570:
571: public void testBoundsProjected() {
572: if (conn == null)
573: return;
574: Envelope extent = dstore.getEnvelope("ORA_TEST_LINES");
575: assertNotNull(extent);
576: assertTrue(extent instanceof ReferencedEnvelope);
577: ReferencedEnvelope envelope = (ReferencedEnvelope) extent;
578: assertFalse(envelope.isNull());
579: }
580:
581: public void testBoundsProjectedFilter() throws IOException {
582: if (conn == null)
583: return;
584:
585: // build a bbox filter
586: GeometryFilter filter = filterFactory
587: .createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
588: // had to reduce the envelope a little, Oracle has trobles with bbox that span the whole earth
589: Expression right = filterFactory
590: .createBBoxExpression(new Envelope(-10, 21, -10, 21));
591: Expression left = filterFactory.createAttributeExpression(
592: dstore.getSchema("ORA_TEST_LINES"), "SHAPE");
593: filter.addLeftGeometry(left);
594: filter.addRightGeometry(right);
595:
596: Envelope extent = dstore.getFeatureSource("ORA_TEST_LINES")
597: .getBounds(new DefaultQuery("ORA_TEST_LINES", filter));
598: assertNotNull(extent);
599: assertTrue(extent instanceof ReferencedEnvelope);
600: ReferencedEnvelope envelope = (ReferencedEnvelope) extent;
601: assertEquals(new Envelope(0, 10, 0, 10), new Envelope(envelope));
602: }
603:
604: public void testGeometryType() throws IOException {
605: if (conn == null)
606: return;
607: FeatureType ft = dstore.getSchema("ORA_TEST_POINTS");
608: assertEquals(Point.class, ft.getDefaultGeometry().getType());
609: }
610:
611: public void testGeometryType2() throws IOException {
612: if (conn == null)
613: return;
614: // here we did not declare a type
615: FeatureType ft = dstore.getSchema("ORA_TEST_LINES");
616: assertEquals(Geometry.class, ft.getDefaultGeometry().getType());
617: }
618: }
|