Class RelationFieldStrategy
- java.lang.Object
-
- org.apache.openjpa.jdbc.meta.strats.AbstractStrategy
-
- org.apache.openjpa.jdbc.meta.strats.AbstractFieldStrategy
-
- org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy
-
- All Implemented Interfaces:
java.io.Serializable,Embeddable,FieldStrategy,Joinable,Strategy
public class RelationFieldStrategy extends AbstractFieldStrategy implements Joinable, Embeddable
Mapping for a single-valued relation to another entity.- Since:
- 0.4.0
- Author:
- Abe White
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractFieldStrategy
field
-
Fields inherited from interface org.apache.openjpa.jdbc.meta.Embeddable
UNSUPPORTED
-
-
Constructor Summary
Constructors Constructor Description RelationFieldStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendIsNotNull(SQLBuffer sql, Select sel, Joins joins)Append a where clause to the given statement checking if this value is not null.voidappendIsNull(SQLBuffer sql, Select sel, Joins joins)Append a where clause to the given statement checking if this value is null.voiddelete(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set the where values appropriately to delete the proper instance, and set all relations on non-secondary tables as updates.ColumnIOgetColumnIO()Return column I/O information for this mapping.Column[]getColumns()The columns managed by this joinable.intgetFieldIndex()Return the field index of this joinable, or -1 if not a field.java.lang.ObjectgetJoinValue(java.lang.Object fieldVal, Column col, JDBCStore store)Return the join value of the given column.java.lang.ObjectgetJoinValue(OpenJPAStateManager sm, Column col, JDBCStore store)Return the join value of the given column.java.lang.ObjectgetPrimaryKeyValue(Result res, Column[] cols, ForeignKey fk, JDBCStore store, Joins joins)Return the value for this joinable from the given result, using the given columns.java.lang.Object[]getResultArguments()Return the arguments needed to extract datastore values viaResult.getObject(java.lang.Object, int, java.lang.Object)for each column.voidinitialize()Perform caching and other initialization operations.voidinsert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set values for the mapping into the proper rows.Joinsjoin(Joins joins, boolean forceOuter)Join this value to the class table.JoinsjoinRelation(Joins joins, boolean forceOuter, boolean traverse)Join this value's table to the table for the related first class object type, if any.voidload(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch)Load secondary data using a connection from the store manager.voidload(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res)Load virtual row data; the given result is not guaranteed to contain data for this field, so the field mapping should make sure the result contains its needed column data before loading.voidloadEagerJoin(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res)Load the joined eager result.java.lang.ObjectloadEagerParallel(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, java.lang.Object res)Load the batched eager result.voidloadEmbedded(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, java.lang.Object val)Load this strategy's field by transforming the given datastore value.voidmap(boolean adapt)Map the owning mapping using this strategy.intselect(Select sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)Select the virtual row columns of this mapping.voidselectEagerJoin(Select sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)Fill in joined select to related objects.voidselectEagerParallel(SelectExecutor sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)Fill in parallel eager select for related objects.voidsetAutoAssignedValue(OpenJPAStateManager sm, JDBCStore store, Column col, java.lang.Object autoInc)Use the given auto-assigned value to set this join value's field on the given instance.intsupportsSelect(Select sel, int type, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch)Return whether this mapping can perform the given select type.java.lang.ObjecttoDataStoreValue(java.lang.Object val, JDBCStore store)Translate the given external field value to its datastore equivalent.java.lang.ObjecttoEmbeddedDataStoreValue(java.lang.Object val, JDBCStore store)Convert the given Java value to its datastore equivalent.java.lang.ObjecttoEmbeddedObjectValue(java.lang.Object val)Convert the given datastore value to its Java equivalent.voidupdate(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set values for the mapping into the proper rows.-
Methods inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractFieldStrategy
appendIndex, appendIsEmpty, appendIsNotEmpty, appendSize, appendType, assertNotMappedBy, isEagerSelectToMany, isVersionable, joinKey, joinKeyRelation, loadKeyProjection, loadProjection, setFieldMapping, toKeyDataStoreValue, where
-
Methods inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractStrategy
customDelete, customInsert, customUpdate, getAlias, isCustomDelete, isCustomInsert, isCustomUpdate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.openjpa.jdbc.meta.Strategy
customDelete, customInsert, customUpdate, getAlias, isCustomDelete, isCustomInsert, isCustomUpdate
-
-
-
-
Method Detail
-
map
public void map(boolean adapt)
Description copied from interface:StrategyMap the owning mapping using this strategy.- Specified by:
mapin interfaceStrategy- Overrides:
mapin classAbstractStrategy- Parameters:
adapt- if true, use the owning mapping's raw mapping info to set its ORM data; if false, ORM data will already be set
-
initialize
public void initialize()
Description copied from interface:StrategyPerform caching and other initialization operations. This method is called afterStrategy.map(boolean), and after all related components have been mapped as well.- Specified by:
initializein interfaceStrategy- Overrides:
initializein classAbstractStrategy
-
insert
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws java.sql.SQLException
Description copied from interface:StrategySet values for the mapping into the proper rows. For class mappings, this method will be called only after the corresponding method has been called for all fields of this mapping.- Specified by:
insertin interfaceStrategy- Overrides:
insertin classAbstractStrategy- Throws:
java.sql.SQLException
-
update
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws java.sql.SQLException
Description copied from interface:StrategySet values for the mapping into the proper rows.- Specified by:
updatein interfaceStrategy- Overrides:
updatein classAbstractStrategy- Throws:
java.sql.SQLException- See Also:
Strategy.insert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.sql.RowManager)
-
delete
public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws java.sql.SQLException
Description copied from interface:StrategySet the where values appropriately to delete the proper instance, and set all relations on non-secondary tables as updates. This allows foreign key analysis.- Specified by:
deletein interfaceStrategy- Overrides:
deletein classAbstractStrategy- Throws:
java.sql.SQLException- See Also:
Strategy.insert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.sql.RowManager)
-
supportsSelect
public int supportsSelect(Select sel, int type, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch)
Description copied from interface:FieldStrategyReturn whether this mapping can perform the given select type. Return 0 if the given type is not supported. If the given type is an eager parallel type, return the number of UNIONed selects necessary to fetch the data. Otherwise, return any positive number if the type is supported. The given state manager may be null if selecting multiple instances.- Specified by:
supportsSelectin interfaceFieldStrategy- Overrides:
supportsSelectin classAbstractFieldStrategy- See Also:
Select
-
selectEagerParallel
public void selectEagerParallel(SelectExecutor sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)
Description copied from interface:FieldStrategyFill in parallel eager select for related objects.- Specified by:
selectEagerParallelin interfaceFieldStrategy- Overrides:
selectEagerParallelin classAbstractFieldStrategy- See Also:
FieldStrategy.select(org.apache.openjpa.jdbc.sql.Select, org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration, int)
-
selectEagerJoin
public void selectEagerJoin(Select sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)
Description copied from interface:FieldStrategyFill in joined select to related objects.- Specified by:
selectEagerJoinin interfaceFieldStrategy- Overrides:
selectEagerJoinin classAbstractFieldStrategy- See Also:
FieldStrategy.select(org.apache.openjpa.jdbc.sql.Select, org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration, int)
-
select
public int select(Select sel, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode)
Description copied from interface:FieldStrategySelect the virtual row columns of this mapping.- Specified by:
selectin interfaceFieldStrategy- Overrides:
selectin classAbstractFieldStrategy- Parameters:
sel- the select to add tosm- the instance being loaded, or null if not initialized yet or selecting for multiple instancesstore- the current store managerfetch- fetch configurationeagerMode- the eager fetch mode to use; this may be more restrictive than the mode of the fetch configuration- Returns:
- > 0 if this mapping requires the selected data (if any), 0 if it selected data but does not require it, or < 0 if no data was selected
-
loadEagerParallel
public java.lang.Object loadEagerParallel(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, java.lang.Object res) throws java.sql.SQLException
Description copied from interface:FieldStrategyLoad the batched eager result.- Specified by:
loadEagerParallelin interfaceFieldStrategy- Overrides:
loadEagerParallelin classAbstractFieldStrategyres- originally theResultto load from, but this method may return a processed result form that will be passed to subsequent calls- Throws:
java.sql.SQLException
-
loadEagerJoin
public void loadEagerJoin(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res) throws java.sql.SQLException
Description copied from interface:FieldStrategyLoad the joined eager result.- Specified by:
loadEagerJoinin interfaceFieldStrategy- Overrides:
loadEagerJoinin classAbstractFieldStrategy- Throws:
java.sql.SQLException
-
load
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res) throws java.sql.SQLException
Description copied from interface:FieldStrategyLoad virtual row data; the given result is not guaranteed to contain data for this field, so the field mapping should make sure the result contains its needed column data before loading.- Specified by:
loadin interfaceFieldStrategy- Overrides:
loadin classAbstractFieldStrategy- Throws:
java.sql.SQLException
-
load
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws java.sql.SQLException
Description copied from interface:FieldStrategyLoad secondary data using a connection from the store manager.- Specified by:
loadin interfaceFieldStrategy- Overrides:
loadin classAbstractFieldStrategy- Throws:
java.sql.SQLException
-
toDataStoreValue
public java.lang.Object toDataStoreValue(java.lang.Object val, JDBCStore store)Description copied from interface:FieldStrategyTranslate the given external field value to its datastore equivalent. If the mapping occupies multiple columns in the datastore, return an object array, else return a single object. Simply returns the given object by default.- Specified by:
toDataStoreValuein interfaceFieldStrategy- Overrides:
toDataStoreValuein classAbstractFieldStrategy
-
appendIsNull
public void appendIsNull(SQLBuffer sql, Select sel, Joins joins)
Description copied from interface:FieldStrategyAppend a where clause to the given statement checking if this value is null.- Specified by:
appendIsNullin interfaceFieldStrategy- Overrides:
appendIsNullin classAbstractFieldStrategy
-
appendIsNotNull
public void appendIsNotNull(SQLBuffer sql, Select sel, Joins joins)
Description copied from interface:FieldStrategyAppend a where clause to the given statement checking if this value is not null.- Specified by:
appendIsNotNullin interfaceFieldStrategy- Overrides:
appendIsNotNullin classAbstractFieldStrategy
-
join
public Joins join(Joins joins, boolean forceOuter)
Description copied from interface:FieldStrategyJoin this value to the class table. Does nothing by default.- Specified by:
joinin interfaceFieldStrategy- Overrides:
joinin classAbstractFieldStrategy
-
joinRelation
public Joins joinRelation(Joins joins, boolean forceOuter, boolean traverse)
Description copied from interface:FieldStrategyJoin this value's table to the table for the related first class object type, if any. Does nothing by default.- Specified by:
joinRelationin interfaceFieldStrategy- Overrides:
joinRelationin classAbstractFieldStrategytraverse- if true, throw proper exception if it is not possible for this mapping to traverse into the related type
-
getFieldIndex
public int getFieldIndex()
Description copied from interface:JoinableReturn the field index of this joinable, or -1 if not a field.- Specified by:
getFieldIndexin interfaceJoinable
-
getPrimaryKeyValue
public java.lang.Object getPrimaryKeyValue(Result res, Column[] cols, ForeignKey fk, JDBCStore store, Joins joins) throws java.sql.SQLException
Description copied from interface:JoinableReturn the value for this joinable from the given result, using the given columns. If the given foreign key is non-null, use the foreign key's columns by translating the given columns throughForeignKey.getColumn(org.apache.openjpa.jdbc.schema.Column).- Specified by:
getPrimaryKeyValuein interfaceJoinable- Throws:
java.sql.SQLException
-
getJoinValue
public java.lang.Object getJoinValue(java.lang.Object fieldVal, Column col, JDBCStore store)Description copied from interface:JoinableReturn the join value of the given column.- Specified by:
getJoinValuein interfaceJoinable- Parameters:
fieldVal- the value of the field for this joinablecol- the column of this joinable whose value to return
-
getJoinValue
public java.lang.Object getJoinValue(OpenJPAStateManager sm, Column col, JDBCStore store)
Description copied from interface:JoinableReturn the join value of the given column.- Specified by:
getJoinValuein interfaceJoinable- Parameters:
sm- the instance from which to get the valuecol- the column whose value to return
-
setAutoAssignedValue
public void setAutoAssignedValue(OpenJPAStateManager sm, JDBCStore store, Column col, java.lang.Object autoInc)
Description copied from interface:JoinableUse the given auto-assigned value to set this join value's field on the given instance.- Specified by:
setAutoAssignedValuein interfaceJoinable
-
getColumns
public Column[] getColumns()
Description copied from interface:JoinableThe columns managed by this joinable.- Specified by:
getColumnsin interfaceEmbeddable- Specified by:
getColumnsin interfaceJoinable
-
getColumnIO
public ColumnIO getColumnIO()
Description copied from interface:EmbeddableReturn column I/O information for this mapping.- Specified by:
getColumnIOin interfaceEmbeddable
-
getResultArguments
public java.lang.Object[] getResultArguments()
Description copied from interface:EmbeddableReturn the arguments needed to extract datastore values viaResult.getObject(java.lang.Object, int, java.lang.Object)for each column.- Specified by:
getResultArgumentsin interfaceEmbeddable
-
toEmbeddedDataStoreValue
public java.lang.Object toEmbeddedDataStoreValue(java.lang.Object val, JDBCStore store)Description copied from interface:EmbeddableConvert the given Java value to its datastore equivalent. If this mapping occupies multiple columns, return an object array with one element per column. For relation id columns, return the state manager the column depends on.- Specified by:
toEmbeddedDataStoreValuein interfaceEmbeddable
-
toEmbeddedObjectValue
public java.lang.Object toEmbeddedObjectValue(java.lang.Object val)
Description copied from interface:EmbeddableConvert the given datastore value to its Java equivalent. IfEmbeddable.getColumns()returns multiple columns, the given datastore value will be an object array of the corresponding length. This method must only be supported by mappings of embedded id objects. In other casesEmbeddable.loadEmbedded(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration, java.lang.Object)will be used instead. ReturnEmbeddable.UNSUPPORTEDif this mapping cannot support this method.- Specified by:
toEmbeddedObjectValuein interfaceEmbeddable
-
loadEmbedded
public void loadEmbedded(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, java.lang.Object val) throws java.sql.SQLException
Description copied from interface:EmbeddableLoad this strategy's field by transforming the given datastore value. IfEmbeddable.getColumns()returns multiple columns, the given datastore value will be an object array of the corresponding length. The value does not have to be loaded immediately; it may be stored as impl data.- Specified by:
loadEmbeddedin interfaceEmbeddable- Throws:
java.sql.SQLException
-
-