public DocumentSchema(StoreOptions options, IConnectionFactory factory, IMartenLogger logger) { _factory = factory; _logger = logger; StoreOptions = options; options.AllDocumentMappings.Each(x => _mappings[x.DocumentType] = x); _sequences = new Lazy <SequenceFactory>(() => { var sequences = new SequenceFactory(this, _factory, options, _logger); var patch = new SchemaPatch(); sequences.GenerateSchemaObjectsIfNecessary(StoreOptions.AutoCreateSchemaObjects, this, patch); apply(sequences, patch); return(sequences); }); Parser = new MartenExpressionParser(StoreOptions.Serializer(), StoreOptions); HandlerFactory = new QueryHandlerFactory(this, options.Serializer()); DbObjects = new DbObjects(_factory, this); addSystemFunction(options, "mt_immutable_timestamp"); }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.ApplyConfiguration(); options.CreatePatching(); options.Validate(); Options = options; _logger = options.Logger(); Serializer = options.Serializer(); _retryPolicy = options.RetryPolicy(); if (options.CreateDatabases != null) { IDatabaseGenerator databaseGenerator = new DatabaseGenerator(); databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases); } Tenancy.Initialize(); Schema = Tenancy.Schema; Storage.PostProcessConfiguration(); Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); Parser = new MartenExpressionParser(Serializer, options); options.InitialData.Each(x => x.Populate(this)); }
public void value_of_constant() { var constant = Expression.Constant("foo"); MartenExpressionParser.Value(constant) .ShouldBe("foo"); }
public void json_locator_of_a_simple_property() { var variable = Expression.Variable(typeof(User), "foo"); var member = Expression.MakeMemberAccess(variable, ReflectionHelper.GetProperty <User>(x => x.FirstName)); MartenExpressionParser.JsonLocator(typeof(User), member) .ShouldBe("data ->> 'FirstName'"); }
public void Configure(MartenExpressionParser parser, IDocumentStorage storage, IQueryableDocument mapping, UpdateBatch batch) { if (Where == null) { batch.Delete(mapping.Table, Id, storage.IdType); } else { batch.DeleteWhere(mapping.Table, Where); } }
protected override IWhereFragment buildWhereFragment(MartenExpressionParser parser) { if (WhereClauses.Count == 0) { return(_storage.DefaultWhereFragment()); } var where = WhereClauses.Count == 1 ? parser.ParseWhereFragment(Fields, WhereClauses.Single().Predicate) : new CompoundWhereFragment(parser, Fields, "and", WhereClauses); return(_storage.FilterDocuments(null, where)); }
protected override IWhereFragment buildWhereFragment(MartenExpressionParser parser) { // TODO -- this logic is duplicated. Pull it into a helper somewhere. // Find the duplication of DefaultWhereFragment/ FilterDocuments in other places if (WhereClauses.Count == 0) { return(_storage.DefaultWhereFragment()); } var where = WhereClauses.Count == 1 ? parser.ParseWhereFragment(Fields, WhereClauses.Single().Predicate) : new CompoundWhereFragment(parser, Fields, "and", WhereClauses); return(_storage.FilterDocuments(null, where)); }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.ApplyConfiguration(); options.CreatePatching(); options.Validate(); Options = options; _logger = options.Logger(); Tenancy = options.Tenancy; if (options.CreateDatabases != null) { IDatabaseGenerator databaseGenerator = new DatabaseGenerator(); databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases); } Tenancy.Initialize(); Schema = Tenancy.Schema; Storage = options.Storage; Storage.PostProcessConfiguration(); Serializer = options.Serializer(); if (options.UseCharBufferPooling) { _writerPool = new CharArrayTextWriter.Pool(); } Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); options.InitialData.Each(x => x.Populate(this)); Parser = new MartenExpressionParser(Serializer, options); HandlerFactory = new QueryHandlerFactory(this); Events = options.Events; }
public DocumentSchema(StoreOptions options, IConnectionFactory factory, IMartenLogger logger) { _factory = factory; _logger = logger; StoreOptions = options; options.AllDocumentMappings.Each(x => _mappings[x.DocumentType] = x); Sequences = new SequenceFactory(this, _factory, options, _logger); Parser = new MartenExpressionParser(StoreOptions.Serializer(), StoreOptions); HandlerFactory = new QueryHandlerFactory(this, options.Serializer()); DbObjects = new DbObjects(_factory, this); }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.Validate(); options.CreatePatching(); Options = options; _logger = options.Logger(); Tenancy = options.Tenancy; Tenancy.Initialize(); Schema = Tenancy.Schema; Storage = options.Storage; Storage.CompileSubClasses(); Serializer = options.Serializer(); if (options.UseCharBufferPooling) { _writerPool = new CharArrayTextWriter.Pool(); } Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); options.InitialData.Each(x => x.Populate(this)); Parser = new MartenExpressionParser(Serializer, options); HandlerFactory = new QueryHandlerFactory(this); Events = options.Events; }
public void DeleteWhere <T>(Expression <Func <T, bool> > expression) { assertNotDisposed(); var parser = new MartenExpressionParser(Options.Serializer(), Options); var model = MartenQueryParser.Flyweight.GetParsedQuery(Query <T>().Where(expression).As <MartenLinqQueryable <T> >().Expression); var storage = StorageFor <T>(); var whereClauses = model.BodyClauses.OfType <WhereClause>().ToArray(); // This is duplicated logic IWhereFragment where = null; switch (whereClauses.Length) { case 0: where = storage.DefaultWhereFragment(); break; case 1: where = parser.ParseWhereFragment(storage.Fields, whereClauses.Single().Predicate); break; default: where = new CompoundWhereFragment(parser, storage.Fields, "and", whereClauses); break; } where = storage.FilterDocuments(null, where); var deletion = storage.DeleteForWhere(@where); _unitOfWork.Add(deletion); }
public void CompileStructure(MartenExpressionParser parser) { Where = buildWhereFragment(parser); Next?.CompileStructure(parser); }
protected virtual IWhereFragment buildWhereFragment(MartenExpressionParser parser) { return(WhereClauses.Count == 1 ? parser.ParseWhereFragment(Fields, WhereClauses.Single().Predicate) : new CompoundWhereFragment(parser, Fields, "and", WhereClauses)); }
protected override void compileStructure(MartenExpressionParser parser) { Inner.CompileStructure(parser); }