use of liquibase.database.core.SQLiteDatabase in project liquibase by liquibase.
the class CopyRowsGenerator method generateSql.
@Override
public Sql[] generateSql(CopyRowsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuilder sql = new StringBuilder();
if (statement.getCopyColumns().isEmpty()) {
return new Sql[] {};
}
if (database instanceof SQLiteDatabase) {
sql.append("INSERT INTO ").append(database.escapeTableName(null, null, statement.getTargetTable())).append(" (");
for (int i = 0; i < statement.getCopyColumns().size(); i++) {
ColumnConfig column = statement.getCopyColumns().get(i);
if (i > 0) {
sql.append(",");
}
sql.append(database.escapeColumnName(null, null, statement.getTargetTable(), column.getName()));
}
sql.append(") SELECT ");
for (int i = 0; i < statement.getCopyColumns().size(); i++) {
ColumnConfig column = statement.getCopyColumns().get(i);
if (i > 0) {
sql.append(",");
}
sql.append(database.escapeColumnName(null, null, statement.getSourceTable(), column.getName()));
}
sql.append(" FROM ").append(database.escapeTableName(null, null, statement.getSourceTable()));
}
return new Sql[] { new UnparsedSql(sql.toString(), getAffectedTable(statement)) };
}
use of liquibase.database.core.SQLiteDatabase in project collect by openforis.
the class ExternalCodeListIntegrationTest method before.
@SuppressWarnings("deprecation")
@Before
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void before() throws IdmlParseException, IOException, SurveyImportException, SQLException, LiquibaseException, SurveyValidationException {
SQLiteDatabase database = new SQLiteDatabase();
Connection connection = DataSourceUtils.getConnection(transactionAwareDataSource);
database.setConnection(new JdbcConnection(connection));
Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database);
liquibase.update((String) null);
survey = loadSurvey();
createHierarchicalTestList();
createFlatTestList();
surveyManager.importModel(survey);
}
use of liquibase.database.core.SQLiteDatabase in project collect by openforis.
the class LiquibaseRelationalSchemaCreator method createRelationalSchema.
@Override
public void createRelationalSchema(RelationalSchema schema, Connection targetConn) throws CollectRdbException {
PrintStream ps = null;
try {
LiquidbaseDatabaseSnapshotBuilder snapshotGen = new LiquidbaseDatabaseSnapshotBuilder();
Database rdb = getDatabaseImplementation(targetConn);
boolean dbSupportsFKs = rdb instanceof SQLiteDatabase ? false : true;
DatabaseSnapshot generatedSnapshot = snapshotGen.createSnapshot(schema, dbSupportsFKs);
String targetSchema = schema.getName();
rdb.setDefaultSchemaName(targetSchema);
DatabaseSnapshot emptyDbSnapshot = new DatabaseSnapshot(rdb, targetSchema);
// Generate change set
Diff diff = new Diff(generatedSnapshot, emptyDbSnapshot);
DiffResult diffResult = diff.compare();
File tmpFile = File.createTempFile("collect-schemagen", ".xml");
ps = new PrintStream(new FileOutputStream(tmpFile));
diffResult.setChangeSetAuthor("collect3");
diffResult.setChangeSetContext("schemagen");
System.out.println("Writing change log to " + tmpFile.getAbsolutePath());
diffResult.printChangeLog(ps, rdb);
ps.flush();
// Execute change set
Liquibase liq = new Liquibase(tmpFile.getName(), new FileSystemResourceAccessor(tmpFile.getParent()), rdb);
liq.update("schemagen");
} catch (LiquibaseException e) {
throw new CollectRdbException("Failed to update schema", e);
} catch (IOException e) {
throw new CollectRdbException("Failed to create temp db changelog file", e);
} catch (ParserConfigurationException e) {
throw new CollectRdbException("Failed to write temp db changelog file", e);
} finally {
if (ps != null) {
ps.close();
}
}
}
Aggregations