/** * Check if one table already exists * * @param connection * @param isH2 * @param requestedTable * @param osmTableName * @throws SQLException */ private void checkOSMTables(Connection connection, boolean isH2, TableLocation requestedTable, String osmTableName) throws SQLException { String[] omsTables = new String[]{OSMTablesFactory.TAG, OSMTablesFactory.NODE, OSMTablesFactory.NODE_TAG, OSMTablesFactory.WAY, OSMTablesFactory.WAY_NODE, OSMTablesFactory.WAY_TAG, OSMTablesFactory.RELATION, OSMTablesFactory.RELATION_TAG, OSMTablesFactory.NODE_MEMBER, OSMTablesFactory.WAY_MEMBER, OSMTablesFactory.RELATION_MEMBER}; for (String omsTableSuffix : omsTables) { String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2); if (JDBCUtilities.tableExists(connection, osmTable)) { throw new SQLException("The table " + osmTable + " already exists."); } } }
/** * Check if one table already exists * * @param connection * @param isH2 * @param requestedTable * @param osmTableName * @throws SQLException */ private void checkOSMTables(Connection connection, boolean isH2, TableLocation requestedTable, String osmTableName) throws SQLException { String[] omsTables = new String[]{TAG, NODE, NODE_TAG, WAY, WAY_NODE, WAY_TAG, RELATION, RELATION_TAG, NODE_MEMBER, WAY_MEMBER, RELATION_MEMBER}; for (String omsTableSuffix : omsTables) { String osmTable = caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2); if (JDBCUtilities.tableExists(connection, osmTable)) { throw new SQLException("The table " + osmTable + " already exists."); } } }
/** * Check if one table already exists * * @param connection * @param isH2 * @param requestedTable * @param osmTableName * @throws SQLException */ private void checkOSMTables(Connection connection, boolean isH2, TableLocation requestedTable, String osmTableName) throws SQLException { String[] omsTables = new String[]{OSMTablesFactory.TAG, OSMTablesFactory.NODE, OSMTablesFactory.NODE_TAG, OSMTablesFactory.WAY, OSMTablesFactory.WAY_NODE, OSMTablesFactory.WAY_TAG, OSMTablesFactory.RELATION, OSMTablesFactory.RELATION_TAG, OSMTablesFactory.NODE_MEMBER, OSMTablesFactory.WAY_MEMBER, OSMTablesFactory.RELATION_MEMBER}; for (String omsTableSuffix : omsTables) { String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2); if (JDBCUtilities.tableExists(connection, osmTable)) { throw new SQLException("The table " + osmTable + " already exists."); } } }
/** * Check if one table already exists * * @param connection * @param isH2 * @param requestedTable * @param osmTableName * @throws SQLException */ private void checkOSMTables(Connection connection, boolean isH2, TableLocation requestedTable, String osmTableName) throws SQLException { String[] omsTables = new String[]{OSMTablesFactory.TAG, OSMTablesFactory.NODE, OSMTablesFactory.NODE_TAG, OSMTablesFactory.WAY, OSMTablesFactory.WAY_NODE, OSMTablesFactory.WAY_TAG, OSMTablesFactory.RELATION, OSMTablesFactory.RELATION_TAG, OSMTablesFactory.NODE_MEMBER, OSMTablesFactory.WAY_MEMBER, OSMTablesFactory.RELATION_MEMBER}; for (String omsTableSuffix : omsTables) { String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2); if (JDBCUtilities.tableExists(connection, osmTable)) { throw new SQLException("The table " + osmTable + " already exists."); } } }
@Override public FunctionTracker addingService(ServiceReference<DataSource> dataSourceServiceReference) { DataSource dataSource = bundleContext.getService(dataSourceServiceReference); try { try (Connection connection = dataSource.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); // If not H2 or in client mode, does not register H2 spatial functions. if (!JDBCUtilities.H2_DRIVER_NAME.equals(meta.getDriverName()) || (meta.getURL() != null && meta.getURL().toLowerCase().startsWith("jdbc:h2:tcp://"))) { return null; } // Check if the database has been properly initialised by the DataSource service provider if (!JDBCUtilities.tableExists(connection, "PUBLIC.GEOMETRY_COLUMNS")) { return null; } } } catch (SQLException ex) { System.err.print(ex.toString()); } FunctionTracker functionTracker = new FunctionTracker(dataSource,bundleContext); functionTracker.open(); return functionTracker; }
@Override public FunctionTracker addingService(ServiceReference<DataSource> dataSourceServiceReference) { DataSource dataSource = bundleContext.getService(dataSourceServiceReference); try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData meta = connection.getMetaData(); // If not H2 or in client mode, does not register H2 spatial functions. if(!JDBCUtilities.H2_DRIVER_NAME.equals(meta.getDriverName()) || (meta.getURL() != null && meta.getURL().toLowerCase().startsWith("jdbc:h2:tcp://"))) { return null; } // Check if the database has been properly initialised by the DataSource service provider if(!JDBCUtilities.tableExists(connection, "PUBLIC.GEOMETRY_COLUMNS")) { return null; } } finally { connection.close(); } } catch (SQLException ex) { System.err.print(ex.toString()); } try { FunctionTracker functionTracker = new FunctionTracker(dataSource,bundleContext); functionTracker.open(); return functionTracker; } catch (SQLException ex) { throw new RuntimeException(ex); } }
Statement st = connection.createStatement()) { if (JDBCUtilities.isH2DataBase(connection.getMetaData()) && !JDBCUtilities.tableExists(connection, "PUBLIC.GEOMETRY_COLUMNS")) { st.execute("CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR\n" + " \"org.h2gis.functions.factory.H2GISFunctions.load\";\n" +
if (!tableExists(connection, tableReference)) { throw new SQLException("Table " + tableReference + " not found.");
if (!tableExists(connection, tableReference)) { throw new SQLException("Table " + tableReference + " not found.");
if (!tableExists(connection, tableReference)) { throw new SQLException("Table " + tableReference + " not found.");
+ "\n" + I18N.tr(newNameMessage)); else if (JDBCUtilities.tableExists(connection, newName)) { message.setText(I18N.tr("A datasource with that name already exists.") + "\n" + I18N.tr(newNameMessage));
+ "\n" + I18N.tr(newNameMessage)); else if (JDBCUtilities.tableExists(connection, newName)) { message.setText(I18N.tr("A datasource with that name already exists.") + "\n" + I18N.tr(newNameMessage));
if (JDBCUtilities.tableExists(connection, wptTableName)) { throw new SQLException("The table " + wptTableName + " already exists."); if (JDBCUtilities.tableExists(connection, routeTableName)) { throw new SQLException("The table " + routeTableName + " already exists."); if (JDBCUtilities.tableExists(connection, routePointsTableName)) { throw new SQLException("The table " + routePointsTableName + " already exists."); && gpxPreparser.getTotalTrkpt() > 0) { String trackTableName = TableUtilities.caseIdentifier(requestedTable, table + GPXTablesFactory.TRACK, isH2); if (JDBCUtilities.tableExists(connection, trackTableName)) { throw new SQLException("The table " + trackTableName + " already exists."); if (JDBCUtilities.tableExists(connection, trackSegmentsTableName)) { throw new SQLException("The table " + trackSegmentsTableName + " already exists."); if (JDBCUtilities.tableExists(connection, trackPointsTableName)) { throw new SQLException("The table " + trackPointsTableName + " already exists.");
@Override public Envelope getEnvelope() { // TODO reset envelope when the Table is updated if(envelope.isNull()) { try { if(isStream()) { return stream.getEnvelope(); } else { try(Connection connection = dataManager.getDataSource().getConnection()) { // Check if the table exists if(!JDBCUtilities.tableExists(connection, tableReference)) { LOGGER.info(I18N.tr("Cannot draw {0} the table does not exists", tableReference)); } envelope = SFSUtilities.getTableEnvelope(connection, TableLocation.parse(tableReference),""); } catch (SQLException ex) { LOGGER.error(I18N.tr("Cannot compute layer envelope:\n")+ex.getLocalizedMessage()); } } } catch (Exception ex) { LOGGER.error(I18N.tr("Cannot compute layer envelope:\n")+ex.getLocalizedMessage()); return new Envelope(); } } return envelope; }
else if (JDBCUtilities.tableExists(connection, nodesName.getTable()) || JDBCUtilities.tableExists(connection, edgesName.getTable())) { throw new IllegalArgumentException(ALREADY_RUN_ERROR + tableName.getTable());
else if (JDBCUtilities.tableExists(connection, nodesName.getTable()) || JDBCUtilities.tableExists(connection, edgesName.getTable())) { throw new IllegalArgumentException(ALREADY_RUN_ERROR + tableName.getTable());
else if (JDBCUtilities.tableExists(connection, nodesName.getTable()) || JDBCUtilities.tableExists(connection, edgesName.getTable())) { throw new IllegalArgumentException(ALREADY_RUN_ERROR + tableName.getTable());
/** * Returns a new unique name when registering a {@link javax.sql.DataSource}. * @param table Table identifier * @param meta JDBC meta data * @param baseName Destination table additional name, may be empty * * @return New unique name */ public static String getNewUniqueName(String table, DatabaseMetaData meta,String baseName) throws SQLException { TableLocation uniqueName; TableLocation tableName = TableLocation.parse(table); int index = 0; if(!baseName.isEmpty()) { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+baseName); } else { uniqueName = tableName; } while (JDBCUtilities.tableExists(meta.getConnection(), uniqueName.toString())) { index++; if(!baseName.isEmpty()) { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+baseName+"_"+index); } else { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+index); } } return uniqueName.toString(); }
/** * Returns a new unique name when registering a {@link javax.sql.DataSource}. * @param table Table identifier * @param meta JDBC meta data * @param baseName Destination table additional name, may be empty * * @return New unique name */ public static String getNewUniqueName(String table, DatabaseMetaData meta,String baseName) throws SQLException { TableLocation uniqueName; TableLocation tableName = TableLocation.parse(table); int index = 0; if(!baseName.isEmpty()) { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+baseName); } else { uniqueName = tableName; } while (JDBCUtilities.tableExists(meta.getConnection(), uniqueName.toString())) { index++; if(!baseName.isEmpty()) { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+baseName+"_"+index); } else { uniqueName = new TableLocation(tableName.getCatalog(),tableName.getSchema(), tableName.getTable()+"_"+index); } } return uniqueName.toString(); }
/** * Recursively add property listeners to the provided node * @param node */ private void addPropertyListeners(TreeNode node) { if(node instanceof TocTreeNodeLayer) { ILayer layer =((TocTreeNodeLayer) node).getLayer(); if(!layer.acceptsChilds()) { layer.addPropertyChangeListener(Layer.PROP_STYLES,tocStyleListListener); try(Connection connection = mapContext.getDataManager().getDataSource().getConnection()) { if (!layer.getTableReference().isEmpty() && JDBCUtilities.tableExists(connection,layer.getTableReference())) { mapContext.getDataManager().addTableEditListener(layer.getTableReference(), this); } } catch (SQLException ex) { // Ignore } for(Style st : layer.getStyles()) { addPropertyListeners(new TocTreeNodeStyle(st)); } } else { for(ILayer subLayer : layer.getChildren()) { addPropertyListeners(new TocTreeNodeLayer(subLayer)); } } } else if(node instanceof TocTreeNodeStyle) { Style st = ((TocTreeNodeStyle) node).getStyle(); st.addPropertyChangeListener(tocStyleListener); } }