Class SqlFileInsertQuery

All Implemented Interfaces:
InsertQuery, ModifyQuery, Query

public class SqlFileInsertQuery extends SqlFileModifyQuery implements InsertQuery
A query that inserts data into a database using an external SQL file.

This class extends SqlFileModifyQuery to provide functionality for executing INSERT statements defined in external SQL files. It handles entity lifecycle callbacks and SQL file execution.

  • Field Details

    • nullExcluded

      protected boolean nullExcluded
      Whether to exclude null properties from the insert operation.
    • entityHandler

      protected SqlFileInsertQuery.EntityHandler<?> entityHandler
      The entity handler for this query.
  • Constructor Details

    • SqlFileInsertQuery

      public SqlFileInsertQuery()
      Constructs a new instance.

      This constructor initializes the query with SqlKind.INSERT to indicate that it performs an INSERT operation.

  • Method Details

    • prepare

      public void prepare()
      Prepares this query for execution. This method must be called before the query is executed.

      This implementation prepares the SQL statement by processing the SQL file and handling entity lifecycle callbacks.

      Specified by:
      prepare in interface Query
      Overrides:
      prepare in class AbstractQuery
    • preInsert

      protected void preInsert()
      Executes pre-insert entity lifecycle callbacks.

      This method delegates to the entity handler if one is available.

    • prepareExecutable

      protected void prepareExecutable()
      Prepares the executable state for this query.

      This method sets the query as executable and clears any skip cause.

    • generateId

      public void generateId(Statement statement)
      Generates an ID for the inserted row.

      This method is called after executing the INSERT statement to retrieve and set auto-generated keys or sequence values for the entity. It's typically used for primary key generation strategies like identity columns or sequences.

      This implementation does nothing because this query does not support auto-generated keys.

      Specified by:
      generateId in interface InsertQuery
      Parameters:
      statement - the statement used for the INSERT operation
    • getEntity

      public <E> E getEntity(Class<E> entityType)
      Returns the entity associated with this query.
      Type Parameters:
      E - the entity type
      Parameters:
      entityType - the entity class
      Returns:
      the entity, or null if no entity is associated with this query
    • complete

      public void complete()
      Completes this query after execution. This method must be called after the query is executed.

      This implementation executes post-insert entity lifecycle callbacks.

      Specified by:
      complete in interface Query
    • setEntityAndEntityType

      public <E> void setEntityAndEntityType(String name, E entity, EntityType<E> entityType)
      Sets the entity and entity type for this query.

      This implementation creates an entity handler for the specified entity.

      Specified by:
      setEntityAndEntityType in class SqlFileModifyQuery
      Type Parameters:
      E - the entity type
      Parameters:
      name - the parameter name for the entity
      entity - the entity
      entityType - the entity type
    • setNullExcluded

      public void setNullExcluded(boolean nullExcluded)
      Sets whether to exclude null properties from the insert operation.
      Parameters:
      nullExcluded - whether to exclude null properties