Dart Documentationpersistent_objectEmbeddedPersistentObject

EmbeddedPersistentObject class

class EmbeddedPersistentObject extends BasePersistentObject{
 BasePersistentObject _parent;
 String _pathToMe;
 bool _elementListMode = false;
 void setDirty(String fieldName){
   super.setDirty(fieldName);
   if (_parent != null) {
     _elementListMode? _parent.setDirty('${_pathToMe}'): _parent.setDirty('${_pathToMe}.${fieldName}');
   }
 }
 remove() {
   throw new Exception('Must not be invoked');
 }
 save() {
   throw new Exception('Must not be invoked');
 }
}

Extends

BasePersistentObject > EmbeddedPersistentObject

Properties

final String collectionName #

inherited from BasePersistentObject

Name of MongoDB collection where instance of this class would be persistet in DB. By default equals to class name, but may be overwritten

String get collectionName => runtimeType.toString();

final Set<String> dirtyFields #

inherited from BasePersistentObject
Set<String> get dirtyFields => _dirtyFields;

Map map #

inherited from BasePersistentObject
Map get map => _map;
set map(Map newValue) {
 _setMap(newValue);
}

bool saveOnUpdate #

inherited from BasePersistentObject
bool saveOnUpdate = false

Methods

void clearDirtyStatus() #

inherited from BasePersistentObject
void clearDirtyStatus() {
 _dirtyFields.clear();
}
inherited from BasePersistentObject
Future<PersistentObject> fetchLinks(){
 var dbRefs = new List<DbRef>();
 getDbRefsFromMap(map, dbRefs);
 var objects = dbRefs.map((each) => objectory.dbRef2Object(each));
 return Future.forEach(objects,(each) => each.fetch()).then((_)=>new Future.value(this));
}

dynamic getDbRefsFromList(List list, List result) #

inherited from BasePersistentObject
getDbRefsFromList(List list, List result){
 for (var each in list) {
   if (each is DbRef) {
     result.add(each);
   }
   if (each is Map) {
     getDbRefsFromMap(each, result);
   }
   if (each is List) {
     getDbRefsFromList(each, result);
   }
 }
}

dynamic getDbRefsFromMap(Map map, List result) #

inherited from BasePersistentObject
getDbRefsFromMap(Map map, List result){
 for(var each in map.values){
   if (each is DbRef) {
     result.add(each);
   }
   if (each is Map) {
     getDbRefsFromMap(each, result);
   }
   if (each is List) {
     getDbRefsFromList(each, result);
   }
 }
}

EmbeddedPersistentObject getEmbeddedObject(Type classType, String property) #

inherited from BasePersistentObject
EmbeddedPersistentObject getEmbeddedObject(Type classType, String property) {
 EmbeddedPersistentObject result = _compoundProperties[property];
 if (result == null) {
   result = objectory.newInstance(classType);
   result._setMap(map[property]);
   map[property] = result.map;
   result._parent = this;
   result._pathToMe = property;
 }
 return result;
}

PersistentObject getLinkedObject(String property) #

inherited from BasePersistentObject
PersistentObject getLinkedObject(String property) {
 DbRef dbRef = map[property];
 if (dbRef == null) {
   return null;
 }
 Type classType = objectory.getClassTypeByCollection(dbRef.collection);
 return objectory.findInCacheOrGetProxy(dbRef.id,classType);
}

PersistentList getPersistentList(Type classType, String property) #

inherited from BasePersistentObject
PersistentList getPersistentList(Type classType, String property) {
 PersistentList result = _compoundProperties[property];
 if (result == null) {
   result = new PersistentList(this,classType,property);
   _compoundProperties[property] = result;
 }
 return result;
}

dynamic getProperty(String property) #

inherited from BasePersistentObject
dynamic getProperty(String property){
 return this.map[property];
}

void init() #

inherited from BasePersistentObject
void init(){}

dynamic isDirty() #

inherited from BasePersistentObject
isDirty() {
 return !_dirtyFields.isEmpty;
}

void onValueChanging(String fieldName, newValue) #

inherited from BasePersistentObject
void onValueChanging(String fieldName, newValue) {
 setDirty(fieldName);
}

dynamic remove() #

remove() {
 throw new Exception('Must not be invoked');
}

dynamic save() #

save() {
 throw new Exception('Must not be invoked');
}

void setDirty(String fieldName) #

void setDirty(String fieldName){
 super.setDirty(fieldName);
 if (_parent != null) {
   _elementListMode? _parent.setDirty('${_pathToMe}'): _parent.setDirty('${_pathToMe}.${fieldName}');
 }
}

dynamic setLinkedObject(String property, PersistentObject value) #

inherited from BasePersistentObject
setLinkedObject(String property, PersistentObject value) {
 if (value == null) {
   map[property] = null;
 } else {
   if (value.id == null) {
     throw new Exception('Attemt to set link to unsaved object: $value');
   }
   onValueChanging(property, value.dbRef);
   map[property] = value.dbRef;
 }
}

void setProperty(String property, value) #

inherited from BasePersistentObject
void setProperty(String property, value){
 onValueChanging(property, value);
 this.map[property] = value;
}

String toString() #

inherited from BasePersistentObject

Returns a string representation of this object.

docs inherited from Object
String toString()=>"$collectionName($map)";