Source

mongo-dart / lib / objectory / Objectory.dart

vadimtsushko 7057331 


vadimtsushko afb0e0c 


vadimtsushko 7057331 

vadimtsushko afb0e0c 
vadimtsushko 7057331 

vadimtsushko afb0e0c 
vadimtsushko 7057331 












vadimtsushko afb0e0c 












vadimtsushko 7057331 

vadimtsushko afb0e0c 


vadimtsushko 7057331 


typedef PersistentObject FactoryMethod();
interface Objectory{  
  void registerClass(String className, FactoryMethod fm);
  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> open(String database, [String url]);
  Future<bool> dropDb();
}
abstract class ObjectoryBaseImpl implements Objectory{
  Map<String,FactoryMethod> factories;
  ObjectoryBaseImpl(){
    factories = new  Map<String,FactoryMethod>();
  }
  PersistentObject newInstance(String className){
    if (factories.containsKey(className)){
      return factories[className]();
    }
    throw "Class $className have not been registered in Objectory";
  }
  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;
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.