01: package liquibase.database.template;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.SqlStatement;
05: import liquibase.exception.JDBCException;
06: import liquibase.util.StreamUtil;
07:
08: import java.io.IOException;
09: import java.io.Writer;
10:
11: public class JdbcOutputTemplate extends JdbcTemplate {
12:
13: private Writer output;
14:
15: public JdbcOutputTemplate(Writer output, Database database) {
16: super (database);
17: this .output = output;
18: }
19:
20: public boolean executesStatements() {
21: return false;
22: }
23:
24: public void execute(SqlStatement sql) throws JDBCException {
25: outputStatement(sql);
26: }
27:
28: public int update(SqlStatement sql) throws JDBCException {
29: outputStatement(sql);
30:
31: return 0;
32: }
33:
34: public void comment(String message) throws JDBCException {
35: try {
36: output.write(database.getLineComment());
37: output.write(" ");
38: output.write(message);
39: output.write(StreamUtil.getLineSeparator());
40: } catch (IOException e) {
41: throw new JDBCException(e);
42: }
43: }
44:
45: private void outputStatement(SqlStatement sql) throws JDBCException {
46: try {
47: output.write(sql.getSqlStatement(database));
48: output.write(";");
49: output.write(StreamUtil.getLineSeparator());
50: output.write(StreamUtil.getLineSeparator());
51: } catch (IOException e) {
52: throw new JDBCException(e);
53: }
54: }
55: }
|