Class ConnectedStatementsWriter
java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.ConnectedStatementsWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,StatementsWriter
An implementation of a
StatementsWriter which writes the SQL statements directly to a database connection.- 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 StringName of the setting that contains the connection driver class, if the writer create the a connection himself.static final StringName of the setting that contains the connection password, if the writer create the a connection himself.static final StringName of the setting that contains the connection URL, if the writer create the a connection himself.static final StringName of the setting that contains the connection user, if the writer create the a connection himself.static final StringName of the setting which turns logging of statements on or off.static final StringName of the setting which controls the maximum size of generated batches. -
Constructor Summary
ConstructorsConstructorDescriptionConnectedStatementsWriter(Connection connection, GeneratorContext context) Creates a new StatementsWriter that writes to a database connection.Creates a new StatementsWriter that writes to a database connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()createInsertStatement(GeneratorDialect dialect, GeneratorTable table) Creates a container for a dedicated "insert into table" statement.voidflush()Flushes any open statements.The database connection that was used when creating this generator.longThe count of statements that we have executed up to now.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.AbstractStatementsWriter
createPlainStatement, createUpdateStatement, writeComment, writeSectionSeparatorMethods 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
-
DATABASE_DRIVER_KEY
Name of the setting that contains the connection driver class, if the writer create the a connection himself.- See Also:
-
DATABASE_URL_KEY
Name of the setting that contains the connection URL, if the writer create the a connection himself.- See Also:
-
DATABASE_USER_KEY
Name of the setting that contains the connection user, if the writer create the a connection himself.- See Also:
-
DATABASE_PASSWORD_KEY
Name of the setting that contains the connection password, if the writer create the a connection himself.- See Also:
-
MAX_BATCH_SIZE_KEY
Name of the setting which controls the maximum size of generated batches. If set to something below 2, no batches are used.- See Also:
-
LOG_STATEMENTS_KEY
Name of the setting which turns logging of statements on or off.- See Also:
-
-
Constructor Details
-
ConnectedStatementsWriter
public ConnectedStatementsWriter(Connection connection, GeneratorContext context) throws SQLException Creates a new StatementsWriter that writes to a database connection.- Parameters:
connection- the database connectioncontext- contains the indices for initialization- Throws:
SQLException- if the connection is invalid
-
ConnectedStatementsWriter
Creates a new StatementsWriter that writes to a database connection. The database connection is created from the properties in the context.- Parameters:
context- contains the properties and indices for initialization- Throws:
SQLException- if the connection is invalid
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractStatementsWriter- Throws:
IOException
-
createInsertStatement
Description copied from interface:StatementsWriterCreates a container for a dedicated "insert into table" statement.- Specified by:
createInsertStatementin interfaceStatementsWriter- Overrides:
createInsertStatementin classAbstractStatementsWriter- Parameters:
dialect- the current database dialecttable- the name of the table- Returns:
- the created statement
-
flush
Description copied from interface:StatementsWriterFlushes any open statements.- Specified by:
flushin interfaceStatementsWriter- Overrides:
flushin classAbstractStatementsWriter- 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
-
writeStatement
Description copied from interface:StatementsWriterWrites the given statement to a file or database.- Parameters:
stmt- contains the values to write- Throws:
IOException- if the file or database throws an exception
-
getConnection
The database connection that was used when creating this generator. -
getStatementsCount
public long getStatementsCount()The count of statements that we have executed up to now.
-