@Override public String valueOf(T t) { return t.getComponents().collect(new Function<SortableDependency, String>() { @Override public String valueOf(SortableDependency sortableDependency) { return "[" + sortableDependency.getChangeKey().getObjectKey().getObjectName() + "." + sortableDependency.getChangeKey().getChangeName() + "]"; } }).makeString(", "); } },
@Override public String valueOf(T t) { return t.getComponents().collect(new Function<SortableDependency, String>() { @Override public String valueOf(SortableDependency sortableDependency) { return "[" + sortableDependency.getChangeKey().getObjectKey().getObjectName() + "." + sortableDependency.getChangeKey().getChangeName() + "]"; } }).makeString(", "); } },
public String getPhysicalSchemaPrefixInternal(String schema) { Validate.isTrue(getAllSchemas().collect(new Function<Schema, String>() { @Override public String valueOf(Schema schema1) { return schema1.getName(); } }).contains(schema), "Schema does not exist in the environment. Requested schema: " + schema + "; available schemas: " + getSchemaNames().makeString(",")); return ObjectUtils.defaultIfNull(this.schemaNameOverrides.get(schema), schema); }
public String getPhysicalSchemaPrefixInternal(String schema) { Validate.isTrue(getAllSchemas().collect(new Function<Schema, String>() { @Override public String valueOf(Schema schema1) { return schema1.getName(); } }).contains(schema), "Schema does not exist in the environment. Requested schema: " + schema + "; available schemas: " + getSchemaNames().makeString(",")); return ObjectUtils.defaultIfNull(this.schemaNameOverrides.get(schema), schema); }
ImmutableSet<SchemaObjectRow> getTablesNeedingReorg(final Connection conn, final DbEnvironment env) { // keeping as system.out for now to facilitate output to maven output LOG.info("Starting DB2 post-deploy action: Querying for tables in reorg-ending state (this may take a minute)"); // trim the schema as DB2 seems to sometimes return the schema w/ spaces (even though where clauses can still // work w/out the spaces) try { return env.getPhysicalSchemas().flatCollect(new Function<PhysicalSchema, Iterable<SchemaObjectRow>>() { @Override public Iterable<SchemaObjectRow> valueOf(PhysicalSchema physicalSchema) { final String sql = String.format( "select '%1$s' schema, trim(TABNAME) name, NUM_REORG_REC_ALTERS, REORG_PENDING\n" + "FROM TABLE (SYSPROC.ADMIN_GET_TAB_INFO('%1$s', null)) WHERE REORG_PENDING = 'Y'" , physicalSchema.getPhysicalName()); LOG.debug("Executing SQL: " + sql); return stmtExecutor.getJdbcTemplate() .query(conn, sql, new BeanListHandler<SchemaObjectRow>(SchemaObjectRow.class)); } }); } catch (RuntimeException e) { // TODO would like a better way to decide on using this SQL apart from catching the exception LOG.info("Query in new >= 9.7 syntax didn't work: {} (debug log shows the full stack trace). Falling back to older (and slower) syntax", e.getMessage()); LOG.debug("Full exception stack trace", e); String sql = "SELECT TRIM(TABSCHEMA) schema, TABNAME name, NUM_REORG_REC_ALTERS, REORG_PENDING\n" + "FROM SYSIBMADM.ADMINTABINFO WHERE REORG_PENDING = 'Y'\n" + "AND TABSCHEMA IN ('" + env.getPhysicalSchemas().makeString("','") + "')"; return CollectionAdapter.wrapSet(Db2PostDeployAction.this.stmtExecutor.getJdbcTemplate() .query(conn, sql, new BeanListHandler<SchemaObjectRow>(SchemaObjectRow.class))).toImmutable(); } }
ImmutableSet<SchemaObjectRow> getTablesNeedingReorg(final Connection conn, final DbEnvironment env) { // keeping as system.out for now to facilitate output to maven output LOG.info("Starting DB2 post-deploy action: Querying for tables in reorg-ending state (this may take a minute)"); // trim the schema as DB2 seems to sometimes return the schema w/ spaces (even though where clauses can still // work w/out the spaces) try { return env.getPhysicalSchemas().flatCollect(new Function<PhysicalSchema, Iterable<SchemaObjectRow>>() { @Override public Iterable<SchemaObjectRow> valueOf(PhysicalSchema physicalSchema) { final String sql = String.format( "select '%1$s' schema, trim(TABNAME) name, NUM_REORG_REC_ALTERS, REORG_PENDING\n" + "FROM TABLE (SYSPROC.ADMIN_GET_TAB_INFO('%1$s', null)) WHERE REORG_PENDING = 'Y'" , physicalSchema.getPhysicalName()); LOG.debug("Executing SQL: " + sql); return stmtExecutor.getJdbcTemplate() .query(conn, sql, new BeanListHandler<SchemaObjectRow>(SchemaObjectRow.class)); } }); } catch (RuntimeException e) { // TODO would like a better way to decide on using this SQL apart from catching the exception LOG.info("Query in new >= 9.7 syntax didn't work: {} (debug log shows the full stack trace). Falling back to older (and slower) syntax", e.getMessage()); LOG.debug("Full exception stack trace", e); String sql = "SELECT TRIM(TABSCHEMA) schema, TABNAME name, NUM_REORG_REC_ALTERS, REORG_PENDING\n" + "FROM SYSIBMADM.ADMINTABINFO WHERE REORG_PENDING = 'Y'\n" + "AND TABSCHEMA IN ('" + env.getPhysicalSchemas().makeString("','") + "')"; return CollectionAdapter.wrapSet(Db2PostDeployAction.this.stmtExecutor.getJdbcTemplate() .query(conn, sql, new BeanListHandler<SchemaObjectRow>(SchemaObjectRow.class))).toImmutable(); } }
@Override public String getDisplayString() { String connectionInfo; if (this.getJdbcUrl() != null) { connectionInfo = this.getJdbcUrl(); } else if (this.getDbDataSourceName() != null) { connectionInfo = this.getDbDataSourceName(); } else if (this.getDbServer() != null) { connectionInfo = this.getDbHost() + ":" + this.getDbPort() + "/" + this.getDbServer(); } else { connectionInfo = this.getDbHost() + ":" + this.getDbPort(); } return super.getDisplayString() + ": Connecting to [" + connectionInfo + "] against schemas [" + this.getPhysicalSchemas().collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString(",") + "]"; }
@Override public String getDisplayString() { String connectionInfo; if (this.getJdbcUrl() != null) { connectionInfo = this.getJdbcUrl(); } else if (this.getDbDataSourceName() != null) { connectionInfo = this.getDbDataSourceName(); } else if (this.getDbServer() != null) { connectionInfo = this.getDbHost() + ":" + this.getDbPort() + "/" + this.getDbServer(); } else { connectionInfo = this.getDbHost() + ":" + this.getDbPort(); } return super.getDisplayString() + ": Connecting to [" + connectionInfo + "] against schemas [" + this.getPhysicalSchemas().collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString(",") + "]"; }
@Test public void testBaselineMismatchScenario() { DbDeployerAppContext appContext = DbEnvironmentFactory.getInstance().readOneFromSourcePath("baselineutil/BaselineValidatorMain/uc1", "test") .buildAppContext(); BaselineValidatorMain main = new BaselineValidatorMain(); ImmutableSet<CompareBreak> compareBreaks = main.calculateBaselineBreaks(appContext); System.out.println("BREAKS\n" + compareBreaks.makeString("\n")); assertEquals(2, compareBreaks.size()); ObjectCompareBreak objectBreak = (ObjectCompareBreak) compareBreaks.detect(Predicates .instanceOf(ObjectCompareBreak.class)); FieldCompareBreak dataTypeBreak = (FieldCompareBreak) compareBreaks.select( Predicates.instanceOf(FieldCompareBreak.class)).detect(new Predicate<CompareBreak>() { @Override public boolean accept(CompareBreak each) { return ((FieldCompareBreak) each).getFieldName().equalsIgnoreCase("columnDataType"); } }); assertNotNull(objectBreak); assertNotNull(dataTypeBreak); } }