@Override public void close() throws MetadataStoreException { JDBCUtils.close( rs, stmt, conn, LOG ); }
@Override public void close() { LOG.debug( "Closing JDBC ResultSet, Statement and Connection" ); JDBCUtils.close( rs, stmt, conn, LOG ); }
@Override public void createDB( Connection adminConn, String dbName ) throws SQLException { String sql = "CREATE DATABASE \"" + dbName + "\" WITH template=template_postgis"; Statement stmt = null; try { stmt = adminConn.createStatement(); stmt.executeUpdate( sql ); } finally { JDBCUtils.close( null, stmt, null, LOG ); } }
@Override public void dropDB( Connection adminConn, String dbName ) throws SQLException { String sql = "DROP DATABASE \"" + dbName + "\""; Statement stmt = null; try { stmt = adminConn.createStatement(); stmt.executeUpdate( sql ); } finally { JDBCUtils.close( null, stmt, null, LOG ); } }
@Override public void rollback() throws MetadataStoreException { LOG.debug( "Performing rollback of transaction." ); try { conn.rollback(); } catch ( SQLException e ) { String msg = "Rollback failed: " + e.getMessage(); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
@Override public void commit() throws MetadataStoreException { LOG.debug( "Performing commit of transaction." ); try { conn.commit(); } catch ( SQLException e ) { String msg = "Commit failed: " + e.getMessage(); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
private List<RasterLevel> fetchScaleLevels( Connection conn ) throws SQLException { List<RasterLevel> scaleLevels = new ArrayList<RasterLevel>(); Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery( "SELECT id, level, minscale, maxscale FROM " + levelTableName + " ORDER BY minscale" ); while ( rs.next() ) { int id = rs.getInt( 1 ); int level = rs.getInt( 2 ); double minScale = rs.getDouble( 3 ); double maxScale = rs.getDouble( 4 ); RasterLevel o = new RasterLevel( id, level, minScale, maxScale ); scaleLevels.add( o ); } return scaleLevels; } finally { JDBCUtils.close( rs ); JDBCUtils.close( stmt ); } }
private RasterLevel[] fetchScaleLevels( Connection conn ) throws SQLException { List<RasterLevel> scaleLevels = new ArrayList<RasterLevel>(); Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery( "SELECT id, level, minscale, maxscale FROM " + levelTableName + " ORDER BY minscale" ); while ( rs.next() ) { int id = rs.getInt( 1 ); int level = rs.getInt( 2 ); double minScale = rs.getDouble( 3 ); double maxScale = rs.getDouble( 4 ); RasterLevel o = new RasterLevel( id, level, minScale, maxScale ); scaleLevels.add( o ); } return scaleLevels.toArray( new RasterLevel[scaleLevels.size()] ); } finally { JDBCUtils.close( rs ); JDBCUtils.close( stmt ); } }
private void deleteExistingRows( Connection connection, int operatesOnId, String databaseTable ) throws MetadataStoreException { PreparedStatement stmt = null; StringWriter sqlStatement = new StringWriter(); try { sqlStatement.append( "DELETE FROM " + databaseTable + " WHERE " + fk_main + " = ?" ); stmt = connection.prepareStatement( sqlStatement.toString() ); stmt.setInt( 1, operatesOnId ); LOG.debug( stmt.toString() ); stmt.executeUpdate(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_SQL", sqlStatement.toString(), e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { close( null, stmt, null, LOG ); } }
@Override public void commit() throws MetadataStoreException { LOG.debug( Messages.getMessage( "INFO_TA_COMMIT" ) ); try { conn.commit(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_TA_COMMIT", e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
@Override public void rollback() throws MetadataStoreException { LOG.debug( Messages.getMessage( "INFO_TA_ROLLBACK" ) ); try { conn.rollback(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_TA_ROLLBACK", e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
@Override public void release( String fid ) throws FeatureStoreException { synchronized ( manager ) { if ( isLocked( fid ) ) { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = connection.getConnection(); stmt = conn.prepareStatement( "DELETE FROM LOCKED_FIDS WHERE FID=?" ); stmt.setString( 1, fid ); stmt.executeUpdate(); conn.commit(); --numLocked; } catch ( SQLException e ) { String msg = "Could not release locked feature: " + e.getMessage(); LOG.debug( msg, e ); throw new RuntimeException( msg, e ); } finally { close( rs, stmt, conn, LOG ); } } } }
private void importDbf( StringBuilder create ) throws IOException { Connection conn = null; PreparedStatement stmt = null; try { conn = connProvider.getConnection(); stmt = conn.prepareStatement( create.toString() ); stmt.executeUpdate(); stmt.close(); createIndexes( conn ); conn.setAutoCommit( false ); Iterator<Pair<float[], Long>> iter = envelopes.first.iterator(); for ( int i = 0; i < dbf.size(); ++i ) { insertRow( conn, iter, i ); } conn.commit(); } catch ( SQLException e ) { e.printStackTrace(); } finally { JDBCUtils.close( stmt ); JDBCUtils.close( conn ); } }
/** * @param connection * @param info * @param objectType * @throws SQLException */ private void updateBackendInfo( Connection connection, ModelBackendInfo info, Type objectType ) throws SQLException { PreparedStatement ps = null; try { ps = connection.prepareStatement( UP_INFO ); ps.setInt( 1, info.getOrdinateCount() ); ps.setInt( 2, info.getTextureOrdinateCount() ); ps.setString( 3, objectType.getModelTypeName() ); ps.execute(); } finally { JDBCUtils.close( ps ); } }
@Override public SQLDialect createDialect( final Connection conn ) { Statement stmt = null; ResultSet rs = null; String version = null; try { version = determinePostGISVersion( conn, LOG ); } catch ( Exception e ) { LOG.trace( e.getMessage(), e ); throw new ResourceInitException( e.getMessage(), e ); } finally { close( rs, stmt, null, LOG ); } return new PostGISDialect( version ); }
private int getSequenceNextVal( String sequenceName ) throws FeatureStoreException { String sql = mgr.getDialect().getSelectSequenceNextVal( sequenceName ); Statement stmt = null; ResultSet rs = null; try { stmt = mgr.getConnection().createStatement(); LOG.debug( "Determing feature ID from db sequence: " + sql ); rs = stmt.executeQuery( sql ); if ( rs.next() ) { return rs.getInt( 1 ); } else { String msg = "Error determining ID from db sequence. No value returned for: " + sql; throw new FeatureStoreException( msg ); } } catch ( SQLException e ) { String msg = "Error determining ID from db sequence. No value returned for: " + sql; throw new FeatureStoreException( msg, e ); } finally { JDBCUtils.close( rs, stmt, null, LOG ); } }
/** * Creates a new {@link MappedSchemaBuilderTableOld} instance. * * @param jdbcConnId * identifier of JDBC connection, must not be <code>null</code> (used to determine columns / types) * @param ftDecls * JAXB feature type declarations, must not be <code>null</code> * @throws SQLException * @throws FeatureStoreException */ public MappedSchemaBuilderTableOld( String jdbcConnId, List<FeatureTypeJAXB> ftDecls, SQLDialect dialect, boolean deleteCascadingByDB, Workspace workspace ) throws SQLException, FeatureStoreException { this.dialect = dialect; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, jdbcConnId ); conn = prov.getConnection(); try { for ( FeatureTypeJAXB ftDecl : ftDecls ) { process( ftDecl ); } } finally { JDBCUtils.close( conn ); } this.deleteCascadingByDB = deleteCascadingByDB; }
/** * Creates a new {@link MappedSchemaBuilderTable} instance. * * @param jdbcConnId * identifier of JDBC connection, must not be <code>null</code> (used to determine columns / types) * @param ftDecls * JAXB feature type declarations, must not be <code>null</code> * @throws SQLException * @throws FeatureStoreException */ public MappedSchemaBuilderTable( String jdbcConnId, List<FeatureTypeMappingJAXB> ftDecls, SQLDialect dialect, boolean deleteCascadingByDB, Workspace workspace ) throws SQLException, FeatureStoreException { this.dialect = dialect; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, jdbcConnId ); conn = prov.getConnection(); try { for ( FeatureTypeMappingJAXB ftDecl : ftDecls ) { process( ftDecl ); } } finally { JDBCUtils.close( conn ); } this.deleteCascadingByDB = deleteCascadingByDB; }
@Override public ConnectionProvider build() { final DataSource ds = initializeDataSourceInstance(); final Method destroyMethod = getDestroyMethod( ds, config.getDataSource().getDestroyMethod() ); final Connection conn = checkConnectivity( ds ); final SQLDialect dialect = SqlDialects.lookupSqlDialect( conn, workspace.getModuleClassLoader() ); close( conn ); return new DataSourceConnectionProvider( metadata, ds, dialect, destroyMethod ); }