Overview | Package | Class | Tree | Deprecated | Index | Help
| Oracle TopLink API Reference 10g Release 3 (10.1.3) B13698-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.toplink.queryframework
Class MethodBaseQueryRedirector

`java.lang.Object
oracle.toplink.queryframework.MethodBaseQueryRedirector`

All Implemented Interfaces:
  QueryRedirector, java.io.Serializable

public class MethodBaseQueryRedirector
extends java.lang.Object
implements QueryRedirector

Purpose: Allows a class to be a `QueryRedirector` without implementing `QueryRedirector`.

Description: Normally to define a Redirector a Class must implement `QueryRedirector` and the required `QueryRedirector.invokeQuery(DatabaseQuery, Record, Session)`.

To maintain transparency it is possible to instead only define a static method that takes the same arguments as `invokeQuery`.

An instance of `MethodBaseQueryRedirector` can be constructed, taking the name of that static method and the `Class` in which it is defined as parameters.

Whenever `invokeQuery` is called on this instance reflection will automatically be used to invoke the custom method instead.

Advantages:

- The Redirector class and method name can be specified dynamically.
- The class containing the `invokeQuery` method does not need to implement `QueryRedirector`.
- The `invokeQuery` method can have any name.
- The `invokeQuery` method can alternatively be defined to accept only `Session session` and `Vector arguments` as parameters.

Disadvantages:

- An extra step is added as the real `invokeQuery` method is called dynamically.

Example:

> // First create a named query, define a redirector for it, and add the query // to the query manager. ReadObjectQuery query = new ReadObjectQuery(Employee.class); query.setName("findEmployeeByAnEmployee"); query.addArgument("employee"); MethodBaseQueryRedirector redirector = new MethodBaseQueryRedirector(QueryRedirectorTest.class, "findEmployeeByAnEmployee"); query.setRedirector(redirector); Descriptor descriptor = getSession().getDescriptor(query.getReferenceClass()); descriptor.getQueryManager().addQuery(query.getName(), query); // Now execute the query by name, passing in an Employee as an argument. Vector arguments = new Vector(); arguments.addElement(employee); objectFromDatabase = getSession().executeQuery("findEmployeeByAnEmployee", Employee.class, arguments); // Note this Class does not implement QueryRedirector or method invokeQuery. public class QueryRedirectorTest { public static Object findEmployeeByAnEmployee(DatabaseQuery query, Record arguments, Session session) { ((ReadObjectQuery) query).setSelectionObject(arguments.get("employee")); return session.executeQuery(query); } }

> > Since:
> >   TOPLink/Java 3.0
> > See Also:
> >   `QueryRedirector`, Serialized Form

> > Constructor Summary
> > `MethodBaseQueryRedirector()` PUBLIC: Returns a new query redirector.
> > `MethodBaseQueryRedirector(java.lang.Class methodClass, java.lang.String methodName)` PUBLIC: Returns a new query redirector based on the static method in methodClass.

> > Method Summary
> > `java.lang.Class` | `getMethodClass()` PUBLIC: Returns the class to execute the static method on.
> > `java.lang.String` | `getMethodName()` PUBLIC: Returns the name of the static method.
> > `void` | `setMethodClass(java.lang.Class newMethodClass)` PUBLIC: Sets the class to execute the static method on.
> > `void` | `setMethodName(java.lang.String newMethodName)` PUBLIC: Sets the name of the static method.

> > Methods inherited from class java.lang.Object
> > `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

> > Constructor Detail

> > ### MethodBaseQueryRedirector

> >     public MethodBaseQueryRedirector()

> >   PUBLIC: Returns a new query redirector.

> > ### MethodBaseQueryRedirector

> >     public MethodBaseQueryRedirector(java.lang.Class methodClass,
> >                                      java.lang.String methodName)

> >   PUBLIC: Returns a new query redirector based on the static method in methodClass.

> > Method Detail

> > ### getMethodClass

> >     public java.lang.Class getMethodClass()

> >   PUBLIC: Returns the class to execute the static method on.

> > ### getMethodName

> >     public java.lang.String getMethodName()

> >   PUBLIC: Returns the name of the static method. This method must be public, static and have argument of DatabaseQuery, Vector, Session.
> >   See Also:
> >     `setMethodName(java.lang.String)`

> > ### setMethodClass

> >     public void setMethodClass(java.lang.Class newMethodClass)

> >   PUBLIC: Sets the class to execute the static method on.

> > ### setMethodName

> >     public void setMethodName(java.lang.String newMethodName)

> >   PUBLIC: Sets the name of the static method.

> >   This method must be public, static and have arguments of DatabaseQuery, Record, and Session.

> >   The DatabaseQuery argument is the query that is currently being executed.

> >   The Record will contain the Argument names added to the Query through addArgument(Sting) or, in the case of an Object query, the object attribute field names. These names will reference the argument values passed into the query, or in the case of an Object Query the values from the object.

> >   The session argument is the session that the query is currently being executed on.

> >   Alternatively the method can take only `(Session session, Vector arguments)` as parameters.

> > Overview | Package | Class | Tree | Deprecated | Index | Help
> > | Copyright © 1998, 2006, Oracle. All Rights Reserved.
> > PREV CLASS NEXT CLASS | FRAMES NO FRAMES
> > SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD