Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.4.3 generated on March 27 2003
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

    java.lang.Object
      |
      +--com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProviderImpl
            |
            +--com.solarmetric.kodo.impl.jdbc.runtime.CustomResultSetResultObjectProvider

All Implemented Interfaces:
  CustomResultObjectProvider

public abstract class CustomResultSetResultObjectProvider
extends CustomResultObjectProviderImpl

Abstract extension of `CustomResultObjectProviderImpl` that populates a `StateManagerImpl` object given a `Map` of `FieldMetaData` objects to `Object` values, created by the abstract `CustomResultObjectProviderImpl.getFieldValues(java.lang.Object, com.solarmetric.kodo.meta.ClassMetaData, boolean)` method.

Extensions of this class can be used to load data via non-SQL means such as via stored procedures. For example:

    	import java.util.*;

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

    	...

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

    		Statement st = conn.createStatement ();
    		ResultSet rs = st.executeQuery
    			("SELECT ID, FIRSTNAME, LASTNAME FROM PERSON");

    		CustomResultSetResultObjectProvider rop =
    			new CustomResultSetResultObjectProvider (pm)
    		{
    			public Class getType (Object input)
    			{
    				return Person.class;
    			}

    			public Map getFieldValues (Object input, ClassMetaData meta,
    				boolean pkOnly)
    				throws SQLException
    			{
    				ResultSet rs = (ResultSet) input;
    				Map map = new HashMap ();
    				map.put (meta.getField ("firstName"), rs.getString (2));
    				map.put (meta.getField ("lastName"), rs.getString (3));
    				return map;
    			}

    			public long getDatastoreId (Object input, ClassMetaData meta)
    				throws SQLException
    			{
    				ResultSet rs = (ResultSet) input;
    				return rs.getLong (1);
    			}

    			public Object getOptimisticLockVersion (Object input,
    				ClassMetaData meta)
    				throws SQLException
    			{
    				return null;
    			}

    			public void free (Object input)
    				throws Exception
    			{
    				super.free (input);
    				store.releaseConnection (conn);
    			}
    		};

    		List l = rop.getResultList (rs);

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

Note that the objects remain valid after the connection used to obtain them is closed, so the connection must not be released until after the result list has been fully loaded. This can be done in the `free(java.lang.Object)` method. The default `free` implementation closes the result set and its owning statement, but does not close or release the owning connection.

`ResultList` objects do not necessarily load in data all at once. Instead, they lazily load rows from the result set as necessary, if the result set is `TYPE_SCROLL_INSENSITIVE`.

This class automatically closes the `ResultSet` and its `Statement` when the result set is fully processed. To change this behavior, override {@link#free}.

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

Fields inherited from class com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProviderImpl
`pm`

Constructor Summary
`CustomResultSetResultObjectProvider(PersistenceManagerImpl pm)` Create a new ResultSetResultObjectProvider for loading objects of into `pm`.

Method Summary
`boolean` | `advance(Object o)` Invokes `ResultSet.next()`.
`void` | `free(Object o)` Closes the result set and its owning statement.
`ResultList` | `getResultList(ResultSet rs)` Retrieve a `ResultList` (implementation of `List`) that is populated by objects created from `rs`.
`boolean` | `open(Object o)` Invokes `ResultSet.next()`.

Methods inherited from class com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProviderImpl
`getDatastoreId, getFieldValues, getObjectId, getOptimisticLockVersion, getPersistenceManager, getROPInfo, initialize, load`

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

Methods inherited from interface com.solarmetric.kodo.runtime.objectprovider.CustomResultObjectProvider
`getType, initialize, load`

Constructor Detail

### CustomResultSetResultObjectProvider

    public CustomResultSetResultObjectProvider(PersistenceManagerImpl pm)

  Create a new ResultSetResultObjectProvider for loading objects of into `pm`.

Method Detail

### getResultList

    public ResultList getResultList(ResultSet rs)
                             throws SQLException

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

### open

    public boolean open(Object o)
                 throws Exception

  Invokes `ResultSet.next()`.

### advance

    public boolean advance(Object o)
                    throws Exception

  Invokes `ResultSet.next()`.

### free

    public void free(Object o)
              throws Exception

  Closes the result set and its owning statement.

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.4.3 generated on March 27 2003
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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