org.jboss.ejb.plugins.cmp.jdbc.bridge
Class JDBCCMRFieldBridge

java.lang.Object
  extended byorg.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge (src) 
      extended byorg.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge
All Implemented Interfaces:
CMRFieldBridge (src) , FieldBridge (src) , JDBCFieldBridge (src)

public final class JDBCCMRFieldBridge
extends JDBCAbstractCMRFieldBridge (src)

JDBCCMRFieldBridge a bean relationship. This class only supports relationships between entities managed by a JDBCStoreManager in the same application.

Life-cycle: Tied to the EntityBridge.

Multiplicity: One for each role that entity has.


Nested Class Summary
static class JDBCCMRFieldBridge.M2MRelationManager (src)
           
static interface JDBCCMRFieldBridge.RelationDataManager (src)
           
 
Constructor Summary
JDBCCMRFieldBridge(JDBCEntityBridge (src)  entity, JDBCStoreManager (src)  manager, JDBCRelationshipRoleMetaData (src)  metadata)
          Creates a cmr field for the entity based on the metadata.
 
Method Summary
 void addRelatedPKsWaitedForMe(EntityEnterpriseContext (src)  ctx)
          Establishes relationships with related entities waited for passed in context to be created.
 void addRelatedPKWaitingForMyPK(java.lang.Object myPK, java.lang.Object relatedPK)
           
 void addRelation(EntityEnterpriseContext (src)  myCtx, java.lang.Object fk)
          Adds the foreign key to the set of related ids, and updates any foreign key fields.
 boolean allFkFieldsMappedToPkFields()
          Returns true if all FK fields are mapped to PK fields
 void cascadeDelete(EntityEnterpriseContext (src)  ctx, java.util.List oldValues)
           
 void createRelationLinks(EntityEnterpriseContext (src)  myCtx, java.lang.Object relatedId)
          Creates the relation links between the instance associated with the context and the related instance (just the id is passed in).
 void createRelationLinks(EntityEnterpriseContext (src)  myCtx, java.lang.Object relatedId, boolean updateForeignKey)
           
 void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx, java.lang.Object relatedId)
          Destroys the relation links between the instance associated with the context and the related instance (just the id is passed in).
 void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx, java.lang.Object relatedId, boolean updateValueCollection)
          Destroys the relation links between the instance associated with the context and the related instance (just the id is passed in).
 void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx, java.lang.Object relatedId, boolean updateValueCollection, boolean updateForeignKey)
           
 DataSource (src) getDataSource()
          Gets the datasource of the relation table if relevent.
 JDBCAbstractEntityBridge (src) getEntity()
          Gets bridge for this entity.
 java.lang.String getFieldName()
          Gets the name of this field.
 JDBCFieldBridge (src) [] getForeignKeyFields()
          Gets the foreign key fields of this entity (i.e., related entities pk fields)
 java.lang.Object getInstanceValue(EntityEnterpriseContext (src)  myCtx)
          Gets the value of the cmr field for the instance associated with the context.
 JDBCStoreManager (src) getJDBCStoreManager()
          Gets the manager of this entity.
 JDBCType (src) getJDBCType()
          Gets the JDBC type of this field.
 JDBCEntityPersistenceStore (src) getManager()
           
 JDBCRelationshipRoleMetaData (src) getMetaData()
          Gets the metadata of the relationship role that this field represents.
 java.lang.String getQualifiedTableName()
          Gets the name of the relation table if relevent.
 JDBCReadAheadMetaData (src) getReadAhead()
          Gets the read ahead meta data.
 JDBCAbstractCMRFieldBridge (src) getRelatedCMRField()
          The related entity's cmr field for this relationship.
 EntityBridge (src) getRelatedEntity()
          The related entity.
 EJBLocalObject (src) getRelatedEntityByFK(java.lang.Object fk)
          Returns related entity's local interface.
 java.lang.Object getRelatedId(EntityEnterpriseContext (src)  myCtx)
          Get the related entity's id.
 java.lang.Object getRelatedIdFromContext(EntityEnterpriseContext (src)  ctx)
          Creates a new instance of related id based on foreign key value in the context.
 LocalProxyFactory (src) getRelatedInvoker()
          The related entity's local container invoker.
 JDBCEntityBridge (src) getRelatedJDBCEntity()
          The related entity.
 java.lang.Class getRelatedLocalInterface()
          The related entity's local home interface.
 JDBCStoreManager (src) getRelatedManager()
          The related manger.
 JDBCCMRFieldBridge.RelationDataManager (src) getRelationDataManager()
           
 JDBCRelationMetaData (src) getRelationMetaData()
          Gets the relation metadata.
 JDBCFieldBridge (src) [] getTableKeyFields()
          Gets the key fields that this entity maintains in the relation table.
 java.lang.String getTableName()
           
 java.lang.Object getValue(EntityEnterpriseContext (src)  ctx)
          Gets the value of this field for the specified instance context.
 boolean hasFKFieldsMappedToCMPFields()
           
 boolean hasForeignKey()
          Does this cmr field have foreign keys.
 void initInstance(EntityEnterpriseContext (src)  ctx)
          Initialized the foreign key fields.
 boolean invalidateCache(EntityEnterpriseContext (src)  ctx)
           
 boolean isBatchCascadeDelete()
           
 boolean isCMPField()
           
 boolean isCollectionValued()
          Is this a collection valued field.
 boolean isDirty(EntityEnterpriseContext (src)  ctx)
          This method is never called.
 boolean isForeignKeyValid(java.lang.Object fk)
          This method is called only for CMR fields with foreign key fields mapped to CMP fields to check the validity of the foreign key value.
 boolean isLoaded(EntityEnterpriseContext (src)  ctx)
          Has the data been loaded?
 boolean isPrimaryKeyMember()
          Is this field a member of the primary key.
 boolean isReadOnly()
          Is this field readonly?
 boolean isReadTimedOut(EntityEnterpriseContext (src)  ctx)
          Had the read time expired?
 boolean isSingleValued()
          Is this a single valued field.
 void load(EntityEnterpriseContext (src)  myCtx, java.util.Collection values)
           
 int loadArgumentResults(java.sql.ResultSet rs, int parameterIndex, java.lang.Object[] fkRef)
          Loads the value of this cmp field from result set into argument referance.
 int loadInstanceResults(java.sql.ResultSet rs, int parameterIndex, EntityEnterpriseContext (src)  ctx)
          Loads the data from result set into the instance associated with the specified context.
 boolean removeFromRelations(EntityEnterpriseContext (src)  ctx, java.lang.Object[] oldRelationsRef)
           
 void removeRelatedPKWaitingForMyPK(java.lang.Object myPK, java.lang.Object relatedPK)
           
 void removeRelation(EntityEnterpriseContext (src)  myCtx, java.lang.Object fk)
          Removes the foreign key to the set of related ids, and updates any foreign key fields.
 void resetPersistenceContext(EntityEnterpriseContext (src)  ctx)
          resets the persistence context of the foreign key fields
 void resolveRelationship()
           
 void scheduleChildrenForBatchCascadeDelete(EntityEnterpriseContext (src)  ctx)
          Schedules children for batch cascade delete.
 void scheduleChildrenForCascadeDelete(EntityEnterpriseContext (src)  ctx)
          Schedules children for cascade delete.
 void setClean(EntityEnterpriseContext (src)  ctx)
          This method is never called.
 void setForeignKey(EntityEnterpriseContext (src)  myCtx, java.lang.Object fk)
          Sets the foreign key field value.
 int setInstanceParameters(java.sql.PreparedStatement ps, int parameterIndex, EntityEnterpriseContext (src)  ctx)
          Sets the prepared statement parameters with the data from the instance associated with the context.
 void setInstanceValue(EntityEnterpriseContext (src)  myCtx, java.lang.Object newValue)
          Sets the value of the cmr field for the instance associated with the context.
 void setValue(EntityEnterpriseContext (src)  ctx, java.lang.Object value)
          Sets new value.
 void start()
          The third phase of deployment.
 java.lang.String toString()
           
 
Methods inherited from class org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge (src)
getPrimaryKeyValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDBCCMRFieldBridge

public JDBCCMRFieldBridge(JDBCEntityBridge (src)  entity,
                          JDBCStoreManager (src)  manager,
                          JDBCRelationshipRoleMetaData (src)  metadata)
                   throws DeploymentException (src) 
Creates a cmr field for the entity based on the metadata.

Method Detail

getRelationDataManager

public JDBCCMRFieldBridge.RelationDataManager (src)  getRelationDataManager()

resolveRelationship

public void resolveRelationship()
                         throws DeploymentException (src) 
Throws:
DeploymentException (src)

start

public void start()
           throws DeploymentException (src) 
The third phase of deployment. The method is called when relationships are already resolved.

Throws:
DeploymentException (src)

removeFromRelations

public boolean removeFromRelations(EntityEnterpriseContext (src)  ctx,
                                   java.lang.Object[] oldRelationsRef)

cascadeDelete

public void cascadeDelete(EntityEnterpriseContext (src)  ctx,
                          java.util.List oldValues)
                   throws RemoveException (src) ,
                          java.rmi.RemoteException
Throws:
RemoveException (src)
java.rmi.RemoteException

isBatchCascadeDelete

public boolean isBatchCascadeDelete()

getJDBCStoreManager

public JDBCStoreManager (src)  getJDBCStoreManager()
Gets the manager of this entity.


getEntity

public JDBCAbstractEntityBridge (src)  getEntity()
Gets bridge for this entity.

Specified by:
getEntity in class JDBCAbstractCMRFieldBridge (src)

getMetaData

public JDBCRelationshipRoleMetaData (src)  getMetaData()
Gets the metadata of the relationship role that this field represents.

Specified by:
getMetaData in class JDBCAbstractCMRFieldBridge (src)

getRelationMetaData

public JDBCRelationMetaData (src)  getRelationMetaData()
Gets the relation metadata.


getFieldName

public java.lang.String getFieldName()
Gets the name of this field.

Returns:
the name of this field

getQualifiedTableName

public java.lang.String getQualifiedTableName()
Gets the name of the relation table if relevent.

Specified by:
getQualifiedTableName in class JDBCAbstractCMRFieldBridge (src)

getTableName

public java.lang.String getTableName()
Specified by:
getTableName in class JDBCAbstractCMRFieldBridge (src)

getDataSource

public DataSource (src)  getDataSource()
Gets the datasource of the relation table if relevent.


getReadAhead

public JDBCReadAheadMetaData (src)  getReadAhead()
Gets the read ahead meta data.


getJDBCType

public JDBCType (src)  getJDBCType()
Description copied from interface: JDBCFieldBridge (src)
Gets the JDBC type of this field.


isPrimaryKeyMember

public boolean isPrimaryKeyMember()
Description copied from interface: JDBCFieldBridge (src)
Is this field a member of the primary key.

Returns:
true if this field is a member of the primary key

hasForeignKey

public boolean hasForeignKey()
Does this cmr field have foreign keys.

Specified by:
hasForeignKey in class JDBCAbstractCMRFieldBridge (src)

allFkFieldsMappedToPkFields

public boolean allFkFieldsMappedToPkFields()
Returns true if all FK fields are mapped to PK fields


isCollectionValued

public boolean isCollectionValued()
Is this a collection valued field.


isSingleValued

public boolean isSingleValued()
Is this a single valued field.


getTableKeyFields

public JDBCFieldBridge (src) [] getTableKeyFields()
Gets the key fields that this entity maintains in the relation table.

Specified by:
getTableKeyFields in class JDBCAbstractCMRFieldBridge (src)

getForeignKeyFields

public JDBCFieldBridge (src) [] getForeignKeyFields()
Gets the foreign key fields of this entity (i.e., related entities pk fields)

Specified by:
getForeignKeyFields in class JDBCAbstractCMRFieldBridge (src)

getRelatedCMRField

public JDBCAbstractCMRFieldBridge (src)  getRelatedCMRField()
The related entity's cmr field for this relationship.

Specified by:
getRelatedCMRField in class JDBCAbstractCMRFieldBridge (src)

getRelatedManager

public JDBCStoreManager (src)  getRelatedManager()
The related manger.


getRelatedEntity

public EntityBridge (src)  getRelatedEntity()
The related entity.


getRelatedJDBCEntity

public JDBCEntityBridge (src)  getRelatedJDBCEntity()
The related entity.


getRelatedLocalInterface

public final java.lang.Class getRelatedLocalInterface()
The related entity's local home interface.


getRelatedInvoker

public final LocalProxyFactory (src)  getRelatedInvoker()
The related entity's local container invoker.


isLoaded

public boolean isLoaded(EntityEnterpriseContext (src)  ctx)
Description copied from interface: JDBCFieldBridge (src)
Has the data been loaded?

Parameters:
ctx - - entity's context
Returns:
true if entity is loaded, false - otherwise.

addRelatedPKsWaitedForMe

public void addRelatedPKsWaitedForMe(EntityEnterpriseContext (src)  ctx)
Establishes relationships with related entities waited for passed in context to be created.

Parameters:
ctx - - entity's context.

isReadOnly

public boolean isReadOnly()
Is this field readonly?

Returns:
true if this field is read only

isReadTimedOut

public boolean isReadTimedOut(EntityEnterpriseContext (src)  ctx)
Had the read time expired?


getValue

public java.lang.Object getValue(EntityEnterpriseContext (src)  ctx)
Description copied from interface: FieldBridge (src)
Gets the value of this field for the specified instance context.

Parameters:
ctx - - entity's context.
Returns:
the value of this field.

setValue

public void setValue(EntityEnterpriseContext (src)  ctx,
                     java.lang.Object value)
Sets new value.

Parameters:
ctx - - entity's context;
value - - new value.

getInstanceValue

public java.lang.Object getInstanceValue(EntityEnterpriseContext (src)  myCtx)
Gets the value of the cmr field for the instance associated with the context.

Parameters:
myCtx - the context for which this field's value should be fetched
Returns:
the value of this field

getRelatedEntityByFK

public EJBLocalObject (src)  getRelatedEntityByFK(java.lang.Object fk)
Returns related entity's local interface. If there are foreign key fields mapped to CMP fields, existence of related entity is checked with findByPrimaryKey and if, in this case, related instance is not found, null is returned. If foreign key fields mapped to its own columns then existence of related entity is not checked and just its local object is returned.

Parameters:
fk - - foreign key value.
Returns:
related local object instance.

isForeignKeyValid

public boolean isForeignKeyValid(java.lang.Object fk)
This method is called only for CMR fields with foreign key fields mapped to CMP fields to check the validity of the foreign key value.

Parameters:
fk - the foreign key to check
Returns:
true if there is related entity with the equal primary key

setInstanceValue

public void setInstanceValue(EntityEnterpriseContext (src)  myCtx,
                             java.lang.Object newValue)
Sets the value of the cmr field for the instance associated with the context.

Parameters:
myCtx - the context for which this field's value should be set
newValue - the new value of this field

createRelationLinks

public void createRelationLinks(EntityEnterpriseContext (src)  myCtx,
                                java.lang.Object relatedId)
Creates the relation links between the instance associated with the context and the related instance (just the id is passed in).

This method calls a.addRelation(b) and b.addRelation(a)


createRelationLinks

public void createRelationLinks(EntityEnterpriseContext (src)  myCtx,
                                java.lang.Object relatedId,
                                boolean updateForeignKey)

destroyRelationLinks

public void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx,
                                 java.lang.Object relatedId)
Destroys the relation links between the instance associated with the context and the related instance (just the id is passed in).

This method calls a.removeRelation(b) and b.removeRelation(a)


destroyRelationLinks

public void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx,
                                 java.lang.Object relatedId,
                                 boolean updateValueCollection)
Destroys the relation links between the instance associated with the context and the related instance (just the id is passed in).

This method calls a.removeRelation(b) and b.removeRelation(a)

If updateValueCollection is false, the related id collection is not updated. This form is only used by the RelationSet iterator.


destroyRelationLinks

public void destroyRelationLinks(EntityEnterpriseContext (src)  myCtx,
                                 java.lang.Object relatedId,
                                 boolean updateValueCollection,
                                 boolean updateForeignKey)

scheduleChildrenForCascadeDelete

public void scheduleChildrenForCascadeDelete(EntityEnterpriseContext (src)  ctx)
Schedules children for cascade delete.


scheduleChildrenForBatchCascadeDelete

public void scheduleChildrenForBatchCascadeDelete(EntityEnterpriseContext (src)  ctx)
Schedules children for batch cascade delete.


getRelatedId

public java.lang.Object getRelatedId(EntityEnterpriseContext (src)  myCtx)
Get the related entity's id. This only works on single valued cmr fields.


getRelatedIdFromContext

public java.lang.Object getRelatedIdFromContext(EntityEnterpriseContext (src)  ctx)
Creates a new instance of related id based on foreign key value in the context.

Parameters:
ctx - - entity's context.
Returns:
related entity's id.

addRelation

public void addRelation(EntityEnterpriseContext (src)  myCtx,
                        java.lang.Object fk)
Adds the foreign key to the set of related ids, and updates any foreign key fields.


removeRelation

public void removeRelation(EntityEnterpriseContext (src)  myCtx,
                           java.lang.Object fk)
Removes the foreign key to the set of related ids, and updates any foreign key fields.


load

public void load(EntityEnterpriseContext (src)  myCtx,
                 java.util.Collection values)

setForeignKey

public void setForeignKey(EntityEnterpriseContext (src)  myCtx,
                          java.lang.Object fk)
Sets the foreign key field value.


initInstance

public void initInstance(EntityEnterpriseContext (src)  ctx)
Initialized the foreign key fields.


resetPersistenceContext

public void resetPersistenceContext(EntityEnterpriseContext (src)  ctx)
resets the persistence context of the foreign key fields


setInstanceParameters

public int setInstanceParameters(java.sql.PreparedStatement ps,
                                 int parameterIndex,
                                 EntityEnterpriseContext (src)  ctx)
Description copied from interface: JDBCFieldBridge (src)
Sets the prepared statement parameters with the data from the instance associated with the context.


loadInstanceResults

public int loadInstanceResults(java.sql.ResultSet rs,
                               int parameterIndex,
                               EntityEnterpriseContext (src)  ctx)
Description copied from interface: JDBCFieldBridge (src)
Loads the data from result set into the instance associated with the specified context.


loadArgumentResults

public int loadArgumentResults(java.sql.ResultSet rs,
                               int parameterIndex,
                               java.lang.Object[] fkRef)
Description copied from interface: JDBCFieldBridge (src)
Loads the value of this cmp field from result set into argument referance.


isDirty

public boolean isDirty(EntityEnterpriseContext (src)  ctx)
This method is never called. In case of a CMR with foreign key fields, only the foreign key fields are asked for the dirty state.


invalidateCache

public boolean invalidateCache(EntityEnterpriseContext (src)  ctx)

setClean

public void setClean(EntityEnterpriseContext (src)  ctx)
This method is never called. In case of a CMR - with foreign key fields, the foreign key fields are cleaned when necessary according to CMP fields' behaviour. - from m:m relationship, added/removed key pairs are cleared in application tx data map on sync.


isCMPField

public boolean isCMPField()

getManager

public JDBCEntityPersistenceStore (src)  getManager()

hasFKFieldsMappedToCMPFields

public boolean hasFKFieldsMappedToCMPFields()

addRelatedPKWaitingForMyPK

public void addRelatedPKWaitingForMyPK(java.lang.Object myPK,
                                       java.lang.Object relatedPK)

removeRelatedPKWaitingForMyPK

public void removeRelatedPKWaitingForMyPK(java.lang.Object myPK,
                                          java.lang.Object relatedPK)

toString

public java.lang.String toString()