|
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 | ||||||||
java.lang.Object | +--com.solarmetric.kodo.impl.jdbc.runtime.ColumnAliasResultObjectProvider
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
rsor 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 |
|
| Field Detail |
protected PersistenceManagerImpl pm
| Constructor Detail |
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 |
public ResultList getResultList(ResultSet rs)
throws SQLException
ResultList (implementation of List)
that is populated by objects created from rs.
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.
protected int getIndex(ResultSet rs,
FieldMapping fm)
throws SQLException
Returns the index of the first column of fm in
rsor 0 if the column could not be
found.
This implementation delegates to
getIndex(ResultSet,Column,ClassMetaData)
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.
protected String getAlias(ResultSet rs,
Column col,
ClassMetaData meta)
col in
rs.
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.
public void initialize(StateManagerImpl sm,
Set fields,
JDOState state,
CustomResultObjectProvider.ROPInfo info)
CustomResultObjectProvidersm with the data in
info, transitioning its JDO state to
state.initialize in interface CustomResultObjectProvider
public void load(StateManagerImpl sm,
Set fields,
boolean setVersion,
CustomResultObjectProvider.ROPInfo info)
CustomResultObjectProviderfields into sm. Also load the
version information if setVersion is
true.load in interface CustomResultObjectProvider
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).
getObjectId in interface CustomResultObjectProviderpublic PersistenceManagerImpl getPersistenceManager()
CustomResultObjectProviderPersistenceManagerImpl that objects loaded
by this provider should be loaded into.getPersistenceManager in interface CustomResultObjectProvider
public CustomResultObjectProvider.ROPInfo getROPInfo(Object input,
Object oid,
ClassMetaData meta)
throws Exception
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).getROPInfo in interface CustomResultObjectProvider
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.
getType in interface CustomResultObjectProvider
public boolean open(Object o)
throws Exception
ResultSet.next().open in interface CustomResultObjectProvider
public boolean advance(Object o)
throws Exception
ResultSet.next().advance in interface CustomResultObjectProvider
public void free(Object o)
throws Exception
free in interface CustomResultObjectProvider
|
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 | ||||||||