Class AbstractSQLInsertClause<C extends AbstractSQLInsertClause<C>>

java.lang.Object
com.querydsl.sql.dml.AbstractSQLClause<C>
com.querydsl.sql.dml.AbstractSQLInsertClause<C>
Type Parameters:
C - The type extending this class.
All Implemented Interfaces:
DMLClause<C>, InsertClause<C>, StoreClause<C>
Direct Known Subclasses:
SQLInsertClause

public abstract class AbstractSQLInsertClause<C extends AbstractSQLInsertClause<C>> extends AbstractSQLClause<C> implements InsertClause<C>
Provides a base class for dialect-specific INSERT clauses.
Author:
tiwe
  • Field Details

    • logger

      protected static final Logger logger
    • entity

      protected final RelationalPath<?> entity
    • metadata

      protected final QueryMetadata metadata
    • subQuery

      @Nullable protected @Nullable SubQueryExpression<?> subQuery
    • subQueryBuilder

      @Nullable protected @Nullable SQLQuery<?> subQueryBuilder
    • batches

      protected final List<SQLInsertBatch> batches
    • columns

      protected final List<Path<?>> columns
    • values

      protected final List<Expression<?>> values
    • queryString

      protected transient String queryString
    • constants

      protected transient List<Object> constants
    • batchToBulk

      protected transient boolean batchToBulk
  • Constructor Details

  • Method Details

    • addFlag

      public C addFlag(QueryFlag.Position position, String flag)
      Add the given String literal at the given position as a query flag
      Parameters:
      position - position
      flag - query flag
      Returns:
      the current object
    • addFlag

      public C addFlag(QueryFlag.Position position, Expression<?> flag)
      Add the given Expression at the given position as a query flag
      Parameters:
      position - position
      flag - query flag
      Returns:
      the current object
    • addBatch

      public C addBatch()
      Add the current state of bindings as a batch item
      Returns:
      the current object
    • setBatchToBulk

      public void setBatchToBulk(boolean b)
      Set whether batches should be optimized into a single bulk operation. Will revert to batches, if bulk is not supported
    • clear

      public void clear()
      Description copied from class: AbstractSQLClause
      Clear the internal state of the clause
      Specified by:
      clear in class AbstractSQLClause<C extends AbstractSQLInsertClause<C>>
    • columns

      public C columns(Path<?>... columns)
      Specified by:
      columns in interface InsertClause<C extends AbstractSQLInsertClause<C>>
    • executeWithKey

      @Nullable public <T> T executeWithKey(Path<T> path)
      Execute the clause and return the generated key with the type of the given path. If no rows were created, null is returned, otherwise the key of the first row is returned.
      Type Parameters:
      T -
      Parameters:
      path - path for key
      Returns:
      generated key
    • executeWithKey

      public <T> T executeWithKey(Class<T> type)
      Execute the clause and return the generated key cast to the given type. If no rows were created, null is returned, otherwise the key of the first row is returned.
      Type Parameters:
      T -
      Parameters:
      type - type of key
      Returns:
      generated key
    • executeWithKey

      protected <T> T executeWithKey(Class<T> type, @Nullable @Nullable Path<T> path)
    • executeWithKeys

      public <T> List<T> executeWithKeys(Path<T> path)
      Execute the clause and return the generated key with the type of the given path. If no rows were created, or the referenced column is not a generated key, null is returned. Otherwise, the key of the first row is returned.
      Type Parameters:
      T -
      Parameters:
      path - path for key
      Returns:
      generated keys
    • executeWithKeys

      public <T> List<T> executeWithKeys(Class<T> type)
    • executeWithKeys

      protected <T> List<T> executeWithKeys(Class<T> type, @Nullable @Nullable Path<T> path)
    • createStatement

      protected PreparedStatement createStatement(boolean withKeys) throws SQLException
      Throws:
      SQLException
    • createStatements

      protected Collection<PreparedStatement> createStatements(boolean withKeys) throws SQLException
      Throws:
      SQLException
    • prepareStatementAndSetParameters

      protected PreparedStatement prepareStatementAndSetParameters(SQLSerializer serializer, boolean withKeys) throws SQLException
      Throws:
      SQLException
    • executeWithKeys

      public ResultSet executeWithKeys()
      Execute the clause and return the generated keys as a ResultSet
      Returns:
      result set with generated keys
    • execute

      public long execute()
      Specified by:
      execute in interface DMLClause<C extends AbstractSQLInsertClause<C>>
    • getSQL

      public List<SQLBindings> getSQL()
      Description copied from class: AbstractSQLClause
      Get the SQL string and bindings
      Specified by:
      getSQL in class AbstractSQLClause<C extends AbstractSQLInsertClause<C>>
      Returns:
      SQL and bindings
    • select

      public C select(SubQueryExpression<?> sq)
      Specified by:
      select in interface InsertClause<C extends AbstractSQLInsertClause<C>>
    • set

      public <T> C set(Path<T> path, T value)
      Specified by:
      set in interface StoreClause<C extends AbstractSQLInsertClause<C>>
    • set

      public <T> C set(Path<T> path, Expression<? extends T> expression)
      Specified by:
      set in interface StoreClause<C extends AbstractSQLInsertClause<C>>
    • setNull

      public <T> C setNull(Path<T> path)
      Specified by:
      setNull in interface StoreClause<C extends AbstractSQLInsertClause<C>>
    • values

      public C values(Object... v)
      Specified by:
      values in interface InsertClause<C extends AbstractSQLInsertClause<C>>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • populate

      public C populate(Object bean)
      Populate the INSERT clause with the properties of the given bean. The properties need to match the fields of the clause's entity instance.
      Parameters:
      bean - bean to use for population
      Returns:
      the current object
    • populate

      public <T> C populate(T obj, Mapper<T> mapper)
      Populate the INSERT clause with the properties of the given bean using the given Mapper.
      Parameters:
      obj - object to use for population
      mapper - mapper to use
      Returns:
      the current object
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface StoreClause<C extends AbstractSQLInsertClause<C>>
    • getBatchCount

      public int getBatchCount()
      Specified by:
      getBatchCount in class AbstractSQLClause<C extends AbstractSQLInsertClause<C>>