public void putAll(TablesById tablesByTableId) { if(tableIdCaseInsensitive) { tablesByTableId.values.entrySet() .forEach(e -> put(e.getKey().toLowercase(), e.getValue())); } else { values.putAll(tablesByTableId.values); } }
/** * Add or update the definition for the identified table. * * @param tableId the identifier of the table * @param changer the function that accepts the current {@link Table} and returns either the same or an updated * {@link Table}; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table updateTable(TableId tableId, Function<Table, Table> changer) { return lock.write(() -> { TableImpl existing = tablesByTableId.get(tableId); Table updated = changer.apply(existing); if (updated != existing) { tablesByTableId.put(tableId, new TableImpl(tableId, updated.columns(), updated.primaryKeyColumnNames(), updated.defaultCharsetName())); } changes.add(tableId); return existing; }); }
public void putAll(TablesById tablesByTableId) { if(tableIdCaseInsensitive) { tablesByTableId.values.entrySet() .forEach(e -> put(e.getKey().toLowercase(), e.getValue())); } else { values.putAll(tablesByTableId.values); } }
/** * Add or update the definition for the identified table. * * @param tableId the identifier of the table * @param columnDefs the list of column definitions; may not be null or empty * @param primaryKeyColumnNames the list of the column names that make up the primary key; may be null or empty * @param defaultCharsetName the name of the character set that should be used by default * @return the previous table definition, or null if there was no prior table definition */ public Table overwriteTable(TableId tableId, List<Column> columnDefs, List<String> primaryKeyColumnNames, String defaultCharsetName) { return lock.write(() -> { TableImpl updated = new TableImpl(tableId, columnDefs, primaryKeyColumnNames, defaultCharsetName); TableImpl existing = tablesByTableId.get(tableId); if ( existing == null || !existing.equals(updated) ) { // Our understanding of the table has changed ... changes.add(tableId); tablesByTableId.put(tableId,updated); } return tablesByTableId.get(tableId); }); }
/** * Rename an existing table. * * @param existingTableId the identifier of the existing table to be renamed; may not be null * @param newTableId the new identifier for the table; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table renameTable(TableId existingTableId, TableId newTableId) { return lock.write(() -> { Table existing = forTable(existingTableId); if (existing == null) return null; tablesByTableId.remove(existing.id()); TableImpl updated = new TableImpl(newTableId, existing.columns(), existing.primaryKeyColumnNames(), existing.defaultCharsetName()); try { return tablesByTableId.put(updated.id(), updated); } finally { changes.add(existingTableId); changes.add(updated.id()); } }); }
/** * Add or update the definition for the identified table. * * @param tableId the identifier of the table * @param changer the function that accepts the current {@link Table} and returns either the same or an updated * {@link Table}; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table updateTable(TableId tableId, Function<Table, Table> changer) { return lock.write(() -> { TableImpl existing = tablesByTableId.get(tableId); Table updated = changer.apply(existing); if (updated != existing) { tablesByTableId.put(tableId, new TableImpl(tableId, updated.columns(), updated.primaryKeyColumnNames(), updated.defaultCharsetName())); } changes.add(tableId); return existing; }); }
/** * Add or update the definition for the identified table. * * @param table the definition for the table; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table overwriteTable(Table table) { return lock.write(() -> { TableImpl updated = new TableImpl(table); try { return tablesByTableId.put(updated.id(), updated); } finally { changes.add(updated.id()); } }); }
/** * Add or update the definition for the identified table. * * @param tableId the identifier of the table * @param columnDefs the list of column definitions; may not be null or empty * @param primaryKeyColumnNames the list of the column names that make up the primary key; may be null or empty * @param defaultCharsetName the name of the character set that should be used by default * @return the previous table definition, or null if there was no prior table definition */ public Table overwriteTable(TableId tableId, List<Column> columnDefs, List<String> primaryKeyColumnNames, String defaultCharsetName) { return lock.write(() -> { TableImpl updated = new TableImpl(tableId, columnDefs, primaryKeyColumnNames, defaultCharsetName); TableImpl existing = tablesByTableId.get(tableId); if ( existing == null || !existing.equals(updated) ) { // Our understanding of the table has changed ... changes.add(tableId); tablesByTableId.put(tableId,updated); } return tablesByTableId.get(tableId); }); }
/** * Rename an existing table. * * @param existingTableId the identifier of the existing table to be renamed; may not be null * @param newTableId the new identifier for the table; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table renameTable(TableId existingTableId, TableId newTableId) { return lock.write(() -> { Table existing = forTable(existingTableId); if (existing == null) return null; tablesByTableId.remove(existing.id()); TableImpl updated = new TableImpl(newTableId, existing.columns(), existing.primaryKeyColumnNames(), existing.defaultCharsetName()); try { return tablesByTableId.put(updated.id(), updated); } finally { changes.add(existingTableId); changes.add(updated.id()); } }); }
/** * Add or update the definition for the identified table. * * @param table the definition for the table; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table overwriteTable(Table table) { return lock.write(() -> { TableImpl updated = new TableImpl(table); try { return tablesByTableId.put(updated.id(), updated); } finally { changes.add(updated.id()); } }); }