Package org.apache.velocity.example
Class DBContext
- java.lang.Object
-
- org.apache.velocity.context.InternalContextBase
-
- org.apache.velocity.context.AbstractContext
-
- org.apache.velocity.example.DBContext
-
- All Implemented Interfaces:
Context
,InternalEventContext
,InternalHousekeepingContext
public class DBContext extends AbstractContext
Example context impl that uses a database to store stuff :) yes, this is silly expects a mysql db test with table CREATE TABLE contextstore ( k varchar(100), val blob ); very fragile, crappy code.... just a demo!- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.sql.Connection
conn
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
internalContainsKey(java.lang.String key)
Not implementing.java.lang.Object
internalGet(java.lang.String key)
retrieves a serialized object from the db and returns the living instance to the caller.java.lang.String[]
internalGetKeys()
Not implementing.java.lang.Object
internalPut(java.lang.String key, java.lang.Object value)
Serializes and stores an object in the database.java.lang.Object
internalRemove(java.lang.String key)
Not implementing.private void
setup()
-
Methods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
-
Methods inherited from class org.apache.velocity.context.InternalContextBase
attachEventCartridge, getCurrentMacroCallDepth, getCurrentMacroName, getCurrentResource, getCurrentTemplateName, getEventCartridge, getMacroLibraries, getMacroNameStack, getTemplateNameStack, icacheGet, icachePut, popCurrentMacroName, popCurrentTemplateName, pushCurrentMacroName, pushCurrentTemplateName, setCurrentResource, setMacroLibraries
-
-
-
-
Constructor Detail
-
DBContext
public DBContext()
-
DBContext
public DBContext(Context inner)
-
-
Method Detail
-
internalGet
public java.lang.Object internalGet(java.lang.String key)
retrieves a serialized object from the db and returns the living instance to the caller.- Specified by:
internalGet
in classAbstractContext
- Parameters:
key
- key whose associated value is to be returned- Returns:
- object stored in the context
-
internalPut
public java.lang.Object internalPut(java.lang.String key, java.lang.Object value)
Serializes and stores an object in the database. This is really a hokey way to do it, and will cause problems. The right way is to use a prepared statement...- Specified by:
internalPut
in classAbstractContext
- Parameters:
key
- key with which to associate the valuevalue
- value to be associated with the key- Returns:
- previously stored value if exists, or null
-
internalContainsKey
public boolean internalContainsKey(java.lang.String key)
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalContainsKey
in classAbstractContext
- Parameters:
key
- key to test for existence- Returns:
- true if found, false if not
-
internalGetKeys
public java.lang.String[] internalGetKeys()
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalGetKeys
in classAbstractContext
- Returns:
- array of keys
-
internalRemove
public java.lang.Object internalRemove(java.lang.String key)
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalRemove
in classAbstractContext
- Parameters:
key
- key to remove- Returns:
- object removed if exists, else null
-
setup
private void setup()
-
-