Class LiquibaseStatementsWriter
java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.LiquibaseStatementsWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,StatementsWriter
Generates statements for the Liquibase changelog file.
- Author:
- Tobias Liefke
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.fastnate.generator.statements.AbstractStatementsWriter
AbstractStatementsWriter.AbstractTableStatement, AbstractStatementsWriter.InsertStatement, AbstractStatementsWriter.PlainStatement, AbstractStatementsWriter.UpdateStatement -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSettings keyfor the generated XML file, if not given in the constructor.static final StringSettings keyfor the generated liquibase version, if not given in the constructor. -
Constructor Summary
ConstructorsConstructorDescriptionLiquibaseStatementsWriter(OutputStream outputStream, String version) Creates a new writer which generates an XML file with "UTF-8" encoding and use the H2 dialect for any plain statement.LiquibaseStatementsWriter(XMLStreamWriter writer, String version) Creates a new writer which uses H2 for any plain statement.Creates a new writer which generates an XML file with "UTF-8" encoding.LiquibaseStatementsWriter(GeneratorDialect dialect, OutputStream outputStream, String version) Creates a new writer which generates an XML file with "UTF-8" encoding.LiquibaseStatementsWriter(GeneratorDialect dialect, XMLStreamWriter writer, String version) Creates a new writer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Writes the remaining elements.voidflush()Flushes any open statements.The author of the next created change set.The comment of the next created change set.The ID of the next created change set.The current database dialect (in case any plain SQL statement needs to be written).The receiver of our XML elements.booleanIndicates if we are currently in a changeSet.booleanIndicates if our liquibase version supports relative dates.voidstartNextChangeSet(String id, String author, String comment) Closes the current change set (if any was started) and sets the infos of the next change set.voidwriteComment(String comment) Writes a SQL comment to the target.voidwritePlainStatement(GeneratorDialect currentDialect, String sql) Writes a plain SQL statement.voidWrites a new line to the target file to separate different sections in the SQL file.voidwriteStatement(EntityStatement statement) Writes the given statement to a file or database.Methods inherited from class org.fastnate.generator.statements.AbstractStatementsWriter
createInsertStatement, createPlainStatement, createUpdateStatementMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.fastnate.generator.statements.StatementsWriter
truncateTables
-
Field Details
-
OUTPUT_FILE_KEY
Settings keyfor the generated XML file, if not given in the constructor.- See Also:
-
VERSION_KEY
Settings keyfor the generated liquibase version, if not given in the constructor.- See Also:
-
-
Constructor Details
-
LiquibaseStatementsWriter
public LiquibaseStatementsWriter(GeneratorContext context) throws XMLStreamException, FileNotFoundException Creates a new writer which generates an XML file with "UTF-8" encoding.- Parameters:
context- contains all the settings that we need to build the file- Throws:
XMLStreamException- if already the root element could not be createdFileNotFoundException- if the parent directory does not exist
-
LiquibaseStatementsWriter
public LiquibaseStatementsWriter(GeneratorDialect dialect, OutputStream outputStream, String version) throws XMLStreamException Creates a new writer which generates an XML file with "UTF-8" encoding.- Parameters:
dialect- the database dialect for any plain SQL statementoutputStream- the target stream, will be close when this wirter is closedversion- the liquibase version - this is only for the referenced schema and won't change anything else- Throws:
XMLStreamException- if already the root element could not be created
-
LiquibaseStatementsWriter
public LiquibaseStatementsWriter(GeneratorDialect dialect, XMLStreamWriter writer, String version) throws XMLStreamException Creates a new writer.- Parameters:
dialect- the database dialect for any plain SQL statementwriter- the stream writer for generating the XMLversion- the liquibase version - this is only for the referenced schema and won't change anything else- Throws:
XMLStreamException- if already the root element could not be created
-
LiquibaseStatementsWriter
public LiquibaseStatementsWriter(OutputStream outputStream, String version) throws XMLStreamException Creates a new writer which generates an XML file with "UTF-8" encoding and use the H2 dialect for any plain statement.- Parameters:
outputStream- the target stream, will be close when this wirter is closedversion- the liquibase version - this is only for the referenced schema and won't change anything else- Throws:
XMLStreamException- if already the root element could not be created
-
LiquibaseStatementsWriter
Creates a new writer which uses H2 for any plain statement.- Parameters:
writer- the stream writer for generating the XMLversion- the liquibase version - this is only for the referenced schema and won't change anything else- Throws:
XMLStreamException- if already the root element could not be created
-
-
Method Details
-
close
Writes the remaining elements. This will not close the output stream, you will need to close it manually.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractStatementsWriter- Throws:
IOException
-
flush
Description copied from interface:StatementsWriterFlushes any open statements.- Specified by:
flushin interfaceStatementsWriter- Overrides:
flushin classAbstractStatementsWriter- Throws:
IOException- if the target throws an exception
-
startNextChangeSet
Closes the current change set (if any was started) and sets the infos of the next change set.- Parameters:
id- the ID of the next change setauthor- the author of the next change setcomment- the (optional) comment of the next change set- Throws:
XMLStreamException- if there is an error during closing the current change set
-
writeComment
Description copied from interface:StatementsWriterWrites a SQL comment to the target.- Specified by:
writeCommentin interfaceStatementsWriter- Overrides:
writeCommentin classAbstractStatementsWriter- Parameters:
comment- the comment to write- Throws:
IOException- if the target throws an exception
-
writePlainStatement
Description copied from interface:StatementsWriterWrites a plain SQL statement. Shortcut forwriteStatement(createPlainStatement(sql), dialect).- Parameters:
currentDialect- the current database dialectsql- the content of the SQL statement- Throws:
IOException- if the file or database throws an exception
-
writeSectionSeparator
Description copied from interface:StatementsWriterWrites a new line to the target file to separate different sections in the SQL file.- Specified by:
writeSectionSeparatorin interfaceStatementsWriter- Overrides:
writeSectionSeparatorin classAbstractStatementsWriter- Throws:
IOException- if the target throws such an exception
-
writeStatement
Description copied from interface:StatementsWriterWrites the given statement to a file or database.- Parameters:
statement- contains the values to write- Throws:
IOException- if the file or database throws an exception
-
getDialect
The current database dialect (in case any plain SQL statement needs to be written). -
getWriter
The receiver of our XML elements. -
isRelativeDatesSupported
public boolean isRelativeDatesSupported()Indicates if our liquibase version supports relative dates. -
getChangeSetId
The ID of the next created change set. -
getChangeSetAuthour
The author of the next created change set. -
getChangeSetComment
The comment of the next created change set. -
isChangeSetStarted
public boolean isChangeSetStarted()Indicates if we are currently in a changeSet.
-