com.scooterframework.orm.activerecord
Class HasManyThroughRecordRelation

java.lang.Object
  extended by com.scooterframework.orm.activerecord.RecordRelation
      extended by com.scooterframework.orm.activerecord.HasManyThroughRecordRelation

public class HasManyThroughRecordRelation
extends RecordRelation

HasManyThroughRecordRelation class represents a has-many-trough relation instance. For example, A has many C and B has many C. Then we can say A has many B through C. In has-many-through relation, class C should have primary keys of both classes A and B held as foreign keys. Class A is the owner of the relation.


Field Summary
 
Fields inherited from class com.scooterframework.orm.activerecord.RecordRelation
associationDataMap, lastUsedOptions, owner, relation
 
Constructor Summary
HasManyThroughRecordRelation(ActiveRecord record, HasManyThroughRelation relation)
           
 
Method Summary
 AssociatedRecords allAssociatedRecords(java.lang.String options, boolean refresh)
          Find the associated record.
protected  int countRecordsInDB()
           
protected  java.lang.String getAllConditionsString(java.lang.String tableB, java.lang.String tableC, HasManyThroughRelation acbRel)
          Creates a concatenated conditions string.
protected  java.lang.String getFKDataMapForMiddleC(ActiveRecord recordA, java.lang.String tableC, java.lang.String mappingAC, java.util.Map<java.lang.String,java.lang.Object> fkData)
           
protected  java.lang.String getTableLinks(java.lang.String table1, java.lang.String mapping12, java.lang.String table2)
           
protected  java.util.List<ActiveRecord> retrieveAssociatedDataList(java.lang.String options)
          Retrieves a list of associated ActiveRecord data.
 
Methods inherited from class com.scooterframework.orm.activerecord.RecordRelation
allAssociatedRecords, allAssociatedRecords, allAssociatedRecords, associatedRecord, associatedRecord, associatedRecord, associatedRecord, getAssociatedData, getFKDataMapForOther, getLastUsedOptions, getNullFKDataMapForOther, getOwner, getRelation, optionsChangedFromLastRetrieval, retrieveAssociatedData, retrieveAssociatedData, retrieveAssociatedDataList, setAssociatedData, setAssociatedData, setLastUsedOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HasManyThroughRecordRelation

public HasManyThroughRecordRelation(ActiveRecord record,
                                    HasManyThroughRelation relation)
Method Detail

allAssociatedRecords

public AssociatedRecords allAssociatedRecords(java.lang.String options,
                                              boolean refresh)
Find the associated record. For example, "projects" has many "employees" thru "assignments".
 SQL: SELECT employees.*
        FROM employees INNER JOIN assignments ON employees.id = assignments.eid
       WHERE (assignments.pid = ?1 AND (other conditions))
 

Overrides:
allAssociatedRecords in class RecordRelation
Parameters:
options - A string of options.
refresh - If true, refresh data from database
Returns:
AssociatedRecords

countRecordsInDB

protected int countRecordsInDB()

retrieveAssociatedDataList

protected java.util.List<ActiveRecord> retrieveAssociatedDataList(java.lang.String options)
Description copied from class: RecordRelation
Retrieves a list of associated ActiveRecord data. This method must be implemented by the subclass of this class for either has-many type or has-many-through type.

Overrides:
retrieveAssociatedDataList in class RecordRelation
Parameters:
options - options used in retrieving the record
Returns:
retrieved active record instance list

getTableLinks

protected java.lang.String getTableLinks(java.lang.String table1,
                                         java.lang.String mapping12,
                                         java.lang.String table2)

getFKDataMapForMiddleC

protected java.lang.String getFKDataMapForMiddleC(ActiveRecord recordA,
                                                  java.lang.String tableC,
                                                  java.lang.String mappingAC,
                                                  java.util.Map<java.lang.String,java.lang.Object> fkData)

getAllConditionsString

protected java.lang.String getAllConditionsString(java.lang.String tableB,
                                                  java.lang.String tableC,
                                                  HasManyThroughRelation acbRel)
Creates a concatenated conditions string. This is a condition string which includes conditions from AB + AC + CB.

Parameters:
acbRel - HasManyThrough relation
Returns:
conditions a string of all related conditions