Class RuntimeConfig

java.lang.Object
org.seasar.doma.internal.RuntimeConfig
All Implemented Interfaces:
Config

public class RuntimeConfig extends Object implements Config
  • Field Details

    • config

      protected final Config config
    • dataSource

      protected final DataSource dataSource
  • Constructor Details

    • RuntimeConfig

      public RuntimeConfig(Config originalConfig)
    • RuntimeConfig

      public RuntimeConfig(Config config, DataSource dataSource)
  • Method Details

    • getDataSource

      public DataSource getDataSource()
      Description copied from interface: Config
      Returns the data source for database connections.

      The data source is used to obtain database connections for executing SQL statements. It is a fundamental component required for all database operations in Doma.

      Specified by:
      getDataSource in interface Config
      Returns:
      the data source that provides database connections
    • getDataSourceName

      public String getDataSourceName()
      Description copied from interface: Config
      Returns the name of the data source.

      Each data source must have a unique name when multiple data sources are used in an application. This name is used to identify the data source for distinguishing between different database connections.

      By default, this method returns the fully qualified class name of the Config implementation. Override this method to provide a more descriptive name for the data source.

      Specified by:
      getDataSourceName in interface Config
      Returns:
      the name of the data source that uniquely identifies it within the application
    • getDialect

      public Dialect getDialect()
      Description copied from interface: Config
      Returns the SQL dialect.

      The SQL dialect provides database-specific functionality and SQL syntax adaptations for different database management systems (such as MySQL, PostgreSQL, Oracle, etc.). It allows Doma to generate appropriate SQL statements that are compatible with the target database.

      Specified by:
      getDialect in interface Config
      Returns:
      the SQL dialect implementation for the target database
    • getSqlFileRepository

      public SqlFileRepository getSqlFileRepository()
      Description copied from interface: Config
      Returns the SQL file repository.

      The SQL file repository is responsible for loading and caching SQL files that contain SQL statements used by DAOs. It manages the lifecycle of SQL templates and ensures efficient access to SQL resources.

      By default, this method returns a shared instance from ConfigSupport.defaultSqlFileRepository. Override this method to provide a custom implementation with different caching or loading strategies.

      Specified by:
      getSqlFileRepository in interface Config
      Returns:
      the SQL file repository that manages SQL templates
    • getScriptFileLoader

      public ScriptFileLoader getScriptFileLoader()
      Description copied from interface: Config
      Returns the Script file loader.

      The Script file loader is responsible for loading SQL script files that contain multiple SQL statements for batch execution. These scripts are typically used for database initialization, schema creation, or test data setup.

      By default, this method returns a shared instance from ConfigSupport.defaultScriptFileLoader. Override this method to provide a custom implementation with different loading strategies or resource resolution mechanisms.

      Specified by:
      getScriptFileLoader in interface Config
      Returns:
      the Script file loader that handles SQL script files
    • getJdbcLogger

      public JdbcLogger getJdbcLogger()
      Description copied from interface: Config
      Returns the JDBC logger.

      The JDBC logger is responsible for logging SQL statements, parameters, execution times, and other JDBC-related operations. It provides visibility into database interactions performed by Doma, which is essential for debugging and performance monitoring.

      By default, this method returns a shared instance from ConfigSupport.defaultJdbcLogger. Override this method to provide a custom implementation that integrates with your application's logging framework or has different logging behavior.

      Specified by:
      getJdbcLogger in interface Config
      Returns:
      the JDBC logger that handles logging of SQL and JDBC operations
      See Also:
    • getRequiresNewController

      public RequiresNewController getRequiresNewController()
      Description copied from interface: Config
      Returns the transaction controller whose transaction attribute is REQUIRES_NEW.

      The RequiresNewController is responsible for managing transactions with the REQUIRES_NEW attribute, which means it always creates a new transaction regardless of whether a transaction already exists. This is useful for operations that must be committed or rolled back independently of the surrounding transaction context.

      By default, this method returns a shared instance from ConfigSupport.defaultRequiresNewController. Override this method to provide a custom implementation that integrates with your application's transaction management system.

      Specified by:
      getRequiresNewController in interface Config
      Returns:
      the transaction controller that manages transactions with the REQUIRES_NEW attribute
    • getClassHelper

      public ClassHelper getClassHelper()
      Description copied from interface: Config
      Returns the class helper.

      The ClassHelper is responsible for loading classes and creating instances of those classes. It provides an abstraction layer over Java's reflection and class loading mechanisms, allowing for customization of how classes are loaded and instantiated in different environments (such as OSGi containers, application servers, or custom classloaders).

      By default, this method returns a shared instance from ConfigSupport.defaultClassHelper. Override this method to provide a custom implementation that integrates with your application's class loading infrastructure.

      Specified by:
      getClassHelper in interface Config
      Returns:
      the class helper that handles class loading and instantiation
    • getCommandImplementors

      public CommandImplementors getCommandImplementors()
      Description copied from interface: Config
      Returns the factory for Command implementation classes.

      The CommandImplementors factory creates implementations of the Command interface, which are responsible for executing various database operations. These commands encapsulate the logic for executing SQL statements, handling results, and managing resources.

      By default, this method returns a shared instance from ConfigSupport.defaultCommandImplementors. Override this method to provide custom implementations of commands that modify the standard behavior of database operations or add additional functionality such as metrics collection, custom error handling, or specialized resource management.

      Specified by:
      getCommandImplementors in interface Config
      Returns:
      the factory that creates implementations of the Command interface
    • getQueryImplementors

      public QueryImplementors getQueryImplementors()
      Description copied from interface: Config
      Returns the factory for Query implementation classes.

      The QueryImplementors factory creates implementations of the Query interface, which are responsible for building and preparing SQL statements for execution. These queries handle parameter binding, SQL transformation, and preparation of execution context.

      By default, this method returns a shared instance from ConfigSupport.defaultQueryImplementors. Override this method to provide custom implementations of queries that modify how SQL statements are built, transformed, or prepared. This can be useful for implementing features like query rewriting, additional validation, or specialized parameter handling.

      Specified by:
      getQueryImplementors in interface Config
      Returns:
      the factory that creates implementations of the Query interface
    • getExceptionSqlLogType

      public SqlLogType getExceptionSqlLogType()
      Description copied from interface: Config
      Returns the SQL log type that determines the SQL log format in exceptions.

      The SQL log type controls how SQL statements are formatted and displayed in exception messages when database errors occur. This affects the readability and detail level of SQL-related information in error logs and stack traces.

      By default, this method returns SqlLogType.FORMATTED, which provides a well-formatted SQL representation with parameter values. Other options include SqlLogType.RAW for raw SQL with bind variables and SqlLogType.NONE to omit SQL from exception messages.

      Override this method to change the default SQL logging behavior for exceptions throughout your application.

      Specified by:
      getExceptionSqlLogType in interface Config
      Returns:
      the SQL log type that controls SQL formatting in exception messages
    • getUnknownColumnHandler

      public UnknownColumnHandler getUnknownColumnHandler()
      Description copied from interface: Config
      Returns the unknown column handler.

      The UnknownColumnHandler determines how Doma responds when it encounters columns in query results that don't match any fields in the corresponding entity class. This can happen when the database schema changes or when using queries that return columns not mapped to entity fields.

      By default, this method returns a shared instance from ConfigSupport.defaultUnknownColumnHandler, which throws an exception when unknown columns are encountered. Alternative implementations might ignore unknown columns or log warnings about unmapped columns instead of throwing exceptions.

      Override this method to provide a custom implementation with different behavior for handling unknown columns in query results.

      Specified by:
      getUnknownColumnHandler in interface Config
      Returns:
      the handler that determines the behavior when unknown columns are encountered
    • getTransactionManager

      public TransactionManager getTransactionManager()
      Description copied from interface: Config
      Returns the transaction manager.

      The TransactionManager is responsible for managing database transactions, including beginning, committing, and rolling back transactions. It provides a consistent API for transaction management across different environments and transaction implementations.

      By default, this method throws an UnsupportedOperationException, indicating that transaction management is not supported by the default configuration. Implementations of this interface must override this method to provide transaction support.

      When implementing this method, consider integrating with your application's existing transaction management system, such as Spring's transaction manager, Jakarta Transactions (JTA), or a custom transaction management solution.

      Specified by:
      getTransactionManager in interface Config
      Returns:
      the transaction manager that handles database transactions
    • getCommenter

      public Commenter getCommenter()
      Description copied from interface: Config
      Returns the commenter for SQL strings.

      The Commenter is responsible for adding comments to SQL statements before they are executed. These comments can include information such as the origin of the SQL (e.g., method name, file name), execution context, or application-specific information that helps with debugging and monitoring database operations.

      By default, this method returns a shared instance from ConfigSupport.defaultCommenter, which typically adds no comments to SQL statements. Custom implementations can add more detailed comments based on application requirements.

      SQL comments are particularly useful when analyzing database performance, auditing SQL execution, or troubleshooting issues in production environments where the source of a query might not be immediately obvious.

      Specified by:
      getCommenter in interface Config
      Returns:
      the commenter that adds comments to SQL statements before execution
    • getNaming

      public Naming getNaming()
      Description copied from interface: Config
      Returns the naming convention controller.

      The Naming controller determines the strategy for converting between Java entity property names and database column names. It provides a consistent way to handle different naming conventions between Java (typically camelCase) and databases (often snake_case or other conventions).

      By default, this method returns a shared instance from ConfigSupport.defaultNaming, which is set to Naming.DEFAULT (equivalent to Naming.NONE). This implementation performs no name conversion, preserving the original names exactly as they are defined in Java. Other options include SNAKE_LOWER_CASE, SNAKE_UPPER_CASE, or others defined in the Naming enum.

      Override this method to provide a different naming convention that matches your database schema design or organizational standards.

      Specified by:
      getNaming in interface Config
      Returns:
      the naming convention controller that handles name conversions between Java and the database
    • getMapKeyNaming

      public MapKeyNaming getMapKeyNaming()
      Description copied from interface: Config
      Returns a naming convention controller for keys contained in a Map<String, Object> object.

      The MapKeyNaming controller determines the strategy for converting between database column names and keys in Map objects when query results are mapped to Map<String, Object> instances. This is particularly useful when working with dynamic queries where the result structure is not known at compile time.

      By default, this method returns a shared instance from ConfigSupport.defaultMapKeyNaming, which typically applies a specific naming convention to map database column names to map keys. For example, it might convert database column names like "USER_ID" to map keys like "userId" or keep them as-is depending on the configuration.

      Override this method to provide a different naming convention for map keys that aligns with your application's conventions for handling dynamic query results.

      Specified by:
      getMapKeyNaming in interface Config
      Returns:
      a naming convention controller that handles conversions between database column names and keys in Map<String, Object> objects
    • getFetchSize

      public int getFetchSize()
      Description copied from interface: Config
      Returns the fetch size.

      The fetch size is a hint to the JDBC driver about how many rows should be fetched from the database when more rows are needed for a result set. It affects the network traffic between the application and the database by controlling how many rows are retrieved in each database round-trip.

      If the value is greater than or equal to 1, it is passed to Statement.setFetchSize(int) for all statements created by Doma. If the value is 0 (the default), the JDBC driver's default fetch size is used.

      Setting an appropriate fetch size can significantly improve performance for queries that return large result sets. A larger fetch size reduces the number of round-trips but requires more memory. A smaller fetch size uses less memory but may require more round-trips to the database.

      Specified by:
      getFetchSize in interface Config
      Returns:
      the fetch size hint for result set retrieval (0 means use the driver's default)
      See Also:
    • getMaxRows

      public int getMaxRows()
      Description copied from interface: Config
      Returns the maximum number of rows for a ResultSet object.

      This setting limits the maximum number of rows that can be returned by a query, which can be useful for preventing excessive memory usage or improving performance when only a subset of results is needed. When set, this value is passed to Statement.setMaxRows(int) for all statements created by Doma.

      If the value is greater than or equal to 1, it is applied as a limit. If the value is 0 (the default), no limit is applied, and all rows matching the query criteria will be returned.

      Note that this is a global setting that affects all queries executed through this configuration. For query-specific limits, consider using SQL-level pagination or limit clauses instead.

      Specified by:
      getMaxRows in interface Config
      Returns:
      the maximum number of rows to return in query results (0 means no limit)
      See Also:
    • getQueryTimeout

      public int getQueryTimeout()
      Description copied from interface: Config
      Returns the query timeout limit in seconds.

      The query timeout specifies the maximum time in seconds that a JDBC driver will wait for a statement to execute before canceling it. This helps prevent long-running queries from consuming excessive resources or blocking application threads indefinitely.

      If the value is greater than or equal to 1, it is passed to Statement.setQueryTimeout(int) for all statements created by Doma. If the value is 0 (the default), no timeout is set, and queries can run for an unlimited amount of time.

      Setting an appropriate timeout is particularly important for applications that need to maintain responsiveness even when database operations take longer than expected. When a timeout occurs, the statement is canceled and an exception is thrown.

      Note that not all JDBC drivers or database systems support query timeouts. Check your specific database documentation for compatibility information.

      Specified by:
      getQueryTimeout in interface Config
      Returns:
      the query timeout limit in seconds (0 means no timeout)
      See Also:
    • getBatchSize

      public int getBatchSize()
      Description copied from interface: Config
      Returns the batch size.

      The batch size determines how many SQL statements are grouped together and sent to the database in a single batch execution. Batch processing can significantly improve performance for operations that need to execute the same SQL statement multiple times with different parameter values (such as bulk inserts, updates, or deletes).

      If the value is greater than or equal to 1, Doma will accumulate that many statements before calling Statement.executeBatch(). If the value is less than 1, it is treated as 1, meaning each statement will be executed individually without batching. A value of 0 (the default) also disables batching.

      Larger batch sizes generally improve performance by reducing the number of round-trips to the database, but they also increase memory usage and may delay error detection until the batch is executed.

      Specified by:
      getBatchSize in interface Config
      Returns:
      the batch size for grouping SQL statements (0 or negative values disable batching)
      See Also:
    • getEntityListenerProvider

      public EntityListenerProvider getEntityListenerProvider()
      Description copied from interface: Config
      Returns the provider for EntityListener.

      The EntityListenerProvider is responsible for creating and managing instances of EntityListener implementations. Entity listeners provide callback methods that are invoked during entity lifecycle events, such as before/after insert, update, or delete operations. This allows for implementing cross-cutting concerns like validation, auditing, or event notification.

      By default, this method returns a shared instance from ConfigSupport.defaultEntityListenerProvider, which creates one instance of each listener class per entity class. Custom implementations might integrate with dependency injection frameworks or provide pooling of listener instances.

      Override this method to provide a custom implementation that integrates with your application's dependency injection or component management system.

      Specified by:
      getEntityListenerProvider in interface Config
      Returns:
      the provider that creates and manages EntityListener instances
    • getSqlBuilderSettings

      public SqlBuilderSettings getSqlBuilderSettings()
      Description copied from interface: Config
      Returns the context for SQL builder settings.

      The SqlBuilderSettings provides configuration options for the SQL builders used by Doma to generate SQL statements. These settings control aspects such as SQL formatting and other SQL generation behaviors.

      By default, this method returns a shared instance from ConfigSupport.defaultSqlBuilderSettings, which applies standard SQL building rules. Custom implementations might modify these rules to accommodate specific database requirements or organizational SQL standards.

      Specified by:
      getSqlBuilderSettings in interface Config
      Returns:
      the context that provides configuration options for SQL generation
    • getStatisticManager

      public StatisticManager getStatisticManager()
      Description copied from interface: Config
      Returns the statistic manager instance.

      The StatisticManager collects and manages statistics about SQL execution, such as execution counts and execution times. These statistics can be valuable for monitoring application performance, identifying bottlenecks, and diagnosing database-related issues.

      By default, this method returns a shared instance from ConfigSupport.defaultStatisticManager, which may or may not collect statistics depending on its configuration. Custom implementations might integrate with application monitoring systems, performance tracking tools, or provide more detailed statistics collection.

      Statistics collection can have a small performance impact, so it's typically configurable to enable or disable collection based on the environment (e.g., enabled in development and testing, but disabled or sampling-based in production).

      Specified by:
      getStatisticManager in interface Config
      Returns:
      the StatisticManager instance that collects and manages SQL execution statistics