mongo-dart / lib / objectory / Objectory.dart

typedef IPersistent FactoryMethod();
class ClassSchema{
  static final SimpleProperty = 0;
  static final InternalObject = 1;
  static final ExternalObject = 2;
  String className;
  FactoryMethod factoryMethod;
  Set<String> properties;
  Map<String,String> components;
  Map<String,String> links;
  ClassSchema(this.className,this.factoryMethod,List<String> propertyList,    
    properties = new Set<String>.from(propertyList);
    if (components !== null){
    if (links !== null){
  void property(String propertyName, String propertyClass){
interface Objectory{  
  void registerClass(ClassSchema schema);
  IPersistent newInstance(String className);
  IPersistent map2Object(String className, Map map);  
  Future<IPersistent> findOne(String className,[Map selector]);
  Future<List<IPersistent>> find(String className,[Map selector]);
  void save(IPersistent persistentObject);
  void remove(IPersistent persistentObject);
  Future<bool> open([String database, String url]);
  Future<bool> dropDb();
  ClassSchema getSchema(String className);
  void close();
abstract class ObjectoryBaseImpl implements Objectory{
  Map<String,ClassSchema> schemata;
    schemata = new  Map<String,ClassSchema>();
  ClassSchema getSchema(String className){
    return schemata[className];
  IPersistent newInstance(String className){
    if (schemata.containsKey(className)){
      return schemata[className].factoryMethod();
    throw "Class $className have not been registered in Objectory";
  IPersistent map2Object(String className, Map map){
    var result = newInstance(className); = map;
    if (result.isRoot()){ = map["_id"];    
    ClassSchema classSchema = schemata[className];
    if (classSchema.components !== null){      
        IPersistent component = map2Object(componentClass,map[property]);
    if (classSchema.links !== null){      
      //  print(property);
        ObjectId linkId = map[property];
        if (linkId !== null){
          RootPersistentObject link = newInstance(linkClass);
 = linkId;
    return result;
  void clearSchemata(){
  void registerClass(ClassSchema schema){
    schemata[schema.className] = schema;
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
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.