public class PostgreSqlBulkWriter extends FileStatementsWriter
StatementsWriter that writes bulk text files for each table, and references them in "COPY
INTO".| Modifier and Type | Class and Description |
|---|---|
private class |
PostgreSqlBulkWriter.ContextListener |
AbstractStatementsWriter.AbstractTableStatement, AbstractStatementsWriter.InsertStatement, AbstractStatementsWriter.PlainStatement, AbstractStatementsWriter.UpdateStatement| Modifier and Type | Field and Description |
|---|---|
private Map<GeneratorTable,Writer> |
bulkWriters
The open bulk files for each table.
|
private GeneratorContext |
context
The current generation context.
|
private ContextModelListener |
contextListener
The current generation context.
|
private File |
directory
The directory for the bulk files.
|
private Charset |
encoding
The encoding of the bulk files.
|
private Map<GeneratorTable,Integer> |
fileNumbers
Remembers for each table which files we've already generated.
|
private List<File> |
generatedFiles
All files generated by this writer.
|
private static org.slf4j.Logger |
log |
private int |
statementsCount
The count of written statements.
|
OUTPUT_ENCODING_KEY, OUTPUT_FILE_KEY| Constructor and Description |
|---|
PostgreSqlBulkWriter(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 sqlFile,
Charset encoding)
Creates a new instance for a SQL file.
|
PostgreSqlBulkWriter(GeneratorContext context,
File directory,
Writer writer,
Charset encoding)
Creates a new instance of
PostgreSqlBulkWriter. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
closeBulkWriter(GeneratorTable table)
Closes the current writer of the given table (for example when the table structure has changed).
|
private void |
closeBulkWriters() |
private Writer |
findBulkWriter(GeneratorTable generatorTable,
GeneratorDialect dialect) |
void |
flush()
Flushes any open statements.
|
File |
getDirectory()
The directory for the bulk files.
|
Charset |
getEncoding()
The encoding of the bulk files.
|
List<File> |
getGeneratedFiles()
All files generated by this writer.
|
int |
getStatementsCount()
The count of written statements.
|
void |
writePlainStatement(GeneratorDialect dialect,
String sql)
Writes a plain SQL statement.
|
private void |
writePlainStatement(String sql) |
void |
writeStatement(EntityStatement stmt)
Writes the given statement to a file or database.
|
ensureDirectoryExists, getStatementSeparator, getWriter, setStatementSeparator, write, writeComment, writeSectionSeparatorcreateInsertStatement, createPlainStatement, createUpdateStatementclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waittruncateTables@Generated(value="lombok") private static final org.slf4j.Logger log
private final GeneratorContext context
private final ContextModelListener contextListener
private final File directory
private final Charset encoding
private final Map<GeneratorTable,Integer> fileNumbers
private final Map<GeneratorTable,Writer> bulkWriters
private int statementsCount
public PostgreSqlBulkWriter(GeneratorContext context) throws FileNotFoundException
context - the current generation contextFileNotFoundException - if the directory is not availablepublic PostgreSqlBulkWriter(GeneratorContext context, File sqlFile) throws FileNotFoundException
context - the current generation contextsqlFile - the file that is feeded with all plain statementsFileNotFoundException - if the directory is not availablepublic PostgreSqlBulkWriter(GeneratorContext context, File sqlFile, Charset encoding) throws FileNotFoundException
context - the current generation contextsqlFile - the file that is feeded with all plain statementsencoding - the encoding of all written filesFileNotFoundException - if the directory is not availablepublic PostgreSqlBulkWriter(GeneratorContext context, File directory, Writer writer, Charset encoding)
PostgreSqlBulkWriter.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.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FileStatementsWriterIOExceptionpublic void closeBulkWriter(GeneratorTable table) throws IOException
table - the table of the writerIOException - if there was a problem when closing the writerprivate void closeBulkWriters()
throws IOException
IOExceptionprivate Writer findBulkWriter(GeneratorTable generatorTable, GeneratorDialect dialect) throws IOException
IOExceptionpublic void flush()
throws IOException
StatementsWriterflush in interface StatementsWriterflush in class FileStatementsWriterIOException - if the target throws an exceptionpublic void writePlainStatement(GeneratorDialect dialect, String sql) throws IOException
StatementsWriterwriteStatement(createPlainStatement(sql), dialect).writePlainStatement in interface StatementsWriterwritePlainStatement in class FileStatementsWriterdialect - the current database dialectsql - the content of the SQL statementIOException - if the file or database throws an exceptionprivate void writePlainStatement(String sql) throws IOException
IOExceptionpublic void writeStatement(EntityStatement stmt) throws IOException
StatementsWriterwriteStatement in interface StatementsWriterwriteStatement in class FileStatementsWriterstmt - contains the values to writeIOException - if the file or database throws an exception@Generated(value="lombok") public File getDirectory()
@Generated(value="lombok") public Charset getEncoding()
@Generated(value="lombok") public List<File> getGeneratedFiles()
@Generated(value="lombok") public int getStatementsCount()
getStatementsCount in class FileStatementsWriterCopyright © 2022 fastnate.org. All rights reserved.