use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.
the class InsertOrUpdateGeneratorH2Test method testGenerateSql_notOnlyUpdate.
/**
* Test method for {@link InsertOrUpdateGenerator#generateSql(InsertOrUpdateStatement, Database, SqlGeneratorChain)}.
*/
@Test
public void testGenerateSql_notOnlyUpdate() {
final InsertOrUpdateGeneratorH2 generator = new InsertOrUpdateGeneratorH2();
final InsertOrUpdateStatement insertOrUpdateStatement = new InsertOrUpdateStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME, "pk1");
final Database database = new H2Database();
final SqlGeneratorChain sqlGeneratorChain = null;
ColumnConfig columnConfig;
columnConfig = new ColumnConfig();
columnConfig.setValue("keyvalue1");
columnConfig.setName("pk1");
insertOrUpdateStatement.addColumn(columnConfig);
columnConfig = new ColumnConfig();
columnConfig.setValue("value0");
columnConfig.setName("col0");
insertOrUpdateStatement.addColumn(columnConfig);
// final String whereClause = generator.getWhereClause(insertOrUpdateStatement, database);
Sql[] results = generator.generateSql(insertOrUpdateStatement, database, sqlGeneratorChain);
assertThat(results, is(arrayWithSize(1)));
assertEquals(String.format("MERGE INTO %s.%s (%s, %s) KEY(%s) VALUES ('%s', '%s');", SCHEMA_NAME, TABLE_NAME, "pk1", "col0", "pk1", "keyvalue1", "value0"), results[0].toSql());
}
use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.
the class InsertOrUpdateGeneratorH2Test method testGetUpdateStatement_onlyUpdate.
/**
* Test method for {@link InsertOrUpdateGeneratorH2#getUpdateStatement(InsertOrUpdateStatement, Database, String, SqlGeneratorChain)}.
* @throws LiquibaseException
*/
@Test
public void testGetUpdateStatement_onlyUpdate() throws LiquibaseException {
final InsertOrUpdateGeneratorH2 generator = new InsertOrUpdateGeneratorH2();
final InsertOrUpdateStatement insertOrUpdateStatement = new InsertOrUpdateStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME, "pk1", true);
final Database database = new H2Database();
final SqlGeneratorChain sqlGeneratorChain = null;
ColumnConfig columnConfig;
columnConfig = new ColumnConfig();
columnConfig.setValue("value0");
columnConfig.setName("col0");
insertOrUpdateStatement.addColumn(columnConfig);
columnConfig = new ColumnConfig();
columnConfig.setValue("keyvalue1");
columnConfig.setName("pk1");
insertOrUpdateStatement.addColumn(columnConfig);
final String whereClause = generator.getWhereClause(insertOrUpdateStatement, database);
String result = generator.getUpdateStatement(insertOrUpdateStatement, database, whereClause, sqlGeneratorChain);
assertEquals(String.format("UPDATE %s.%s SET %s = '%s' WHERE %s = '%s';\n", SCHEMA_NAME, TABLE_NAME, "col0", "value0", "pk1", "keyvalue1"), result);
}
use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.
the class AddDefaultValueGeneratorInformixTest method shouldGenerateINT8TypeForBIGINTAndDefaultValue.
@Test
public void shouldGenerateINT8TypeForBIGINTAndDefaultValue() throws Exception {
AddDefaultValueGeneratorInformix informix = new AddDefaultValueGeneratorInformix();
AddDefaultValueStatement statement = new AddDefaultValueStatement(null, null, "tbl1", "id", "BIGINT", 1);
InformixDatabase database = new InformixDatabase();
SortedSet<SqlGenerator> sqlGenerators = new TreeSet<SqlGenerator>();
SqlGeneratorChain sqlGenerationChain = new SqlGeneratorChain(sqlGenerators);
Sql[] sqls = informix.generateSql(statement, database, sqlGenerationChain);
assertEquals("ALTER TABLE tbl1 MODIFY (id INT8 DEFAULT 1)", sqls[0].toSql());
}
Aggregations