001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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: package org.geotools.data.hsql;
017:
018: import java.io.File;
019: import java.io.FilenameFilter;
020: import java.sql.Connection;
021: import java.sql.Statement;
022: import java.util.logging.Logger;
023:
024: import org.geotools.data.AbstractDataStoreTest;
025: import org.geotools.data.DataStore;
026: import org.geotools.data.DataUtilities;
027: import org.geotools.data.Transaction;
028: import org.geotools.feature.Feature;
029: import org.geotools.feature.SimpleFeature;
030: import org.geotools.filter.FidFilter;
031: import org.geotools.filter.FilterFactory;
032: import org.geotools.filter.FilterFactoryFinder;
033:
034: import com.vividsolutions.jts.geom.Envelope;
035: import com.vividsolutions.jts.geom.GeometryFactory;
036:
037: /**
038: * DOCUMENT ME!
039: *
040: * @author Jody Garnett, Refractions Research
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/hsql/src/test/java/org/geotools/data/hsql/HsqlDataStoreTest.java $
042: */
043: public class HsqlDataStoreTest extends AbstractDataStoreTest {
044: private HsqlConnectionFactory connFactory;
045: /** The logger for the filter module. */
046: private static final Logger LOGGER = org.geotools.util.logging.Logging
047: .getLogger("org.geotools.hsql");
048:
049: /**
050: * Constructor for MemoryDataStoreTest.
051: *
052: * @param arg0
053: */
054: public HsqlDataStoreTest(String arg0) {
055: super (arg0);
056: }
057:
058: protected void dataSetUp() throws Exception {
059: String namespace = getName();
060: roadType = DataUtilities.createType(namespace + ".ROAD",
061: "ID:0,GEOM:LineString,NAME:String");
062: subRoadType = DataUtilities.createType(namespace + "ROAD",
063: "ID:0,GEOM:LineString");
064: gf = new GeometryFactory();
065:
066: roadFeatures = new SimpleFeature[3];
067:
068: // 3,2
069: // 2,2 +-----+-----+ 4,2
070: // / rd1 \
071: // 1,1+ +5,1
072: roadFeatures[0] = (SimpleFeature) roadType.create(new Object[] {
073: new Integer(1),
074: line(new int[] { 1, 1, 2, 2, 4, 2, 5, 1 }), "r1", },
075: "road.rd1");
076:
077: // + 3,4
078: // + 3,3
079: // rd2 + 3,2
080: // |
081: // 3,0+
082: roadFeatures[1] = (SimpleFeature) roadType.create(new Object[] {
083: new Integer(2),
084: line(new int[] { 3, 0, 3, 2, 3, 3, 3, 4 }), "r2" },
085: "road.rd2");
086:
087: // rd3 + 5,3
088: // /
089: // 3,2 +----+ 4,2
090: roadFeatures[2] = (SimpleFeature) roadType.create(new Object[] {
091: new Integer(3), line(new int[] { 3, 2, 4, 2, 5, 3 }),
092: "r3" }, "road.rd3");
093: roadBounds = new Envelope();
094: roadBounds.expandToInclude(roadFeatures[0].getBounds());
095: roadBounds.expandToInclude(roadFeatures[1].getBounds());
096: roadBounds.expandToInclude(roadFeatures[2].getBounds());
097:
098: FilterFactory factory = FilterFactoryFinder
099: .createFilterFactory();
100: rd1Filter = factory.createFidFilter("0");
101: rd2Filter = factory.createFidFilter("1");
102:
103: FidFilter create = factory.createFidFilter();
104: create.addFid("0");
105: create.addFid("1");
106:
107: rd12Filter = create;
108:
109: rd12Bounds = new Envelope();
110: rd12Bounds.expandToInclude(roadFeatures[0].getBounds());
111: rd12Bounds.expandToInclude(roadFeatures[1].getBounds());
112: // + 2,3
113: // / rd4
114: // + 1,2
115: newRoad = roadType.create(new Object[] { new Integer(4),
116: line(new int[] { 1, 2, 2, 3 }), "r4" }, "road.rd4");
117:
118: riverType = DataUtilities.createType(namespace + ".RIVER",
119: "ID:0,GEOM:MultiLineString,RIVER:String,FLOW:0.0");
120: subRiverType = DataUtilities.createType(namespace + ".RIVER",
121: "RIVER:String,FLOW:0.0");
122: gf = new GeometryFactory();
123: riverFeatures = new Feature[2];
124:
125: // 9,7 13,7
126: // +------+
127: // 5,5 /
128: // +---+ rv1
129: // 7,5 \
130: // 9,3 +----+ 11,3
131: riverFeatures[0] = riverType.create(
132: new Object[] {
133: new Integer(1),
134: lines(new int[][] { { 5, 5, 7, 4 },
135: { 7, 5, 9, 7, 13, 7 },
136: { 7, 5, 9, 3, 11, 3 } }), "rv1",
137: new Double(4.5) }, "river.rv1");
138:
139: // + 6,10
140: // /
141: // rv2+ 4,8
142: // |
143: // 4,6 +
144: riverFeatures[1] = riverType.create(new Object[] {
145: new Integer(2),
146: lines(new int[][] { { 4, 6, 4, 8, 6, 10 } }), "rv2",
147: new Double(3.0) }, "river.rv2");
148: riverBounds = new Envelope();
149: riverBounds.expandToInclude(riverFeatures[0].getBounds());
150: riverBounds.expandToInclude(riverFeatures[1].getBounds());
151:
152: rv1Filter = FilterFactoryFinder.createFilterFactory()
153: .createFidFilter("0");
154:
155: // 9,5 11,5
156: // +-----+
157: // rv3 \
158: // + 13,3
159: //
160: newRiver = riverType.create(new Object[] { new Integer(3),
161: lines(new int[][] { { 9, 5, 11, 5, 13, 3 } }), "rv3",
162: new Double(1.5) }, "river.rv3");
163:
164: lakeType = DataUtilities.createType(namespace + ".LAKE",
165: "ID:0,GEOM:Polygon:nillable,NAME:String");
166: lakeFeatures = new Feature[1];
167: // + 14,8
168: // / \
169: // 12,6 + + 16,6
170: // \ |
171: // 14,4 +-+ 16,4
172: //
173: lakeFeatures[0] = lakeType.create(new Object[] {
174: new Integer(0),
175: polygon(new int[] { 12, 6, 14, 8, 16, 6, 16, 4, 14, 4,
176: 12, 6 }), "muddy" }, "lake.lk1");
177: lakeBounds = new Envelope();
178: lakeBounds.expandToInclude(lakeFeatures[0].getBounds());
179:
180: }
181:
182: public DataStore createDataStore() throws Exception {
183: connFactory = new HsqlConnectionFactory("tempDB", "sa", "");
184:
185: DataStore hsql = null;
186: hsql = new HsqlDataStore(connFactory, null, getName());
187:
188: File dir = new File(".");
189: String found[] = dir.list(new FilenameFilter() {
190: public boolean accept(File dir, String name) {
191: return name.startsWith("tempDB");
192: }
193: });
194: for (int i = 0; i < found.length; i++) {
195: new File(found[i]).deleteOnExit();
196: }
197: return hsql;
198: }
199:
200: public DataStore tearDownDataStore(DataStore data) throws Exception {
201: ((HsqlDataStore) data).removeSchema(roadType);
202: ((HsqlDataStore) data).removeSchema(riverType);
203: Connection conn = ((HsqlDataStore) data)
204: .getConnection(Transaction.AUTO_COMMIT);
205: Statement st = conn.createStatement();
206: st.execute("SHUTDOWN");
207: st.close();
208: conn.close();
209: File file = new File("tempDB.log");
210: if (file.exists())
211: file.delete();
212: file = new File("tempDB.properties");
213: if (file.exists())
214: file.delete();
215: file = new File("tempDB.data");
216: if (file.exists())
217: file.delete();
218: file = new File("tempDB.script");
219: if (file.exists())
220: file.delete();
221: file = new File("tempDB.backup");
222: if (file.exists())
223: file.delete();
224: file = new File("tempDB.lck");
225: if (file.exists())
226: file.delete();
227: return null;
228: }
229:
230: }
|