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 TypeFieldDescriptionprivate StringThe author of the next created change set.private StringThe comment of the next created change set.private StringThe ID of the next created change set.private booleanIndicates if we are currently in a changeSet.private static final RelativeDate.Precision[]private final GeneratorDialectThe current database dialect (in case any plain SQL statement needs to be written).private static final org.apache.commons.lang3.time.FastDateFormatstatic final StringSettings keyfor the generated XML file, if not given in the constructor.private OutputStreamThe outputstream to close, if this writer is closed.private final booleanIndicates if our liquibase version supports relative dates.static final StringSettings keyfor the generated liquibase version, if not given in the constructor.private final XMLStreamWriterThe receiver of our XML elements. -
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.private voidvoidflush()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.private voidwriteColumnExpression(ColumnExpression expression) voidwriteComment(String comment) Writes a SQL comment to the target.private voidwriteDateExpression(ColumnExpression expression, Date value, Date databaseValue) voidwritePlainStatement(GeneratorDialect currentDialect, String sql) Writes a plain SQL statement.private voidwritePrimitiveExpression(PrimitiveColumnExpression<?> expression) private voidwriteRelativeDateExpression(ColumnExpression expression, Date value) voidWrites a new line to the target file to separate different sections in the SQL file.private voidwriteSequenceExpression(SequenceValueExpression expression) voidwriteStatement(EntityStatement statement) Writes the given statement to a file or database.private voidwriteString(ColumnExpression expression, String value) private voidMethods 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:
-
DATE_PRECISIONS
-
ISO_DATETIMESECONDS_FORMAT
private static final org.apache.commons.lang3.time.FastDateFormat ISO_DATETIMESECONDS_FORMAT -
dialect
The current database dialect (in case any plain SQL statement needs to be written). -
writer
The receiver of our XML elements. -
relativeDatesSupported
private final boolean relativeDatesSupportedIndicates if our liquibase version supports relative dates. -
outputStream
The outputstream to close, if this writer is closed. -
changeSetId
The ID of the next created change set. -
changeSetAuthour
The author of the next created change set. -
changeSetComment
The comment of the next created change set. -
changeSetStarted
private boolean changeSetStartedIndicates if we are currently in a changeSet.
-
-
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
-
ensureChangeSetStarted
- Throws:
XMLStreamException
-
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
-
writeColumnExpression
- Throws:
XMLStreamException
-
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
-
writeDateExpression
private void writeDateExpression(ColumnExpression expression, Date value, Date databaseValue) throws XMLStreamException - Throws:
XMLStreamException
-
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
-
writePrimitiveExpression
private void writePrimitiveExpression(PrimitiveColumnExpression<?> expression) throws XMLStreamException - Throws:
XMLStreamException
-
writeRelativeDateExpression
private void writeRelativeDateExpression(ColumnExpression expression, Date value) throws XMLStreamException - Throws:
XMLStreamException
-
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
-
writeSequenceExpression
- Throws:
XMLStreamException
-
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
-
writeString
- Throws:
XMLStreamException
-
writeTableStatement
private void writeTableStatement(AbstractStatementsWriter.AbstractTableStatement insert) throws XMLStreamException - Throws:
XMLStreamException
-
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.
-