@Override public String handleAnySqlPostTranslation(String string, ChangeInput change) { if (change != null && change.getMetadataSection() != null && change.getMetadataSection().isTogglePresent(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS)) { if (!change.getChangeKey().getChangeType().getName().equals(ChangeType.VIEW_STR)) { // only needed for HSQL seemingly for views only, seemingly not for H2 string = string.replace('"', '\''); } } Matcher varbinaryDefaultMatcher = this.varbinaryDefaultPattern.matcher(string); if (varbinaryDefaultMatcher.find()) { string = varbinaryDefaultMatcher.replaceFirst("varbinary(1)" + varbinaryDefaultMatcher.group(1)); } return string; }
@Override public String handleAnySqlPostTranslation(String string, ChangeInput change) { if (change != null && change.getMetadataSection() != null && change.getMetadataSection().isTogglePresent(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS)) { if (!change.getChangeKey().getChangeType().getName().equals(ChangeType.VIEW_STR)) { // only needed for HSQL seemingly for views only, seemingly not for H2 string = string.replace('"', '\''); } } Matcher varbinaryDefaultMatcher = this.varbinaryDefaultPattern.matcher(string); if (varbinaryDefaultMatcher.find()) { string = varbinaryDefaultMatcher.replaceFirst("varbinary(1)" + varbinaryDefaultMatcher.group(1)); } return string; }
@Override public String handleAnySqlPostTranslation(String string, ChangeInput change) { if (change != null && change.getMetadataSection() != null && change.getMetadataSection().isTogglePresent(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS)) { if (!change.getChangeKey().getChangeType().getName().equals(ChangeType.VIEW_STR)) { // only needed for HSQL seemingly for views only, seemingly not for H2 string = string.replace('"', '\''); } } Matcher varbinaryDefaultMatcher = this.varbinaryDefaultPattern.matcher(string); if (varbinaryDefaultMatcher.find()) { string = varbinaryDefaultMatcher.replaceFirst("varbinary(1)" + varbinaryDefaultMatcher.group(1)); } return string; }
@Override public String handleAnySqlPostTranslation(String string, ChangeInput change) { if (change != null && change.getMetadataSection() != null && change.getMetadataSection().isTogglePresent(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS)) { if (!change.getChangeKey().getChangeType().getName().equals(ChangeType.VIEW_STR)) { // only needed for HSQL seemingly for views only, seemingly not for H2 string = string.replace('"', '\''); } } Matcher varbinaryDefaultMatcher = this.varbinaryDefaultPattern.matcher(string); if (varbinaryDefaultMatcher.find()) { string = varbinaryDefaultMatcher.replaceFirst("varbinary(1)" + varbinaryDefaultMatcher.group(1)); } return string; }
@Override public final String prepare(String sql, final ChangeInput change, final Environment env) { if (change != null && Objects.equals(change.getChangeKey().getChangeType().getName(), ChangeType.STATICDATA_STR) && !StaticDataChangeTypeBehavior.isInsertModeStaticData(sql)) { return sql; } sql = CommentRemover.removeComments(sql, change != null ? change.getChangeKey().toString() : sql); MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(sql); MutableList<String> convertedSqls = sqls.collect(new Function<String, String>() { @Override public String valueOf(String object) { return InMemoryTranslator.this.translateStatement(object, change); } }); return convertedSqls.makeString("\n\nGO\n\n"); }
@Override public final String prepare(String sql, final ChangeInput change, final Environment env) { if (change != null && Objects.equals(change.getChangeKey().getChangeType().getName(), ChangeType.STATICDATA_STR) && !StaticDataChangeTypeBehavior.isInsertModeStaticData(sql)) { return sql; } sql = CommentRemover.removeComments(sql, change != null ? change.getChangeKey().toString() : sql); MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(sql); MutableList<String> convertedSqls = sqls.collect(new Function<String, String>() { @Override public String valueOf(String object) { return InMemoryTranslator.this.translateStatement(object, change); } }); return convertedSqls.makeString("\n\nGO\n\n"); }
@Test public void readFileWithBody() throws Exception { RerunnableChangeParser parser = new RerunnableChangeParser(); String fileContent = "main\n" + "//// BODY\n" + "body content\n" + ""; ChangeType mainChangeType = mock(ChangeType.class); ChangeType bodyChangeType = mock(ChangeType.class); when(mainChangeType.getBodyChangeType()).thenReturn(bodyChangeType); ImmutableList<ChangeInput> changes = parser.value(mainChangeType, null, fileContent, objectName, "schema", null); Verify.assertSize(2, changes); ChangeInput c1 = changes.get(0); assertEquals(objectName, c1.getObjectName()); assertEquals("main", c1.getContent()); ChangeInput c2 = changes.get(1); assertEquals(objectName, c2.getObjectName()); assertEquals("body", c2.getChangeKey().getChangeName()); assertEquals("body content", c2.getContent()); }
@Test public void testDbChange() { ChangeInput change = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType) .value(tableChangeType, null, "//// CHANGE name=chng5Rollback applyGrants=true INACTIVE baselinedChanges=\"a,b,c\" \nmychange\n\n// ROLLBACK-IF-ALREADY-DEPLOYED\nmyrollbackcommand\n", objectName , "schem", null).get(0); assertEquals("schem", change.getObjectKey().getSchema()); assertEquals("chng5Rollback", change.getChangeKey().getChangeName()); assertEquals("mychange\n", change.getContent()); assertEquals("mychan", change.getContentHash()); assertEquals("myrollbackcommand", change.getRollbackIfAlreadyDeployedContent()); assertEquals(UnifiedSet.newSetWith("a", "b", "c"), change.getBaselinedChanges().toSet()); assertFalse(change.isActive()); assertTrue(change.getApplyGrants()); }
@Test public void testDbChange2DiffValues() { ChangeInput change = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType) .value(tableChangeType, null, "//// CHANGE name=chng5Rollback INACTIVE baselinedChanges=\"a,b,c\" \nmychange\n\n// ROLLBACK-IF-ALREADY-DEPLOYED\nmyrollbackcommand\n", objectName , "schem", null).get(0); assertEquals("schem", change.getObjectKey().getSchema()); assertEquals("chng5Rollback", change.getChangeKey().getChangeName()); assertEquals("mychange\n", change.getContent()); assertEquals("mychan", change.getContentHash()); assertEquals("myrollbackcommand", change.getRollbackIfAlreadyDeployedContent()); assertEquals(UnifiedSet.newSetWith("a", "b", "c"), change.getBaselinedChanges().toSet()); assertFalse(change.isActive()); assertNull(change.getApplyGrants()); }
assertThat("Mismatch on row " + i + " on changeKey", changes.get(i).getChangeKey(), equalTo(expected.get(i).getChangeKey())); assertThat("Mismatch on row " + i + " on content", changes.get(i).getContent(), equalToIgnoringWhiteSpace(expected.get(i).getContent())); ImmutableList<ArtifactRestrictions> restrictions = expected.get(i).getRestrictions() == null ?