com.scooterframework.orm.activerecord
Class AssociatedRecordsHMT

java.lang.Object
  extended by com.scooterframework.orm.activerecord.AssociatedRecords
      extended by com.scooterframework.orm.activerecord.AssociatedRecordsHMT

public class AssociatedRecordsHMT
extends AssociatedRecords

AssociatedRecordsHMT class contains a list of ActiveRecord objects and its owner in a has-many-through association.


Field Summary
 
Fields inherited from class com.scooterframework.orm.activerecord.AssociatedRecords
associatedRecords, latestRecordsLoaded, log, recordRelation
 
Constructor Summary
AssociatedRecordsHMT(RecordRelation recordRelation)
           
AssociatedRecordsHMT(RecordRelation recordRelation, java.util.List<? extends ActiveRecord> records)
           
 
Method Summary
 AssociatedRecords add(ActiveRecord record, java.util.Map<java.lang.String,java.lang.Object> joinInput)
          Adds a record to the association.
 AssociatedRecords add(java.util.List<? extends ActiveRecord> records)
          Adds a list of records to the association.
 AssociatedRecords add(java.util.List<? extends ActiveRecord> records, java.util.List<java.util.Map<java.lang.String,java.lang.Object>> joinInputs)
          Adds a list of records to the association.
protected  int countRecordsInDB()
          Count number of associated records in the database.
 AssociatedRecords delete(java.util.List<? extends ActiveRecord> records)
          Deletes a list objects from the associated list and delete the records in database whether the objects are dependent on the owner or not.
 AssociatedRecords detach(ActiveRecord target, boolean keepJoinRecord)
          Removes target record from the association.
 AssociatedRecords detach(java.util.List<? extends ActiveRecord> records)
          Removes a list of records from the association.
 AssociatedRecords detach(java.util.List<? extends ActiveRecord> records, boolean keepJoinRecord)
          Removes a list of records from the association.
 ActiveRecord getJoinRecord(ActiveRecord target)
          Retrieves the join record between the owner and the target.
 AssociatedRecords replace(java.util.List<? extends ActiveRecord> records)
          This feature is not supported for has-many-through relation.
 
Methods inherited from class com.scooterframework.orm.activerecord.AssociatedRecords
add, cleanCache, clear, count, delete, detach, findBy, getOwner, getRecord, getRecords, getRecords, getRelation, getSqlService, hasLoadedFromDatabase, isEmpty, ownerIsNew, removeRecordFromList, size, storeLoadedAssociatedRecords, validateRecordType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssociatedRecordsHMT

public AssociatedRecordsHMT(RecordRelation recordRelation)

AssociatedRecordsHMT

public AssociatedRecordsHMT(RecordRelation recordRelation,
                            java.util.List<? extends ActiveRecord> records)
Method Detail

add

public AssociatedRecords add(ActiveRecord record,
                             java.util.Map<java.lang.String,java.lang.Object> joinInput)
Adds a record to the association. If the owner object is already in the database, the record will be either inserted or updated in the database. If the owner record is not in the database, the record will not be saved to the database.

Parameters:
record - A record to be added to the relation.
joinInput - A map of input data for the join record.
Returns:
updated AssociatedRecords

add

public AssociatedRecords add(java.util.List<? extends ActiveRecord> records)
Adds a list of records to the association. If the owner object is already in the database, the records will be either inserted or updated in the database. If the owner record is not in the database, the records will not be saved to the database.

Specified by:
add in class AssociatedRecords
Parameters:
records - a list of records to be added to the relation.
Returns:
updated AssociatedRecords.

add

public AssociatedRecords add(java.util.List<? extends ActiveRecord> records,
                             java.util.List<java.util.Map<java.lang.String,java.lang.Object>> joinInputs)
Adds a list of records to the association. If the owner object is already in the database, the records will be either inserted or updated in the database. If the owner record is not in the database, the records will not be saved to the database.

Parameters:
records - a list of records to be added to the relation.
joinInputs - a list of input data map for the through table.
Returns:
updated AssociatedRecords.

detach

public AssociatedRecords detach(ActiveRecord target,
                                boolean keepJoinRecord)

Removes target record from the association. The record is not deleted. The join record is deleted if the value of the keepJoinRecord input is false or the join record depends on the record to be deleted.

If the owner object doesn't exist in database, only those objects that have been added to the relation before can be detached.

Parameters:
target - a record to be detached from the association.
keepJoinRecord - if true, keep the join record. Otherwise, delete it.
Returns:
updated AssociatedRecords.

detach

public AssociatedRecords detach(java.util.List<? extends ActiveRecord> records)

Removes a list of records from the association. No record is deleted. Only the join record is deleted.

If the owner object doesn't exist in database, only those objects that have been added to the relation before can be detached.

Specified by:
detach in class AssociatedRecords
Parameters:
records - list of records to be detached.
Returns:
updated AssociatedRecords.

detach

public AssociatedRecords detach(java.util.List<? extends ActiveRecord> records,
                                boolean keepJoinRecord)

Removes a list of records from the association. No record is deleted. The join record is deleted if the value of the keepJoinRecord input is false or the join record depends on the record to be deleted.

Proper use of keepJoinRecord parameter is good for a three-way join association.

If the owner object doesn't exist in database, only those objects that have been added to the relation before can be detached.

Parameters:
records - list of records to be detached.
keepJoinRecord - if true, keep the join record. Otherwise, delete it.
Returns:
updated AssociatedRecords.

delete

public AssociatedRecords delete(java.util.List<? extends ActiveRecord> records)

Deletes a list objects from the associated list and delete the records in database whether the objects are dependent on the owner or not.

The associated records in the join table can either be deleted or have its foreign key nullified, depending on how you specify the cascade property in the "to-be-deleted" record class.

If the owner object doesn't exist in database, only those objects that have been added to the relation before can be detached.

Specified by:
delete in class AssociatedRecords
Parameters:
records - a list of records to be deleted.
Returns:
updated AssociatedRecords.

replace

public AssociatedRecords replace(java.util.List<? extends ActiveRecord> records)

This feature is not supported for has-many-through relation.

This is equivalent to detach() and add(records).

Removes all existing associated objects from the associated list by setting their foreign keys to NULL. The records are not deleted unless they depend on the owner.

Adds the new records to the association.

Specified by:
replace in class AssociatedRecords
Returns:
updated AssociatedRecords

getJoinRecord

public ActiveRecord getJoinRecord(ActiveRecord target)
Retrieves the join record between the owner and the target.

Parameters:
target - the associated record
Returns:
the join record

countRecordsInDB

protected int countRecordsInDB()
Count number of associated records in the database.

Specified by:
countRecordsInDB in class AssociatedRecords
Returns:
number of associated records