net.spy.db
Class DefaultQuerySelector

java.lang.Object
  extended bynet.spy.db.DefaultQuerySelector
All Implemented Interfaces:
QuerySelector

public class DefaultQuerySelector
extends Object
implements QuerySelector

Default implementation of query selector. This implementation of QuerySelector works by finding the best match for the given Connection by package name. If given a SpyConfig, it looks for either an entry called queryName or a prefix match against the driver name as specified for SpyDB.

The following driver prefixes are mapped to their respective names in this implementation:

Driver class prefixQuery NameDriver Provider
org.postgresql.pgsqlhttp://www.postgresql.org
oracle.jdbc.driver.oraclehttp://www.oracle.com
weblogic.jdbc.oci.oraclehttp://www.bea.com
com.ashna.jturbo.mssqlhttp://www.newatlanta.com/

See Also:
SpyDB

Field Summary
 
Fields inherited from interface net.spy.db.QuerySelector
DEFAULT_QUERY
 
Constructor Summary
DefaultQuerySelector()
          Get an instance of DefaultQuerySelector.
 
Method Summary
 String getQuery(Connection conn, Map queryMap)
          Get the query for the given connection.
 String getQuery(SpyConfig conf, Map queryMap)
          Get the query for the given config.
protected  String getQuery(String name, Map queryMap)
          Attempt to get a query in the given map by a name.
protected  void initNameMap()
          Initialize the prefix to name map.
protected  void registerNameMapping(String prefix, String name)
          Register a prefix -> name mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultQuerySelector

public DefaultQuerySelector()
Get an instance of DefaultQuerySelector. This should really only be called from QuerySelectorFactory

Method Detail

initNameMap

protected void initNameMap()
Initialize the prefix to name map.


registerNameMapping

protected void registerNameMapping(String prefix,
                                   String name)
Register a prefix -> name mapping.

Parameters:
prefix - the prefix to match for a name
name - the name

getQuery

public String getQuery(Connection conn,
                       Map queryMap)
Description copied from interface: QuerySelector
Get the query for the given connection.

Specified by:
getQuery in interface QuerySelector
Parameters:
conn - the connection that wants the query
queryMap - the Map of queries by name
Returns:
the query (as a String), null if a suitable query can't be found
See Also:
QuerySelector

getQuery

public String getQuery(SpyConfig conf,
                       Map queryMap)
Description copied from interface: QuerySelector
Get the query for the given config.

Specified by:
getQuery in interface QuerySelector
Parameters:
conf - a SpyConfig containing enough information to find a query
queryMap - the Map of queries by name
Returns:
the query (as a String), null if a suitable query can't be found
See Also:
QuerySelector

getQuery

protected String getQuery(String name,
                          Map queryMap)
Attempt to get a query in the given map by a name.

Parameters:
name - the name against which to search
queryMap - the map containing the queries
Returns:
the query, or null if one cannot be found