Skip to content

Commit

Permalink
https://github.com/liquibase/liquibase-oracle/issues/15
Browse files Browse the repository at this point in the history
adding alternative to "procedure" attribute for the create trigger a
procedureNode xml node.
  • Loading branch information
Istvan Szilagyi committed Dec 4, 2017
1 parent a480e97 commit 5320541
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
</developers>

<scm>
<connection>scm:git:[email protected]:liquibase/liquibase-oracle.git</connection>
<url>scm:git:https://github.com/liquibase/liquibase-oracle.git</url>
<developerConnection>scm:git:[email protected]:liquibase/liquibase-oracle.git</developerConnection>
<connection>scm:git:[email protected]:iszilagyigit/liquibase-oracle.git</connection>
<url>scm:git:https://github.com/iszilagyigit/liquibase-oracle.git</url>
<developerConnection>scm:git:[email protected]:iszilagyigit/liquibase-oracle.git</developerConnection>
</scm>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import liquibase.change.Change;
import liquibase.change.ChangeMetaData;
import liquibase.change.DatabaseChange;
import liquibase.change.DatabaseChangeProperty;
import liquibase.database.Database;
import liquibase.ext.ora.droptrigger.DropTriggerChange;
import liquibase.serializer.LiquibaseSerializable;
import liquibase.statement.SqlStatement;

@DatabaseChange(name="createTrigger", description = "Create Trigger", priority = ChangeMetaData.PRIORITY_DEFAULT)
Expand All @@ -29,6 +31,8 @@ public class CreateTriggerChange extends AbstractChange {

private String procedure;

private String procedureNode;

public CreateTriggerChange() {
}

Expand Down Expand Up @@ -153,7 +157,6 @@ public void setWhenCondition(String whenCondition) {
this.whenCondition = whenCondition;
}


public String getProcedure() {
return procedure;
}
Expand Down Expand Up @@ -220,8 +223,17 @@ public SqlStatement[] generateStatements(Database database) {
statement.setViewName(getViewName());
statement.setWhenCondition(getWhenCondition());
statement.setTableName(getTableName());
statement.setProcedure(getProcedure());
statement.setProcedure(getProcedureNode() != null ? getProcedureNode() : getProcedure());

return new SqlStatement[]{statement};
}

@DatabaseChangeProperty(serializationType=LiquibaseSerializable.SerializationType.DIRECT_VALUE)
public String getProcedureNode() {
return procedureNode;
}

public void setProcedureNode(String procedureNode) {
this.procedureNode = procedureNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public void getConfirmationMessage() {

@Test
public void generateStatement() {
final String triggerBodyExample = " DECLARE v_username varchar2(10);\r\n"
+ " BEGIN\r\n"
+ " SELECT pierwsza INTO v_username FROM TriggerTest;\r\n"
+ " :new.created_by := v_username;\r\n"
+ " END;\r\n";

CreateTriggerChange change = new CreateTriggerChange();
change.setSchemaName("SCHEMA_NAME");
Expand All @@ -63,7 +68,8 @@ public void generateStatement() {
change.setTablespace("TABLESPACE_NAME");
change.setAfterBeforeInsteadOf("AFTER_BEFORE_INSTEADOF");
change.setNestedTableColumn("NESTED_TABLE_COLUMN");
change.setProcedure("POCEDURE");
change.setProcedureNode( triggerBodyExample);

change.setTriggerName("TRIGGER_NAME");
change.setViewName("VIEW_NAME");
change.setWhenCondition("WHEN_CONDITION");
Expand All @@ -88,7 +94,7 @@ public void generateStatement() {
assertEquals("TABLESPACE_NAME", sqlStatement.getTablespace());
assertEquals("AFTER_BEFORE_INSTEADOF", sqlStatement.getAfterBeforeInsteadOf());
assertEquals("NESTED_TABLE_COLUMN", sqlStatement.getNestedTableColumn());
assertEquals("POCEDURE", sqlStatement.getProcedure());
assertEquals(triggerBodyExample, sqlStatement.getProcedure());
assertEquals("TRIGGER_NAME", sqlStatement.getTriggerName());
assertEquals("VIEW_NAME", sqlStatement.getViewName());
assertEquals("WHEN_CONDITION", sqlStatement.getWhenCondition());
Expand Down

0 comments on commit 5320541

Please sign in to comment.