@Override public Set<K> keySet() { return Sets.immutable.<K>of().castToSet(); }
/** * @since 9.2 */ @Override default <P, V> ImmutableSet<V> flatCollectWith(Function2<? super T, ? super P, ? extends Iterable<V>> function, P parameter) { return this.flatCollect(each -> function.apply(each, parameter)); }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(this.set.size()); try { this.set.forEach(new CheckedProcedure<T>() { public void safeValue(T value) throws IOException { out.writeObject(value); } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw e; } }
public ImmutableSet<PhysicalSchema> getAllPhysicalSchemas() { return this.getAllSchemas().collect(new Function<Schema, String>() { @Override public String valueOf(Schema schema1) { return schema1.getName(); } }).collect(new Function<String, PhysicalSchema>() { @Override public PhysicalSchema valueOf(String schema) { return Environment.this.getPhysicalSchema(schema); } }); }
@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); }
@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); } }
private Document getDocumentFromDeployExecution(DeployExecution deployExecution, boolean forUpdate) { ImmutableSet<Document> attrs = deployExecution.getAttributes().collect(new Function<DeployExecutionAttribute, Document>() { @Override public Document valueOf(DeployExecutionAttribute object) { return new Document() .append(attrNameColName, object.getName()) .append(attrValueColName, object.getValue()); } }); return new Document() .append(idColName, deployExecution.getId()) .append(requesterIdColName, deployExecution.getRequesterId()) .append(deployExecutionIdColName, deployExecution.getExecutorId()) .append(dbSchemaColName, deployExecution.getSchema()) .append(toolVersionColName, deployExecution.getToolVersion()) .append(deployTimeColName, new Date(deployExecution.getDeployTime().getTime())) .append(initCommandColName, deployExecution.isInit()) .append(rollbackCommandColName, deployExecution.isRollback()) .append(productVersionColName, deployExecution.getProductVersion()) .append(reasonColName, deployExecution.getReason()) .append("attrs", new ArrayList<>(attrs.toList())); }
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 void value(final DbEnvironment env) { // TODO would prefer to avoid this hack w/ the "executeWithinContext" here and picking a schema arbitrarily stmtExecutor.executeWithinContext(env.getPhysicalSchemas().getFirst(), new Procedure<Connection>() { @Override public void value(Connection conn) { // TODO refactor these into separate components that can be chained together (GITHUB#5) // TODO measure how long each of these takes: GITHUB#6 if (env.isInvalidObjectCheckEnabled()) { checkForInvalidObjects(conn, env.getPhysicalSchemas()); } else { LOG.info("Skipping invalid object check as configured in your environment"); } if (env.isReorgCheckEnabled()) { checkForTablesNeedingReorg(conn, env); } else { LOG.info("Skipping check for tables pending reorg as configured in your environment"); } LOG.info("Done in DB2 post-deploy action:"); } }); }
@Override public ImmutableList<Change> getDeployedChanges() { return env.getPhysicalSchemas().flatCollect(new Function<PhysicalSchema, Iterable<Change>>() { @Override public Iterable<Change> valueOf(PhysicalSchema physicalSchema) { }).toList().toImmutable();
appContext.cleanAndDeploy(); final MutableMap<PhysicalSchema, ImmutableCollection<DaTable>> regularTableMap = physicalSchemas.toMap(Functions.<PhysicalSchema>getPassThru(), new Function<PhysicalSchema, ImmutableCollection<DaTable>>() { @Override public ImmutableCollection<DaTable> valueOf(PhysicalSchema object) { final MutableMap<PhysicalSchema, ImmutableCollection<DaTable>> baselineTableMap = physicalSchemas.toMap(Functions.<PhysicalSchema>getPassThru(), new Function<PhysicalSchema, ImmutableCollection<DaTable>>() { @Override public ImmutableCollection<DaTable> valueOf(PhysicalSchema object) { return physicalSchemas.flatCollect(new Function<PhysicalSchema, Iterable<CompareBreak>>() { @Override public Iterable<CompareBreak> valueOf(PhysicalSchema schema) {
@Override public ImmutableSet<String> getGroupNamesOptional(Connection conn, PhysicalSchema physicalSchema) throws SQLException { return Sets.immutable .withAll(jdbc.query(conn, "select ROLENAME from sysibm.SYSROLES", new ColumnListHandler<String>())) .newWithAll(jdbc.query(conn, "select GRANTEE from sysibm.SYSDBAUTH", new ColumnListHandler<String>())) .collect(StringFunctions.trim()); // db2 sometimes has whitespace in its return results that needs trimming } }
@Override public boolean accept(String key) { return !TextMarkupDocumentSection.this.toggles.contains(key); } }));
private void validateNoBaselineBreaks(DbDeployerAppContext appContext, Predicate<? super CompareBreak> breakIgnorePredicate) { MutableList<CompareBreak> sortedCompareBreaks = this.calculateBaselineBreaks(appContext).toList().sortThis( Comparators.fromFunctions( CompareBreak.TO_COMPARE_SUBJECT, Functions.chain(CompareBreak.TO_CLAZZ, CLASS_TO_NAME), Functions.chain(Functions.getToClass(), CLASS_TO_NAME) )); MutableList<CompareBreak> relevantBreaks = sortedCompareBreaks.reject(breakIgnorePredicate); LOG.info("Found " + relevantBreaks.size() + " breaks"); if (!relevantBreaks.isEmpty()) { throw new IllegalArgumentException( "Found some mismatches between your change alters (LEFT) and your baseline files (RIGHT). Please review:\n" + relevantBreaks.makeString("\n")); } }
/** * Returns true/false if all the schemas in the environment either need rollback (true) or don't (false). * * If some do and some don't, an exception is thrown. */ @Override public boolean determineRollback(final String productVersion, final ImmutableSet<String> schemas, final DeployExecutionDao deployExecutionDao) { MutableMap<String, Boolean> rollbackFlags = schemas.toMap( Functions.<String>getPassThru(), new Function<String, Boolean>() { @Override public Boolean valueOf(String schema) { LOG.info("Checking rollback status on Product Version {} and Schema {}", productVersion, schema); return DefaultRollbackDetector.this.determineRollbackForSchema(productVersion, deployExecutionDao.getDeployExecutions(schema)); } } ); MutableSet<Boolean> values = rollbackFlags.valuesView().toSet(); if (values.size() > 1) { MutableSetMultimap<Boolean, String> schemasByRollbackFlag = rollbackFlags.flip(); MutableSet<String> rollbackSchemas = schemasByRollbackFlag.get(Boolean.TRUE); MutableSet<String> nonrollbackSchemas = schemasByRollbackFlag.get(Boolean.FALSE); throw new IllegalArgumentException("The following schemas were calculated for rollback [" + rollbackSchemas + "], though the rest were not [" + nonrollbackSchemas + "]; cannot proceed in this mixed mode"); } return values.iterator().next().booleanValue(); }
/** * Assert the size of the given {@link ImmutableSet}. */ public static void assertSize(String immutableSetName, int expectedSize, ImmutableSet<?> actualImmutableSet) { try { int actualSize = actualImmutableSet.size(); if (actualSize != expectedSize) { Assert.fail("Incorrect size for " + immutableSetName + "; expected:<" + expectedSize + "> but was:<" + actualSize + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } }
public ImmutableSet<PhysicalSchema> getPhysicalSchemas() { return this.getSchemas().collect(new Function<Schema, String>() { @Override public String valueOf(Schema schema1) { return schema1.getName(); } }).collect(new Function<String, PhysicalSchema>() { @Override public PhysicalSchema valueOf(String schema) { return Environment.this.getPhysicalSchema(schema); } }); }
@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); }