@Override public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) throws SQLException { this.update = type == UPDATE; this.tableIdentifier = new TableLocation(schemaName, tableName).toString(true); if(!dataManager.hasTableEditListener(tableIdentifier)) { try(Statement st = conn.createStatement()) { st.execute("DROP TRIGGER IF EXISTS "+triggerName); } throw new SQLException("This trigger does not exists"); } else { // Fetch primary key column pkColumn = JDBCUtilities.getIntegerPrimaryKey(conn, tableIdentifier); } }
@Override protected Object doInBackground() throws SQLException { try(Connection connection = dataSource.getConnection()) { boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); int columnId = JDBCUtilities.getIntegerPrimaryKey(connection, tableName); if(columnId > 0) { String pkColumnName = JDBCUtilities.getFieldName(connection.getMetaData(), tableName, columnId); // A deletion batch is an ordered set of pk values to remove (a complete serial of integer without holes) List<Long> deletionBatch = rowPkToDelete.getValueRanges(); ProgressMonitor pmBatch = getProgressMonitor().startTask(deletionBatch.size() / 2); try(PreparedStatement st = connection.prepareStatement( String.format("DELETE FROM %s WHERE %s >= ? AND %s <= ?", TableLocation.parse(tableName).toString(isH2),pkColumnName, pkColumnName))) { for (int idDelBatch = 0; idDelBatch < deletionBatch.size() - 1; idDelBatch += 2) { long startBatch = deletionBatch.get(idDelBatch); long endBatch = deletionBatch.get(idDelBatch + 1); st.setLong(1, startBatch); st.setLong(2, endBatch); st.execute(); pmBatch.endTask(); } } } } return null; }
public static boolean isActiveLayerEditable(MapContext vc) throws SQLException { // A primary key must be defined in the table ILayer activeLayer = vc.getActiveLayer(); if(activeLayer == null) { return false; } else { String table = activeLayer.getTableReference(); if(table!=null && !table.isEmpty()) { try(Connection connection = vc.getDataManager().getDataSource().getConnection()) { int pk = JDBCUtilities.getIntegerPrimaryKey(connection, activeLayer.getTableReference()); return pk>0; } } else { return false; } } }
try (Statement st = connection.createStatement()) { DatabaseMetaData meta = connection.getMetaData(); int pkId = JDBCUtilities.getIntegerPrimaryKey(connection, tableLocation.toString()); if (pkId > 0) {
try (Statement st = connection.createStatement()) { DatabaseMetaData meta = connection.getMetaData(); int pkId = JDBCUtilities.getIntegerPrimaryKey(connection, tableLocation.toString()); if (pkId > 0) {
listener); try { int pkIndex = JDBCUtilities.getIntegerPrimaryKey(connection, tableLocation.toString()); if (pkIndex > 0) { ProgressMonitor jobProgress = progressMonitor.startTask(2);
COORDS_TABLE = TableLocation.parse(System.currentTimeMillis()+"_COORDS", isH2).toString(); final int pkIndex = JDBCUtilities.getIntegerPrimaryKey(connection, tableName.getTable()); if (pkIndex == 0) { throw new IllegalStateException("Table " + tableName.getTable()
COORDS_TABLE = TableLocation.parse(System.currentTimeMillis()+"_COORDS", isH2).toString(); final int pkIndex = JDBCUtilities.getIntegerPrimaryKey(connection, tableName.getTable()); if (pkIndex == 0) { throw new IllegalStateException("Table " + tableName.getTable()
private JComponent makeFilterManager() { JPanel filterComp = filterManager.makeFilterPanel(false); filterManager.setUserCanRemoveFilter(false); FieldsContainsFilterFactory factory = new FieldsContainsFilterFactory(table); filterManager.registerFilterFactory(factory); // SQL Filter is only available if there is a primary key try(Connection connection = dataSource.getConnection()) { int idPk = JDBCUtilities.getIntegerPrimaryKey(connection, tableEditableElement.getTableReference()); if(idPk > 0) { filterManager.registerFilterFactory(new WhereSQLFilterFactory()); } } catch (SQLException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } filterManager.addFilter(factory.getDefaultFilterValue()); filterManager.getEventFilterChange().addListener(this, EventHandler.create(FilterFactoryManager.FilterChangeListener.class, this, "onApplySelectionFilter")); return filterComp; }
final int pkIndex = JDBCUtilities.getIntegerPrimaryKey(connection, tableName.getTable()); if (pkIndex == 0) { throw new IllegalStateException("Table " + tableName.getTable()
progressMonitor.addPropertyChangeListener(ProgressMonitor.PROP_CANCEL,listener); try { int pkIndex = JDBCUtilities.getIntegerPrimaryKey(connection, tableLocation.toString()); DatabaseMetaData meta = connection.getMetaData(); String pkFieldName = TableLocation.quoteIdentifier(JDBCUtilities.getFieldName(meta, table, pkIndex));