Skip to content

Commit

Permalink
orcas 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
llsand committed Sep 15, 2017
1 parent 9a89abb commit c2ae93a
Show file tree
Hide file tree
Showing 87 changed files with 2,852 additions and 438 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
.vagrant
target
build

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ColumnRef :
column_name=DBNAME (",")?;

Sequence:
"create" "sequence" sequence_name=DBNAME_WITH_SCHEMA ("increment" "by" increment_by=INT)? ("maxvalue" maxvalue=INT)? ("minvalue" minvalue=INT)? (cycle=CycleType)? ("cache" cache=INT)? (order=OrderType)? ("orcas_ext_max_value_select" max_value_select=STRING)?";";
"create" "sequence" sequence_name=DBNAME_WITH_SCHEMA ("start" "with" startwith=INT)? ("increment" "by" increment_by=INT)? ("maxvalue" maxvalue=INT)? ("minvalue" minvalue=INT)? (cycle=CycleType)? ("cache" cache=INT)? (order=OrderType)? ("orcas_ext_max_value_select" max_value_select=STRING)?";";

ColumnIdentity:
"generated" ( always="always"|"by" by_default="default" ("on" on_null="null")? ) "as" "identity" ( "(" ("increment" "by" increment_by=INT)? ("maxvalue" maxvalue=INT)? ("minvalue" minvalue=INT)? (cycle=CycleType)? ("cache" cache=INT)? (order=OrderType)? ")" )?;
Expand Down
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 );
}
}
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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public abstract class DatabaseHandler

public abstract String getDefaultTablespace( CallableStatementProvider pCallableStatementProvider );

public abstract DdlBuilder createDdlBuilder();
public abstract DdlBuilder createDdlBuilder(Parameters pParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public String getDefaultTablespace( CallableStatementProvider pCallableStatement
}

@Override
public DdlBuilder createDdlBuilder()
public DdlBuilder createDdlBuilder( Parameters pParameters )
{
return new DdlBuilderMySql();
return new DdlBuilderMySql( pParameters );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public String getDefaultTablespace( CallableStatementProvider pCallableStatement
}

@Override
public DdlBuilder createDdlBuilder()
public DdlBuilder createDdlBuilder( Parameters pParameters )
{
return new DdlBuilderOracle();
return new DdlBuilderOracle( pParameters );
}
}
Loading

0 comments on commit c2ae93a

Please sign in to comment.