Class ConnectedStatementsWriter

java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.ConnectedStatementsWriter
All Implemented Interfaces:
Closeable, AutoCloseable, StatementsWriter

public class ConnectedStatementsWriter extends AbstractStatementsWriter
An implementation of a StatementsWriter which writes the SQL statements directly to a database connection.
Author:
Tobias Liefke
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • DATABASE_DRIVER_KEY

      public static final String 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

      public static final String 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

      public static final String 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

      public static final String 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

      public static final String 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

      public static final String LOG_STATEMENTS_KEY
      Name of the setting which turns logging of statements on or off.
      See Also:
    • MILLISECONDS_BETWEEN_LOG_MESSAGES

      private static final long MILLISECONDS_BETWEEN_LOG_MESSAGES
      The count of milliseconds to wait, until a log message with the current count of statements is written.
      See Also:
    • MINIMUM_JDBC_DRIVER_MAJOR_VERSION

      private static final int MINIMUM_JDBC_DRIVER_MAJOR_VERSION
      The minimum major version of the JDBC API that the driver needs to support.
      See Also:
    • MINIMUM_JDBC_DRIVER_MINOR_VERSION

      private static final int MINIMUM_JDBC_DRIVER_MINOR_VERSION
      The minimum minor version of the JDBC API that the driver needs to support.
      See Also:
    • context

      private final GeneratorContext context
      The generator context that is attached to this writer.
    • contextListener

      private final ContextModelListener contextListener
      The listener for model changes in the context when new classes are discovered.
    • connection

      private final Connection connection
      The database connection that was used when creating this generator.
    • closeConnection

      private final boolean closeConnection
      Indicates that we should close the connection at the end.
    • batchSupported

      private final boolean batchSupported
      Indicates that the database connection supports batch statements.
    • logStatements

      private final boolean logStatements
      Indicates that we log each statement for debugging purposes.
    • maxBatchSize

      private final int maxBatchSize
      The maximum count of statements per batch job.
    • plainStatement

      private final Statement plainStatement
      Used to execute all plain SQL statements.
    • preparedStatements

      private final List<ConnectedStatementsWriter.PreparedInsertStatement> preparedStatements
      All prepared statements for the tables.
    • availablePreparedStatements

      private final Map<GeneratorTable,List<ConnectedStatementsWriter.PreparedInsertStatement>> availablePreparedStatements
      All available prepared statements per table.
    • batchCount

      private int batchCount
      The count of statements executed in the current batch.
    • lastLogTime

      private long lastLogTime
      The last time that we have written a log message about the count of statements.
    • statementsCount

      private long statementsCount
      The count of statements that we have executed up to now.
  • Constructor Details

    • ConnectedStatementsWriter

      private ConnectedStatementsWriter(Connection connection, boolean closeConnection, GeneratorContext context) throws SQLException
      Throws:
      SQLException
    • ConnectedStatementsWriter

      public ConnectedStatementsWriter(Connection connection, GeneratorContext context) throws SQLException
      Creates a new StatementsWriter that writes to a database connection.
      Parameters:
      connection - the database connection
      context - contains the indices for initialization
      Throws:
      SQLException - if the connection is invalid
    • ConnectedStatementsWriter

      public ConnectedStatementsWriter(GeneratorContext context) throws SQLException
      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