-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
2,852 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.gradle | ||
.vagrant | ||
target | ||
build |
5 changes: 0 additions & 5 deletions
5
examples/gradle/src/main/sql/replaceables/views/business_partners_v.sql
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
examples/maven/src/main/sql/replaceables/views/business_partners_v.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...urce/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/AbstractStatementBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.opitzconsulting.orcas.diff; | ||
|
||
import de.opitzconsulting.orcas.orig.diff.TableDiff; | ||
|
||
public class AbstractStatementBuilder | ||
{ | ||
protected String _stmt; | ||
protected AlterTableCombiner alterTableCombiner; | ||
|
||
public AbstractStatementBuilder( AlterTableCombiner pAlterTableCombiner ) | ||
{ | ||
alterTableCombiner = pAlterTableCombiner; | ||
} | ||
|
||
protected void stmtAppend( String pString ) | ||
{ | ||
_stmt = _stmt + " " + pString; | ||
} | ||
|
||
protected void stmtStart( String pString ) | ||
{ | ||
_stmt = pString; | ||
} | ||
|
||
protected void stmtStartAlterTable( String pTablename ) | ||
{ | ||
stmtStart( "alter table " + pTablename ); | ||
} | ||
|
||
protected void stmtStartAlterTable( TableDiff pTableDiff ) | ||
{ | ||
stmtStartAlterTable( pTableDiff, true ); | ||
} | ||
|
||
protected void stmtStartAlterTableNoCombine( TableDiff pTableDiff ) | ||
{ | ||
stmtStartAlterTable( pTableDiff, false ); | ||
} | ||
|
||
private void stmtStartAlterTable( TableDiff pTableDiff, boolean pIsUseAlterTableCombiner ) | ||
{ | ||
String lStatementStart = "alter table "; | ||
|
||
if( pTableDiff.isNew ) | ||
{ | ||
lStatementStart += pTableDiff.nameNew; | ||
} | ||
else | ||
{ | ||
lStatementStart += pTableDiff.nameOld; | ||
} | ||
|
||
if( alterTableCombiner != null ) | ||
{ | ||
if( pIsUseAlterTableCombiner ) | ||
{ | ||
alterTableCombiner.handleStartAlterTable( pTableDiff, lStatementStart ); | ||
} | ||
else | ||
{ | ||
alterTableCombiner.finishIfNeeded(); | ||
} | ||
} | ||
|
||
stmtStart( lStatementStart ); | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
...ild_source/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/AlterTableCombiner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package de.opitzconsulting.orcas.diff; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
import de.opitzconsulting.orcas.diff.DiffAction.DiffReasonType; | ||
import de.opitzconsulting.orcas.diff.DiffAction.Statement; | ||
import de.opitzconsulting.orcas.diff.DiffReasonKey.DiffReasonKeyRegistry; | ||
import de.opitzconsulting.orcas.orig.diff.TableDiff; | ||
|
||
public class AlterTableCombiner | ||
{ | ||
private DiffAction combinedDiffAction; | ||
private String currentStatementStart; | ||
private DiffReasonKeyRegistry diffReasonKeyRegistry; | ||
private Consumer<DiffAction> combinedDiffActionHandler; | ||
private DiffAction dummyDiffAction; | ||
private List<DiffAction> handledDiffAction; | ||
|
||
public AlterTableCombiner( DiffReasonKeyRegistry pDiffReasonKeyRegistry, Consumer<DiffAction> pCombinedDiffActionHandler ) | ||
{ | ||
diffReasonKeyRegistry = pDiffReasonKeyRegistry; | ||
combinedDiffActionHandler = pCombinedDiffActionHandler; | ||
} | ||
|
||
public void finishIfNeeded() | ||
{ | ||
if( isCombining() ) | ||
{ | ||
finish(); | ||
} | ||
} | ||
|
||
private void finish() | ||
{ | ||
List<Statement> lStatementsToCombine = new ArrayList<>(); | ||
|
||
if( handledDiffAction.size() == 1 ) | ||
{ | ||
combinedDiffAction = handledDiffAction.get( 0 ); | ||
} | ||
|
||
for( Statement lStatement : dummyDiffAction.getStatements() ) | ||
{ | ||
if( lStatement.isIgnore() ) | ||
{ | ||
combinedDiffAction.addIgnoredStatement( lStatement.getStatement(), lStatement.getComment() ); | ||
} | ||
else | ||
{ | ||
if( lStatement.isFailure() ) | ||
{ | ||
combinedDiffAction.addFailureStatement( lStatement.getStatement(), lStatement.getComment() ); | ||
} | ||
else | ||
{ | ||
lStatementsToCombine.add( lStatement ); | ||
} | ||
} | ||
} | ||
|
||
if( lStatementsToCombine.size() != 0 ) | ||
{ | ||
String lCombinedStatement; | ||
|
||
if( lStatementsToCombine.size() == 1 ) | ||
{ | ||
lCombinedStatement = lStatementsToCombine.get( 0 ).getStatement(); | ||
} | ||
else | ||
{ | ||
String lSeparator = "\n "; | ||
lCombinedStatement = currentStatementStart + lSeparator + // | ||
lStatementsToCombine.stream()// | ||
.map( Statement::getStatement )// | ||
.map( p -> p.substring( currentStatementStart.length() + 1 ) )// | ||
.collect( Collectors.joining( lSeparator ) ); | ||
} | ||
|
||
List<String> lComments = lStatementsToCombine.stream()// | ||
.map( Statement::getComment )// | ||
.filter( Objects::nonNull )// | ||
.collect( Collectors.toList() ); | ||
|
||
if( lComments.isEmpty() ) | ||
{ | ||
combinedDiffAction.addStatement( lCombinedStatement ); | ||
} | ||
else | ||
{ | ||
combinedDiffAction.addStatement( lCombinedStatement, lComments.stream().collect( Collectors.joining( ";" ) ) ); | ||
} | ||
} | ||
|
||
combinedDiffActionHandler.accept( combinedDiffAction ); | ||
|
||
dummyDiffAction = null; | ||
combinedDiffAction = null; | ||
currentStatementStart = null; | ||
} | ||
|
||
private boolean isCombining() | ||
{ | ||
return combinedDiffAction != null && currentStatementStart != null && dummyDiffAction != null; | ||
} | ||
|
||
public void handleStartAlterTable( TableDiff pTableDiff, String pStatementStart ) | ||
{ | ||
finishIfNotMatching( pStatementStart ); | ||
|
||
if( !isCombining() ) | ||
{ | ||
dummyDiffAction = new DiffAction( diffReasonKeyRegistry.getDiffReasonKey( pTableDiff ), DiffReasonType.ALTER ); | ||
combinedDiffAction = new DiffAction( diffReasonKeyRegistry.getDiffReasonKey( pTableDiff ), DiffReasonType.ALTER ); | ||
currentStatementStart = pStatementStart; | ||
handledDiffAction = new ArrayList<>(); | ||
} | ||
} | ||
|
||
public DiffAction getDiffActionForAddStatement( DiffAction pDiffAction, String pStatement ) | ||
{ | ||
finishIfNotMatching( pStatement ); | ||
|
||
if( isCombining() ) | ||
{ | ||
if( !handledDiffAction.contains( pDiffAction ) ) | ||
{ | ||
pDiffAction.getDiffActionReasons().forEach( combinedDiffAction::addDiffActionReason ); | ||
handledDiffAction.add( pDiffAction ); | ||
} | ||
|
||
return dummyDiffAction; | ||
} | ||
|
||
return pDiffAction; | ||
} | ||
|
||
private void finishIfNotMatching( String pStatement ) | ||
{ | ||
if( isCombining() ) | ||
{ | ||
if( !pStatement.startsWith( currentStatementStart ) ) | ||
{ | ||
finish(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.