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; } }
public AbstractTableDataReader(Batch batch, String catalogName, String schemaName, String tableName, Reader reader) { this.reader = reader; this.batch = batch; if (StringUtils.isNotBlank(tableName)) { this.table = new Table(catalogName, schemaName, tableName); } }
protected String[] getRowData(CsvData data, String dataType) { String[] targetValues = new String[targetTable.getColumnCount()]; String[] targetColumnNames = targetTable.getColumnNames(); String[] originalValues = data.getParsedData(dataType); String[] sourceColumnNames = sourceTable.getColumnNames(); if (originalValues != null) { for (int i = 0; i < sourceColumnNames.length && i < originalValues.length; i++) { for (int t = 0; t < targetColumnNames.length; t++) { if (sourceColumnNames[i].equalsIgnoreCase(targetColumnNames[t])) { targetValues[t] = originalValues[i]; break; } } } } return targetValues; }
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; }
@Override public void allowInsertIntoAutoIncrementColumns(boolean allow, Table table, String quote) { if (table != null && table.getAutoIncrementColumns().length > 0) { if (allow) { execute(String.format("SET IDENTITY_INSERT %s ON", table.getFullyQualifiedTableName(quote))); } else { execute(String.format("SET IDENTITY_INSERT %s OFF", table.getFullyQualifiedTableName(quote))); } } }
List<Column> lookupKeys = null; if (!useConflictDetection) { lookupKeys = targetTable.getPrimaryKeyColumnsAsList(); } else { switch (conflict.getDetectType()) { case USE_OLD_DATA: lookupKeys = targetTable.getColumnsAsList(); break; case USE_VERSION: case USE_TIMESTAMP: List<Column> lookupColumns = new ArrayList<Column>(); Column versionColumn = targetTable.getColumnWithName(conflict .getDetectExpression()); if (versionColumn != null) { Column[] pks = targetTable.getPrimaryKeyColumns(); for (Column column : pks) { case USE_PK_DATA: default: lookupKeys = targetTable.getPrimaryKeyColumnsAsList(); break; lookupKeys = targetTable.getColumnsAsList(); + targetTable.getFullyQualifiedTableName() + ". Cannot build an update statement. "; if (lookupKeyCountBeforeColumnRemoval > 0) {
protected Table lookupTableAtTarget(Table sourceTable) { String tableNameKey = sourceTable.getTableKey(); Table table = targetTables.get(tableNameKey); if (table == null) { table = platform.getTableFromCache(sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false); if (table != null) { table = table.copyAndFilterColumns(sourceTable.getColumnNames(), sourceTable.getPrimaryKeyColumnNames(), this.writerSettings.isUsePrimaryKeysFromSource()); if (StringUtils.isBlank(sourceTable.getCatalog())) { table.setCatalog(null); if (StringUtils.isBlank(sourceTable.getSchema())) { table.setSchema(null); Column[] columns = table.getColumns(); for (Column column : columns) { if (column != null) {
public String createCsvPrimaryKeySql(Trigger trigger, TriggerHistory triggerHistory, Table table, Channel channel, String whereClause) { String sql = sqlTemplates.get(INITIAL_LOAD_SQL_TEMPLATE); Column[] columns = table.getPrimaryKeyColumns(); String columnsText = buildColumnString(symmetricDialect.getInitialLoadTableAlias(), symmetricDialect.getInitialLoadTableAlias(), "", columns, DataEventType.INSERT, false, channel, trigger).toString(); sql = FormatUtils.replace("columns", columnsText, sql); sql = FormatUtils.replace("oracleToClob", trigger.isUseCaptureLobs() ? "to_clob('')||" : "", sql); sql = FormatUtils.replace("tableName", SymmetricUtils.quote(symmetricDialect, table.getName()), sql); sql = FormatUtils.replace("schemaName", triggerHistory == null ? getSourceTablePrefix(trigger) : getSourceTablePrefix(triggerHistory), sql); sql = FormatUtils.replace("whereClause", whereClause, sql); sql = FormatUtils.replace( "primaryKeyWhereString", getPrimaryKeyWhereString(symmetricDialect.getInitialLoadTableAlias(), table.hasPrimaryKey() ? table.getPrimaryKeyColumns() : table.getColumns()), sql); return sql; }
table = new Table(); table.setName(tableName); table.setType(type); table.setCatalog(catalog); metaData.setCatalog(catalog); table.setSchema(schema); metaData.setSchemaPattern(schema); table.setDescription((String) values.get("REMARKS")); table.addColumns(readColumns(metaData, tableName)); if (table.getColumnCount() > 0) { table.addForeignKeys(readForeignKeys(connection, metaData, tableName)); table.addIndices(readIndices(connection, metaData, tableName)); table.findColumn(it.next(), true).setPrimaryKey(true);
protected Table toAuditTable(Table table) { Table auditTable = table.copy(); String tableName = table.getName(); if (!FormatUtils.isMixedCase(tableName)) { tableName = tableName.toUpperCase(); } auditTable.setName(String.format("%s_AUDIT", tableName)); Column[] columns = auditTable.getColumns(); auditTable.removeAllColumns(); auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0)); for (Column column : columns) { column.setRequired(false); column.setPrimaryKey(false); column.setAutoIncrement(false); auditTable.addColumn(column); } auditTable.removeAllForeignKeys(); auditTable.removeAllIndices(); engine.getDatabasePlatform().alterCaseToMatchDatabaseDefaultCase(auditTable); return auditTable; }
/** * 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; }
public String getFullyQualifiedTargetTableName() { return Table.getFullyQualifiedTableName(sourceCatalogName, sourceSchemaName, sourceTableName); }
protected String getCurData(ISqlTransaction transaction) { String curVal = null; if (writerSettings.isSaveCurrentValueOnError()) { String[] keyNames = Table.getArrayColumns(context.getTable().getPrimaryKeyColumns()); String[] columnNames = Table.getArrayColumns(context.getTable().getColumns()); context.getTable().getCatalog(), context.getTable().getSchema(), context.getTable().getName(), false); targetTable = targetTable.copyAndFilterColumns(columnNames, keyNames, true); Column[] columns = targetTable.getColumns(); .toMap(columnNames, objectValues); Column[] pkColumns = targetTable.getPrimaryKeyColumns(); Object[] args = new Object[pkColumns.length]; for (int i = 0; i < pkColumns.length; i++) {
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()); } } }
if (useDatabaseDefinition) { table = platform.getTableFromCache(catalogName, schemaName, tableName, false); table = table.copyAndFilterColumns(triggerHistory.getParsedColumnNames(), triggerHistory.getParsedPkColumnNames(), true); } else { table = new Table(tableName); table.addColumns(triggerHistory.getParsedColumnNames()); table.setPrimaryKeys(triggerHistory.getParsedPkColumnNames()); table.setCatalog(catalogName); table.setSchema(schemaName); Router router = triggerRouterService.getRouterById(routerId, false); if (router != null && setTargetTableName) { if (StringUtils.equals(Constants.NONE_TOKEN, router.getTargetCatalogName())) { table.setCatalog(null); } else if (StringUtils.isNotBlank(router.getTargetCatalogName())) { table.setCatalog(router.getTargetCatalogName()); table.setSchema(null); } else if (StringUtils.isNotBlank(router.getTargetSchemaName())) { table.setSchema(router.getTargetSchemaName()); table.setName(router.getTargetTableName());
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; }
CollectionUtils.copyOfRange(tokens, 1, context.getLastParsedTable().getColumnCount() + 1)); data.putParsedData(CsvData.PK_DATA, CollectionUtils.copyOfRange(tokens, context.getLastParsedTable().getColumnCount() + 1, tokens.length)); data.putParsedData(CsvData.OLD_DATA, parsedOldData); tokens = null; table = context.getParsedTables().get(Table.getFullyQualifiedTableName(catalogName, schemaName, tableName)); if (table != null) { context.setLastParsedTable(table); } else { table = new Table(catalogName, schemaName, tableName); context.setLastParsedTable(table); table.removeAllColumns(); for (int i = 1; i < tokens.length; i++) { Column column = new Column(tokens[i], keys != null && keys.contains(tokens[i])); table.addColumn(column); context.getParsedTables().put(table.getFullyQualifiedTableName(), table); } else if (tokens[0].equals(CsvConstants.COMMIT)) { if (batch != null) {
String sqlSelect = platform.createDmlStatement(DmlType.SELECT, table.getCatalog(), table.getSchema(), table.getName(), selectColumnArray, table.getColumns(), null).getSql(); Object[] values = new Object[selectColumnArray.length]; for (int i=0; i<selectColumnArray.length; i++) { Row row = selectRandomRow(table); if (row == null) { log.warn("Unable to delete a random record from empty table '" + table.getName() + "'."); return; if (tbl.getName().equals(table.getName())) for (ForeignKey fk : tbl.getForeignKeys()) { if (fk.getForeignTableName().equals(table.getName())) { Map<Column, Object> selectValues = new HashMap<Column, Object>(); for (Reference ref : fk.getReferences()) { platform.getSqlTemplate().update(statement.getSql(), keyValues); if (verbose) { System.out.println("Successful delete from " + table.getName());
table = new Table(); data = new CsvData(); for (int i = 0; i < parser.getAttributeCount(); i++) { String attributeValue = parser.getAttributeValue(i); if (attributeName.equalsIgnoreCase("entity")) { table.setName(attributeValue); } else if (attributeName.equalsIgnoreCase("catalog")) { table.setCatalog(attributeValue); } else if (attributeName.equalsIgnoreCase("schema")) { table.setSchema(attributeValue); } else if (attributeName.equalsIgnoreCase("dml")) { if (attributeValue.equals("I")) { new String[rowData.keySet().size()]); for (String colName : columnNames) { table.addColumn(new Column(colName)); if (lastTable == null || !lastTable.equals(table)) { return table; } else {
File file = new File(dir, String.format("%s.%s", table.getName(), format .toString().replace('_', '.').toLowerCase())); FileUtils.deleteQuietly(file); csvWriter.setForceQualifier(true); } else if (format == Format.SQL) { Table targetTable = table.copy(); targetTable.setSchema(schema); targetTable.setCatalog(catalog); insertSql = DmlStatementFactory.createDmlStatement( compatible.toString().toLowerCase(), DmlType.INSERT, targetTable, useQuotedIdentifiers); writeComment("Catalog: " + StringUtils.defaultString(getCatalogToUse())); writeComment("Schema: " + StringUtils.defaultString(getSchemaToUse())); writeComment("Table: " + table.getName()); writeComment("Started on " + df.format(new Date())); csvWriter.writeRecord(table.getColumnNames()); } else if (!noData && format == Format.XML) { write("<table_data name=\"", table.getName(), "\">\n");