Class SqlFileModifyQuery

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.SqlFileModifyQuery
All Implemented Interfaces:
ModifyQuery, Query
Direct Known Subclasses:
SqlFileDeleteQuery, SqlFileInsertQuery, SqlFileUpdateQuery

public abstract class SqlFileModifyQuery extends AbstractQuery implements ModifyQuery
An abstract base class for SQL file-based data modification queries.

This class provides common functionality for SQL file-based INSERT, UPDATE, and DELETE operations. It handles SQL file loading, parameter binding, and SQL statement preparation.

  • Field Details

    • EMPTY_STRINGS

      protected static final String[] EMPTY_STRINGS
      Empty string array used as default for property name arrays.
    • kind

      protected final SqlKind kind
      The SQL kind (INSERT, UPDATE, or DELETE).
    • sqlFilePath

      protected String sqlFilePath
      The path to the SQL file.
    • parameters

      protected final Map<String,Value> parameters
      The parameters to be bound to the SQL statement.
    • sql

      protected PreparedSql sql
      The prepared SQL statement.
    • optimisticLockCheckRequired

      protected boolean optimisticLockCheckRequired
      Whether optimistic lock checking is required for this query.
    • sqlLogType

      protected SqlLogType sqlLogType
      The SQL log type for this query.
    • includedPropertyNames

      protected String[] includedPropertyNames
      The property names to be included in the operation.
    • excludedPropertyNames

      protected String[] excludedPropertyNames
      The property names to be excluded from the operation.
    • executable

      protected boolean executable
      Whether this query is executable.
    • sqlExecutionSkipCause

      protected SqlExecutionSkipCause sqlExecutionSkipCause
      The cause for skipping SQL execution, if applicable.
  • Constructor Details

    • SqlFileModifyQuery

      protected SqlFileModifyQuery(SqlKind kind)
      Constructs a new instance with the specified SQL kind.
      Parameters:
      kind - the SQL kind
  • Method Details

    • prepareOptions

      protected void prepareOptions()
      Prepares the query options.

      This method sets the query timeout from the configuration if it's not already set.

    • prepareSql

      protected void prepareSql()
      Prepares the SQL statement.

      This method loads the SQL file, evaluates expressions, and builds the prepared SQL statement.

    • expandColumns

      protected List<String> expandColumns(ExpandNode node)
      Expands columns in the SQL statement.

      This method is called when an expand node is encountered in the SQL file.

      Parameters:
      node - the expand node
      Returns:
      the expanded column list
      Throws:
      UnsupportedOperationException - if this operation is not supported by the implementing class
    • populateValues

      protected void populateValues(PopulateNode node, SqlContext context)
      Populates values in the SQL context.

      This method is called when a populate node is encountered in the SQL file.

      Parameters:
      node - the populate node
      context - the SQL context
      Throws:
      UnsupportedOperationException - if this operation is not supported by the implementing class
    • setSqlFilePath

      public void setSqlFilePath(String sqlFilePath)
      Sets the path to the SQL file.
      Parameters:
      sqlFilePath - the SQL file path
    • addParameter

      public void addParameter(String name, Class<?> type, Object value)
      Adds a parameter to this query.
      Parameters:
      name - the parameter name
      type - the parameter type
      value - the parameter value
    • addParameterInternal

      public void addParameterInternal(String name, Class<?> type, Object value)
      Adds a parameter to this query without null checks.

      This method is used internally when null checks have already been performed.

      Parameters:
      name - the parameter name
      type - the parameter type
      value - the parameter value
    • setSqlLogType

      public void setSqlLogType(SqlLogType sqlLogType)
      Sets the SQL log type for this query.
      Parameters:
      sqlLogType - the SQL log type
    • setIncludedPropertyNames

      public void setIncludedPropertyNames(String... includedPropertyNames)
      Sets the property names to be included in the operation.
      Parameters:
      includedPropertyNames - the property names to be included
    • setExcludedPropertyNames

      public void setExcludedPropertyNames(String... excludedPropertyNames)
      Sets the property names to be excluded from the operation.
      Parameters:
      excludedPropertyNames - the property names to be excluded
    • getSql

      public PreparedSql getSql()
      Returns the prepared SQL for this modification query.
      Specified by:
      getSql in interface ModifyQuery
      Specified by:
      getSql in interface Query
      Returns:
      the prepared SQL
    • isOptimisticLockCheckRequired

      public boolean isOptimisticLockCheckRequired()
      Returns whether optimistic lock checking is required for this query.
      Specified by:
      isOptimisticLockCheckRequired in interface ModifyQuery
      Returns:
      true if optimistic lock checking is required
    • isExecutable

      public boolean isExecutable()
      Returns whether this query is executable.
      Specified by:
      isExecutable in interface ModifyQuery
      Returns:
      true if this query is executable
    • getSqlExecutionSkipCause

      public SqlExecutionSkipCause getSqlExecutionSkipCause()
      Returns the cause if SQL execution should be skipped.
      Specified by:
      getSqlExecutionSkipCause in interface ModifyQuery
      Returns:
      the cause of SQL execution skip, or null if execution should not be skipped
    • isAutoGeneratedKeysSupported

      public boolean isAutoGeneratedKeysSupported()
      Returns whether auto-generated keys are supported for this query.
      Specified by:
      isAutoGeneratedKeysSupported in interface ModifyQuery
      Returns:
      true if auto-generated keys are supported
    • getSqlLogType

      public SqlLogType getSqlLogType()
      Returns the SQL log type for this query.
      Specified by:
      getSqlLogType in interface ModifyQuery
      Returns:
      the SQL log type
    • setEntityAndEntityType

      public abstract <E> void setEntityAndEntityType(String name, E entity, EntityType<E> entityType)
      Sets the entity and entity type for this query.
      Type Parameters:
      E - the entity type
      Parameters:
      name - the parameter name for the entity
      entity - the entity
      entityType - the entity type
    • toString

      public String toString()
      Overrides:
      toString in class Object