Package org.apache.velocity.example
Class DBContext
java.lang.Object
org.apache.velocity.context.AbstractContext
org.apache.velocity.example.DBContext
- All Implemented Interfaces:
Context,InternalEventContext
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$
- Author:
- Geir Magnusson Jr.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintget the current macro call depthget the current macro nameget the current template nameString[]get the current macro name stackString[]get the current template name stackreturns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the keyvoidicachePut(Object key, IntrospectionCacheData o) places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified keybooleanNot implementing.internalGet(String key) retrieves a serialized object from the db and returns the living instance to the caller.String[]Not implementing.internalPut(String key, Object value) Serializes and stores an object in the database.internalRemove(String key) Not implementing.voidremove the current macro name from stackvoidremove the current template name from stackvoidset the current macro name on top of stackvoidset the current template name on top of stackvoidvoidsetMacroLibraries(List<Template> macroLibraries) Methods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
-
Constructor Details
-
DBContext
public DBContext() -
DBContext
-
-
Method Details
-
internalGet
retrieves a serialized object from the db and returns the living instance to the caller.- Specified by:
internalGetin classAbstractContext- Parameters:
key- key whose associated value is to be returned- Returns:
- object stored in the context
-
internalPut
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:
internalPutin 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
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalContainsKeyin classAbstractContext- Parameters:
key- key to test for existence- Returns:
- true if found, false if not
-
internalGetKeys
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalGetKeysin classAbstractContext- Returns:
- array of keys
-
internalRemove
Not implementing. Not required for Velocity core operation, so not bothering. As we say above : "very fragile, crappy code..."- Specified by:
internalRemovein classAbstractContext- Parameters:
key- key to remove- Returns:
- object removed if exists, else null
-
pushCurrentTemplateName
set the current template name on top of stack- Parameters:
s- current template name
-
popCurrentTemplateName
public void popCurrentTemplateName()remove the current template name from stack -
getCurrentTemplateName
get the current template name- Returns:
- String current template name
-
getTemplateNameStack
get the current template name stack- Returns:
- String[] with the template name stack contents.
-
pushCurrentMacroName
set the current macro name on top of stack- Parameters:
s- current macro name
-
popCurrentMacroName
public void popCurrentMacroName()remove the current macro name from stack -
getCurrentMacroName
get the current macro name- Returns:
- String current macro name
-
getCurrentMacroCallDepth
public int getCurrentMacroCallDepth()get the current macro call depth- Returns:
- int current macro call depth
-
getMacroNameStack
get the current macro name stack- Returns:
- String[] with the macro name stack contents.
-
icacheGet
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key- Parameters:
key- key to find in cache- Returns:
- cache object
-
icachePut
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key- Parameters:
key- keyo- IntrospectionCacheData object to place in cache
-
setCurrentResource
- See Also:
-
getCurrentResource
- See Also:
-
setMacroLibraries
- See Also:
-
getMacroLibraries
- See Also:
-
attachEventCartridge
- Specified by:
attachEventCartridgein interfaceInternalEventContext- Parameters:
ec-- Returns:
- The old EventCartridge.
- See Also:
-
getEventCartridge
- Specified by:
getEventCartridgein interfaceInternalEventContext- Returns:
- The current EventCartridge.
- See Also:
-