public class LiquibaseStatementsWriter extends AbstractStatementsWriter
AbstractStatementsWriter.AbstractTableStatement, AbstractStatementsWriter.InsertStatement, AbstractStatementsWriter.PlainStatement, AbstractStatementsWriter.UpdateStatement
Modifier and Type | Field and Description |
---|---|
private String |
changeSetAuthour
The author of the next created change set.
|
private String |
changeSetComment
The comment of the next created change set.
|
private String |
changeSetId
The ID of the next created change set.
|
private boolean |
changeSetStarted
Indicates if we are currently in a changeSet.
|
private static RelativeDate.Precision[] |
DATE_PRECISIONS |
private static org.apache.commons.lang.time.FastDateFormat |
ISO_DATETIMESECONDS_FORMAT |
static String |
OUTPUT_FILE_KEY
Settings key for the generated XML file, if not given in the constructor. |
private OutputStream |
outputStream
The outputstream to close, if this writer is closed.
|
private boolean |
relativeDatesSupported
Indicates if our liquibase version supports relative dates.
|
static String |
VERSION_KEY
Settings key for the generated liquibase version, if not given in the
constructor. |
private XMLStreamWriter |
writer
The receiver of our XML elements.
|
Constructor and Description |
---|
LiquibaseStatementsWriter(GeneratorContext context)
Creates a new writer which generates an XML file with "UTF-8" encoding.
|
LiquibaseStatementsWriter(OutputStream outputStream,
String version)
Creates a new writer which generates an XML file with "UTF-8" encoding.
|
LiquibaseStatementsWriter(XMLStreamWriter writer,
String version)
Creates a new instance of
LiquibaseStatementsWriter . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Writes the remaining elements.
|
private void |
ensureChangeSetStarted() |
void |
flush()
Flushes any open statements.
|
String |
getChangeSetAuthour()
The author of the next created change set.
|
String |
getChangeSetComment()
The comment of the next created change set.
|
String |
getChangeSetId()
The ID of the next created change set.
|
XMLStreamWriter |
getWriter()
The receiver of our XML elements.
|
boolean |
isChangeSetStarted()
Indicates if we are currently in a changeSet.
|
boolean |
isRelativeDatesSupported()
Indicates if our liquibase version supports relative dates.
|
void |
startNextChangeSet(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 void |
writeColumnExpression(ColumnExpression expression) |
void |
writeComment(String comment)
Writes a SQL comment to the target.
|
private void |
writeDateExpression(ColumnExpression expression,
Date value,
Date databaseValue) |
void |
writePlainStatement(GeneratorDialect dialect,
String sql)
Writes a plain SQL statement.
|
private void |
writePrimitiveExpression(PrimitiveColumnExpression<?> expression) |
private void |
writeRelativeDateExpression(ColumnExpression expression,
Date value) |
void |
writeSectionSeparator()
Writes a new line to the target file to separate different sections in the SQL file.
|
private void |
writeSequenceExpression(SequenceValueExpression expression) |
void |
writeStatement(EntityStatement statement)
Writes the given statement to a file or database.
|
private void |
writeString(ColumnExpression expression,
String value) |
private void |
writeTableStatement(AbstractStatementsWriter.AbstractTableStatement insert) |
createInsertStatement, createPlainStatement, createUpdateStatement
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
truncateTables
public static final String OUTPUT_FILE_KEY
Settings key
for the generated XML file, if not given in the constructor.public static final String VERSION_KEY
Settings key
for the generated liquibase version, if not given in the
constructor.private static final RelativeDate.Precision[] DATE_PRECISIONS
private static final org.apache.commons.lang.time.FastDateFormat ISO_DATETIMESECONDS_FORMAT
private final XMLStreamWriter writer
private final boolean relativeDatesSupported
private OutputStream outputStream
private String changeSetId
private String changeSetAuthour
private String changeSetComment
private boolean changeSetStarted
public LiquibaseStatementsWriter(GeneratorContext context) throws XMLStreamException, FileNotFoundException
context
- contains all the settings that we need to build the fileXMLStreamException
- if already the root element could not be createdFileNotFoundException
- if the parent directory does not existpublic LiquibaseStatementsWriter(OutputStream outputStream, String version) throws XMLStreamException
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 elseXMLStreamException
- if already the root element could not be createdpublic LiquibaseStatementsWriter(XMLStreamWriter writer, String version) throws XMLStreamException
LiquibaseStatementsWriter
.writer
- the stream writer for generating the XMLversion
- the liquibase version - this is only for the referenced schema and won't change anything elseXMLStreamException
- if already the root element could not be createdpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class AbstractStatementsWriter
IOException
private void ensureChangeSetStarted() throws XMLStreamException
XMLStreamException
public void flush() throws IOException
StatementsWriter
flush
in interface StatementsWriter
flush
in class AbstractStatementsWriter
IOException
- if the target throws an exceptionpublic void startNextChangeSet(String id, String author, String comment) throws XMLStreamException
id
- the ID of the next change setauthor
- the author of the next change setcomment
- the (optional) comment of the next change setXMLStreamException
- if there is an error during closing the current change setprivate void writeColumnExpression(ColumnExpression expression) throws XMLStreamException
XMLStreamException
public void writeComment(String comment) throws IOException
StatementsWriter
writeComment
in interface StatementsWriter
writeComment
in class AbstractStatementsWriter
comment
- the comment to writeIOException
- if the target throws an exceptionprivate void writeDateExpression(ColumnExpression expression, Date value, Date databaseValue) throws XMLStreamException
XMLStreamException
public void writePlainStatement(GeneratorDialect dialect, String sql) throws IOException
StatementsWriter
writeStatement(createPlainStatement(sql), dialect)
.dialect
- the current database dialectsql
- the content of the SQL statementIOException
- if the file or database throws an exceptionprivate void writePrimitiveExpression(PrimitiveColumnExpression<?> expression) throws XMLStreamException
XMLStreamException
private void writeRelativeDateExpression(ColumnExpression expression, Date value) throws XMLStreamException
XMLStreamException
public void writeSectionSeparator() throws IOException
StatementsWriter
writeSectionSeparator
in interface StatementsWriter
writeSectionSeparator
in class AbstractStatementsWriter
IOException
- if the target throws such an exceptionprivate void writeSequenceExpression(SequenceValueExpression expression) throws XMLStreamException
XMLStreamException
public void writeStatement(EntityStatement statement) throws IOException
StatementsWriter
statement
- contains the values to writeIOException
- if the file or database throws an exceptionprivate void writeString(ColumnExpression expression, String value) throws XMLStreamException
XMLStreamException
private void writeTableStatement(AbstractStatementsWriter.AbstractTableStatement insert) throws XMLStreamException
XMLStreamException
@Generated(value="lombok") public XMLStreamWriter getWriter()
@Generated(value="lombok") public boolean isRelativeDatesSupported()
@Generated(value="lombok") public String getChangeSetId()
@Generated(value="lombok") public String getChangeSetAuthour()
@Generated(value="lombok") public String getChangeSetComment()
@Generated(value="lombok") public boolean isChangeSetStarted()
Copyright © 2022 fastnate.org. All rights reserved.