private static String columnId(TableId tableId, String columnName) { return tableId.toString() + "." + columnName; } }
public ChangeTable(TableId sourceTableId, String captureInstance, int changeTableObjectId, Lsn startLsn, Lsn stopLsn) { super(); this.sourceTableId = sourceTableId; this.captureInstance = captureInstance; this.changeTableObjectId = changeTableObjectId; this.startLsn = startLsn; this.stopLsn = stopLsn; this.changeTableId = sourceTableId != null ? new TableId(sourceTableId.catalog(), CDC_SCHEMA, captureInstance + "_CT") : null; }
protected List<String> readPrimaryKeyNames(DatabaseMetaData metadata, TableId id) throws SQLException { final List<String> pkColumnNames = new ArrayList<>(); try (ResultSet rs = metadata.getPrimaryKeys(id.catalog(), id.schema(), id.table())) { while (rs.next()) { String columnName = rs.getString(4); int columnIndex = rs.getInt(5); Collect.set(pkColumnNames, columnIndex - 1, columnName, null); } } return pkColumnNames; }
/** * Create a {@link TableId} from the supplied schema and table names. By default, this method uses the supplied schema name * as the TableId's catalog, which often matches the catalog name in JDBC database metadata. * * @param schemaName the name of the schema; may be null if not specified * @param tableName the name of the table; should not be null * @return the table identifier; never null */ public TableId resolveTableId(String schemaName, String tableName) { return new TableId(schemaName, null, tableName); }
/** * Parse the supplied string, extracting up to the first 3 parts into a TableID. * * @param str the string representation of the table identifier; may not be null * @return the table ID, or null if it could not be parsed */ public static TableId parse(String str) { return parse(str, true); }
/** * Get the default topic selector logic, which uses a '.' delimiter character when needed. * * @param prefix the name of the prefix to be used for all topics; may not be null and must not terminate in the * {@code delimiter} * @param heartbeatPrefix the name of the prefix to be used for all heartbeat topics; may not be null and must not terminate in the * {@code delimiter} * @return the topic selector; never null */ static TopicSelector<TableId> defaultSelector(String prefix, String heartbeatPrefix) { return TopicSelector.defaultSelector(prefix, heartbeatPrefix, ".", (t, pref, delimiter) -> String.join(delimiter, pref, t.catalog(), t.table())); } }
private Predicate<TableId> buildStartingFromDbFilter(Predicate<String> dbFilter, Predicate<String> schemaFilter, Predicate<TableId> tableFilter) { assert dbFilter != null; if (schemaFilter != null) { if (tableFilter != null) { return (id) -> dbFilter.test(id.catalog()) && schemaFilter.test(id.schema()) && tableFilter.test(id); } else { return (id) -> schemaFilter.test(id.schema()); } } else if (tableFilter != null) { return (id) -> dbFilter.test(id.catalog()) && tableFilter.test(id); } else { return (id) -> dbFilter.test(id.catalog()); } } }
/** * Get the name of the table. * * @return the table name; never null */ public String table() { return tableId.table(); }
/** * Get the name of the JDBC catalog. * * @return the catalog name, or null if the table does not belong to a catalog */ public String catalog() { return tableId.catalog(); }
/** * Get the name of the JDBC schema. * * @return the JDBC schema name, or null if the table does not belong to a JDBC schema */ public String schema() { return tableId.schema(); }
/** * Returns the type schema name for the given table. */ private String tableSchemaName(TableId tableId) { if (Strings.isNullOrEmpty(tableId.catalog())) { if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.table(); } else { return tableId.schema() + "." + tableId.table(); } } else if (Strings.isNullOrEmpty(tableId.schema())) { return tableId.catalog() + "." + tableId.table(); } // When both catalog and schema is present then only schema is used else { return tableId.schema() + "." + tableId.table(); } }
public TableId toLowercase() { return new TableId(catalogName, schemaName, tableName.toLowerCase()); } }
/** * Parse the supplied string, extracting up to the first 3 parts into a TableID. * * @param str the string representation of the table identifier; may not be null * @param useCatalogBeforeSchema {@code true} if the parsed string contains only 2 items and the first should be used as * the catalog and the second as the table name, or {@code false} if the first should be used as the schema and the * second as the table name * @return the table ID, or null if it could not be parsed */ public static TableId parse(String str, boolean useCatalogBeforeSchema) { String[] parts = TableIdParser.parse(str).stream() .toArray(String[]::new); return TableId.parse(parts, parts.length, useCatalogBeforeSchema); }
public void removeTablesForDatabase(String catalogName, String schemaName) { lock.write(() -> { tablesByTableId.entrySet().removeIf(tableIdTableEntry -> { TableId tableId = tableIdTableEntry.getKey(); boolean equalCatalog = Objects.equals(catalogName, tableId.catalog()); boolean equalSchema = Objects.equals(schemaName, tableId.schema()); return equalSchema && equalCatalog; }); }); }
/** * Creates an exclusive lock for a given table. * * @param tableId to be locked * @throws SQLException */ public void lockTable(TableId tableId) throws SQLException { final String lockTableStmt = LOCK_TABLE.replace(STATEMENTS_PLACEHOLDER, tableId.table()); execute(lockTableStmt); }