Class PostgreSqlBulkWriter
java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.FileStatementsWriter
org.fastnate.generator.statements.PostgreSqlBulkWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,StatementsWriter
Implementation of a
StatementsWriter that writes bulk text files for each table, and references them in "COPY
INTO".- 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
Fields inherited from class org.fastnate.generator.statements.FileStatementsWriter
OUTPUT_ENCODING_KEY, OUTPUT_FILE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionPostgreSqlBulkWriter(GeneratorContext context) Creates a new instance for a SQL file with UTF-8 encoding.PostgreSqlBulkWriter(GeneratorContext context, File sqlFile) Creates a new instance for a SQL file with UTF-8 encoding.PostgreSqlBulkWriter(GeneratorContext context, File directory, Writer writer, Charset encoding) Creates a new instance ofPostgreSqlBulkWriter.PostgreSqlBulkWriter(GeneratorContext context, File sqlFile, Charset encoding) Creates a new instance for a SQL file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidcloseBulkWriter(GeneratorTable table) Closes the current writer of the given table (for example when the table structure has changed).voidflush()Flushes any open statements.The directory for the bulk files.The encoding of the bulk files.All files generated by this writer.intThe count of written statements.voidwritePlainStatement(GeneratorDialect dialect, String sql) Writes a plain SQL statement.voidWrites the given statement to a file or database.Methods inherited from class org.fastnate.generator.statements.FileStatementsWriter
ensureDirectoryExists, getStatementSeparator, getWriter, setStatementSeparator, write, writeComment, writeSectionSeparatorMethods 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
-
Constructor Details
-
PostgreSqlBulkWriter
Creates a new instance for a SQL file with UTF-8 encoding. All bulk files will end up in the same directory as the given file.- Parameters:
context- the current generation context- Throws:
FileNotFoundException- if the directory is not available
-
PostgreSqlBulkWriter
Creates a new instance for a SQL file with UTF-8 encoding. All bulk files will end up in the same directory as the given file.- Parameters:
context- the current generation contextsqlFile- the file that is feeded with all plain statements- Throws:
FileNotFoundException- if the directory is not available
-
PostgreSqlBulkWriter
public PostgreSqlBulkWriter(GeneratorContext context, File sqlFile, Charset encoding) throws FileNotFoundException Creates a new instance for a SQL file. All bulk files will end up in the same directory as the given file.- Parameters:
context- the current generation contextsqlFile- the file that is feeded with all plain statementsencoding- the encoding of all written files- Throws:
FileNotFoundException- if the directory is not available
-
PostgreSqlBulkWriter
public PostgreSqlBulkWriter(GeneratorContext context, File directory, Writer writer, Charset encoding) Creates a new instance ofPostgreSqlBulkWriter.- Parameters:
context- the current generation contextdirectory- the directory for the bulk fileswriter- the SQL file which contains the plain and the "COPY" statementsencoding- The encoding of the bulk files.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFileStatementsWriter- Throws:
IOException
-
closeBulkWriter
Closes the current writer of the given table (for example when the table structure has changed).- Parameters:
table- the table of the writer- Throws:
IOException- if there was a problem when closing the writer
-
flush
Description copied from interface:StatementsWriterFlushes any open statements.- Specified by:
flushin interfaceStatementsWriter- Overrides:
flushin classFileStatementsWriter- Throws:
IOException- if the target throws an exception
-
writePlainStatement
Description copied from interface:StatementsWriterWrites a plain SQL statement. Shortcut forwriteStatement(createPlainStatement(sql), dialect).- Specified by:
writePlainStatementin interfaceStatementsWriter- Overrides:
writePlainStatementin classFileStatementsWriter- Parameters:
dialect- the current database dialectsql- the content of the SQL statement- Throws:
IOException- if the file or database throws an exception
-
writeStatement
Description copied from interface:StatementsWriterWrites the given statement to a file or database.- Specified by:
writeStatementin interfaceStatementsWriter- Overrides:
writeStatementin classFileStatementsWriter- Parameters:
stmt- contains the values to write- Throws:
IOException- if the file or database throws an exception
-
getDirectory
The directory for the bulk files. -
getEncoding
The encoding of the bulk files. -
getGeneratedFiles
All files generated by this writer. -
getStatementsCount
public int getStatementsCount()The count of written statements.- Overrides:
getStatementsCountin classFileStatementsWriter
-