org.apache.beehive.netui.databinding.datagrid.runtime.sql
Class SQLSupport

Object
  extended by SQLSupport

public final class SQLSupport
extends Object

This class provides support for the SQL query language for a data grid's Sort and Filter JavaBeans. Support is provided here for obtaining a list of supported SQL filter operations. There is also support for generating two kinds of SQL statements:


Method Summary
 void configure(SQLSupportConfig config)
          Set the SQLSupportConfig object useed to configure the SQL statements produced by this class.
 String createOrderByClause(List sorts)
           Create a SQL ORDER BY clause from the list of Sort objects.
 String createOrderByFragment(List sorts)
           Create a SQL order fragment from the list of Sort objects.
 String createWhereClause(List filters)
           Create a SQL WHERE clause from the list of Filter objects.
 String createWhereFragment(List filters)
           Create a SQL WHERE clause from the list of Filter objects.
static SQLSupport getInstance()
          Get an instance of this class configured using a default SQLSupportConfig.
static SQLSupport getInstance(DatabaseMetaData databaseMetaData)
          Get an instance of this class configured using a SQLSupportConfig that has been configured using the provided DatabaseMetaData.
static SQLSupport getInstance(SQLSupportConfig config)
          Get an instance of this class configured using the provided SQLSupportConfig.
static String lookoupDefaultFilterOperationAbbreviation(String typeHint)
           Lookup the default filter operation's abbreviation given a filter type hint abbreviation.
static Map lookupFilterOperationLabels(String typeHint)
          Get the readable string labels for a filter operation.
static FilterOperation mapFilterAbbreviationToOperation(String abbrev)
          Lookup a filter operation given a filter operation abbreviation.
static FilterOperation mapFilterHintToOperation(FilterOperationHint hint)
          Map a FilterOperationHint to a SQL-specific FilterOperation.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SQLSupport getInstance()
Get an instance of this class configured using a default SQLSupportConfig.

Returns:
a SQLSupport instance

getInstance

public static SQLSupport getInstance(DatabaseMetaData databaseMetaData)
                              throws SQLException
Get an instance of this class configured using a SQLSupportConfig that has been configured using the provided DatabaseMetaData.

Parameters:
databaseMetaData - the database metadata used to configure a SQLSupportConfig object
Returns:
a SQLSupport instance
Throws:
SQLException - when an error occurs reading from DatabaseMetaData

getInstance

public static SQLSupport getInstance(SQLSupportConfig config)
Get an instance of this class configured using the provided SQLSupportConfig. The caller should create and appropriately initialize the config object.

Parameters:
config - the config object use to configure a SQLSupport instance
Returns:
a SQLSupport instance

lookupFilterOperationLabels

public static Map lookupFilterOperationLabels(String typeHint)
Get the readable string labels for a filter operation. This Map contains a set of filter operation abbreviations mapped to a label for that filter operation. The abbreviations can be used to lookup the correct filter operation. This method accepts values enumerated in FilterTypeHint and available via FilterTypeHint.getHint().

Parameters:
typeHint - the type hint whose matching operations to lookup
Returns:
Map a Map of String abbreviations to readable string names for the operation

lookoupDefaultFilterOperationAbbreviation

public static String lookoupDefaultFilterOperationAbbreviation(String typeHint)

Lookup the default filter operation's abbreviation given a filter type hint abbreviation. The type hint should be obtained via FilterTypeHint.getHint(). The default filter operations for a given FilterTypeHint string maps to the following FilterOperationHint. The string returned is the associated FilterOperation's abbreviation

Type Hint
FilterTypeHint.DATEFilterOperationHint.EQUAL
FilterTypeHint.NUMERICFilterOperationHint.EQUAL
FilterTypeHint.STRINGFilterOperationHint.CONTAINS

Parameters:
typeHint - the type hint whose default operation to lookup
Returns:
String the abbreviation

mapFilterAbbreviationToOperation

public static final FilterOperation mapFilterAbbreviationToOperation(String abbrev)
Lookup a filter operation given a filter operation abbreviation. The abbreviation should be obtained via FilterOperation.getAbbreviation().

Parameters:
abbrev -
Returns:
the filter operation

mapFilterHintToOperation

public static final FilterOperation mapFilterHintToOperation(FilterOperationHint hint)
Map a FilterOperationHint to a SQL-specific FilterOperation. When using SQL as a query language, all of the operations defined in FilterOperationHint should be supported.

Parameters:
hint - the hint
Returns:
the FilterOperation matching the given hint.

configure

public void configure(SQLSupportConfig config)
Set the SQLSupportConfig object useed to configure the SQL statements produced by this class.

Parameters:
config - the config object

createOrderByFragment

public final String createOrderByFragment(List sorts)

Create a SQL order fragment from the list of Sort objects. This fragment does not begin with ORDER BY and is just the fragment for such a clause. If the given list of sorts contains a sort with sort expression "foo" and sort direction SortDirection.DESCENDING, the generated SQL statement will appear as:

     foo DESC
 

Parameters:
sorts - the list of Sort objects
Returns:
the generated SQL statement order fragment or an emtpy string if there are no sorts

createOrderByClause

public final String createOrderByClause(List sorts)

Create a SQL ORDER BY clause from the list of Sort objects. This fragment begins with ORDER BY. If the given list of sorts contains a sort with sort expression "foo" and sort direction SortDirection.DESCENDING, the generated SQL statement will appear as:

     ORDER BY foo DESC
 

Parameters:
sorts - the list of Sort objects
Returns:
the generated SQL ORDER BY clause or an emtpy string if there are no sorts

createWhereFragment

public String createWhereFragment(List filters)

Create a SQL WHERE clause from the list of Filter objects. This fragment does not begin with WHERE. If the given list of sorts contains a Filter with filter expression "foo", operation equals, and value '42', the generated SQL statement will appear as:

     foo = 42
 
When multiple Filters in the list, the filters will be AND'ed together in the generated SQL statement.

Parameters:
filters - the list of Filter objects
Returns:
the generated SQL where clause fragment or an emtpy string if there are no filters

createWhereClause

public String createWhereClause(List filters)

Create a SQL WHERE clause from the list of Filter objects. This fragment begins with WHERE. If the given list of sorts contains a Filter with filter expression "foo", operation equals, and value '42', the generated SQL statement will appear as:

     WHERE foo = 42
 
When multiple Filters in the list, the filters will be AND'ed together in the generated SQL statement.

Parameters:
filters - the list of Filter objects
Returns:
the generated SQL WHERE clause or an emtpy string if there are no filters