velosurf.tools
Class VelosurfTool

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by velosurf.context.DBReference
              extended by velosurf.tools.VelosurfTool
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, org.apache.velocity.tools.view.tools.Configurable, org.apache.velocity.tools.view.tools.ViewTool, DataAccessor

public class VelosurfTool
extends DBReference
implements org.apache.velocity.tools.view.tools.ViewTool, org.apache.velocity.tools.view.tools.Configurable

This class is a tool meant to be referenced in toolbox.xml

It can be used in any scope you want (application/session/request), depending on the behaviour you need for the refinement and ordering mechanisms (which will follow the same scope). The initialization itself is very fast once all static initialization has been done, so there is no performance bottleneck when using request scope.

Since version 1.0rc1, you can have several instances of VelosurfTool, each with a distinct configuration file. This can be useful to have one instance per schema, or one instance per database if dealing with several databases.

For this to work, you have to give each instance the pathname of its configuration file via the 'config' parameter in the toolbox.xml file (this is a new feature of VelocityTools 1.2), like this:


  <!-- first instance -->
  <tool>
    <key>db1</key>
    <scope>request</scope>
    <class>velosurf.tools.VelosurfTool</scope>
    <parameter name="config" value="WEB-INF/db1.xml" />
  </tool>

  <!-- second instance -->
  <tool>
    <key>db2</key>
    <scope>request</scope>
    <class>velosurf.tools.VelosurfTool</scope>
    <parameter name="config" value="WEB-INF/db2.xml" />
   </tool>

Author:
Claude Brisson
See Also:
Serialized Form

Field Summary
protected static java.lang.String DATABASE_CONFIG_FILE_KEY
          key used in the deployment descriptor (web.xml) to set the name of the config file
protected static java.lang.String DEFAULT_DATABASE_CONFIG_FILE
          default database config file
protected  java.lang.String mConfigFile
          path to the config file
protected static java.util.Map sDBMap
          database connections
 
Fields inherited from class velosurf.context.DBReference
mCache, mDB, mExternalParams
 
Constructor Summary
VelosurfTool()
          builds a new VelosurfTool
 
Method Summary
 void configure(java.util.Map map)
          configure
static Database getConnection(java.lang.String inConfigFile)
          returns the existing Database for the specified config file, or null if it does not already exist.
static Database getConnection(java.lang.String inConfigFile, javax.servlet.ServletContext inServletContext)
          returns the existing Database for the specified config file and servlet context, or null if an error occurs.
static Database getDefaultConnection()
          returns the existing Database for the default config file, or null if it does not already exist.
static Database getDefaultConnection(javax.servlet.ServletContext inServletContext)
          returns the existing Database for the default config file and servlet context, or null if an error occurs.
 void init(java.lang.Object inViewContext)
          Initializes this instance using the given ViewContext
protected  Database initDB(javax.servlet.ServletContext inServletContext)
          initialization
 
Methods inherited from class velosurf.context.DBReference
deobfuscate, get, getError, getSchema, init, obfuscate, put
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

DATABASE_CONFIG_FILE_KEY

protected static final java.lang.String DATABASE_CONFIG_FILE_KEY
key used in the deployment descriptor (web.xml) to set the name of the config file

See Also:
Constant Field Values

DEFAULT_DATABASE_CONFIG_FILE

protected static final java.lang.String DEFAULT_DATABASE_CONFIG_FILE
default database config file

See Also:
Constant Field Values

mConfigFile

protected java.lang.String mConfigFile
path to the config file


sDBMap

protected static java.util.Map sDBMap
database connections

Constructor Detail

VelosurfTool

public VelosurfTool()
builds a new VelosurfTool

Method Detail

init

public void init(java.lang.Object inViewContext)
Initializes this instance using the given ViewContext

Specified by:
init in interface org.apache.velocity.tools.view.tools.ViewTool
Parameters:
inViewContext - initialization data

initDB

protected Database initDB(javax.servlet.ServletContext inServletContext)
initialization

Parameters:
inServletContext - servlet context
Returns:
database connection

configure

public void configure(java.util.Map map)
configure

Specified by:
configure in interface org.apache.velocity.tools.view.tools.Configurable
Parameters:
map - parameters

getConnection

public static Database getConnection(java.lang.String inConfigFile)
returns the existing Database for the specified config file, or null if it does not already exist.

Parameters:
inConfigFile -
Returns:
a Database

getConnection

public static Database getConnection(java.lang.String inConfigFile,
                                     javax.servlet.ServletContext inServletContext)
returns the existing Database for the specified config file and servlet context, or null if an error occurs.

Parameters:
inConfigFile -
Returns:
a Database

getDefaultConnection

public static Database getDefaultConnection()
returns the existing Database for the default config file, or null if it does not already exist.

Returns:
a Database

getDefaultConnection

public static Database getDefaultConnection(javax.servlet.ServletContext inServletContext)
returns the existing Database for the default config file and servlet context, or null if an error occurs.

Returns:
a Database


~ooOoo~