com.opengamma.elsql
Class ElSqlConfig

java.lang.Object
  extended by com.opengamma.elsql.ElSqlConfig

public class ElSqlConfig
extends Object

Configuration that provides support for differences between databases.

The class provides SQL fragments that the tags use to build the complete SQL. Some standard implementations have been provided, but subclasses may be added.

Implementations must be thread-safe.


Field Summary
static ElSqlConfig DEFAULT
          A constant for the standard set of config, based on ANSI SQL.
static ElSqlConfig HSQL
          A constant for the config needed for HSQL, which escapes the LIKE clause.
static ElSqlConfig MYSQL
          A constant for the config needed for MySQL, which uses LIMIT-OFFSET instead of FETCH-OFFSET.
static ElSqlConfig ORACLE
          A constant for the config needed for Oracle RDBMS.
static ElSqlConfig POSTGRES
          A constant for the config needed for Postgres, the same as DEFAULT.
static ElSqlConfig SQL_SERVER_2008
          A constant for the config needed for SQL Server 2008, which pages in a different way.
static ElSqlConfig VERTICA
          A constant for the config needed for Vertica, the same as DEFAULT.
 
Constructor Summary
ElSqlConfig(String name)
          Creates an instance.
 
Method Summary
 String addPaging(String selectToPage, int offset, int fetchLimit)
          Alters the supplied SQL to add paging, such as OFFSET-FETCH.
 String getLikeSuffix()
          Gets the suffix to add after LIKE, which would typically be an ESCAPE clause.
 String getName()
          Gets the config name.
 String getPaging(int offset, int fetchLimit)
          Gets the paging SQL, such as OFFSET-FETCH.
 boolean isLikeWildcard(String value)
          Checks if the value contains a wildcard.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final ElSqlConfig DEFAULT
A constant for the standard set of config, based on ANSI SQL.


POSTGRES

public static final ElSqlConfig POSTGRES
A constant for the config needed for Postgres, the same as DEFAULT.


HSQL

public static final ElSqlConfig HSQL
A constant for the config needed for HSQL, which escapes the LIKE clause.


MYSQL

public static final ElSqlConfig MYSQL
A constant for the config needed for MySQL, which uses LIMIT-OFFSET instead of FETCH-OFFSET.


ORACLE

public static final ElSqlConfig ORACLE
A constant for the config needed for Oracle RDBMS.


SQL_SERVER_2008

public static final ElSqlConfig SQL_SERVER_2008
A constant for the config needed for SQL Server 2008, which pages in a different way.


VERTICA

public static final ElSqlConfig VERTICA
A constant for the config needed for Vertica, the same as DEFAULT.

Constructor Detail

ElSqlConfig

public ElSqlConfig(String name)
Creates an instance.

Parameters:
name - a descriptive name for the config, not null
Method Detail

getName

public final String getName()
Gets the config name.

Returns:
the config name, not null

isLikeWildcard

public boolean isLikeWildcard(String value)
Checks if the value contains a wildcard.

The default implementation matches % and _, using backslash as an escape character. This matches Postgres and other databases.

Parameters:
value - the value to check, not null
Returns:
true if the value contains wildcards

getLikeSuffix

public String getLikeSuffix()
Gets the suffix to add after LIKE, which would typically be an ESCAPE clause.

The default implementation returns an empty string. This matches Postgres and other databases.

The returned SQL must be end in a space if non-empty.

Returns:
the suffix to add after LIKE, not null

addPaging

public String addPaging(String selectToPage,
                        int offset,
                        int fetchLimit)
Alters the supplied SQL to add paging, such as OFFSET-FETCH.

The default implementation calls getPaging(int, int).

The returned SQL must be end in a space if non-empty.

Parameters:
selectToPage - the SELECT statement to page, not null
offset - the OFFSET amount, zero to start from the beginning
fetchLimit - the FETCH/LIMIT amount, zero to fetch all
Returns:
the updated SELECT, not null

getPaging

public String getPaging(int offset,
                        int fetchLimit)
Gets the paging SQL, such as OFFSET-FETCH.

The default implementation uses 'FETCH FIRST n ROWS ONLY' or 'OFFSET n ROWS FETCH NEXT n ROWS ONLY'. This matches Postgres, HSQL and other databases.

The returned SQL must be end in a space if non-empty.

Parameters:
offset - the OFFSET amount, zero to start from the beginning
fetchLimit - the FETCH/LIMIT amount, zero to fetch all
Returns:
the SQL to use, not null

toString

public String toString()
Overrides:
toString in class Object


Copyright 2009-Present by OpenGamma Inc. and individual contributors, released under the Apache License Version 2.0