|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.scooterframework.orm.activerecord.AssociatedRecords
public abstract class AssociatedRecords
AssociatedRecords class contains a list of ActiveRecord objects and its owner. It also has methods for the association.
Field Summary | |
---|---|
protected java.util.List<ActiveRecord> |
associatedRecords
The list of associated records. |
protected boolean |
latestRecordsLoaded
Indicates if associated records have been retrieved or not |
protected LogUtil |
log
|
protected RecordRelation |
recordRelation
The RecordRelation instance for this association. |
Constructor Summary | |
---|---|
AssociatedRecords(RecordRelation recordRelation)
|
|
AssociatedRecords(RecordRelation recordRelation,
java.util.List<? extends ActiveRecord> records)
|
Method Summary | |
---|---|
AssociatedRecords |
add(ActiveRecord record)
Adds a record to the association. |
abstract AssociatedRecords |
add(java.util.List<? extends ActiveRecord> records)
Adds a list of records to the association. |
void |
cleanCache()
Cleans up cached data. |
AssociatedRecords |
clear()
Removes all associated objects from the associated list by setting their foreign keys to NULL. |
int |
count()
Count number of associated records in the database. |
protected abstract int |
countRecordsInDB()
Counts number of associated records in the database. |
AssociatedRecords |
delete(ActiveRecord record)
Deletes an object from the associated list and delete the record in database whether the object is dependent on the owner or not. |
abstract 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 record)
Removes an object from the associated list. |
abstract AssociatedRecords |
detach(java.util.List<? extends ActiveRecord> records)
Removes a list of objects from the associated list by setting their foreign keys to NULL. |
boolean |
findBy(java.lang.String field,
java.lang.Object value)
Checks if a field's value of a record in the association is equal to a specific value. |
ActiveRecord |
getOwner()
Returns owner of the association. |
ActiveRecord |
getRecord(int index)
Returns a specific associated record at index from the list. |
java.util.List<ActiveRecord> |
getRecords()
Returns the associated records. |
java.util.List<ActiveRecord> |
getRecords(boolean refresh)
Returns the associated records. |
Relation |
getRelation()
Returns relation of the association. |
protected SqlService |
getSqlService()
Returns gateway to database |
boolean |
hasLoadedFromDatabase()
Checks if the associated record has been loaded from database. |
boolean |
isEmpty()
Return true if this list contains no elements. |
protected boolean |
ownerIsNew()
Checks if the owner record is a new record. |
protected java.util.List<ActiveRecord> |
removeRecordFromList(java.util.List<? extends ActiveRecord> records,
ActiveRecord record)
Removes a record from a list of records. |
abstract AssociatedRecords |
replace(java.util.List<? extends ActiveRecord> records)
This is equivelent to clear() and add(records). |
int |
size()
Returns the number of associated objects. |
void |
storeLoadedAssociatedRecords(java.util.List<? extends ActiveRecord> records)
Stores newly loaded database records from database. |
protected void |
validateRecordType(java.lang.Class<? extends ActiveRecord> expected,
java.util.List<? extends ActiveRecord> records)
Validates that the records are of the same type as expected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected RecordRelation recordRelation
protected java.util.List<ActiveRecord> associatedRecords
protected boolean latestRecordsLoaded
protected LogUtil log
Constructor Detail |
---|
public AssociatedRecords(RecordRelation recordRelation)
public AssociatedRecords(RecordRelation recordRelation, java.util.List<? extends ActiveRecord> records)
Method Detail |
---|
public ActiveRecord getRecord(int index)
public java.util.List<ActiveRecord> getRecords()
public java.util.List<ActiveRecord> getRecords(boolean refresh)
Returns the associated records.
If refresh is true, a database retrieval will be tried for the owner object.
public ActiveRecord getOwner()
public Relation getRelation()
public AssociatedRecords add(ActiveRecord record)
record
- a record to be added to the relation.
public abstract AssociatedRecords add(java.util.List<? extends ActiveRecord> records)
records
- a list of records to be added to the relation.
public AssociatedRecords detach(ActiveRecord record)
Removes an object from the associated list. If the object is a record in database, its foreign key will be set to NULL. The record is not deleted unless it depends on the owner.
If the owner object doesn't exist in database, only the object that has been added to the relation before can be detached.
record
- a record to be detached.
public abstract 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.
records
- list of records to be detached.
public AssociatedRecords delete(ActiveRecord record)
Deletes an object from the associated list and delete the record in database whether the object is dependent on the owner or not.
If the owner object doesn't exist in database, only the object that has been added to the relation before can be deleted.
record
- The record to be deleted.
public abstract 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.
records
- a list of records to be deleted.
public AssociatedRecords clear()
public abstract AssociatedRecords replace(java.util.List<? extends ActiveRecord> records)
This is equivelent 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.
public boolean isEmpty()
public int size()
Returns the number of associated objects. If the associated collection has already been loaded or the owner is new, this method simply returns the length of the current associated collection. If it hasn't been loaded yet, it calls count to get the length.
If you want to force a data load before calling size(), call getRecords(true) first.
public int count()
public void cleanCache()
public boolean hasLoadedFromDatabase()
public void storeLoadedAssociatedRecords(java.util.List<? extends ActiveRecord> records)
records
- newly loaded database records from database.public boolean findBy(java.lang.String field, java.lang.Object value)
field
- a field namevalue
- a specific value to compare
protected SqlService getSqlService()
protected abstract int countRecordsInDB()
protected boolean ownerIsNew()
protected void validateRecordType(java.lang.Class<? extends ActiveRecord> expected, java.util.List<? extends ActiveRecord> records)
expected
- expected class typerecords
- list of records to be checkedprotected java.util.List<ActiveRecord> removeRecordFromList(java.util.List<? extends ActiveRecord> records, ActiveRecord record)
records
- list of recordsrecord
- the record to be removed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |