private static boolean isLocalH2DataBase(DatabaseMetaData meta) throws SQLException { return JDBCUtilities.isH2DataBase(meta) && meta.getURL().startsWith("jdbc:h2:") && !meta.getURL().startsWith("jdbc:h2:tcp:/"); }
private static boolean isLocalH2DataBase(DatabaseMetaData meta) throws SQLException { return JDBCUtilities.isH2DataBase(meta) && meta.getURL().startsWith("jdbc:h2:") && !meta.getURL().startsWith("jdbc:h2:tcp:/"); }
@Reference public void setDataSource(DataSource dataSource) throws SQLException { this.dataSource = dataSource; try (Connection connection = dataSource.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); isH2 = JDBCUtilities.isH2DataBase(meta); isLocalH2Table = connection.getMetaData().getURL().startsWith("jdbc:h2:") && !connection.getMetaData().getURL().startsWith("jdbc:h2:tcp:/"); } }
@Reference public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; try (Connection connection = dataSource.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); isH2 = JDBCUtilities.isH2DataBase(meta); isLocalH2Table = connection.getMetaData().getURL().startsWith("jdbc:h2:") && !connection.getMetaData().getURL().startsWith("jdbc:h2:tcp:/"); } catch (SQLException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } }
/** * Convert an input table String to a TableLocation * * @param connection Connection * @param inputTable Input table * @return corresponding TableLocation * @throws SQLException */ public static TableLocation parseInputTable(Connection connection, String inputTable) throws SQLException { return TableLocation.parse(inputTable, JDBCUtilities.isH2DataBase(connection.getMetaData())); }
/** * Convert an input table String to a TableLocation * * @param connection Connection * @param inputTable Input table * @return corresponding TableLocation * @throws SQLException */ public static TableLocation parseInputTable(Connection connection, String inputTable) throws SQLException { return TableLocation.parse(inputTable, JDBCUtilities.isH2DataBase(connection.getMetaData())); }
@Deactivate public void deactivate() throws SQLException { // Wait for H2 close try(Connection connection = getConnection(); Statement st = connection.createStatement()) { DatabaseMetaData metaData = connection.getMetaData(); if(JDBCUtilities.isH2DataBase(metaData) && !metaData.getURL().contains("tcp")) { st.execute("SHUTDOWN"); } } }
/** * Convert an input table String to a TableLocation * * @param connection Connection * @param inputTable Input table * * @return corresponding TableLocation * * @throws SQLException */ public static TableLocation parseInputTable(Connection connection, String inputTable) throws SQLException { return TableLocation.parse(inputTable, JDBCUtilities.isH2DataBase(connection.getMetaData())); }
@Override public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress, boolean deleteTables) throws SQLException, IOException { if(deleteTables) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation requestedTable = TableLocation.parse(tableReference, isH2); String table = requestedTable.getTable(); Statement stmt = connection.createStatement(); stmt.execute("DROP TABLE IF EXISTS " + table); stmt.close(); } importFile(connection, tableReference, fileName, progress); }
@Override public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress, boolean deleteTables) throws SQLException, IOException { if(deleteTables) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation requestedTable = TableLocation.parse(tableReference, isH2); String table = requestedTable.getTable(); Statement stmt = connection.createStatement(); stmt.execute("DROP TABLE IF EXISTS " + table); stmt.close(); } importFile(connection, tableReference, fileName, progress); }
@Override public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress, boolean deleteTables) throws SQLException, IOException { if(deleteTables) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation requestedTable = TableLocation.parse(tableReference, isH2); String table = requestedTable.getTable(); Statement stmt = connection.createStatement(); stmt.execute("DROP TABLE IF EXISTS " + table); stmt.close(); } importFile(connection, tableReference, fileName, progress); } }
public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(ISO_FIELD_NAME, Types.INTEGER,10,0); return rs; } }
/** * Explode Geometry Collection into multiple geometries * @param connection * @param tableName the name of the input table * @param fieldName the name of geometry field. If null the first geometry column is used. * @return * @throws java.sql.SQLException */ public static ResultSet explode(Connection connection, String tableName, String fieldName) throws SQLException { ExplodeResultSet rowSource = new ExplodeResultSet(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())).toString(),fieldName); return rowSource.getResultSet(); }
/** * Return the exploded geometries as multiple rows * @return * @throws SQLException */ public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(EXPLODE_FIELD, Types.INTEGER,10,0); return rs; } }
public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(ISO_FIELD_NAME, Types.INTEGER,10,0); return rs; } }
public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(ISO_FIELD_NAME, Types.INTEGER,10,0); return rs; } }
/** * Return the exploded geometries as multiple rows * @return * @throws SQLException */ public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(EXPLODE_FIELD, Types.INTEGER,10,0); return rs; } }
/** * Return the exploded geometries as multiple rows * @return * @throws SQLException */ public ResultSet getResultSet() throws SQLException { SimpleResultSet rs = new SimpleResultSet(this); // Feed with fields TableUtilities.copyFields(connection, rs, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); rs.addColumn(EXPLODE_FIELD, Types.INTEGER,10,0); return rs; } }
/** * Explode Geometry Collection into multiple geometries * @param connection * @param tableName the name of the input table * @param fieldName the name of geometry field. If null the first geometry column is used. * @return * @throws java.sql.SQLException */ public static ResultSet explode(Connection connection, String tableName, String fieldName) throws SQLException { ExplodeResultSet rowSource = new ExplodeResultSet(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())).toString(),fieldName); return rowSource.getResultSet(); }
/** * Explode Geometry Collection into multiple geometries * @param connection * @param tableName the name of the input table * @param fieldName the name of geometry field. If null the first geometry column is used. * @return * @throws java.sql.SQLException */ public static ResultSet explode(Connection connection, String tableName, String fieldName) throws SQLException { ExplodeResultSet rowSource = new ExplodeResultSet(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())).toString(),fieldName); return rowSource.getResultSet(); }