com.scooterframework.orm.activerecord
Class AssociatedRecordsHM

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

public class AssociatedRecordsHM
extends AssociatedRecords

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


Field Summary
 
Fields inherited from class com.scooterframework.orm.activerecord.AssociatedRecords
associatedRecords, latestRecordsLoaded, log, recordRelation
 
Constructor Summary
AssociatedRecordsHM(RecordRelation recordRelation)
           
AssociatedRecordsHM(RecordRelation recordRelation, java.util.List<? extends ActiveRecord> records)
           
 
Method Summary
 AssociatedRecords add(java.util.List<? extends ActiveRecord> records)
          Adds a list of records to the association.
protected  int countRecordsInDB()
          Counts 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(java.util.List<? extends ActiveRecord> records)
          Removes a list of objects from the associated list by setting their foreign keys to NULL.
 AssociatedRecords replace(java.util.List<? extends ActiveRecord> records)
          This is equivalent to clear() and add(records).
 
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

AssociatedRecordsHM

public AssociatedRecordsHM(RecordRelation recordRelation)

AssociatedRecordsHM

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

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.

detach

public AssociatedRecords detach(java.util.List<? extends ActiveRecord> records)
Removes a list of objects from the associated list by setting their foreign keys to NULL. The objects are not deleted unless they depend on the owner. 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.

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. 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 is equivalent to clear() 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

countRecordsInDB

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

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