001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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;
009: * version 2.1 of the License.
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.arcsde.data;
018:
019: import java.io.IOException;
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022:
023: import junit.framework.TestCase;
024:
025: import org.geotools.arcsde.pool.ArcSDEConnectionPool;
026: import org.geotools.arcsde.pool.UnavailableArcSDEConnectionException;
027:
028: import com.esri.sde.sdk.client.SDEPoint;
029: import com.esri.sde.sdk.client.SeColumnDefinition;
030: import com.esri.sde.sdk.client.SeConnection;
031: import com.esri.sde.sdk.client.SeCoordinateReference;
032: import com.esri.sde.sdk.client.SeException;
033: import com.esri.sde.sdk.client.SeExtent;
034: import com.esri.sde.sdk.client.SeFilter;
035: import com.esri.sde.sdk.client.SeLayer;
036: import com.esri.sde.sdk.client.SeQuery;
037: import com.esri.sde.sdk.client.SeQueryInfo;
038: import com.esri.sde.sdk.client.SeShape;
039: import com.esri.sde.sdk.client.SeShapeFilter;
040: import com.esri.sde.sdk.client.SeSqlConstruct;
041: import com.esri.sde.sdk.client.SeTable;
042:
043: /**
044: * Exersices the ArcSDE Java API to ensure our assumptions are correct.
045: *
046: * <p>
047: * Some of this tests asserts the information from the documentation found on <a
048: * href="http://arcsdeonline.esri.com">arcsdeonline </a>, and others are needed
049: * to validate our assumptions in the API behavoir due to the very little
050: * documentation ESRI provides about the less obvious things.
051: * </p>
052: *
053: * @author Gabriel Roldan, Axios Engineering
054: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/data/ArcSDEJavaApiTest.java $
055: * @version $Id: ArcSDEJavaApiTest.java 27863 2007-11-12 20:34:34Z desruisseaux $
056: */
057: public class ArcSDEJavaApiTest extends TestCase {
058: /** package logger */
059: private static Logger LOGGER = org.geotools.util.logging.Logging
060: .getLogger(ArcSDEJavaApiTest.class.getPackage().getName());
061:
062: /** utility to load test parameters and build a datastore with them */
063: private TestData testData;
064:
065: private SeConnection conn;
066: private ArcSDEConnectionPool pool;
067:
068: /**
069: * DOCUMENT ME!
070: *
071: * @param args
072: * DOCUMENT ME!
073: */
074: public static void main(String[] args) {
075: junit.textui.TestRunner.run(ArcSDEJavaApiTest.class);
076: }
077:
078: /**
079: * loads {@code test-data/testparams.properties} into a Properties object, wich is
080: * used to obtain test tables names and is used as parameter to find the DataStore
081: *
082: * @throws Exception
083: * DOCUMENT ME!
084: */
085: protected void setUp() throws Exception {
086: super .setUp();
087: this .testData = new TestData();
088: this .testData.setUp();
089: this .pool = this .testData.getDataStore().getConnectionPool();
090: this .conn = this .pool.getConnection();
091: }
092:
093: /**
094: * DOCUMENT ME!
095: *
096: * @throws Exception
097: * DOCUMENT ME!
098: */
099: protected void tearDown() throws Exception {
100: super .tearDown();
101: this .testData.tearDown(false, true); //this also closes the connection
102: this .testData = null;
103: }
104:
105: public void testNullSQLConstruct() throws Exception {
106: String[] columns = { "POP_ADMIN" };
107: SeSqlConstruct sql = null;
108:
109: try {
110: SeQuery rowQuery = new SeQuery(conn, columns, sql);
111: rowQuery.prepareQuery();
112: rowQuery.execute();
113: fail("A null SeSqlConstruct should have thrown an exception!");
114: } catch (SeException e) {
115: LOGGER.fine("Null SqlConstruct throwed exception, it's OK");
116: }
117: }
118:
119: public void testEmptySQLConstruct() throws Exception {
120: String typeName = this .testData.getPolygon_table();
121:
122: String[] columns = { "POP_ADMIN" };
123: SeSqlConstruct sql = new SeSqlConstruct(typeName);
124:
125: SeQuery rowQuery = new SeQuery(conn, columns, sql);
126: rowQuery.prepareQuery();
127: rowQuery.execute();
128: }
129:
130: /**
131: * DOCUMENT ME!
132: *
133: * @throws Exception
134: * DOCUMENT ME!
135: */
136: public void testGetBoundsWhileFetchingRows() throws Exception {
137: try {
138: ArcSDEConnectionPool pool = this .testData.getDataStore()
139: .getConnectionPool();
140: String typeName = this .testData.getPolygon_table();
141: String where = "POP_ADMIN < 270000";
142:
143: String[] columns = { "POP_ADMIN" };
144: SeSqlConstruct sql = new SeSqlConstruct(typeName, where);
145:
146: SeQueryInfo qInfo = new SeQueryInfo();
147: qInfo.setConstruct(sql);
148:
149: // add a bounding box filter and verify both spatial and non spatial
150: // constraints affects the COUNT statistics
151: SeExtent extent = new SeExtent(-68, -55, -63, -52);
152:
153: SeLayer layer = pool.getSdeLayer(typeName);
154: SeShape filterShape = new SeShape(layer.getCoordRef());
155: filterShape.generateRectangle(extent);
156:
157: SeShapeFilter bboxFilter = new SeShapeFilter(typeName,
158: layer.getSpatialColumn(), filterShape,
159: SeFilter.METHOD_ENVP, true);
160: SeFilter[] spatFilters = { bboxFilter };
161:
162: for (int i = 0; i < 26; i++) {
163: LOGGER.fine("Running iteration #" + i);
164:
165: SeQuery rowQuery = new SeQuery(conn, columns, sql);
166: rowQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE,
167: false, spatFilters);
168: rowQuery.prepareQuery();
169: rowQuery.execute();
170:
171: // fetch some rows
172: rowQuery.fetch();
173: rowQuery.fetch();
174: rowQuery.fetch();
175:
176: SeQuery countQuery = new SeQuery(conn, columns, sql);
177: countQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE,
178: true, spatFilters);
179:
180: final int expCount = 2;
181:
182: SeTable.SeTableStats tableStats = countQuery
183: .calculateTableStatistics("POP_ADMIN",
184: SeTable.SeTableStats.SE_COUNT_STATS,
185: qInfo, 0);
186:
187: rowQuery.fetch();
188: rowQuery.fetch();
189:
190: int resultCount = tableStats.getCount();
191:
192: assertEquals(expCount, resultCount);
193:
194: rowQuery.close();
195: countQuery.close();
196: }
197: LOGGER.fine("TEST PASSED");
198: } catch (SeException e) {
199: LOGGER.warning(e.getSeError().getErrDesc());
200: e.printStackTrace();
201: throw e;
202: }
203: }
204:
205: /**
206: * DOCUMENT ME!
207: *
208: * @throws Exception
209: * DOCUMENT ME!
210: */
211: public void testCalculateCount() throws Exception {
212: try {
213: String typeName = this .testData.getPolygon_table();
214: String where = "POP_ADMIN < 270000";
215: int expCount = 4;
216:
217: String[] columns = { "POP_ADMIN" };
218: SeSqlConstruct sql = new SeSqlConstruct(typeName, where);
219: SeQuery query = new SeQuery(conn, columns, sql);
220: SeQueryInfo qInfo = new SeQueryInfo();
221: qInfo.setConstruct(sql);
222:
223: SeTable.SeTableStats tableStats = query
224: .calculateTableStatistics("POP_ADMIN",
225: SeTable.SeTableStats.SE_COUNT_STATS, qInfo,
226: 0);
227:
228: assertEquals(expCount, tableStats.getCount());
229: query.close();
230:
231: // add a bounding box filter and verify both spatial and non spatial
232: // constraints affects the COUNT statistics
233: SeExtent extent = new SeExtent(-68, -55, -63, -52);
234:
235: SeLayer layer = pool.getSdeLayer(typeName);
236: SeShape filterShape = new SeShape(layer.getCoordRef());
237: filterShape.generateRectangle(extent);
238:
239: query = new SeQuery(conn, columns, sql);
240:
241: SeShapeFilter bboxFilter = new SeShapeFilter(typeName,
242: layer.getSpatialColumn(), filterShape,
243: SeFilter.METHOD_ENVP, true);
244: SeFilter[] spatFilters = { bboxFilter };
245:
246: query.setSpatialConstraints(SeQuery.SE_OPTIMIZE, true,
247: spatFilters);
248:
249: expCount = 2;
250: tableStats = query.calculateTableStatistics("POP_ADMIN",
251: SeTable.SeTableStats.SE_COUNT_STATS, qInfo, 0);
252:
253: int resultCount = tableStats.getCount();
254:
255: assertEquals(expCount, resultCount);
256: } catch (SeException e) {
257: LOGGER.warning(e.getSeError().getErrDesc());
258: e.printStackTrace();
259: throw e;
260: }
261: }
262:
263: /**
264: * DOCUMENT ME!
265: *
266: * @throws SeException
267: * DOCUMENT ME!
268: */
269: public void testGenericSeCoordinateReferenceLimits()
270: throws SeException {
271: SeCoordinateReference crs = TestData.getGenericCoordRef();
272: LOGGER.fine("CRS constraints: " + crs.getXYEnvelope()
273: + ", presision: " + crs.getXYUnits());
274:
275: SDEPoint[] ptArray = new SDEPoint[2];
276: SeShape shape = new SeShape(crs);
277: ptArray[0] = new SDEPoint(0.0, 0.0);
278:
279: // find the lower limit of separation between coordinates
280: double shift = 1.0;
281:
282: try {
283: while (true) {
284: ptArray[1] = new SDEPoint(shift, shift);
285: shape.generateLine(2, 1, new int[] { 0 }, ptArray);
286: shift /= 10;
287: }
288: } catch (SeException e) {
289: LOGGER.fine("Lower limit: " + String.valueOf(10 * shift));
290: }
291:
292: int numPts = 5;
293: ptArray = new SDEPoint[numPts];
294: ptArray[0] = new SDEPoint(-1, 0);
295: ptArray[1] = new SDEPoint(0, 1);
296: ptArray[2] = new SDEPoint(1, 0);
297: ptArray[3] = new SDEPoint(0, -1);
298: ptArray[4] = new SDEPoint(-1, 0);
299:
300: SeShape polygon = new SeShape(crs);
301: polygon.generatePolygon(numPts, 1, new int[] { 0 }, ptArray);
302: }
303:
304: /**
305: * Ensures a point SeShape behaves as expected.
306: *
307: * @throws SeException
308: * if it is thrown while constructing the SeShape
309: */
310: public void testPointFormat() throws SeException {
311: int numPts = 1;
312: SDEPoint[] ptArray = new SDEPoint[numPts];
313: ptArray[0] = new SDEPoint(3000, 100);
314:
315: SeShape point = new SeShape();
316: point.generatePoint(numPts, ptArray);
317:
318: int numParts = 0;
319: double[][][] coords = point.getAllCoords();
320:
321: assertEquals("Num of parts invalid", numPts, coords.length);
322:
323: for (; numParts < numPts; numParts++) {
324: assertEquals("Num subparts invalid", 1,
325: coords[numParts].length);
326: }
327:
328: for (; numParts < numPts; numParts++) {
329: int numSubParts = 0;
330:
331: for (; numSubParts < coords[numParts].length; numParts++) {
332: assertEquals("Num of points invalid", 2,
333: coords[numParts][numSubParts].length);
334: }
335: }
336: }
337:
338: /**
339: * Ensures a multipoint SeShape behaves as expected.
340: *
341: * @throws SeException
342: * if it is thrown while constructing the SeShape
343: */
344: public void testMultiPointFormat() throws SeException {
345: int numPts = 4;
346: SDEPoint[] ptArray = new SDEPoint[numPts];
347: ptArray[0] = new SDEPoint(3000, 100);
348: ptArray[1] = new SDEPoint(3000, 300);
349: ptArray[2] = new SDEPoint(4000, 300);
350: ptArray[3] = new SDEPoint(4000, 100);
351:
352: SeShape point = new SeShape();
353: point.generatePoint(numPts, ptArray);
354:
355: double[][][] coords = point.getAllCoords();
356: assertEquals("Num of parts invalid", numPts, coords.length);
357:
358: int numParts = 0;
359:
360: for (; numParts < numPts; numParts++) {
361: assertEquals("Num subparts invalid", 1,
362: coords[numParts].length);
363: }
364:
365: for (; numParts < numPts; numParts++) {
366: int numSubParts = 0;
367:
368: for (; numSubParts < coords[numParts].length; numParts++) {
369: assertEquals("Num of points invalid", 2,
370: coords[numParts][numSubParts].length);
371: }
372: }
373: }
374:
375: /**
376: * Ensures a linestring SeShape behaves as expected.
377: *
378: * @throws SeException
379: * if it is thrown while constructing the SeShape
380: */
381: public void testLineStringFormat() throws SeException {
382: int numPts = 4;
383: SDEPoint[] ptArray = new SDEPoint[numPts];
384: ptArray[0] = new SDEPoint(3000, 100);
385: ptArray[1] = new SDEPoint(3000, 300);
386: ptArray[2] = new SDEPoint(4000, 300);
387: ptArray[3] = new SDEPoint(4000, 100);
388:
389: SeShape point = new SeShape();
390: int numParts = 1;
391: int[] partOffsets = { 0 }; // index of each part's start in the gobal
392: // coordinate array
393: point.generateLine(numPts, numParts, partOffsets, ptArray);
394:
395: double[][][] coords = point.getAllCoords();
396:
397: assertEquals("Num of parts invalid", 1, coords.length);
398:
399: assertEquals("Num subparts invalid", 1, coords[0].length);
400:
401: assertEquals("Num of points invalid", 2 * numPts,
402: coords[0][0].length);
403: }
404:
405: /**
406: * Ensures a multilinestring SeShape behaves as expected.
407: *
408: * @throws SeException
409: * if it is thrown while constructing the SeShape
410: */
411: public void testMultiLineStringFormat() throws SeException {
412: int numPts = 4;
413: SDEPoint[] ptArray = new SDEPoint[numPts];
414: ptArray[0] = new SDEPoint(3000, 100);
415: ptArray[1] = new SDEPoint(3000, 300);
416: ptArray[2] = new SDEPoint(4000, 300);
417: ptArray[3] = new SDEPoint(4000, 100);
418:
419: SeShape point = new SeShape();
420: int numParts = 2;
421: int[] partOffsets = { 0, 2 }; // index of each part's start in the
422: // gobal coordinate array
423: point.generateLine(numPts, numParts, partOffsets, ptArray);
424:
425: double[][][] coords = point.getAllCoords();
426:
427: assertEquals("Num of parts invalid", numParts, coords.length);
428:
429: assertEquals("Num subparts invalid", 1, coords[0].length);
430: assertEquals("Num subparts invalid", 1, coords[1].length);
431:
432: assertEquals("Num of points invalid", numPts,
433: coords[0][0].length);
434: assertEquals("Num of points invalid", numPts,
435: coords[1][0].length);
436: }
437:
438: /**
439: * Ensures a polygon SeShape behaves as expected, building a simple polygon
440: * and a polygon with a hole.
441: *
442: * @throws SeException
443: * if it is thrown while constructing the SeShape
444: */
445: public void testPolygonFormat() throws SeException {
446: /*
447: * Generate an area shape composed of two polygons, the first with a
448: * hole
449: */
450: int numPts = 4;
451: int numParts = 1;
452: int[] partOffsets = new int[numParts];
453: partOffsets[0] = 0;
454:
455: SDEPoint[] ptArray = new SDEPoint[numPts];
456:
457: // simple polygon
458: ptArray[0] = new SDEPoint(1600, 1200);
459: ptArray[1] = new SDEPoint(2800, 1650);
460: ptArray[2] = new SDEPoint(1800, 2000);
461: ptArray[3] = new SDEPoint(1600, 1200);
462:
463: SeShape polygon = new SeShape();
464: polygon.generatePolygon(numPts, numParts, partOffsets, ptArray);
465:
466: double[][][] coords = polygon.getAllCoords();
467:
468: assertEquals("Num of parts invalid", numParts, coords.length);
469: assertEquals("Num subparts invalid", 1, coords[0].length);
470: assertEquals("Num of points invalid", 2 * 4,
471: coords[0][0].length);
472:
473: numPts = 14;
474: numParts = 1;
475: ptArray = new SDEPoint[numPts];
476: partOffsets = new int[numParts];
477: partOffsets[0] = 0;
478:
479: // part one
480: ptArray[0] = new SDEPoint(100, 1100);
481: ptArray[1] = new SDEPoint(1500, 1100);
482: ptArray[2] = new SDEPoint(1500, 1900);
483: ptArray[3] = new SDEPoint(100, 1900);
484: ptArray[4] = new SDEPoint(100, 1100);
485:
486: // Hole - sub part of part one
487: ptArray[5] = new SDEPoint(200, 1200);
488: ptArray[6] = new SDEPoint(200, 1500);
489: ptArray[7] = new SDEPoint(500, 1500);
490: ptArray[8] = new SDEPoint(500, 1700);
491: ptArray[9] = new SDEPoint(800, 1700);
492: ptArray[10] = new SDEPoint(800, 1500);
493: ptArray[11] = new SDEPoint(500, 1500);
494: ptArray[12] = new SDEPoint(500, 1200);
495: ptArray[13] = new SDEPoint(200, 1200);
496:
497: polygon = new SeShape();
498: polygon.generatePolygon(numPts, numParts, partOffsets, ptArray);
499:
500: coords = polygon.getAllCoords();
501:
502: assertEquals("Num of parts invalid", numParts, coords.length);
503: assertEquals("Num subparts invalid", 2, coords[0].length);
504:
505: // first part of first polygon (shell) has 5 points
506: assertEquals("Num of points invalid", 2 * 5,
507: coords[0][0].length);
508:
509: // second part of first polygon (hole) has 9 points
510: assertEquals("Num of points invalid", 2 * 9,
511: coords[0][1].length);
512: }
513:
514: /**
515: * Ensures a multipolygon SeShape behaves as expected.
516: *
517: * @throws SeException
518: * if it is thrown while constructing the SeShape
519: */
520: public void testMultiPolygonFormat() throws SeException {
521: /*
522: * Generate an area shape composed of two polygons, the first with a
523: * hole
524: */
525: int numPts = 18;
526: int numParts = 2;
527: int[] partOffsets = new int[numParts];
528: partOffsets[0] = 0;
529: partOffsets[1] = 14;
530:
531: SDEPoint[] ptArray = new SDEPoint[numPts];
532:
533: // part one
534: ptArray[0] = new SDEPoint(100, 1100);
535: ptArray[1] = new SDEPoint(1500, 1100);
536: ptArray[2] = new SDEPoint(1500, 1900);
537: ptArray[3] = new SDEPoint(100, 1900);
538: ptArray[4] = new SDEPoint(100, 1100);
539:
540: // Hole - sub part of part one
541: ptArray[5] = new SDEPoint(200, 1200);
542: ptArray[6] = new SDEPoint(200, 1500);
543: ptArray[7] = new SDEPoint(500, 1500);
544: ptArray[8] = new SDEPoint(500, 1700);
545: ptArray[9] = new SDEPoint(800, 1700);
546: ptArray[10] = new SDEPoint(800, 1500);
547: ptArray[11] = new SDEPoint(500, 1500);
548: ptArray[12] = new SDEPoint(500, 1200);
549: ptArray[13] = new SDEPoint(200, 1200);
550:
551: // part two
552: ptArray[14] = new SDEPoint(1600, 1200);
553: ptArray[15] = new SDEPoint(2800, 1650);
554: ptArray[16] = new SDEPoint(1800, 2000);
555: ptArray[17] = new SDEPoint(1600, 1200);
556:
557: SeShape multipolygon = new SeShape();
558: multipolygon.generatePolygon(numPts, numParts, partOffsets,
559: ptArray);
560:
561: double[][][] coords = multipolygon.getAllCoords();
562:
563: assertEquals("Num of parts invalid", numParts, coords.length);
564:
565: // the first polygon has 2 parts
566: assertEquals("Num subparts invalid", 2, coords[0].length);
567:
568: // the second polygon has only 1 part
569: assertEquals("Num subparts invalid", 1, coords[1].length);
570:
571: // first part of first polygon (shell) has 5 points
572: assertEquals("Num of points invalid", 2 * 5,
573: coords[0][0].length);
574:
575: // second part of first polygon (hole) has 9 points
576: assertEquals("Num of points invalid", 2 * 9,
577: coords[0][1].length);
578:
579: // second polygon (shell with no holes) has 4 points
580: assertEquals("Num of points invalid", 2 * 4,
581: coords[1][0].length);
582: }
583:
584: /**
585: * Creates an ArcSDE table, "EXAMPLE", and adds a spatial column, "SHAPE",
586: * to it.
587: *
588: * <p>
589: * This code is directly taken from the createBaseTable mehtod of the
590: * arcsdeonline "Working with layers" example, to verify that it works prior
591: * to blame the gt implementation.
592: * </p>
593: *
594: * @throws SeException
595: * DOCUMENT ME!
596: * @throws IOException
597: * DOCUMENT ME!
598: * @throws UnavailableArcSDEConnectionException
599: * DOCUMENT ME!
600: */
601: public void testCreateBaseTable() throws SeException, IOException,
602: UnavailableArcSDEConnectionException {
603: SeLayer layer = new SeLayer(conn);
604: SeTable table = null;
605:
606: try {
607: /*
608: * Create a qualified table name with current user's name and the
609: * name of the table to be created, "EXAMPLE".
610: */
611: String tableName = (conn.getUser() + ".EXAMPLE");
612: table = new SeTable(conn, tableName);
613: layer.setTableName("EXAMPLE");
614:
615: try {
616: table.delete();
617: } catch (Exception e) {
618: LOGGER.warning(e.getMessage());
619: }
620:
621: SeColumnDefinition[] colDefs = new SeColumnDefinition[7];
622:
623: /*
624: * Define the columns and their attributes for the table to be
625: * created. NOTE: The valid range/values of size and scale
626: * parameters vary from one database to another.
627: */
628: boolean isNullable = true;
629: colDefs[0] = new SeColumnDefinition("INT32_COL",
630: SeColumnDefinition.TYPE_INTEGER, 10, 0, isNullable);
631: colDefs[1] = new SeColumnDefinition("INT16_COL",
632: SeColumnDefinition.TYPE_SMALLINT, 4, 0, isNullable);
633: colDefs[2] = new SeColumnDefinition("FLOAT32_COL",
634: SeColumnDefinition.TYPE_FLOAT, 5, 2, isNullable);
635: colDefs[3] = new SeColumnDefinition("FLOAT64_COL",
636: SeColumnDefinition.TYPE_DOUBLE, 15, 4, isNullable);
637: colDefs[4] = new SeColumnDefinition("STRING_COL",
638: SeColumnDefinition.TYPE_STRING, 25, 0, isNullable);
639: colDefs[5] = new SeColumnDefinition("DATE_COL",
640: SeColumnDefinition.TYPE_DATE, 1, 0, isNullable);
641: colDefs[6] = new SeColumnDefinition("INT64_COL",
642: SeColumnDefinition.TYPE_INTEGER, 10, 0, isNullable);
643:
644: /*
645: * Create the table using the DBMS default configuration keyword.
646: * Valid keywords are defined in the dbtune table.
647: */
648: if (LOGGER.isLoggable(Level.FINE)) {
649: System.out
650: .println("\n--> Creating a table using DBMS Default Keyword");
651: }
652: table.create(colDefs, testData.getConfigKeyword());
653: if (LOGGER.isLoggable(Level.FINE)) {
654: System.out.println(" - Done.");
655: }
656: /*
657: * Define the attributes of the spatial column
658: */
659: layer.setSpatialColumnName("SHAPE");
660:
661: /*
662: * Set the type of shapes that can be inserted into the layer. Shape
663: * type can be just one or many. NOTE: Layers that contain more than
664: * one shape type can only be accessed through the C and Java APIs
665: * and Arc Explorer Java 3.x. They cannot be seen from ArcGIS
666: * desktop applications.
667: */
668: layer.setShapeTypes(SeLayer.SE_NIL_TYPE_MASK
669: | SeLayer.SE_POINT_TYPE_MASK
670: | SeLayer.SE_LINE_TYPE_MASK
671: | SeLayer.SE_SIMPLE_LINE_TYPE_MASK
672: | SeLayer.SE_AREA_TYPE_MASK
673: | SeLayer.SE_MULTIPART_TYPE_MASK);
674: layer.setGridSizes(1100.0, 0.0, 0.0);
675: layer.setDescription("Layer Example");
676:
677: SeExtent ext = new SeExtent(0.0, 0.0, 10000.0, 10000.0);
678: layer.setExtent(ext);
679:
680: /*
681: * Define the layer's Coordinate Reference
682: */
683: SeCoordinateReference coordref = TestData
684: .getGenericCoordRef();
685: layer.setCoordRef(coordref);
686:
687: /*
688: * Spatially enable the new table...
689: */
690: if (LOGGER.isLoggable(Level.FINE)) {
691: System.out
692: .println("\n--> Adding spatial column \"SHAPE\"...");
693: }
694: layer.setCreationKeyword(testData.getConfigKeyword());
695: layer.create(3, 4);
696: if (LOGGER.isLoggable(Level.FINE)) {
697: System.out.println(" - Done.");
698: }
699: } catch (SeException e) {
700: System.out.println(e.getSeError().getErrDesc());
701: e.printStackTrace();
702: throw e;
703: }
704: } // End method createBaseTable
705:
706: /**
707: * Creates an ArcSDE table, "EXAMPLE", and adds a spatial column, "SHAPE",
708: * to it.
709: *
710: * <p>
711: * This code is directly taken from the createBaseTable mehtod of the
712: * arcsdeonline "Working with layers" example, to verify that it works prior
713: * to blame the gt implementation.
714: * </p>
715: *
716: * @throws SeException
717: * DOCUMENT ME!
718: * @throws IOException
719: * DOCUMENT ME!
720: * @throws UnavailableArcSDEConnectionException
721: * DOCUMENT ME!
722: */
723: public void testCreateNonStandardSchema() throws SeException,
724: IOException, UnavailableArcSDEConnectionException {
725: SeLayer layer = new SeLayer(conn);
726: SeTable table = null;
727:
728: try {
729: /*
730: * Create a qualified table name with current user's name and the
731: * name of the table to be created, "EXAMPLE".
732: */
733: String tableName = (conn.getUser() + ".NOTENDSWITHGEOM");
734: table = new SeTable(conn, tableName);
735: layer.setTableName("NOTENDSWITHGEOM");
736:
737: try {
738: table.delete();
739: } catch (Exception e) {
740: // intentionally blank
741: }
742:
743: /*
744: * Create the table using the DBMS default configuration keyword.
745: * Valid keywords are defined in the dbtune table.
746: */
747: if (LOGGER.isLoggable(Level.FINE)) {
748: System.out
749: .println("\n--> Creating a table using DBMS Default Keyword");
750: }
751: SeColumnDefinition[] tmpCols = new SeColumnDefinition[] { new SeColumnDefinition(
752: "tmp", SeColumnDefinition.TYPE_STRING, 5, 0, true) };
753: table.create(tmpCols, testData.getConfigKeyword());
754: if (LOGGER.isLoggable(Level.FINE)) {
755: System.out.println(" - Done.");
756: }
757: SeColumnDefinition[] colDefs = new SeColumnDefinition[7];
758:
759: /*
760: * Define the columns and their attributes for the table to be
761: * created. NOTE: The valid range/values of size and scale
762: * parameters vary from one database to another.
763: */
764: boolean isNullable = true;
765: colDefs[0] = new SeColumnDefinition("INT32_COL",
766: SeColumnDefinition.TYPE_INTEGER, 10, 0, isNullable);
767: colDefs[1] = new SeColumnDefinition("INT16_COL",
768: SeColumnDefinition.TYPE_SMALLINT, 4, 0, isNullable);
769: colDefs[2] = new SeColumnDefinition("FLOAT32_COL",
770: SeColumnDefinition.TYPE_FLOAT, 5, 2, isNullable);
771: colDefs[3] = new SeColumnDefinition("FLOAT64_COL",
772: SeColumnDefinition.TYPE_DOUBLE, 15, 4, isNullable);
773: colDefs[4] = new SeColumnDefinition("STRING_COL",
774: SeColumnDefinition.TYPE_STRING, 25, 0, isNullable);
775: colDefs[5] = new SeColumnDefinition("DATE_COL",
776: SeColumnDefinition.TYPE_DATE, 1, 0, isNullable);
777: colDefs[6] = new SeColumnDefinition("INT64_COL",
778: SeColumnDefinition.TYPE_INTEGER, 10, 0, isNullable);
779:
780: table.addColumn(colDefs[0]);
781: table.addColumn(colDefs[1]);
782: table.addColumn(colDefs[2]);
783: table.addColumn(colDefs[3]);
784: table.dropColumn(tmpCols[0].getName());
785:
786: /*
787: * Define the attributes of the spatial column
788: */
789: layer.setSpatialColumnName("SHAPE");
790:
791: /*
792: * Set the type of shapes that can be inserted into the layer. Shape
793: * type can be just one or many. NOTE: Layers that contain more than
794: * one shape type can only be accessed through the C and Java APIs
795: * and Arc Explorer Java 3.x. They cannot be seen from ArcGIS
796: * desktop applications.
797: */
798: layer.setShapeTypes(SeLayer.SE_NIL_TYPE_MASK
799: | SeLayer.SE_POINT_TYPE_MASK
800: | SeLayer.SE_LINE_TYPE_MASK
801: | SeLayer.SE_SIMPLE_LINE_TYPE_MASK
802: | SeLayer.SE_AREA_TYPE_MASK
803: | SeLayer.SE_MULTIPART_TYPE_MASK);
804: layer.setGridSizes(1100.0, 0.0, 0.0);
805: layer.setDescription("Layer Example");
806:
807: SeExtent ext = new SeExtent(0.0, 0.0, 10000.0, 10000.0);
808: layer.setExtent(ext);
809:
810: /*
811: * Define the layer's Coordinate Reference
812: */
813: SeCoordinateReference coordref = new SeCoordinateReference();
814: coordref.setXY(0, 0, 100);
815: layer.setCoordRef(coordref);
816:
817: /*
818: * Spatially enable the new table...
819: */
820: if (LOGGER.isLoggable(Level.FINE)) {
821: System.out
822: .println("\n--> Adding spatial column \"SHAPE\"...");
823: }
824: layer.setCreationKeyword(testData.getConfigKeyword());
825:
826: layer.create(3, 4);
827: if (LOGGER.isLoggable(Level.FINE)) {
828: System.out.println(" - Done.");
829: }
830:
831: table.addColumn(colDefs[4]);
832: table.addColumn(colDefs[5]);
833: table.addColumn(colDefs[6]);
834: } catch (SeException e) {
835: System.out.println(e.getSeError().getErrDesc());
836: e.printStackTrace();
837: throw e;
838: } finally {
839: try {
840: table.delete();
841: } catch (Exception e) {
842: // intentionally blank
843: }
844:
845: try {
846: layer.delete();
847: } catch (Exception e) {
848: // intentionally blank
849: }
850: }
851: } // End method createBaseTable
852:
853: }
|