SqlConst

Framework Components [com.onepg.db]

← Back to Class List

Class Information

Package: com.onepg.db

Class Name: SqlConst

Extends: SqlBean

Description

Fixed SQL.
  • Stores SQL string and bind item definitions (item name and type).
  • When executing SQL, parameters with bind values are passed together with this SQL.
  • The same item name can be bound multiple times with the same type.
  • If there are no bind items, it is used as is.
[SQL Declaration Example 1]SqlConst SQL_INS_PET = SqlConst.begin()
    .addQuery("INSERT INTO t_pet ( ")
    .addQuery("  pet_no ")
    .addQuery(", pet_nm ")
    .addQuery(", birth_dt ")
    .addQuery(", ins_ts ")
    .addQuery(", upd_ts ")
    .addQuery(" ) VALUES ( ")
    .addQuery("  ? ", "pet_no", BindType.BigDecimal)
    .addQuery(", ? ", "pet_nm", BindType.String)
    .addQuery(", ? ", "birth_dt", BindType.Date)
    .addQuery(", ? ", "now_ts", BindType.Timestamp)
    .addQuery(", ? ", "now_ts", BindType.Timestamp)
    .addQuery(" ) ")
    .end();
[SQL Execution Example 1] SqlUtil.executeOne(conn, SQL_INS_PET.bind(io));
[SQL Declaration Example 2]SqlConst SQL_SEL_USER = SqlConst.begin()
    .addQuery("SELECT ")
    .addQuery("  u.user_id ")
    .addQuery(", u.user_nm ")
    .addQuery(", u.email ")
    .addQuery(", u.birth_dt ")
    .addQuery(" FROM t_user u ")
    .addQuery(" ORDER BY u.user_id ")
    .end();
[SQL Execution Example 2] SqlResultSet rSet = SqlUtil.select(getDbConn(), SQL_SEL_USER);

Enumeration List

BindType

public enum BindType
Bind type.
  • Indicates the type when binding to SQL.
  • Numeric types are unified to BigDecimal.

Constants

  • STRING
  • BIGDECIMAL
  • DATE
  • TIMESTAMP

Method List

begin

public SqlConstBuilder begin()
Creates fixed SQL builder instance.

Return Value

SqlConstBuilder - the fixed SQL builder instance

bind

public SqlBean bind(AbstractIoTypeMap params)
Sets bind values.
  • Returns a SQL Bean with the stored SQL string and the parameter value map received as an argument.
  • Creates a bind value list from the parameter value map based on the bind item name list and bind item definition map, and sets it in the SQL Bean.
  • Each element of the bind value list is Object, and each item value is stored in the type according to the bind item definition.
  • If the bind item name does not exist in the parameter value map, a runtime error occurs.

Parameters

Name Type Description
params AbstractIoTypeMap the parameter value map

Return Value

SqlBean - the SQL Bean

end

public SqlConst end()
Returns fixed SQL.

Return Value

SqlConst - the fixed SQL

addQuery

public SqlConstBuilder addQuery(String sql)
Adds SQL.
  • Replaces 2 or more consecutive blanks with a single blank when appending.

Parameters

Name Type Description
sql String the SQL

Return Value

SqlConstBuilder - the instance itself

addQuery

public SqlConstBuilder addQuery(String sql, String itemName, BindType bindType)
Adds SQL and bind item definition (item name and type).
  • The SQL string must contain exactly one bind placeholder ?.
  • The bind item name must be a valid value as an Io object key. (Key rule of AbstractIoTypeMap)

Parameters

Name Type Description
sql String the SQL
itemName String the bind item name
bindType BindType the bind type

Return Value

SqlConstBuilder - the instance itself