public class ConnectedStatementsWriter extends AbstractStatementsWriter
StatementsWriter
which writes the SQL statements directly to a database connection.Modifier and Type | Class and Description |
---|---|
private static class |
ConnectedStatementsWriter.ContextListener |
private static class |
ConnectedStatementsWriter.PreparedInsertStatement |
AbstractStatementsWriter.AbstractTableStatement, AbstractStatementsWriter.InsertStatement, AbstractStatementsWriter.PlainStatement, AbstractStatementsWriter.UpdateStatement
Modifier and Type | Field and Description |
---|---|
private Map<GeneratorTable,List<ConnectedStatementsWriter.PreparedInsertStatement>> |
availablePreparedStatements
All available prepared statements per table.
|
private int |
batchCount
The count of statements executed in the current batch.
|
private boolean |
batchSupported
Indicates that the database connection supports batch statements.
|
private boolean |
closeConnection
Indicates that we should close the connection at the end.
|
private Connection |
connection
The database connection that was used when creating this generator.
|
private GeneratorContext |
context
The generator context that is attached to this writer.
|
private ContextModelListener |
contextListener
The listener for model changes in the context when new classes are discovered.
|
static String |
DATABASE_DRIVER_KEY
Name of the setting that contains the connection driver class, if the writer create the a connection himself.
|
static String |
DATABASE_PASSWORD_KEY
Name of the setting that contains the connection password, if the writer create the a connection himself.
|
static String |
DATABASE_URL_KEY
Name of the setting that contains the connection URL, if the writer create the a connection himself.
|
static String |
DATABASE_USER_KEY
Name of the setting that contains the connection user, if the writer create the a connection himself.
|
private long |
lastLogTime
The last time that we have written a log message about the count of statements.
|
private static org.slf4j.Logger |
log |
static String |
LOG_STATEMENTS_KEY
Name of the setting which turns logging of statements on or off.
|
private boolean |
logStatements
Indicates that we log each statement for debugging purposes.
|
static String |
MAX_BATCH_SIZE_KEY
Name of the setting which controls the maximum size of generated batches.
|
private int |
maxBatchSize
The maximum count of statements per batch job.
|
private static long |
MILLISECONDS_BETWEEN_LOG_MESSAGES
The count of milliseconds to wait, until a log message with the current count of statements is written.
|
private static int |
MINIMUM_JDBC_DRIVER_MAJOR_VERSION
The minimum major version of the JDBC API that the driver needs to support.
|
private static int |
MINIMUM_JDBC_DRIVER_MINOR_VERSION
The minimum minor version of the JDBC API that the driver needs to support.
|
private Statement |
plainStatement
Used to execute all plain SQL statements.
|
private List<ConnectedStatementsWriter.PreparedInsertStatement> |
preparedStatements
All prepared statements for the tables.
|
private long |
statementsCount
The count of statements that we have executed up to now.
|
Modifier | Constructor and Description |
---|---|
private |
ConnectedStatementsWriter(Connection connection,
boolean closeConnection,
GeneratorContext context) |
|
ConnectedStatementsWriter(Connection connection,
GeneratorContext context)
Creates a new StatementsWriter that writes to a database connection.
|
|
ConnectedStatementsWriter(GeneratorContext context)
Creates a new StatementsWriter that writes to a database connection.
|
Modifier and Type | Method and Description |
---|---|
private static Connection |
buildConnection(GeneratorContext context) |
private void |
checkUpdate(int updatedRows,
String sql) |
void |
close() |
private void |
closeBatch() |
TableStatement |
createInsertStatement(GeneratorDialect dialect,
GeneratorTable table)
Creates a container for a dedicated "insert into table" statement.
|
void |
flush()
Flushes any open statements.
|
Connection |
getConnection()
The database connection that was used when creating this generator.
|
long |
getStatementsCount()
The count of statements that we have executed up to now.
|
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.
|
private void |
writeTableStatement(String sql) |
createPlainStatement, createUpdateStatement, writeComment, writeSectionSeparator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
truncateTables
@Generated(value="lombok") private static final org.slf4j.Logger log
public static final String DATABASE_DRIVER_KEY
public static final String DATABASE_URL_KEY
public static final String DATABASE_USER_KEY
public static final String DATABASE_PASSWORD_KEY
public static final String MAX_BATCH_SIZE_KEY
public static final String LOG_STATEMENTS_KEY
private static final long MILLISECONDS_BETWEEN_LOG_MESSAGES
private static final int MINIMUM_JDBC_DRIVER_MAJOR_VERSION
private static final int MINIMUM_JDBC_DRIVER_MINOR_VERSION
private final GeneratorContext context
private final ContextModelListener contextListener
private final Connection connection
private final boolean closeConnection
private final boolean batchSupported
private final boolean logStatements
private final int maxBatchSize
private final Statement plainStatement
private final List<ConnectedStatementsWriter.PreparedInsertStatement> preparedStatements
private final Map<GeneratorTable,List<ConnectedStatementsWriter.PreparedInsertStatement>> availablePreparedStatements
private int batchCount
private long lastLogTime
private long statementsCount
private ConnectedStatementsWriter(Connection connection, boolean closeConnection, GeneratorContext context) throws SQLException
SQLException
public ConnectedStatementsWriter(Connection connection, GeneratorContext context) throws SQLException
connection
- the database connectioncontext
- contains the indices for initializationSQLException
- if the connection is invalidpublic ConnectedStatementsWriter(GeneratorContext context) throws SQLException
context
- contains the properties and indices for initializationSQLException
- if the connection is invalidprivate static Connection buildConnection(GeneratorContext context) throws SQLException
SQLException
private void checkUpdate(int updatedRows, String sql)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class AbstractStatementsWriter
IOException
private void closeBatch() throws IOException
IOException
public TableStatement createInsertStatement(GeneratorDialect dialect, GeneratorTable table)
StatementsWriter
createInsertStatement
in interface StatementsWriter
createInsertStatement
in class AbstractStatementsWriter
dialect
- the current database dialecttable
- the name of the tablepublic void flush() throws IOException
StatementsWriter
flush
in interface StatementsWriter
flush
in class AbstractStatementsWriter
IOException
- if the target throws an exceptionpublic void writePlainStatement(GeneratorDialect dialect, String sql) throws IOException
StatementsWriter
writeStatement(createPlainStatement(sql), dialect)
.dialect
- the current database dialectsql
- the content of the SQL statementIOException
- if the file or database throws an exceptionprivate void writePlainStatement(String sql) throws IOException
IOException
public void writeStatement(EntityStatement stmt) throws IOException
StatementsWriter
stmt
- contains the values to writeIOException
- if the file or database throws an exceptionprivate void writeTableStatement(String sql) throws IOException
IOException
@Generated(value="lombok") public Connection getConnection()
@Generated(value="lombok") public long getStatementsCount()
Copyright © 2022 fastnate.org. All rights reserved.