Source

mongo-dart / lib / objectory / Objectory.dart

Diff from to

File lib/objectory/Objectory.dart

 typedef PersistentObject FactoryMethod();
 interface Objectory{  
   void registerClass(String className, FactoryMethod fm);
-  Future<PersistentObject> findOne(String className,[Map query]);
-  Future<List<PersistentObject>> find(String className,[Map query]);
+  PersistentObject newInstance(String className);
+  Future<PersistentObject> findOne(String className,[Map selector]);
+  Future<List<PersistentObject>> find(String className,[Map selector]);
   void save(PersistentObject persistentObject);
   void remove(PersistentObject persistentObject);
-  Future<bool> connect(String database, [String url]);
+  Future<bool> open(String database, [String url]);
   Future<bool> dropDb();
 }
-class ObjectoryBaseImpl implements Objectory{
+abstract class ObjectoryBaseImpl implements Objectory{
   Map<String,FactoryMethod> factories;
   ObjectoryBaseImpl(){
     factories = new  Map<String,FactoryMethod>();
   PersistentObject map2Object(String className, Map map){
     PersistentObject result = newInstance(className);
     result.map = map;
+    if (result.isRoot()){
+      result.id = map["_id"];    
+    }      
+    for (var key in map.getKeys()){
+      var value = map[key];
+      if (value is Map){
+        if (value.containsKey("_pt")){
+          PersistentObject subComponent = map2Object(value["_pt"],value);
+          result.setProperty(key,subComponent);  
+          result.clearDirtyStatus();
+        }
+      }
+    }
     return result;
   }
+  void clearFactories(){
+    factories.clear();
+  }
   void registerClass(String className, FactoryMethod fm){
     factories[className] = fm;
   }