org.apache.cayenne.access.jdbc

## Class ResultDirective

- java.lang.Object
- - org.apache.velocity.runtime.directive.Directive
  - - org.apache.cayenne.access.jdbc.ResultDirective

- All Implemented Interfaces:
    Cloneable, org.apache.velocity.runtime.directive.DirectiveConstants

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

  A custom Velocity directive to describe a ResultSet column. There are the following possible invocation formats inside the template:

             #result(column_name) - e.g. #result('ARTIST_ID')
             #result(column_name java_type) - e.g. #result('ARTIST_ID' 'String')
             #result(column_name java_type column_alias) - e.g. #result('ARTIST_ID' 'String' 'ID')
             #result(column_name java_type column_alias data_row_key) - e.g. #result('ARTIST_ID' 'String' 'ID' 'toArtist.ID')

  'data_row_key' is needed if SQL 'column_alias' is not appropriate as a DataRow key on the Cayenne side. One common case when this happens is when a DataRow retrieved from a query is mapped using joint prefetch keys. In this case DataRow must use DB_PATH expressions for joint column keys, and their format is incompatible with most databases alias format.

  Most common Java types used in JDBC can be specified without a package. This includes all numeric types, primitives, String, SQL dates, BigDecimal and BigInteger.

  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

    Constructors
    Constructor and Description
    `ResultDirective()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `bindResult(org.apache.velocity.context.InternalContextAdapter context, ColumnDescriptor columnDescriptor)` Adds value to the list of result columns in the context.
    `protected Object` | `getChild(org.apache.velocity.context.InternalContextAdapter context, org.apache.velocity.runtime.parser.node.Node node, int i)`
    `protected String` | `getChildAsString(org.apache.velocity.context.InternalContextAdapter context, org.apache.velocity.runtime.parser.node.Node node, int i)` Returns a directive argument at a given index converted to String.
    `String` | `getName()`
    `int` | `getType()`
    `protected String` | `guessType(String type)` Converts "short" type notation to the fully qualified class name.
    `boolean` | `render(org.apache.velocity.context.InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node)`

    - ### 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

    - #### ResultDirective

          public ResultDirective()

  - ### 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

      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`

    - #### 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`

    - #### getChildAsString

          protected String getChildAsString(org.apache.velocity.context.InternalContextAdapter context,
                                            org.apache.velocity.runtime.parser.node.Node node,
                                            int i)
                                     throws org.apache.velocity.exception.MethodInvocationException

      Returns a directive argument at a given index converted to String.
      Throws:
        `org.apache.velocity.exception.MethodInvocationException`
      Since:
        1.2

    - #### guessType

          protected String guessType(String type)

      Converts "short" type notation to the fully qualified class name. Right now supports all major standard SQL types, including primitives. All other types are expected to be fully qualified, and are not converted.

    - #### bindResult

          protected void bindResult(org.apache.velocity.context.InternalContextAdapter context,
                                    ColumnDescriptor columnDescriptor)

      Adds value to the list of result columns in the context.

Copyright © 2001–2018 Apache Cayenne. All rights reserved.