org.apache.cayenne.access.jdbc
Class BindDirective

java.lang.Object
  extended by org.apache.velocity.runtime.directive.Directive
      extended by org.apache.cayenne.access.jdbc.BindDirective
All Implemented Interfaces:
Cloneable, org.apache.velocity.runtime.directive.DirectiveConstants
Direct Known Subclasses:
BindEqualDirective, BindNotEqualDirective, BindObjectEqualDirective

public class BindDirective
extends org.apache.velocity.runtime.directive.Directive

A custom Velocity directive to create a PreparedStatement parameter text. There are the following possible invocation formats inside the template:

 #bind(value) - e.g. #bind($xyz)
 #bind(value jdbc_type_name) - e.g. #bind($xyz 'VARCHAR'). This is the most common and useful form.
 #bind(value jdbc_type_name, scale) - e.g. #bind($xyz 'VARCHAR' 2)
 

Other examples:

Binding literal parameter value:

"WHERE SOME_COLUMN > #bind($xyz)" produces "WHERE SOME_COLUMN > ?" and also places the value of the "xyz" parameter in the context "bindings" collection.

Binding ID column of a DataObject value:

"WHERE ID_COL1 = #bind($helper.cayenneExp($xyz, 'db:ID_COL2')) AND ID_COL2 = #bind($helper.cayenneExp($xyz, 'db:ID_COL2'))" produces "WHERE ID_COL1 = ? AND ID_COL2 = ?" and also places the values of id columns of the DataObject parameter "xyz" in the context "bindings" collection.

Since:
1.1

Field Summary
 
Fields inherited from class org.apache.velocity.runtime.directive.Directive
rsvc
 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
 
Constructor Summary
BindDirective()
           
 
Method Summary
protected  void bind(org.apache.velocity.context.InternalContextAdapter context, ParameterBinding binding)
          Adds value to the list of bindings in the context.
protected  Object getChild(org.apache.velocity.context.InternalContextAdapter context, org.apache.velocity.runtime.parser.node.Node node, int i)
           
 String getName()
           
 int getType()
           
 boolean render(org.apache.velocity.context.InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node)
          Extracts the value of the object property to render and passes control to render(InternalContextAdapter, Writer, ParameterBinding) to do the actual rendering.
protected  void render(org.apache.velocity.context.InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node, Object value, String typeString, int scale)
           
protected  void render(org.apache.velocity.context.InternalContextAdapter context, Writer writer, ParameterBinding binding)
           
 
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, init, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BindDirective

public BindDirective()
Method Detail

getName

public String getName()
Specified by:
getName in class org.apache.velocity.runtime.directive.Directive

getType

public int getType()
Specified by:
getType in class org.apache.velocity.runtime.directive.Directive

render

public boolean render(org.apache.velocity.context.InternalContextAdapter context,
                      Writer writer,
                      org.apache.velocity.runtime.parser.node.Node node)
               throws IOException,
                      org.apache.velocity.exception.ResourceNotFoundException,
                      org.apache.velocity.exception.ParseErrorException,
                      org.apache.velocity.exception.MethodInvocationException
Extracts the value of the object property to render and passes control to render(InternalContextAdapter, Writer, ParameterBinding) to do the actual rendering.

Specified by:
render in class org.apache.velocity.runtime.directive.Directive
Throws:
IOException
org.apache.velocity.exception.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException

render

protected void render(org.apache.velocity.context.InternalContextAdapter context,
                      Writer writer,
                      org.apache.velocity.runtime.parser.node.Node node,
                      Object value,
                      String typeString,
                      int scale)
               throws IOException,
                      org.apache.velocity.exception.ParseErrorException
Throws:
IOException
org.apache.velocity.exception.ParseErrorException
Since:
3.0

render

protected void render(org.apache.velocity.context.InternalContextAdapter context,
                      Writer writer,
                      ParameterBinding binding)
               throws IOException
Throws:
IOException

getChild

protected Object getChild(org.apache.velocity.context.InternalContextAdapter context,
                          org.apache.velocity.runtime.parser.node.Node node,
                          int i)
                   throws org.apache.velocity.exception.MethodInvocationException
Throws:
org.apache.velocity.exception.MethodInvocationException

bind

protected void bind(org.apache.velocity.context.InternalContextAdapter context,
                    ParameterBinding binding)
Adds value to the list of bindings in the context.



Copyright © 2001-2011 Apache Cayenne. All Rights Reserved.