Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.5.8 generated on January 11 2004
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.solarmetric.kodo.impl.jdbc.runtime
Class ColumnAliasResultObjectProvider

    java.lang.Object
      |
      +--com.solarmetric.kodo.impl.jdbc.runtime.ColumnAliasResultObjectProvider

All Implemented Interfaces:
  CustomResultObjectProvider

public class ColumnAliasResultObjectProvider
extends Object
implements CustomResultObjectProvider

Concrete implementation of `CustomResultObjectProvider` that loads data from a result set by using column aliases as defined by the mapping configuration of the metadata of the class being loaded.

This is useful for loading `ResultSet` objects whose column alias information matches up exactly with the column names that Kodo JDO expects. For example, if you need to execute a SELECT statement with a WHERE clause not attainable with JDO or our custom query extensions, you could obtain a `ResultList` containing the contents of the `ResultSet` like so:

    	import java.util.*;

    	import com.solarmetric.kodo.runtime.*;
    	import com.solarmetric.kodo.impl.jdbc.runtime.*;

    	...

    		PersistenceManagerImpl pm = (PersistenceManagerImpl) pman;
    		JDBCStoreManager store = (JDBCStoreManager) pm.getStoreManager ();
    		Connection conn = store.getConnection ();

    		Statement st = conn.createStatement ();
    		ResultSet rs = st.executeQuery ("SELECT * FROM PERSON");

    		ColumnAliasResultObjectProvider rop =
    			new ColumnAliasResultObjectProvider (Person.class, pm);

    		List l = rop.getResultList (rs);

    		for (Iterator iter = l.iterator (); iter.hasNext (); )
    		{
    			System.out.println ("person: " + iter.next ());
    		}

    		store.releaseConnection (conn);

This class automatically closes the `ResultSet` and its `Statement` when the result set is fully processed. To change this behavior, override `free(java.lang.Object)`.

Inner classes inherited from class com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider
`CustomResultObjectProvider.ResultObjectProviderAdapter, CustomResultObjectProvider.ROPInfo`

Field Summary
`protected PersistenceManagerImpl` | `pm`

Constructor Summary
`ColumnAliasResultObjectProvider(Class cls, PersistenceManagerImpl pm)` Creates a new `ColumnAliasResultObjectProvider` capable of loading classes and subclasses of type `cls` into `pm`.

Method Summary
`boolean` | `advance(Object o)` Invokes `ResultSet.next()`.
`void` | `free(Object o)` Closes the result set and its owning statement.
`protected String` | `getAlias(ResultSet rs, Column col, ClassMetaData meta)` Returns the alias to use when looking up `col` in `rs`.
`protected int` | `getIndex(ResultSet rs, Column col, ClassMetaData meta)` Returns the index of `col` in `rs`, or `0` if the column could not be found.
`protected int` | `getIndex(ResultSet rs, FieldMapping fm)` Returns the index of the first column of `fm` in `rs`or `0` if the column could not be found.
`Object` | `getObjectId(Object input, ClassMetaData meta)` Finds the index of the first column in the set of PK cols for `meta`, and delegates loading the PK values to the corresponding `ClassMapping`.
`protected Object` | `getOptimisticLockVersion(StateManagerImpl sm, CustomResultObjectProvider.ROPInfo info)` Return the optimistic lock version object for the data in the current data of `input`.
`PersistenceManagerImpl` | `getPersistenceManager()` Return the `PersistenceManagerImpl` that objects loaded by this provider should be loaded into.
`ResultList` | `getResultList(ResultSet rs)` Retrieve a `ResultList` (implementation of `List`) that is populated by objects created from `rs`.
`CustomResultObjectProvider.ROPInfo` | `getROPInfo(Object input, Object oid, ClassMetaData meta)` Implementations that override this method should also override `initialize(com.solarmetric.kodo.runtime.StateManagerImpl, java.util.Set, com.solarmetric.kodo.runtime.JDOState, com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider.ROPInfo)` and `load(com.solarmetric.kodo.runtime.StateManagerImpl, java.util.Set, boolean, com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider.ROPInfo)`.
`Class` | `getType(Object input)` Finds the index of the first column in the set of subclass indicator columns for `meta`, and delegates loading the type to the corresponding `SubclassProvider`.
`void` | `initialize(StateManagerImpl sm, Set fields, JDOState state, CustomResultObjectProvider.ROPInfo info)` Initializes `sm` with the data in `info`, transitioning its JDO state to `state`.
`void` | `load(StateManagerImpl sm, Set fields, boolean setVersion, CustomResultObjectProvider.ROPInfo info)` Loads `fields` into `sm`.
`protected void` | `loadFieldValues(ResultSet rs, StateManagerImpl sm)` Load the current row in `rs` into `sm` by looking in `rs` for columns with aliases corresponding to the mapping information for the fields in `meta`.
`boolean` | `open(Object o)` Invokes `ResultSet.next()`.

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

Field Detail

### pm

    protected PersistenceManagerImpl pm

Constructor Detail

### ColumnAliasResultObjectProvider

    public ColumnAliasResultObjectProvider(Class cls,
                                           PersistenceManagerImpl pm)

  Creates a new `ColumnAliasResultObjectProvider` capable of loading classes and subclasses of type `cls` into `pm`.

  Unlike `DefaultResultObjectProvider`, instances of this class can only be used to load a particular class and its subclasses. This is because this implementation must be able to determine which column stores the concrete subclass in a given `ResultSet`, which is defined on a per-class-hierarchy basis.

Method Detail

### getResultList

    public ResultList getResultList(ResultSet rs)
                             throws SQLException

  Retrieve a `ResultList` (implementation of `List`) that is populated by objects created from `rs`.

### loadFieldValues

    protected void loadFieldValues(ResultSet rs,
                                   StateManagerImpl sm)

  Load the current row in `rs` into `sm` by looking in `rs` for columns with aliases corresponding to the mapping information for the fields in `meta`.

  This implementation only loads `LoadPrimary` field mappings. It finds the column index of the 0th element in the column array returned from `FieldMapping.getDataColumns()`, and uses this index in a call to `LoadPrimary.load(com.solarmetric.kodo.runtime.StateManagerImpl, int, java.sql.ResultSet, int)`. So, if using a custom multi-column `LoadPrimary` implementation, you should ensure that the columns are returned in the appropriate order.

### getIndex

    protected int getIndex(ResultSet rs,
                           FieldMapping fm)
                    throws SQLException

  Returns the index of the first column of `fm` in `rs`or `0` if the column could not be found.

  This implementation delegates to `getIndex(ResultSet,Column,ClassMetaData)`

### getIndex

    protected int getIndex(ResultSet rs,
                           Column col,
                           ClassMetaData meta)

  Returns the index of `col` in `rs`, or `0` if the column could not be found.

  This implementation looks up the column index using `ResultSet.findColumn(java.lang.String)` with the column's full name (e.g., `TABLENAME.FIELDNAME`) as the argument.

### getAlias

    protected String getAlias(ResultSet rs,
                              Column col,
                              ClassMetaData meta)

  Returns the alias to use when looking up `col` in `rs`.

### getOptimisticLockVersion

    protected Object getOptimisticLockVersion(StateManagerImpl sm,
                                              CustomResultObjectProvider.ROPInfo info)
                                       throws SQLException

  Return the optimistic lock version object for the data in the current data of `input`. This can return `null` if no version information is available.

### initialize

    public void initialize(StateManagerImpl sm,
                           Set fields,
                           JDOState state,
                           CustomResultObjectProvider.ROPInfo info)

  Description copied from interface: `CustomResultObjectProvider`
  Initializes `sm` with the data in `info`, transitioning its JDO state to `state`.
  Specified by:
    `initialize` in interface `CustomResultObjectProvider`

### load

    public void load(StateManagerImpl sm,
                     Set fields,
                     boolean setVersion,
                     CustomResultObjectProvider.ROPInfo info)

  Description copied from interface: `CustomResultObjectProvider`
  Loads `fields` into `sm`. Also load the version information if `setVersion` is `true`.
  Specified by:
    `load` in interface `CustomResultObjectProvider`

### getObjectId

    public Object getObjectId(Object input,
                              ClassMetaData meta)
                       throws Exception

  Finds the index of the first column in the set of PK cols for `meta`, and delegates loading the PK values to the corresponding `ClassMapping`. For custom pk value loading, either override this method or `ClassMapping.getObjectId(com.solarmetric.kodo.runtime.PersistenceManagerImpl, java.sql.ResultSet, int)`.

  Specified by:
    `getObjectId` in interface `CustomResultObjectProvider`

### getPersistenceManager

    public PersistenceManagerImpl getPersistenceManager()

  Description copied from interface: `CustomResultObjectProvider`
  Return the `PersistenceManagerImpl` that objects loaded by this provider should be loaded into.
  Specified by:
    `getPersistenceManager` in interface `CustomResultObjectProvider`

### getROPInfo

    public CustomResultObjectProvider.ROPInfo getROPInfo(Object input,
                                                         Object oid,
                                                         ClassMetaData meta)
                                                  throws Exception

  Implementations that override this method should also override `initialize(com.solarmetric.kodo.runtime.StateManagerImpl, java.util.Set, com.solarmetric.kodo.runtime.JDOState, com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider.ROPInfo)` and `load(com.solarmetric.kodo.runtime.StateManagerImpl, java.util.Set, boolean, com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider.ROPInfo)`.
  Specified by:
    `getROPInfo` in interface `CustomResultObjectProvider`

### getType

    public Class getType(Object input)
                  throws Exception

  Finds the index of the first column in the set of subclass indicator columns for `meta`, and delegates loading the type to the corresponding `SubclassProvider`.

  Specified by:
    `getType` in interface `CustomResultObjectProvider`

### open

    public boolean open(Object o)
                 throws Exception

  Invokes `ResultSet.next()`.
  Specified by:
    `open` in interface `CustomResultObjectProvider`

### advance

    public boolean advance(Object o)
                    throws Exception

  Invokes `ResultSet.next()`.
  Specified by:
    `advance` in interface `CustomResultObjectProvider`

### free

    public void free(Object o)
              throws Exception

  Closes the result set and its owning statement.
  Specified by:
    `free` in interface `CustomResultObjectProvider`

Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.5.8 generated on January 11 2004
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.