public class FileStatementsWriter extends AbstractStatementsWriter
AbstractStatementsWriter.AbstractTableStatement, AbstractStatementsWriter.InsertStatement, AbstractStatementsWriter.PlainStatement, AbstractStatementsWriter.UpdateStatement| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
log |
static String |
OUTPUT_ENCODING_KEY
Settings key for the encoding of the generated SQL file, if not given in
the constructor. |
static String |
OUTPUT_FILE_KEY
Settings key for the generated SQL file, if not given in the constructor. |
private int |
statementsCount
The count of written statements.
|
private String |
statementSeparator
The separator of the single statements, defaults to
";\n". |
private Writer |
writer
Used to write the SQL statements.
|
| Constructor and Description |
|---|
FileStatementsWriter(File file)
Creates a new instance for a specifc file and UTF-8 encoding.
|
FileStatementsWriter(File file,
Charset encoding)
Creates a new instance for a specifc file and encoding.
|
FileStatementsWriter(GeneratorContext context)
Creates a new instance of
FileStatementsWriter. |
FileStatementsWriter(Writer writer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected static File |
ensureDirectoryExists(File outputFile)
Ensures, that the parent directory of the given output file exists.
|
void |
flush()
Flushes any open statements.
|
int |
getStatementsCount()
The count of written statements.
|
String |
getStatementSeparator()
The separator of the single statements, defaults to
";\n". |
Writer |
getWriter()
Used to write the SQL statements.
|
void |
setStatementSeparator(String statementSeparator)
The separator of the single statements, defaults to
";\n". |
void |
write(String statements)
Writes a bunch of SQL statements to the file.
|
void |
writeComment(String comment)
Writes a SQL comment to the target.
|
void |
writePlainStatement(GeneratorDialect dialect,
String sql)
Writes a plain SQL statement.
|
void |
writeSectionSeparator()
Writes a new line to the target file to separate different sections in the SQL file.
|
void |
writeStatement(EntityStatement statement)
Writes the given statement to a file or database.
|
createInsertStatement, createPlainStatement, createUpdateStatementclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittruncateTables@Generated(value="lombok") private static final org.slf4j.Logger log
public static final String OUTPUT_FILE_KEY
Settings key for the generated SQL file, if not given in the constructor.public static final String OUTPUT_ENCODING_KEY
Settings key for the encoding of the generated SQL file, if not given in
the constructor.private final Writer writer
private String statementSeparator
";\n".private int statementsCount
public FileStatementsWriter(File file) throws FileNotFoundException
file - the target fileFileNotFoundException - if the file could not be opened for writingpublic FileStatementsWriter(File file, Charset encoding) throws FileNotFoundException
file - the target fileencoding - the charset of the target fileFileNotFoundException - if the file could not be opened for writingpublic FileStatementsWriter(GeneratorContext context) throws FileNotFoundException
FileStatementsWriter.
The target file and its encoding are taken from the settings OUTPUT_FILE_KEY and
OUTPUT_ENCODING_KEY.context - the context of the generation (for lookup of the properties)FileNotFoundException - if the file path is not available for writing@ConstructorProperties(value="writer") @Generated(value="lombok") public FileStatementsWriter(Writer writer)
protected static File ensureDirectoryExists(File outputFile)
outputFile - the output filepublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class AbstractStatementsWriterIOExceptionpublic void flush()
throws IOException
StatementsWriterflush in interface StatementsWriterflush in class AbstractStatementsWriterIOException - if the target throws an exceptionpublic void write(String statements) throws IOException
statements - the SQL statements (or anything else what should be added to the file)IOException - if the writer throws onepublic void writeComment(String comment) throws IOException
StatementsWriterwriteComment in interface StatementsWriterwriteComment in class AbstractStatementsWritercomment - the comment to writeIOException - if the target throws an exceptionpublic void writePlainStatement(GeneratorDialect dialect, String sql) throws IOException
StatementsWriterwriteStatement(createPlainStatement(sql), dialect).dialect - the current database dialectsql - the content of the SQL statementIOException - if the file or database throws an exceptionpublic void writeSectionSeparator()
throws IOException
StatementsWriterwriteSectionSeparator in interface StatementsWriterwriteSectionSeparator in class AbstractStatementsWriterIOException - if the target throws such an exceptionpublic void writeStatement(EntityStatement statement) throws IOException
StatementsWriterstatement - contains the values to writeIOException - if the file or database throws an exception@Generated(value="lombok") public Writer getWriter()
@Generated(value="lombok") public String getStatementSeparator()
";\n".@Generated(value="lombok") public void setStatementSeparator(String statementSeparator)
";\n".@Generated(value="lombok") public int getStatementsCount()
Copyright © 2022 fastnate.org. All rights reserved.