Coverage Report - liquibase.sqlgenerator.core.CopyRowsGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
CopyRowsGenerator
5%
1/17
0%
0/6
2
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.change.ColumnConfig;
 4  
 import liquibase.database.Database;
 5  
 import liquibase.database.core.SQLiteDatabase;
 6  
 import liquibase.exception.ValidationErrors;
 7  
 import liquibase.sql.Sql;
 8  
 import liquibase.sql.UnparsedSql;
 9  
 import liquibase.sqlgenerator.SqlGenerator;
 10  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 11  
 import liquibase.statement.core.CopyRowsStatement;
 12  
 
 13  10
 public class CopyRowsGenerator extends AbstractSqlGenerator<CopyRowsStatement> {
 14  
 
 15  
     @Override
 16  
     public boolean supports(CopyRowsStatement statement, Database database) {
 17  0
         return (database instanceof SQLiteDatabase);
 18  
     }
 19  
 
 20  
     public ValidationErrors validate(CopyRowsStatement copyRowsStatement, Database database,
 21  
             SqlGeneratorChain sqlGeneratorChain) {
 22  0
         ValidationErrors validationErrors = new ValidationErrors();
 23  0
         validationErrors.checkRequiredField("targetTable", copyRowsStatement.getTargetTable());
 24  0
         validationErrors.checkRequiredField("sourceTable", copyRowsStatement.getSourceTable());
 25  0
         validationErrors.checkRequiredField("copyColumns", copyRowsStatement.getCopyColumns());
 26  0
         return validationErrors;
 27  
     }
 28  
 
 29  
     public Sql[] generateSql(CopyRowsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
 30  0
         StringBuffer sql = new StringBuffer();
 31  0
         if (database instanceof SQLiteDatabase) {
 32  0
             sql.append("INSERT INTO `").append(statement.getTargetTable()).append("` SELECT ");
 33  0
             for (int i = 0; i < statement.getCopyColumns().size(); i++) {
 34  0
                 ColumnConfig column = statement.getCopyColumns().get(i);
 35  0
                 if (i > 0) {
 36  0
                     sql.append(",");
 37  
                 }
 38  0
                 sql.append("`").append(column.getName()).append("`");
 39  
             }
 40  0
             sql.append(" FROM `").append(statement.getSourceTable()).append("`");
 41  
         }
 42  
 
 43  0
         return new Sql[] { new UnparsedSql(sql.toString()) };
 44  
     }
 45  
 }