Class FileStatementsWriter
java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.FileStatementsWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,StatementsWriter
- Direct Known Subclasses:
PostgreSqlBulkWriter
- Author:
- Tobias Liefke
-
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 encoding of the generated SQL file, if not given in the constructor.static final StringSettings keyfor the generated SQL file, if not given in the constructor. -
Constructor Summary
ConstructorsConstructorDescriptionFileStatementsWriter(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(Writer writer) Creates a newFileStatementsWriterinstance.FileStatementsWriter(GeneratorContext context) Creates a new instance ofFileStatementsWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected static FileensureDirectoryExists(File outputFile) Ensures, that the parent directory of the given output file exists.voidflush()Flushes any open statements.intThe count of written statements.The separator of the single statements, defaults to";\n".Used to write the SQL statements.voidsetStatementSeparator(String statementSeparator) The separator of the single statements, defaults to";\n".voidWrites a bunch of SQL statements to the file.voidwriteComment(String comment) Writes a SQL comment to the target.voidwritePlainStatement(GeneratorDialect dialect, 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 SQL file, if not given in the constructor.- See Also:
-
OUTPUT_ENCODING_KEY
Settings keyfor the encoding of the generated SQL file, if not given in the constructor.- See Also:
-
-
Constructor Details
-
FileStatementsWriter
Creates a new instance for a specifc file and UTF-8 encoding.- Parameters:
file- the target file- Throws:
FileNotFoundException- if the file could not be opened for writing
-
FileStatementsWriter
Creates a new instance for a specifc file and encoding.- Parameters:
file- the target fileencoding- the charset of the target file- Throws:
FileNotFoundException- if the file could not be opened for writing
-
FileStatementsWriter
Creates a new instance ofFileStatementsWriter. The target file and its encoding are taken from the settingsOUTPUT_FILE_KEYandOUTPUT_ENCODING_KEY.- Parameters:
context- the context of the generation (for lookup of the properties)- Throws:
FileNotFoundException- if the file path is not available for writing
-
FileStatementsWriter
Creates a newFileStatementsWriterinstance.- Parameters:
writer- Used to write the SQL statements.
-
-
Method Details
-
ensureDirectoryExists
Ensures, that the parent directory of the given output file exists.- Parameters:
outputFile- the output file- Returns:
- the output file (for chaining)
-
close
- 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
-
write
Writes a bunch of SQL statements to the file.- Parameters:
statements- the SQL statements (or anything else what should be added to the file)- Throws:
IOException- if the writer throws one
-
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:
dialect- 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
-
getWriter
Used to write the SQL statements. -
getStatementSeparator
The separator of the single statements, defaults to";\n". -
setStatementSeparator
The separator of the single statements, defaults to";\n". -
getStatementsCount
public int getStatementsCount()The count of written statements.
-