com.onewebsql.query.adapter
Class DB2DBAdapter

java.lang.Object
  extended by com.onewebsql.query.adapter.BaseDBAdapter
      extended by com.onewebsql.query.adapter.DB2DBAdapter
All Implemented Interfaces:
DBAdapter

public class DB2DBAdapter
extends BaseDBAdapter

Implementation of DBAdapter interface for the DB2 database.


Field Summary
static DB2ValueListParameterHandler DB2_VALUE_LIST_PARAMETER_HANDLER
          Standard parameter handler which binds values to SQL statement parameters, compatible with DB2 driver.
static String VALUES_NEXTVAL_FOR
          SQL prefix to get the next value of the sequence.
 
Fields inherited from class com.onewebsql.query.adapter.BaseDBAdapter
DEFAULT_VALUE_LIST_PARAMETER_HANDLER, LOB_BURST_SIZE, NEXT_VALUE_FOR, SEQUENCE_ROW_HANDLER
 
Constructor Summary
DB2DBAdapter()
           
 
Method Summary
 void buildQuery(SelectQuery query, String schemaName, StringBuilder sb, List<Value> objs)
          Builds a SELECT query in a way specific for DB2.
 Long getNextId(String sequenceName, String schemaName, DataSource ds)
          Returns the next value from the sequence with the specified name and the specified schema name, from the specified data source.
 ParameterHandler<List<Value>> getValueListParameterHandler()
          Returns an object binding the value lists built by OneWebSQL to SQL query parameters in a way specific for the database.
 void setBlob(DataSource ds, String schemaName, Column column, Object id, InputStream is, long length)
          Reads from the specified stream and writes its contents to the Blob column.
 void setClob(DataSource ds, String schemaName, Column column, Object id, Reader reader, long length)
          Reads from the specified Reader and writes its contents to the Clob column.
 
Methods inherited from class com.onewebsql.query.adapter.BaseDBAdapter
buildIdWhere, getBlob, getClob, join
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUES_NEXTVAL_FOR

public static final String VALUES_NEXTVAL_FOR
SQL prefix to get the next value of the sequence.

See Also:
Constant Field Values

DB2_VALUE_LIST_PARAMETER_HANDLER

public static final DB2ValueListParameterHandler DB2_VALUE_LIST_PARAMETER_HANDLER
Standard parameter handler which binds values to SQL statement parameters, compatible with DB2 driver.

Constructor Detail

DB2DBAdapter

public DB2DBAdapter()
Method Detail

buildQuery

public void buildQuery(SelectQuery query,
                       String schemaName,
                       StringBuilder sb,
                       List<Value> objs)
Builds a SELECT query in a way specific for DB2. It handles SELECT limits in a different way. If an upper limit is present (LIMIT) the following query is built:
 SELECT ... // original query
 FETCH FIRST <LIMIT> ROWS ONLY
 
If both an upper and a lower limit are present (OFFSET), the following query is built:
 SELECT ORIGINAL_QUERY.<first column in original query>, ORIGINAL_QUERY.<second column in original query>, ...
 FROM 
 (
        SELECT <first column in original query>, <second column in original query>, ..., ROW_NUMBER() OVER(<ORDER BY clause of the original query>) ROWNUM
        // the rest of the original query with ORDER BY clause removed
 ) 
 ORIGINAL_QUERY 
 WHERE ROWNUM > <OFFSET> AND ROWNUM <= <LIMIT + OFFSET>
 

Specified by:
buildQuery in interface DBAdapter
Overrides:
buildQuery in class BaseDBAdapter
Parameters:
query - SELECT query
schemaName - schema name used to build the query
sb - StringBuilder where we build the query
objs - an accumulator list to which join parameters are added

getNextId

public Long getNextId(String sequenceName,
                      String schemaName,
                      DataSource ds)
Description copied from interface: DBAdapter
Returns the next value from the sequence with the specified name and the specified schema name, from the specified data source.

Specified by:
getNextId in interface DBAdapter
Overrides:
getNextId in class BaseDBAdapter
Parameters:
sequenceName - sequence name
schemaName - name of the schema
ds - data source
Returns:
next value of the sequence

setBlob

public void setBlob(DataSource ds,
                    String schemaName,
                    Column column,
                    Object id,
                    InputStream is,
                    long length)
Description copied from interface: DBAdapter
Reads from the specified stream and writes its contents to the Blob column. The specified row must exist in the database. The row identifier might be

Specified by:
setBlob in interface DBAdapter
Overrides:
setBlob in class BaseDBAdapter
Parameters:
ds - data source
schemaName - name of the table's schema
column - column to which we are writing
id - row id
is - InputStream containing data to write or null if the column is to be set to NULL
length - the number of bytes to write or -1 if the whole stream content is to be written

setClob

public void setClob(DataSource ds,
                    String schemaName,
                    Column column,
                    Object id,
                    Reader reader,
                    long length)
Description copied from interface: DBAdapter
Reads from the specified Reader and writes its contents to the Clob column. The specified row must exist in the database. The row identifier might be

Specified by:
setClob in interface DBAdapter
Overrides:
setClob in class BaseDBAdapter
Parameters:
ds - data source
schemaName - name of the table's schema
column - column to which we are writing
id - row id
reader - Reader containing data to write or null if the column is to be set to NULL
length - the number of bytes to write or -1 if the whole stream content is to be written

getValueListParameterHandler

public ParameterHandler<List<Value>> getValueListParameterHandler()
Description copied from interface: DBAdapter
Returns an object binding the value lists built by OneWebSQL to SQL query parameters in a way specific for the database.

Specified by:
getValueListParameterHandler in interface DBAdapter
Overrides:
getValueListParameterHandler in class BaseDBAdapter
Returns:
an object binding value lists to SQL query parameters
See Also:
SelectQuery.build(StringBuilder, String, List, DBAdapter), InsertQuery.build(StringBuilder, String, List, DBAdapter), DeleteQuery.build(StringBuilder, String, List, DBAdapter)


Copyright © 2011-2013 e-point SA. All Rights Reserved.