01: package org.geotools.data.postgis;
02:
03: import org.geotools.data.DefaultTransaction;
04: import org.geotools.data.FeatureWriter;
05: import org.geotools.data.Transaction;
06: import org.geotools.data.postgis.fidmapper.PostgisFIDMapperFactory;
07: import org.geotools.feature.Feature;
08:
09: public class PostgisFeatureWriterOnlineTest extends
10: AbstractPostgisOnlineTestCase {
11:
12: public void testWrite() throws Exception {
13: if (((PostgisFIDMapperFactory) ds.getFIDMapperFactory())
14: .isReturningTypedFIDMapper()) {
15: assertEquals(table1 + ".1", attemptWrite(table1));
16: assertEquals(table1 + ".2", attemptWrite(table1));
17: assertEquals(table2 + ".1001", attemptWrite(table2));
18: assertEquals(table2 + ".1002", attemptWrite(table2));
19: assertEquals(table3 + ".1", attemptWrite(table3));
20: assertEquals(table3 + ".2", attemptWrite(table3));
21: assertEquals(table4 + ".1000001", attemptWrite(table4));
22: assertEquals(table4 + ".1000002", attemptWrite(table4));
23: assertEquals(table5 + ".1", attemptWrite(table5));
24: assertEquals(table5 + ".2", attemptWrite(table5));
25: assertEquals(table6 + ".1001", attemptWrite(table6));
26: assertEquals(table6 + ".1002", attemptWrite(table6));
27: } else {
28: assertEquals("1", attemptWrite(table1));
29: assertEquals("2", attemptWrite(table1));
30: assertEquals("1001", attemptWrite(table2));
31: assertEquals("1002", attemptWrite(table2));
32: assertEquals("1", attemptWrite(table3));
33: assertEquals("2", attemptWrite(table3));
34: assertEquals("1000001", attemptWrite(table4));
35: assertEquals("1000002", attemptWrite(table4));
36: assertEquals("1", attemptWrite(table5));
37: assertEquals("2", attemptWrite(table5));
38: assertEquals("1001", attemptWrite(table6));
39: assertEquals("1002", attemptWrite(table6));
40:
41: }
42:
43: }
44:
45: public String attemptWrite(String table) throws Exception {
46: Transaction transaction = new DefaultTransaction(
47: "attemptWriteFW");
48: FeatureWriter writer = ds.getFeatureWriter(table, transaction);
49: Feature feature;
50:
51: while (writer.hasNext()) {
52: feature = (Feature) writer.next();
53: }
54:
55: feature = (Feature) writer.next();
56: feature.setAttribute(0, "test");
57: writer.write();
58: String id = feature.getID();
59: transaction.commit();
60: transaction.close();
61: return id;
62: }
63: }
|