Class Configuration

java.lang.Object
com.querydsl.sql.Configuration

public final class Configuration extends Object
Configuration for SQLQuery instances
Author:
tiwe
  • Constructor Details

    • Configuration

      public Configuration(SQLTemplates templates)
      Create a new Configuration instance
      Parameters:
      templates - templates for SQL serialization
  • Method Details

    • asLiteral

      public String asLiteral(Object o)
      Get the literal representation of the given constant
      Parameters:
      o - object
      Returns:
      literal representation
    • getTemplates

      public SQLTemplates getTemplates()
    • getJavaType

      public Class<?> getJavaType(int sqlType, String typeName, int size, int digits, String tableName, String columnName)
      Get the java type for the given jdbc type, table name and column name
      Parameters:
      sqlType - JDBC type
      typeName - JDBC type name
      size - size
      digits - digits
      tableName - table name
      columnName - column name
      Returns:
      Java type
    • get

      @Nullable public <T> T get(ResultSet rs, @Nullable @Nullable Path<?> path, int i, Class<T> clazz) throws SQLException
      Get the value at the given index from the result set
      Type Parameters:
      T - type to return
      Parameters:
      rs - result set
      path - path
      i - one based index in result set row
      clazz - type
      Returns:
      value
      Throws:
      SQLException
    • getOverride

      @Nullable public @Nullable SchemaAndTable getOverride(SchemaAndTable key)
      Get the schema/table override
      Parameters:
      key - schema and table
      Returns:
      overridden schema and table
    • getColumnOverride

      public String getColumnOverride(SchemaAndTable key, String column)
      Get the column override
      Parameters:
      key - schema and table
      column - column
      Returns:
      overridden column
    • setDynamicNameMapping

      public void setDynamicNameMapping(NameMapping nameMapping)
      Programmers can specify name mappings by implementing the NameMapping interface. The mapping rules that are specified by this property are checked if no mapping is specified by any of the register*Override functions.
      Parameters:
      nameMapping - The name mapping that is implemented by the user.
    • set

      public <T> void set(PreparedStatement stmt, Path<?> path, int i, T value) throws SQLException
      Set the value at the given index in the statement
      Type Parameters:
      T -
      Parameters:
      stmt - statement
      path - path
      i - one based index in statement
      value - value to bind
      Throws:
      SQLException
    • getTypeName

      public String getTypeName(Class<?> type)
      Get the SQL type name for the given java type
      Parameters:
      type - java type
      Returns:
      SQL type name
    • getTypeNameForCast

      public String getTypeNameForCast(Class<?> type)
      Get the SQL type name for a cast operation
      Parameters:
      type - java type
      Returns:
      SQL type name
    • registerSchemaOverride

      @Deprecated public String registerSchemaOverride(String oldSchema, String newSchema)
      Deprecated.
      Register a schema override
      Parameters:
      oldSchema - schema to override
      newSchema - override
      Returns:
      previous override value
    • registerTableOverride

      @Deprecated public String registerTableOverride(String oldTable, String newTable)
      Deprecated.
      Register a table override
      Parameters:
      oldTable - table to override
      newTable - override
      Returns:
      previous override value
    • registerTableOverride

      @Deprecated public String registerTableOverride(String schema, String oldTable, String newTable)
      Deprecated.
      Register a schema specific table override
      Parameters:
      schema - schema of table
      oldTable - table to override
      newTable - override
      Returns:
      previous override value
    • registerTableOverride

      @Deprecated public SchemaAndTable registerTableOverride(String schema, String oldTable, String newSchema, String newTable)
      Deprecated.
      Register a schema specific table override
      Parameters:
      schema - schema of table
      oldTable - table to override
      newSchema - override schema
      newTable - override table
      Returns:
      previous override value
    • registerTableOverride

      @Deprecated public SchemaAndTable registerTableOverride(SchemaAndTable from, SchemaAndTable to)
      Deprecated.
      Register a schema specific table override
      Parameters:
      from - schema and table to override
      to - override
      Returns:
      previous override
    • registerColumnOverride

      @Deprecated public String registerColumnOverride(String schema, String table, String oldColumn, String newColumn)
      Deprecated.
      Register a column override
      Parameters:
      schema - schema
      table - table
      oldColumn - column
      newColumn - override
      Returns:
      previous override
    • registerColumnOverride

      @Deprecated public String registerColumnOverride(String table, String oldColumn, String newColumn)
      Deprecated.
      Register a column override
      Parameters:
      table - table
      oldColumn - column
      newColumn - override
      Returns:
      previous override
    • register

      public void register(Type<?> type)
      Register the given Type converter
      Parameters:
      type - type
    • registerType

      public void registerType(String typeName, Class<?> clazz)
      Register a typeName to Class mapping
      Parameters:
      typeName - SQL type name
      clazz - java type
    • registerNumeric

      public void registerNumeric(int total, int decimal, Class<?> javaType)
      Override the binding for the given NUMERIC type
      Parameters:
      total - total amount of digits
      decimal - amount of fractional digits
      javaType - java type
    • registerNumeric

      public void registerNumeric(int beginTotal, int endTotal, int beginDecimal, int endDecimal, Class<?> javaType)
      Override multiple numeric bindings, both begin and end are inclusive
      Parameters:
      beginTotal - inclusive start of range
      endTotal - inclusive end of range
      beginDecimal - inclusive start of range
      endDecimal - inclusive end of range
      javaType - java type
    • register

      public void register(String table, String column, Class<?> javaType)
      Register the given javaType for the given table and column
      Parameters:
      table - table
      column - column
      javaType - java type
    • register

      public void register(String table, String column, Type<?> type)
      Register the given Type converter for the given table and column
      Parameters:
      table - table
      column - column
      type - type
    • translate

      public RuntimeException translate(SQLException ex)
      Translate the given SQLException
      Parameters:
      ex - SQLException to translate
      Returns:
      translated exception
    • translate

      public RuntimeException translate(String sql, List<Object> bindings, SQLException ex)
      Translate the given SQLException
      Parameters:
      sql - SQL string
      bindings - bindings
      ex - SQLException to translate
      Returns:
      translated exception
    • addListener

      public void addListener(SQLListener listener)
      Add a listener
      Parameters:
      listener - listener
    • getListeners

      public SQLListeners getListeners()
      Get the registered listener
      Returns:
      listeners as single listener instance
    • getUseLiterals

      public boolean getUseLiterals()
      Get whether literals are serialized or prepared statement bindings are used
      Returns:
      true for literals and false for bindings
    • setUseLiterals

      public void setUseLiterals(boolean useLiterals)
      Set whether literals are used in SQL strings instead of parameter bindings (default: false)

      Warning: When literals are used, prepared statement won't have any parameter bindings and also batch statements will only be simulated, but not executed as actual batch statements.

      Parameters:
      useLiterals - true for literals and false for bindings
    • setExceptionTranslator

      public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)
      Set the exception translator
      Parameters:
      exceptionTranslator - exception translator
    • setTemplates

      public void setTemplates(SQLTemplates templates)
      Set the templates to use for serialization
      Parameters:
      templates - templates