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}.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CustomResultSetResultObjectProvider
public CustomResultSetResultObjectProvider(PersistenceManagerImpl pm)
- Create a new ResultSetResultObjectProvider for loading objects of
into
pm.
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.
Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.