@Override public MutableMap<K, V> withAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues) { MutableMap<K, V> map = this; for (Pair<? extends K, ? extends V> keyVal : keyValues) { map = map.withKeyValue(keyVal.getOne(), keyVal.getTwo()); } return map; }
@Override public MutableMap<K, V> withAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues) { MutableMap<K, V> map = this; for (Pair<? extends K, ? extends V> keyVal : keyValues) { map = map.withKeyValue(keyVal.getOne(), keyVal.getTwo()); } return map; }
private ImmutableMap<ChangeType, Pattern> initPatternMap(Platform platform) { MutableMap<String, Pattern> params = Maps.mutable.<String, Pattern>with() .withKeyValue(ChangeType.SP_STR, Pattern.compile("(?i)create\\s+proc(?:edure)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.FUNCTION_STR, Pattern.compile("(?i)create\\s+func(?:tion)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.VIEW_STR, Pattern.compile("(?i)create\\s+view\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.SEQUENCE_STR, Pattern.compile("(?i)create\\s+seq(?:uence)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.TABLE_STR, Pattern.compile("(?i)create\\s+table\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.DEFAULT_STR, Pattern.compile("(?i)create\\s+default\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.RULE_STR, Pattern.compile("(?i)create\\s+rule\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.USERTYPE_STR, Pattern.compile("(?i)^\\s*sp_addtype\\s+", Pattern.DOTALL)) .withKeyValue(ChangeType.INDEX_STR, Pattern.compile("(?i)create\\s+(?:unique\\s+)?(?:\\w+\\s+)?index\\s+\\w+\\s+on\\s+(\\w+)", Pattern.DOTALL)); MutableMap<ChangeType, Pattern> patternMap = Maps.mutable.<ChangeType, Pattern>with(); for (String changeTypeName : params.keysView()) { if (platform.hasChangeType(changeTypeName)) { ChangeType changeType = platform.getChangeType(changeTypeName); patternMap.put(changeType, params.get(changeTypeName)); } } return patternMap.toImmutable(); }
private ImmutableMap<ChangeType, Pattern> initPatternMap(Platform platform) { MutableMap<String, Pattern> params = Maps.mutable.<String, Pattern>with() .withKeyValue(ChangeType.SP_STR, Pattern.compile("(?i)create\\s+proc(?:edure)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.FUNCTION_STR, Pattern.compile("(?i)create\\s+func(?:tion)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.VIEW_STR, Pattern.compile("(?i)create\\s+view\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.SEQUENCE_STR, Pattern.compile("(?i)create\\s+seq(?:uence)?\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.TABLE_STR, Pattern.compile("(?i)create\\s+table\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.DEFAULT_STR, Pattern.compile("(?i)create\\s+default\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.RULE_STR, Pattern.compile("(?i)create\\s+rule\\s+(\\w+)", Pattern.DOTALL)) .withKeyValue(ChangeType.USERTYPE_STR, Pattern.compile("(?i)^\\s*sp_addtype\\s+", Pattern.DOTALL)) .withKeyValue(ChangeType.INDEX_STR, Pattern.compile("(?i)create\\s+(?:unique\\s+)?(?:\\w+\\s+)?index\\s+\\w+\\s+on\\s+(\\w+)", Pattern.DOTALL)); MutableMap<ChangeType, Pattern> patternMap = Maps.mutable.<ChangeType, Pattern>with(); for (String changeTypeName : params.keysView()) { if (platform.hasChangeType(changeTypeName)) { ChangeType changeType = platform.getChangeType(changeTypeName); patternMap.put(changeType, params.get(changeTypeName)); } } return patternMap.toImmutable(); }
@Override public MutableMap<K, V> withAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues) { MutableMap<K, V> map = this; for (Pair<? extends K, ? extends V> keyVal : keyValues) { map = map.withKeyValue(keyVal.getOne(), keyVal.getTwo()); } return map; }
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); } }
@Override public String prepare(String content, ChangeInput change, DbEnvironment env) { MutableMap<String, String> tokens = Maps.mutable.<String, String>empty() .withKeyValue("dbSchemaSuffix", env.getDbSchemaSuffix()) .withKeyValue("dbSchemaPrefix", env.getDbSchemaPrefix()); for (Schema schema : env.getSchemas()) { PhysicalSchema physicalSchema = env.getPhysicalSchema(schema.getName()); tokens.put(schema.getName() + "_physicalName", physicalSchema.getPhysicalName()); if (env.getPlatform() != null) { tokens.put(schema.getName() + "_schemaSuffixed", env.getPlatform().getSchemaPrefix(physicalSchema)); tokens.put(schema.getName() + "_subschemaSuffixed", env.getPlatform().getSubschemaPrefix(physicalSchema)); } } if (env.getDefaultTablespace() != null) { tokens.put("defaultTablespace", env.getDefaultTablespace()); } tokens.putAll(env.getTokens().castToMap()); // allow clients to override these values if needed return new Tokenizer(tokens, env.getTokenPrefix(), env.getTokenSuffix()).tokenizeString(content); } }
@Override public String prepare(String content, ChangeInput change, DbEnvironment env) { MutableMap<String, String> tokens = Maps.mutable.<String, String>empty() .withKeyValue("dbSchemaSuffix", env.getDbSchemaSuffix()) .withKeyValue("dbSchemaPrefix", env.getDbSchemaPrefix()); for (Schema schema : env.getSchemas()) { PhysicalSchema physicalSchema = env.getPhysicalSchema(schema.getName()); tokens.put(schema.getName() + "_physicalName", physicalSchema.getPhysicalName()); if (env.getPlatform() != null) { tokens.put(schema.getName() + "_schemaSuffixed", env.getPlatform().getSchemaPrefix(physicalSchema)); tokens.put(schema.getName() + "_subschemaSuffixed", env.getPlatform().getSubschemaPrefix(physicalSchema)); } } if (env.getDefaultTablespace() != null) { tokens.put("defaultTablespace", env.getDefaultTablespace()); } tokens.putAll(env.getTokens().castToMap()); // allow clients to override these values if needed return new Tokenizer(tokens, env.getTokenPrefix(), env.getTokenSuffix()).tokenizeString(content); } }