예제 #1
0
        public MongoDBDocumentManager(MongoConfiguration config, String db, String collection, MongoDBSchemas schema)
            : base(null)
        {
            this._connection = new Mongo(config);
            this._db         = this._connection.GetDatabase(db);
            this._connection.Connect();
            this._collection = collection;

            //Ensure the DB is setup correctly
            this._db.GetCollection(Collection);

            //Set up the Data Adaptor and Graph Registry
            this._schema = schema;
            switch (schema)
            {
            case MongoDBSchemas.GraphCentric:
                this.DataAdaptor = new MongoDBGraphCentricAdaptor();
                if (!this.HasDocument(GraphRegistryDocument))
                {
                    if (!this.CreateDocument(GraphRegistryDocument))
                    {
                        throw new AlexandriaException("Unable to create the Required Graph Registry Document");
                    }
                }
                this._registry = new MongoDBGraphCentricRegistry(this.GetDocument(GraphRegistryDocument));
                break;

            case MongoDBSchemas.TripleCentric:
                this.DataAdaptor = new MongoDBTripleCentricAdaptor(this);
                this._registry   = new MongoDBTripleCentricGraphRegistry(this);
                break;

            default:
                throw new ArgumentException("Unknown MongoDB Schema", "schema");
            }
        }
예제 #2
0
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            switch (targetType.FullName)
            {
            case MongoDBManager:
                String server       = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer));
                String storeID      = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase));
                String collectionID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                String loadMode     = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));

                MongoDBSchemas schema = MongoDBDocumentManager.DefaultSchema;
                if (loadMode != null)
                {
                    switch (loadMode)
                    {
                    case "GraphCentric":
                        schema = MongoDBSchemas.GraphCentric;
                        break;

                    case "TripleCentric":
                        schema = MongoDBSchemas.TripleCentric;
                        break;
                    }
                }

                if (storeID != null)
                {
                    AlexandriaMongoDBManager manager;
                    if (server == null)
                    {
                        if (collectionID == null)
                        {
                            manager = new AlexandriaMongoDBManager(storeID, schema);
                        }
                        else
                        {
                            manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(new MongoConfiguration(), storeID, collectionID, schema));
                        }
                    }
                    else
                    {
                        //Have a Custom Connection String
                        if (collectionID == null)
                        {
                            manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, schema));
                        }
                        else
                        {
                            manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, collectionID, schema));
                        }
                    }

                    obj = manager;
                    return(true);
                }

                //If we get here then the required dnr:database property was missing
                throw new DotNetRdfConfigurationException("Unable to load the MongoDB Manager identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:database");
                break;

            case MongoDBDataset:
                INode managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:genericManager"));
                if (managerNode == null)
                {
                    throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since there we no value for the required property dnr:genericManager");
                }

                Object temp = ConfigurationLoader.LoadObject(g, managerNode);
                if (temp is AlexandriaMongoDBManager)
                {
                    obj = new AlexandriaMongoDBDataset((AlexandriaMongoDBManager)temp);
                    return(true);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since the value for the dnr:genericManager property pointed to an Object which could not be loaded as an object of type AlexandriaMongoDBManager");
                }

                break;
            }

            obj = null;
            return(false);
        }
예제 #3
0
 public MongoDBDocumentManager(String connectionString, String db, MongoDBSchemas schema)
     : this(MongoDBHelper.GetConfiguration(connectionString), db, schema)
 {
 }
예제 #4
0
 public MongoDBDocumentManager(String db, MongoDBSchemas schema)
     : this(new MongoConfiguration(), db, schema)
 {
 }
예제 #5
0
 public MongoDBDocumentManager(MongoConfiguration config, String db, MongoDBSchemas schema)
     : this(config, db, DefaultCollection, schema)
 {
 }
예제 #6
0
 public AlexandriaMongoDBManager(String connectionString, String db, MongoDBSchemas schema)
     : this(new MongoDBDocumentManager(connectionString, db, schema))
 {
 }
예제 #7
0
 public AlexandriaMongoDBManager(MongoConfiguration config, String db, MongoDBSchemas schema)
     : this(new MongoDBDocumentManager(config, db, schema))
 {
 }
예제 #8
0
 public AlexandriaMongoDBManager(String db, MongoDBSchemas schema)
     : this(new MongoDBDocumentManager(db, schema))
 {
 }