@Override public FeatureStoreTransaction acquireTransaction() throws FeatureStoreException { SQLFeatureStoreTransaction ta = null; try { final Connection conn = getConnection(); conn.setAutoCommit( false ); ta = new SQLFeatureStoreTransaction( this, conn, getSchema(), inspectors ); transaction.set( ta ); } catch ( SQLException e ) { throw new FeatureStoreException( "Unable to acquire JDBC connection for transaction: " + e.getMessage(), e ); } return ta; }
private int performDeleteRelational( IdFilter filter, Lock lock ) throws FeatureStoreException { checkIfFeaturesAreNotLocked( filter, lock ); int deleted = 0; for ( ResourceId id : filter.getSelectedIds() ) { LOG.debug( "Analyzing id: " + id.getRid() ); IdAnalysis analysis = null; try { analysis = schema.analyzeId( id.getRid() ); LOG.debug( "Analysis: " + analysis ); if ( !schema.getKeyDependencies().getDeleteCascadingByDB() ) { LOG.debug( "Deleting joined rows manually." ); deleteJoinedRows( analysis ); } else { LOG.debug( "Depending on database to delete joined rows automatically." ); } deleted += deleteFeatureRow( analysis ); } catch ( IllegalArgumentException e ) { throw new FeatureStoreException( "Unable to determine feature type for id '" + id + "'." ); } } return deleted; }
private void updateFeatureBlob( final PreparedStatement stmt, final Feature feature ) throws SQLException { LOG.debug( "Updating feature with id '" + feature.getId() + "' (BLOB)" ); final ICRS crs = blobMapping.getCRS(); final byte[] bytes = encodeFeatureBlob( feature, crs ); stmt.setBytes( 1, bytes ); LOG.debug( "Feature blob size: " + bytes.length ); final Geometry bboxGeom = getFeatureEnvelopeAsGeometry( feature ); blobGeomConverter.setParticle( stmt, bboxGeom, 2 ); stmt.setString( 3, feature.getId() ); stmt.execute(); }
private List<String> performUpdateRelational( QName ftName, List<ParsedPropertyReplacement> replacementProps, IdFilter filter ) throws FeatureStoreException, FilterEvaluationException { FeatureTypeMapping ftMapping = schema.getFtMapping( ftName ); FIDMapping fidMapping = ftMapping.getFidMapping(); int updated = 0; PreparedStatement stmt = null; try { String sql = createRelationalUpdateStatement( ftMapping, fidMapping, replacementProps, filter.getSelectedIds() ); if ( sql != null ) { LOG.debug( "Update: " + sql ); stmt = conn.prepareStatement( sql.toString() ); setRelationalUpdateValues( replacementProps, ftMapping, stmt, filter, fidMapping ); int[] updates = stmt.executeBatch(); for ( int noUpdated : updates ) { updated += noUpdated; } } } catch ( SQLException e ) { JDBCUtils.log( e, LOG ); throw new FeatureStoreException( JDBCUtils.getMessage( e ), e ); } finally { JDBCUtils.close( stmt ); } LOG.debug( "Updated {} features.", updated ); return new ArrayList<String>( filter.getMatchingIds() ); }
String newFid = "FEATURE_" + generateNewId(); String oldFid = feature.getId(); if ( oldFid != null ) { String newGid = "GEOMETRY_" + generateNewId(); String oldGid = geometry.getId(); if ( oldGid != null ) { String newFid = "FEATURE_" + generateNewId(); feature.setId( newFid ); fids.add( newFid ); String newGid = "GEOMETRY_" + generateNewId(); geometry.setId( newGid ); gids.add( newGid ); fid = feature.getId(); if ( blobInsertStmt != null ) { insertFeatureBlob( blobInsertStmt, feature );
CompoundMapping cm = (CompoundMapping) particle; for ( Mapping child : cm.getParticles() ) { deleteJoinedRows( child, joinKeyColToValue );
void closeAndDetachTransactionConnection() throws FeatureStoreException { try { transaction.get().getConnection().close(); } catch ( final SQLException e ) { LOG.error( "Error closing connection/removing it from the pool: " + e.getMessage() ); } finally { transaction.remove(); } }
private int performDeleteBlob( IdFilter filter, Lock lock ) throws FeatureStoreException { checkIfFeaturesAreNotLocked( filter, lock ); int deleted = 0; PreparedStatement stmt = null; try { stmt = conn.prepareStatement( "DELETE FROM " + blobMapping.getTable() + " WHERE " + blobMapping.getGMLIdColumn() + "=?" ); for ( ResourceId id : filter.getSelectedIds() ) { stmt.setString( 1, id.getRid() ); stmt.addBatch(); if ( fs.getCache() != null ) { fs.getCache().remove( id.getRid() ); } } int[] deletes = stmt.executeBatch(); for ( int noDeleted : deletes ) { deleted += noDeleted; } } catch ( SQLException e ) { LOG.debug( e.getMessage(), e ); throw new FeatureStoreException( e.getMessage(), e ); } finally { JDBCUtils.close( stmt ); } LOG.debug( "Deleted " + deleted + " features." ); return deleted; }
if ( mapping != null ) { if ( mapping.getJoinedTable() != null && !mapping.getJoinedTable().isEmpty() ) { addRelationallyMappedMultiProperty( replacement, mapping, ftMapping, list ); continue;
joinKeyToValue.put( toColumn, rs.getObject( i++ ) ); deleteJoinedRows( particle, tableJoin, joinKeyToValue ); CompoundMapping cm = (CompoundMapping) particle; for ( Mapping child : cm.getParticles() ) { deleteJoinedRows( child, keyColToValue );
protected Connection getConnection() throws SQLException { if ( isTransactionActive() ) { return transaction.get().getConnection(); } final Connection conn = connProvider.getConnection(); conn.setAutoCommit( readAutoCommit ); return conn; }
stmt.setString( 1, feature.getId() ); stmt.setShort( 2, fs.getFtId( feature.getName() ) ); byte[] bytes = encodeFeatureBlob( feature, crs ); stmt.setBytes( 3, bytes ); LOG.debug( "Feature blob size: " + bytes.length ); Geometry bboxGeom = getFeatureEnvelopeAsGeometry( feature ); blobGeomConverter.setParticle( stmt, bboxGeom, 4 ); stmt.execute();
/** * Deletes the joined rows for the specified feature id. * <p> * Deletes all joined rows and transitive join rows, but stops at joins to subfeature tables. * </p> * * @param fid * feature id, must not be <code>null</code> * @throws FeatureStoreException */ private void deleteJoinedRows( IdAnalysis fid ) throws FeatureStoreException { Map<SQLIdentifier, Object> keyColsToValues = new HashMap<SQLIdentifier, Object>(); FeatureTypeMapping ftMapping = schema.getFtMapping( fid.getFeatureType().getName() ); // add values for feature id columns int i = 0; for ( Pair<SQLIdentifier, BaseType> fidColumns : ftMapping.getFidMapping().getColumns() ) { PrimitiveType pt = new PrimitiveType( fidColumns.second ); PrimitiveValue value = new PrimitiveValue( fid.getIdKernels()[i], pt ); Object sqlValue = SQLValueMangler.internalToSQL( value ); keyColsToValues.put( fidColumns.first, sqlValue ); i++; } // traverse mapping particles for ( Mapping particle : ftMapping.getMappings() ) { deleteJoinedRows( particle, keyColsToValues ); } }