FeatureEntry e = new FeatureEntry(); e.init(entry); e.setTableName(schema.getTypeName()); if (e.getGeometryColumn() != null) { if (schema.getDescriptor(e.getGeometryColumn()) == null) { throw new IllegalArgumentException( format( "Geometry column %s does not exist in schema", e.getGeometryColumn())); e.setGeometryColumn(findGeometryColumn(schema)); if (e.getIdentifier() == null) { e.setIdentifier(schema.getTypeName()); if (e.getDescription() == null) { e.setDescription(e.getIdentifier()); if (e.getBounds() == null) { throw new IllegalArgumentException("Entry must have bounds"); if (e.getSrid() == null) { try { e.setSrid(findSRID(schema)); } catch (Exception ex) { throw new IllegalArgumentException(ex);
void addGeometryColumnsEntry(FeatureEntry e) throws IOException { if (e.getGeometryColumn() == null || e.getGeometryColumn().isEmpty()) { return; PreparedStatement ps = prepare(cx, sql) .set(e.getTableName()) .set(e.getGeometryColumn()) .set( e.getGeometryType() != null ? e.getGeometryType().getName() : null) .set(e.getSrid()) .set(e.isZ()) .set(e.isM()) .log(Level.FINE) .statement();
@Override FeatureEntry copy() { FeatureEntry e = new FeatureEntry(); e.init(this); return e; } }
protected String getSpatialIndexName(FeatureEntry entry) { String spatial_index = "rtree_" + entry.getTableName() + "_" + entry.getGeometryColumn(); return spatial_index; } /**
void init(FeatureEntry e) { super.init(e); setGeometryColumn(e.getGeometryColumn()); setGeometryType(e.getGeometryType()); setZ(e.isZ()); setM(e.isM()); }
fe = new FeatureEntry(); fe.setIdentifier(featureType.getTypeName()); fe.setDescription(featureType.getTypeName()); fe.setTableName(featureType.getTypeName()); fe.setLastChange(new java.util.Date()); fe.setGeometryColumn(gd.getLocalName()); fe.setGeometryType(Geometries.getForBinding((Class) gd.getType().getBinding())); fe.setSrid(epsgCode); if (descr instanceof GeometryDescriptor) { GeometryDescriptor gd1 = (GeometryDescriptor) descr; if (!(gd1.getLocalName()).equals(fe.getGeometryColumn())) { FeatureEntry fe1 = new FeatureEntry(); fe1.init(fe); fe1.setGeometryColumn(gd1.getLocalName()); fe1.setGeometryType( Geometries.getForBinding((Class) gd1.getType().getBinding())); geopkg.addGeometryColumnsEntry(fe1);
FeatureEntry createFeatureEntry(ResultSet rs) throws SQLException, IOException { FeatureEntry e = new FeatureEntry(); initEntry(e, rs); e.setGeometryColumn(rs.getString("column_name")); e.setGeometryType(Geometries.getForName(rs.getString("geometry_type_name"))); e.setZ(rs.getBoolean("z")); e.setM(rs.getBoolean("m")); return e; }
@Override public void postDropTable(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException { super.postDropTable(schemaName, featureType, cx); FeatureEntry fe = (FeatureEntry) featureType.getUserData().get(FeatureEntry.class); if (fe == null) { fe = new FeatureEntry(); fe.setIdentifier(featureType.getTypeName()); fe.setDescription(featureType.getTypeName()); fe.setTableName(featureType.getTypeName()); } GeoPackage geopkg = geopkg(); try { geopkg.deleteGeoPackageContentsEntry(fe); geopkg.deleteGeometryColumnsEntry(fe); } catch (IOException e) { throw new SQLException(e); } }
FeatureEntry e = new FeatureEntry(); e.init(entry); if (e.getBounds() == null) { e.setBounds(collection.getBounds()); entry.init(e);
/** * Returns a writer used to modify or add to the contents of a feature dataset. * * @param entry The feature entry. * @param append Flag controlling whether to modify existing contents, or append to the dataset. * @param filter Filter determining what subset of dataset to modify, only relevant when * <tt>append</tt> set to false. May be <code>null</code> to specify no filter. * @param tx Transaction object, may be <code>null</code> to specify auto commit transaction. */ public SimpleFeatureWriter writer( FeatureEntry entry, boolean append, Filter filter, Transaction tx) throws IOException { DataStore dataStore = dataStore(); FeatureWriter w = append ? dataStore.getFeatureWriterAppend(entry.getTableName(), tx) : dataStore.getFeatureWriter(entry.getTableName(), filter, tx); return Features.simple(w); }
@Override public int getGeometryDimension( String schemaName, String tableName, String columnName, Connection cx) throws SQLException { try { FeatureEntry fe = geopkg().feature(tableName); if (fe != null) { return 2 + (fe.isZ() ? 1 : 0) + (fe.isM() ? 1 : 0); } else { // fallback - shouldn't happen return super.getGeometryDimension(schemaName, tableName, columnName, cx); } } catch (IOException e) { throw new SQLException(e); } }
/** * Create the audit tables for the specified feature type. * * @param geopackage the geopackage to add the tables to * @param mappedPath the feature tree path * @param fe the feature entry to add audit logs too * @param commitId the commit that the exported features came from * @throws SQLException */ private void createAuditLog(final GeoPackage geopackage, final String mappedPath, final FeatureEntry fe, final ObjectId commitId) throws SQLException { info("Creating audit metadata for table '%s'", fe.getIdentifier()); final DataSource dataSource = geopackage.getDataSource(); try (Connection connection = dataSource.getConnection(); GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(connection)) { URI repoURI = context.repository().getLocation(); metadata.init(repoURI); final String auditedTable = fe.getIdentifier(); metadata.createAudit(auditedTable, mappedPath, commitId); } }
public Integer getGeometrySRID( String schemaName, String tableName, String columnName, Connection cx) throws SQLException { try { FeatureEntry fe = geopkg().feature(tableName); return fe != null ? fe.getSrid() : null; } catch (IOException e) { throw new SQLException(e); } }
fe = new FeatureEntry(); fe.setIdentifier(featureType.getTypeName()); fe.setDescription(featureType.getTypeName()); fe.setTableName(featureType.getTypeName()); fe.setLastChange(new java.util.Date()); fe.setGeometryColumn(gd.getLocalName()); fe.setGeometryType(Geometries.getForBinding((Class) gd.getType().getBinding())); fe.setSrid(epsgCode); if (descr instanceof GeometryDescriptor) { GeometryDescriptor gd1 = (GeometryDescriptor) descr; if (!(gd1.getLocalName()).equals(fe.getGeometryColumn())) { FeatureEntry fe1 = new FeatureEntry(); fe1.init(fe); fe1.setGeometryColumn(gd1.getLocalName()); fe1.setGeometryType( Geometries.getForBinding((Class) gd1.getType().getBinding())); geopkg.addGeometryColumnsEntry(fe1);
void init(FeatureEntry e) { super.init(e); setGeometryColumn(e.getGeometryColumn()); setGeometryType(e.getGeometryType()); setZ(e.isZ()); setM(e.isM()); }
FeatureEntry createFeatureEntry(ResultSet rs) throws SQLException, IOException { FeatureEntry e = new FeatureEntry(); initEntry(e, rs); e.setGeometryColumn(rs.getString("column_name")); e.setGeometryType(Geometries.getForName(rs.getString("geometry_type_name"))); e.setZ(rs.getBoolean("z")); e.setM(rs.getBoolean("m")); return e; }
/** * 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); } }
@Override public void postDropTable(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException { super.postDropTable(schemaName, featureType, cx); FeatureEntry fe = (FeatureEntry) featureType.getUserData().get(FeatureEntry.class); if (fe == null) { fe = new FeatureEntry(); fe.setIdentifier(featureType.getTypeName()); fe.setDescription(featureType.getTypeName()); fe.setTableName(featureType.getTypeName()); } GeoPackage geopkg = geopkg(); try { geopkg.deleteGeoPackageContentsEntry(fe); geopkg.deleteGeometryColumnsEntry(fe); } catch (IOException e) { throw new SQLException(e); } }
FeatureEntry e = new FeatureEntry(); e.init(entry); if (e.getBounds() == null) { e.setBounds(collection.getBounds()); entry.init(e);
void deleteGeometryColumnsEntry(FeatureEntry e) throws IOException { String sql = format("DELETE FROM %s WHERE table_name = ?", GEOMETRY_COLUMNS); try { Connection cx = connPool.getConnection(); try { PreparedStatement ps = prepare(cx, sql).set(e.getTableName()).log(Level.FINE).statement(); try { ps.execute(); } finally { close(ps); } } finally { close(cx); } } catch (SQLException ex) { throw new IOException(ex); } }