Example #1
0
        T IQueryExecutor.ExecuteScalar <T>(QueryModel queryModel)
        {
            if (queryModel.ResultOperators.OfType <AnyResultOperator>().Any())
            {
                var storage    = _schema.StorageFor(queryModel.SelectClause.Selector.Type);
                var anyCommand = storage.AnyCommand(queryModel);

                return(_runner.Execute(conn =>
                {
                    anyCommand.Connection = conn;
                    return (T)anyCommand.ExecuteScalar();
                }));
            }

            if (queryModel.ResultOperators.OfType <CountResultOperator>().Any())
            {
                var storage      = _schema.StorageFor(queryModel.SelectClause.Selector.Type);
                var countCommand = storage.CountCommand(queryModel);

                return(_runner.Execute(conn =>
                {
                    countCommand.Connection = conn;
                    var returnValue = countCommand.ExecuteScalar();
                    return Convert.ToInt32(returnValue).As <T>();
                }));
            }

            throw new NotSupportedException();
        }
Example #2
0
        public void DeleteEntity <T>(T entity)
        {
            var id   = _schema.StorageFor(typeof(T)).Identity(entity);
            var list = _deletes.GetOrAdd(typeof(T), _ => new List <PendingDeletion>());

            list.Add(new PendingDeletion(typeof(T), id, entity));
        }
Example #3
0
        private string findJsonById <T>(object id)
        {
            var storage = _schema.StorageFor(typeof(T));

            var loader = storage.LoaderCommand(id);

            return(_connection.Execute(loader, c => loader.ExecuteScalar() as string));
        }
Example #4
0
        public void Delete <T>(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            _unitOfWork.DeleteEntity(entity);

            var storage = _schema.StorageFor(typeof(T));

            storage.Remove(_identityMap, entity);
        }
Example #5
0
        public when_deriving_the_table_definition_from_the_database_schema_Tests()
        {
            _schema = theStore.Schema;

            theMapping = _schema.MappingFor(typeof(User)).As<DocumentMapping>();
            theMapping.DuplicateField("UserName");

            _storage = _schema.StorageFor(typeof(User));

            theDerivedTable = _schema.DbObjects.TableSchema(theMapping);
        }
        public when_deriving_the_table_definition_from_the_database_schema_Tests()
        {
            _schema = theStore.Schema;

            theMapping = _schema.MappingFor(typeof(User)).As <DocumentMapping>();
            theMapping.DuplicateField("UserName");


            _storage = _schema.StorageFor(typeof(User));

            theDerivedTable = _schema.DbObjects.TableSchema(theMapping);
        }
Example #7
0
        public Guid StartStream <T>(params IEvent[] events) where T : IAggregate
        {
            // TODO --- temp!
            var streamStorage = _schema.StorageFor(typeof(Stream <T>)) as IAggregateStorage;
            var stream        = Guid.NewGuid();

            events.Each(@event =>
            {
                var mapping = _schema.Events.EventMappingFor(@event.GetType());

                appendEvent(mapping, stream, @event, streamStorage.StreamTypeName);
            });

            return(stream);
        }
Example #8
0
        private Action <TInclude> GetJoinDictionaryCallback <TKey, TInclude>(PropertyInfo property, IncludeResultOperator @operator, ICompiledQuery <TDoc, TOut> query)
        {
            var queryProperty = GetPropertyInfo(property, @operator);

            var storage = _schema.StorageFor(typeof(TInclude));

            var dictionary = (IDictionary <TKey, TInclude>)(queryProperty).GetValue(query);

            if (dictionary == null)
            {
                queryProperty.SetValue(query, new Dictionary <TKey, TInclude>());
                dictionary = (IDictionary <TKey, TInclude>)queryProperty.GetValue(query);
            }

            return(x => {
                var id = storage.Identity(x).As <TKey>();
                if (!dictionary.ContainsKey(id))
                {
                    dictionary.Add(id, x);
                }
            });
        }
Example #9
0
        private Task <T> load <T>(object id) where T : class
        {
            if (_identityMap.Has <T>(id))
            {
                return(Task.FromResult(_identityMap.Retrieve <T>(id)));
            }

            var source = new TaskCompletionSource <T>();

            var mapping   = _schema.MappingFor(typeof(T));
            var parameter = _command.AddParameter(id);

            _command.AppendQuery(
                $"select {mapping.SelectFields("d")} from {mapping.TableName} as d where id = :{parameter.ParameterName}");

            var handler = new SingleResultReader <T>(source, _schema.StorageFor(typeof(T)), _identityMap);

            addHandler(handler);

            return(source.Task);
        }
 private IResolver <T> resolver <T>()
 {
     return(_schema.StorageFor(typeof(T)).As <IResolver <T> >());
 }
Example #11
0
 /// <summary>
 ///     Compiles all of the IDocumentStorage classes upfront for all known document types
 /// </summary>
 /// <returns></returns>
 public IList <IDocumentStorage> PrecompileAllStorage()
 {
     return(Options.AllDocumentMappings.Select(x => _schema.StorageFor(x.DocumentType)).ToList());
 }
Example #12
0
 private IDocumentStorage storage <T>()
 {
     return(_schema.StorageFor(typeof(T)));
 }
Example #13
0
        public void DeleteEntity <T>(T entity)
        {
            var id = _schema.StorageFor(typeof(T)).Identity(entity);

            delete <T>(id);
        }