private ImmutableList<DbCleanCommand> getDropStatements(PhysicalSchema physicalSchema) { DaCatalog database = this.dbMetadataManager.getDatabase(physicalSchema, new DaSchemaInfoLevel().setRetrieveAllObjectsMinimum().setRetrieveTableForeignKeys(true), true, true); MutableSet<DbCleanCommand> cleanCommands = Sets.mutable.empty(); cleanCommands.withAll(getRoutineDrops(database, physicalSchema)); cleanCommands.withAll(getTableDrops(database, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getPackages(), ChangeType.PACKAGE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getSequences(), ChangeType.SEQUENCE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getSynonyms(), ChangeType.SYNONYM_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getRules(), ChangeType.RULE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getUserTypes(), ChangeType.USERTYPE_STR, physicalSchema)); return cleanCommands.toList().toImmutable(); }
private ImmutableList<DbCleanCommand> getDropStatements(PhysicalSchema physicalSchema) { DaCatalog database = this.dbMetadataManager.getDatabase(physicalSchema, new DaSchemaInfoLevel().setRetrieveAllObjectsMinimum().setRetrieveTableForeignKeys(true), true, true); MutableSet<DbCleanCommand> cleanCommands = Sets.mutable.empty(); cleanCommands.withAll(getRoutineDrops(database, physicalSchema)); cleanCommands.withAll(getTableDrops(database, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getPackages(), ChangeType.PACKAGE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getSequences(), ChangeType.SEQUENCE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getSynonyms(), ChangeType.SYNONYM_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getRules(), ChangeType.RULE_STR, physicalSchema)); cleanCommands.withAll(getObjectDrops(database.getUserTypes(), ChangeType.USERTYPE_STR, physicalSchema)); return cleanCommands.toList().toImmutable(); }
private void generate(String schema) { MutableSet<MyInput> inputs = Sets.mutable.empty(); inputs.withAll(getUserTypes(numTypes)); inputs.withAll(getTables()); inputs.withAll(getViews()); inputs.withAll(getSps()); MutableSet<String> types = Sets.mutable.of("table", "view", "sp", "usertype"); File outputDir = new File("./target/testoutput"); FileUtils.deleteQuietly(outputDir); outputDir.mkdirs(); for (MyInput input : inputs) { MutableMap<String, Object> params = Maps.mutable.<String, Object>empty().withKeyValue( "name", input.getName() ); for (String type : types) { params.put("dependent" + type + "s", input.getDependenciesByType().get(type)); } File outputFile = new File(outputDir, schema + "/" + input.getType() + "/" + input.getName() + ".sql"); outputFile.getParentFile().mkdirs(); TestTemplateUtil.getInstance().writeTemplate("schemagen/" + input.getType() + ".sql.ftl", params, outputFile); } }
@VisibleForTesting MutableSet<SchemaObjectRow> getInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) { LOG.info("Checking for invalid objects"); String schemaInClause = physicalSchemas.collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString("('", "','", "')"); MutableSet<SchemaObjectRow> oldInvalidObjects = queryOldInvalidObjects(conn, schemaInClause); try { MutableSet<SchemaObjectRow> newInvalidObjects = queryNewInvalidObjects(conn, schemaInClause); if (oldInvalidObjects.isEmpty() && newInvalidObjects.notEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInNew", true); } else if (oldInvalidObjects.notEmpty() && newInvalidObjects.isEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInOld", true); } return oldInvalidObjects.withAll(newInvalidObjects); } catch (DataAccessException e) { deployMetricsCollector.addMetric("oldInvalidObjectQueryRequired", true); LOG.debug("Failed to execute new invalid objects SQL; falling back to old query"); return oldInvalidObjects; } }
@VisibleForTesting MutableSet<SchemaObjectRow> getInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) { LOG.info("Checking for invalid objects"); String schemaInClause = physicalSchemas.collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString("('", "','", "')"); MutableSet<SchemaObjectRow> oldInvalidObjects = queryOldInvalidObjects(conn, schemaInClause); try { MutableSet<SchemaObjectRow> newInvalidObjects = queryNewInvalidObjects(conn, schemaInClause); if (oldInvalidObjects.isEmpty() && newInvalidObjects.notEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInNew", true); } else if (oldInvalidObjects.notEmpty() && newInvalidObjects.isEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInOld", true); } return oldInvalidObjects.withAll(newInvalidObjects); } catch (DataAccessException e) { deployMetricsCollector.addMetric("oldInvalidObjectQueryRequired", true); LOG.debug("Failed to execute new invalid objects SQL; falling back to old query"); return oldInvalidObjects; } }
SetIterable<String> allChecksumKeys = newChecksumMap.keysView().toSet().withAll(existingChecksumMap.keysView());
SetIterable<String> allChecksumKeys = newChecksumMap.keysView().toSet().withAll(existingChecksumMap.keysView());