예제 #1
0
		public DocumentStorageActions(
			JET_INSTANCE instance,
			string database,
			TableColumnsCache tableColumnsCache,
			OrderedPartCollection<AbstractDocumentCodec> documentCodecs,
			IUuidGenerator uuidGenerator,
			IDocumentCacher cacher,
			TransactionalStorage transactionalStorage)
		{
			this.tableColumnsCache = tableColumnsCache;
			this.documentCodecs = documentCodecs;
			this.uuidGenerator = uuidGenerator;
			this.cacher = cacher;
			this.transactionalStorage = transactionalStorage;
			try
			{
				session = new Session(instance);
				transaction = new Transaction(session);
				Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.None);
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}
		}
예제 #2
0
 public ViewStorage()
 {
     transactionalStorage = new TransactionalStorage(new RavenConfiguration
     {
         DataDirectory = "raven.db.test.esent",
         RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
     }, () => { });
     transactionalStorage.Initialize();
 }
예제 #3
0
        public IndexDefinitionStorage(TransactionalStorage transactionalStorage, string path, IEnumerable <AbstractViewGenerator> compiledGenerators)
        {
            this.path = Path.Combine(path, IndexDefDir);

            if (Directory.Exists(this.path) == false)
            {
                Directory.CreateDirectory(this.path);
            }

            foreach (var index in Directory.GetFiles(this.path, "*.index"))
            {
                try
                {
                    AddAndCompileIndex(
                        HttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)),
                        JsonConvert.DeserializeObject <IndexDefinition>(File.ReadAllText(index), new JsonEnumConverter())
                        );
                }
                catch (Exception e)
                {
                    logger.Warn("Could not compile index " + index + ", skipping bad index", e);
                }
            }

            //compiled view generators always overwrite dynamic views
            foreach (var generator in compiledGenerators)
            {
                var copy           = generator;
                var displayNameAtt = TypeDescriptor.GetAttributes(copy)
                                     .OfType <DisplayNameAttribute>()
                                     .FirstOrDefault();

                var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;

                transactionalStorage.Batch(actions =>
                {
                    if (actions.GetIndexesStats().Any(x => x.Name == name))
                    {
                        return;
                    }

                    actions.AddIndex(name);
                });

                var indexDefinition = new IndexDefinition
                {
                    Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
                    // need to supply this so the index storage will create map/reduce index
                    Reduce     = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
                    Indexes    = generator.Indexes,
                    Stores     = generator.Stores,
                    IsCompiled = true
                };
                indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
                indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
            }
        }
예제 #4
0
파일: General.cs 프로젝트: 925coder/ravendb
		public DocumentStorageActions(
			JET_INSTANCE instance,
			string database,
			TableColumnsCache tableColumnsCache,
			OrderedPartCollection<AbstractDocumentCodec> documentCodecs,
			IUuidGenerator uuidGenerator,
			IDocumentCacher cacher,
			EsentTransactionContext transactionContext,
			TransactionalStorage transactionalStorage)
		{
			this.tableColumnsCache = tableColumnsCache;
			this.documentCodecs = documentCodecs;
			this.uuidGenerator = uuidGenerator;
			this.cacher = cacher;
			this.transactionalStorage = transactionalStorage;
			this.transactionContext = transactionContext;

			try
			{
				if (transactionContext == null)
				{
					session = new Session(instance);
					transaction = new Transaction(session);
					sessionAndTransactionDisposer = () =>
					{
						if(transaction != null)
							transaction.Dispose();
						if(session != null)
							session.Dispose();
					};
				}
				else
				{
					session = transactionContext.Session;
					transaction = transactionContext.Transaction;
					var disposable = transactionContext.EnterSessionContext();
					sessionAndTransactionDisposer = disposable.Dispose;
				}
				Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.None);
			}
			catch (Exception ex)
			{
			    logger.WarnException("Error when trying to open a new DocumentStorageActions", ex);
			    try
			    {
			        Dispose();
			    }
			    catch (Exception e)
			    {
			        logger.WarnException("Error on dispose when the ctor threw an exception, resources may have leaked", e);
			    }
				throw;
			}
		}
예제 #5
0
        public IndexDefinitionStorage(TransactionalStorage  transactionalStorage,string path, IEnumerable<AbstractViewGenerator> compiledGenerators)
        {
            this.path = Path.Combine(path, IndexDefDir);

            if (Directory.Exists(this.path) == false)
                Directory.CreateDirectory(this.path);

            foreach (var index in Directory.GetFiles(this.path, "*.index"))
            {
                try
                {
                    AddAndCompileIndex(
                        HttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)),
                        JsonConvert.DeserializeObject<IndexDefinition>(File.ReadAllText(index), new JsonEnumConverter())
                        );
                }
                catch (Exception e)
                {
                    logger.Warn("Could not compile index " + index + ", skipping bad index", e);
                }
            }

            //compiled view generators always overwrite dynamic views
            foreach (var generator in compiledGenerators)
            {
                var copy = generator;
                var displayNameAtt = TypeDescriptor.GetAttributes(copy)
                    .OfType<DisplayNameAttribute>()
                    .FirstOrDefault();

                var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;

                transactionalStorage.Batch(actions =>
                {
                    if (actions.GetIndexesStats().Any(x => x.Name == name))
                        return;

                    actions.AddIndex(name);
                });

                var indexDefinition = new IndexDefinition
                {
                    Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
                    // need to supply this so the index storage will create map/reduce index
                    Reduce = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
                    Indexes = generator.Indexes,
                    Stores = generator.Stores,
                    IsCompiled = true
                };
                indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
                indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
            }
        }
예제 #6
0
        public DocumentDatabase(RavenConfiguration configuration)
        {
            this.configuration = configuration;
            workContext = new WorkContext();
            TransactionalStorage = new TransactionalStorage(configuration.DataDirectory, workContext.NotifyAboutWork);
            bool newDb;
            try
            {
                newDb = TransactionalStorage.Initialize();
            }
            catch (Exception)
            {
                TransactionalStorage.Dispose();
                throw;
            }

            IndexDefinitionStorage = new IndexDefinitionStorage(configuration.DataDirectory);
            IndexStorage = new IndexStorage(configuration.DataDirectory, IndexDefinitionStorage);

            workContext.IndexStorage = IndexStorage;
            workContext.TransactionaStorage = TransactionalStorage;
            workContext.IndexDefinitionStorage = IndexDefinitionStorage;

            if (!newDb)
                return;

            if(configuration.ShouldCreateDefaultsWhenBuildingNewDatabaseFromScratch)
            {
                PutIndex("Raven/DocumentsByEntityName",
                         new IndexDefinition
                         {
                         	Map =
                         		@"
            from doc in docs
            where doc[""@metadata""][""Raven-Entity-Name""] != null
            select new { Tag = doc[""@metadata""][""Raven-Entity-Name""] };
            "
                         });
            }

            configuration.RaiseDatabaseCreatedFromScratch(this);
        }
예제 #7
0
		public DocumentDatabase(RavenConfiguration configuration)
		{
			Configuration = configuration;
			
			configuration.Container.SatisfyImportsOnce(this);

		    workContext = new WorkContext {IndexUpdateTriggers = IndexUpdateTriggers};

			TransactionalStorage = new TransactionalStorage(configuration, workContext.NotifyAboutWork);
			configuration.Container.SatisfyImportsOnce(TransactionalStorage);
			
            bool newDb;
			try
			{
				newDb = TransactionalStorage.Initialize();
			}
			catch (Exception)
			{
				TransactionalStorage.Dispose();
				throw;
			}

			IndexDefinitionStorage = new IndexDefinitionStorage(
                TransactionalStorage,
                configuration.DataDirectory, 
                configuration.Container.GetExportedValues<AbstractViewGenerator>());
			IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration);

			workContext.IndexStorage = IndexStorage;
			workContext.TransactionaStorage = TransactionalStorage;
			workContext.IndexDefinitionStorage = IndexDefinitionStorage;


			InitializeTriggers();
			ExecuteStartupTasks();

			if (!newDb) 
				return;

			OnNewlyCreatedDatabase();
		}
예제 #8
0
 public ViewStorage()
 {
     transactionalStorage = new TransactionalStorage("raven.db.test.esent", () => { });
     transactionalStorage.Initialize();
 }
예제 #9
0
 public TaskExecuter(TransactionalStorage transactionalStorage, WorkContext context)
 {
     this.transactionalStorage = transactionalStorage;
     this.context = context;
 }