public boolean matches(Table table, String defaultCatalog, String defaultSchema, boolean ignoreCase) { boolean schemaAndCatalogMatch = (StringUtils.equals(sourceCatalogName, table.getCatalog()) || (StringUtils .isBlank(sourceCatalogName) && StringUtils.equals(defaultCatalog, table.getCatalog()))) && (StringUtils.equals(sourceSchemaName, table.getSchema()) || (StringUtils .isBlank(sourceSchemaName) && StringUtils.equals(defaultSchema, table.getSchema()))); boolean tableMatches = ignoreCase ? table.getName().equalsIgnoreCase(sourceTableName) : table.getName().equals(sourceTableName); if (!tableMatches && isSourceTableNameWildCarded()) { String[] wildcardTokens = sourceTableName.split(","); for (String wildcardToken : wildcardTokens) { if (FormatUtils.isWildCardMatch(table.getName(), wildcardToken, ignoreCase)) { if (!wildcardToken.startsWith(FormatUtils.NEGATE_TOKEN)) { tableMatches = true; } else { tableMatches = false; } } } } return schemaAndCatalogMatch && tableMatches; }
private boolean containsExactMatchForSourceTableName(Table table, List<Trigger> triggers, boolean ignoreCase) { for (Trigger trigger : triggers) { String sourceCatalogName = trigger.getSourceCatalogName() != null ? trigger.getSourceCatalogName() : platform.getDefaultCatalog(); String sourceSchemaName = trigger.getSourceSchemaName() != null ? trigger.getSourceSchemaName() : platform.getDefaultSchema(); if (trigger.getSourceTableName().equals(table.getName()) && (sourceCatalogName == null || sourceCatalogName.equals(table.getCatalog())) && (sourceSchemaName == null || sourceSchemaName.equals(table.getSchema()))) { return true; } else if (ignoreCase && trigger.getSourceTableName().equalsIgnoreCase(table.getName()) && sourceCatalogName.equalsIgnoreCase(table.getCatalog()) && sourceSchemaName.equalsIgnoreCase(table.getSchema())) { return true; } } return false; }
if (table.getCatalog() != null && !table.getCatalog().trim().equals("")) { appendIdentifier(query, table.getCatalog()); query.append(catalogSeparator);
/** * Select a random row from the table in the connected database. Return null if there are no rows. * * TODO: Cache rows. * * @param sqlTemplate * @param table The table to select a row from. * @return A random row from the table. Null if there are no rows. */ private Row selectRandomRow(Table table) { Row row = null; // Select all rows and return the primary key columns. String sql = platform.createDmlStatement(DmlType.SELECT_ALL, table.getCatalog(), table.getSchema(), table.getName(), table.getPrimaryKeyColumns(), table.getColumns(), null).getSql(); final List<Row> rows = new ArrayList<Row>(); platform.getSqlTemplate().query(sql, RANDOM_SELECT_SIZE, new ISqlRowMapper<Object>() { public Object mapRow(Row row) { rows.add(row); return Boolean.TRUE; } }, null, null); if (rows.size() != 0) { int rowNum = getRand().nextInt(rows.size()); row = rows.get(rowNum); } return row; }
protected void importTablesFromCsv(InputStream in, String tableName) { Table table = platform.readTableFromDatabase(catalog, schema, tableName); if (table == null) { throw new RuntimeException("Unable to find table"); } CsvTableDataReader reader = new CsvTableDataReader(BinaryEncoding.HEX, table.getCatalog(), table.getSchema(), table.getName(), in); DatabaseWriter writer = new DatabaseWriter(platform, buildDatabaseWriterSettings()); DataProcessor dataProcessor = new DataProcessor(reader, writer, "import"); dataProcessor.process(); }
public boolean start(Table table) { if (!batch.isIgnored()) { this.table = table; if (!backwardsCompatible) { String catalogName = table.getCatalog(); println(CsvConstants.CATALOG, StringUtils.isNotBlank(catalogName) ? catalogName : ""); String schemaName = table.getSchema(); println(CsvConstants.SCHEMA, StringUtils.isNotBlank(schemaName) ? schemaName : ""); } String tableKey = table.getTableKey(); String fullyQualifiedTableName = table.getFullyQualifiedTableName(); String previousTableKey = processedTables.get(fullyQualifiedTableName); println(CsvConstants.TABLE, table.getName()); if (!tableKey.equals(previousTableKey)) { println(CsvConstants.KEYS, table.getPrimaryKeyColumns()); println(CsvConstants.COLUMNS, table.getColumns()); this.processedTables.put(fullyQualifiedTableName, tableKey); } return true; } else { return false; } }
Table table = targetTables.get(tableNameKey); if (table == null) { table = platform.getTableFromCache(sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false); if (table != null) { this.writerSettings.isUsePrimaryKeysFromSource()); if (StringUtils.isBlank(sourceTable.getCatalog())) { table.setCatalog(null);
public void syncTriggers(Table table, boolean force) { boolean ignoreCase = this.parameterService.is(ParameterConstants.DB_METADATA_IGNORE_CASE); /* Re-lookup just in case the table was just altered */ platform.resetCachedTableModel(); table = platform.getTableFromCache(table.getCatalog(), table.getSchema(), table.getName(), true); List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode(); for (Trigger trigger : triggersForCurrentNode) { if (trigger.matches(table, platform.getDefaultCatalog(), platform.getDefaultSchema(), ignoreCase)) { log.info("Synchronizing triggers for {}", table.getFullyQualifiedTableName()); updateOrCreateDatabaseTriggers(trigger, table, null, force, true); log.info("Done synchronizing triggers for {}", table.getFullyQualifiedTableName()); } } }
targetTable.getCatalog(), targetTable.getSchema(), targetTable.getName(), lookupKeys.toArray(new Column[lookupKeys.size()]),
targetTable.getCatalog(), targetTable.getSchema(), targetTable.getName(), lookupKeys.toArray(new Column[lookupKeys.size()]), null, nullKeyValues); if (log.isDebugEnabled()) {
if (!table.getName().toLowerCase().startsWith(engine.getTablePrefix() + "_")) { wildcardLoadFilters = loadFilters.get(Table.getFullyQualifiedTableName( table.getCatalog(), table.getSchema(), FormatUtils.WILDCARD)); tableName = Table.getFullyQualifiedTableName(table.getCatalog(), table.getSchema(), table.getName().toUpperCase(), "");
String sqlSelect = platform.createDmlStatement(DmlType.SELECT, table.getCatalog(), table.getSchema(), table.getName(), selectColumnArray, table.getColumns(), null).getSql(); Object[] values = new Object[selectColumnArray.length];
table.getCatalog(), table.getSchema(), table.getName(), table.getPrimaryKeyColumns(), table.getNonPrimaryKeyColumns(), null); Column[] columns = updStatement.getMetaData();
public boolean start(Table table) { /* * in the case when the target schema or catalog is set then we need to * use the previous schema or catalog to look up the table locally. */ this.currentTable = platform.getTableFromCache(table.getOldCatalog(), table.getOldSchema(), table.getName(), false); this.currentTable = currentTable.copyAndFilterColumns(table.getColumnNames(), table.getPrimaryKeyColumnNames(), true); /* * restore the schema and catalog from the passed in table because they * might have not been originally set, but were set when looking up the table locally */ this.currentTable.setSchema(table.getSchema()); this.currentTable.setCatalog(table.getCatalog()); this.currentTable.setName(table.getName()); return true; }
error.setBatchId(this.currentBatch.getBatchId()); error.setNodeId(this.currentBatch.getNodeId()); error.setTargetCatalogName(context.getTable().getCatalog()); error.setTargetSchemaName(context.getTable().getSchema()); error.setTargetTableName(context.getTable().getName());
protected String preprocessSqlStatement(String sql) { sql = FormatUtils.replace("nodeId", batch.getTargetNodeId(), sql); if (targetTable != null) { sql = FormatUtils.replace("catalogName", quoteString(targetTable.getCatalog()),sql); sql = FormatUtils.replace("schemaName", quoteString(targetTable.getSchema()), sql); sql = FormatUtils.replace("tableName", quoteString(targetTable.getName()), sql); } else if (sourceTable != null){ sql = FormatUtils.replace("catalogName", quoteString(sourceTable.getCatalog()),sql); sql = FormatUtils.replace("schemaName", quoteString(sourceTable.getSchema()), sql); sql = FormatUtils.replace("tableName", quoteString(sourceTable.getName()), sql); } sql = platform.scrubSql(sql); sql = FormatUtils.replace("sourceNodeId", (String) context.get("sourceNodeId"), sql); sql = FormatUtils.replace("sourceNodeExternalId", (String) context.get("sourceNodeExternalId"), sql); sql = FormatUtils.replace("sourceNodeGroupId", (String) context.get("sourceNodeGroupId"), sql); sql = FormatUtils.replace("targetNodeId", (String) context.get("targetNodeId"), sql); sql = FormatUtils.replace("targetNodeExternalId", (String) context.get("targetNodeExternalId"), sql); sql = FormatUtils.replace("targetNodeGroupId", (String) context.get("targetNodeGroupId"), sql); return sql; }
context.getTable().getCatalog(), context.getTable().getSchema(), context.getTable().getName(), false);