/** * Create a spatial index * * @param e feature entry to create spatial index for */ public void createSpatialIndex(FeatureEntry e) throws IOException { Map<String, String> properties = new HashMap<String, String>(); PrimaryKey pk = ((JDBCFeatureStore) (dataStore.getFeatureSource(e.getTableName()))).getPrimaryKey(); if (pk.getColumns().size() != 1) { throw new IOException("Spatial index only supported for primary key of single column."); } properties.put("t", e.getTableName()); properties.put("c", e.getGeometryColumn()); properties.put("i", pk.getColumns().get(0).getName()); Connection cx; try { cx = connPool.getConnection(); try { runScript(SPATIAL_INDEX + ".sql", cx, properties); } finally { cx.close(); } } catch (SQLException ex) { throw new IOException(ex); } }
public void testAssignedSinglePKeyView() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("assignedsinglepk")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); }
public void testNonIncrementingPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("noninc")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testUniqueIndex() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("uniq")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); assertNull(fs.getSchema().getDescriptor(fs.getPrimaryKey().getColumns().get(0).getName())); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testAutoGeneratedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("auto")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn); assertNull(fs.getSchema().getDescriptor(fs.getPrimaryKey().getColumns().get(0).getName())); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testSequencedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("seqtable")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof SequencedPrimaryKeyColumn); ContentFeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testSequencedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("seq")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof SequencedPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testAssignedMultiPKeyView() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("assignedmultipk")); assertEquals(2, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); assertTrue( fs.getPrimaryKey().getColumns().get(1) instanceof NonIncrementingPrimaryKeyColumn); try (FeatureIterator i = fs.getFeatures().features()) { for (int j = 1; i.hasNext(); j++) { SimpleFeature f = (SimpleFeature) i.next(); assertEquals(tname("assignedmultipk") + "." + j + "." + (j + 1), f.getID()); } } }
public void testMultiColumnPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("multi")); assertEquals(2, fs.getPrimaryKey().getColumns().size()); FeatureCollection features = fs.getFeatures(); assertMultiPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertMultiPrimaryKeyValues(features, 4); // test with a filter FilterFactory ff = dataStore.getFilterFactory(); Id id = ff.id(Collections.singleton(ff.featureId(tname("multi") + ".1.x"))); features = fs.getFeatures(id); assertEquals(1, features.size()); }
/** * Create a spatial index * * @param e feature entry to create spatial index for */ public void createSpatialIndex(FeatureEntry e) throws IOException { Map<String, String> properties = new HashMap<String, String>(); PrimaryKey pk = ((JDBCFeatureStore) (dataStore.getFeatureSource(e.getTableName()))).getPrimaryKey(); if (pk.getColumns().size() != 1) { throw new IOException("Spatial index only supported for primary key of single column."); } properties.put("t", e.getTableName()); properties.put("c", e.getGeometryColumn()); properties.put("i", pk.getColumns().get(0).getName()); Connection cx; try { cx = connPool.getConnection(); try { runScript(SPATIAL_INDEX + ".sql", cx, properties); } finally { cx.close(); } } catch (SQLException ex) { throw new IOException(ex); } }