com.onewebsql.query.adapter
Class MSSQLDBAdapter

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

public class MSSQLDBAdapter
extends BaseDBAdapter

Implementation of DBAdapter interface for the MSSQL database.


Field Summary
 
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
MSSQLDBAdapter()
          Creates a new MSSQLDBAdapter object.
 
Method Summary
 void buildQuery(SelectQuery query, String schemaName, StringBuilder sb, List<Value> objs)
          Builds a SELECT query in a way specific for MSSQL.
 boolean getBlob(DataSource ds, String schemaName, Column column, Object id, OutputStream is, long length)
          Retrieves the value of Blob column and writes its contents to the specified stream.
 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.
 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.
 
Methods inherited from class com.onewebsql.query.adapter.BaseDBAdapter
buildIdWhere, getClob, getValueListParameterHandler, join, setClob
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MSSQLDBAdapter

public MSSQLDBAdapter()
Creates a new MSSQLDBAdapter object.

Method Detail

buildQuery

public void buildQuery(SelectQuery query,
                       String schemaName,
                       StringBuilder sb,
                       List<Value> objs)
Builds a SELECT query in a way specific for MSSQL. It handles SELECT limits in a different way. If an upper limit is present (LIMIT) the following query is built:
 SELECT TOP <LIMIT> <first column in original query>, <second column in original query>, ...
 // rest of the original query
 
If both an upper and a lower limit are present (OFFSET), the following query is built:
 SELECT TOP_QUERY.<first column in original query>, TOP_QUERY.<second column in original query>, ...
 FROM
        ( 
        SELECT TOP <LIMIT> ORIGINAL_QUERY.<first column in original query>, ORIGINAL_QUERY.<second column in original query>, ...
        FROM 
                (
                        SELECT TOP <LIMIT + OFFSET> <first column in original query>, <second column in original query>, ...
                        // rest of the original query
                ) ORIGINAL_QUERY <ORDER BY clause of the original query with reversed sorting>
 ) TOP_QUERY <ORDER BY clause of the original>
 
 

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)
Returns the next value from the sequence with the specified name and the specified schema name, from the specified data source. The method uses a store procedure get_next_id() to generate unique identifiers. The procedure should be created by SQL script creating database structure.

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

getBlob

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

Specified by:
getBlob in interface DBAdapter
Overrides:
getBlob in class BaseDBAdapter
Parameters:
ds - data source
schemaName - name of the table's schema
column - column we are reading
id - row id
is - OutputStream to which the column contents is to be written
length - the maximal number of bytes to write or -1 if the whole column contents is to be written
Returns:
true if the column value was retrieved false if the column value was NULL

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


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