Exemple #1
0
        public async Task CommitInternal()
        {
            if (!_mutations.Any())
            {
                return;
            }

            var queries = _mutations.Select(p => p.Query).ToList();
            var ret     = new Return(queries.OfType <Let>().ToArray());

            queries.Add(ret);
            var batch   = new OrientQueryBatch(_graph.Setup.Connection, queries.ToArray());
            var command = new Batch <List <ReturnResult> >(batch, _graph.Setup.Client);
            var result  = (await command.Execute()) switch
            {
                Result <List <ReturnResult>, Exception> .OkCase o => o
                .Payload.SelectMany(p => p.Value)
                .ToDictionary(p => p[0], p => p[1]),
                Result <List <ReturnResult>, Exception> .ErrCase e => throw e.Payload,
                      _ => throw new InvalidCastException()
            };

            Debug.WriteLine("database -> ok");
            foreach (var mutation in _mutations.OrderBy(p => p.Idx))
            {
                await mutation.RefreshItem(result, _graph.Setup.Connection, _graph.Setup.Client);

                mutation.Apply(_graph);
            }

            Debug.WriteLine("graph -> ok");
            _mutations.Clear();
        }
Exemple #2
0
        public async Task <IEnumerable <OrientTypeScheme> > ReadScheme()
        {
            var query       = new ReadSchemeQuery();
            var batchQuery  = new OrientQueryBatch(await GetConnection(), query.Query);
            var batch       = new Batch <List <OrientTypeScheme> >(batchQuery, _restClient);
            var batchResult = await batch.Execute();

            var result = batchResult switch
            {
                Result <List <OrientTypeScheme>, Exception> .OkCase ok => ok.Payload,
                Result <List <OrientTypeScheme>, Exception> .ErrCase err => throw err.Payload,
                      _ => throw new InvalidOperationException()
            };

            return(result);
        }
Exemple #3
0
        public async Task RefreshItem(Dictionary <string, string> result, OrientConnection setupConnection, IRestClient setupClient)
        {
            var rid     = new Rid(Item.IsNew() ? result[Identifier.Sql] : Item.Rid);
            var select  = new Select(new From(rid));
            var batch   = new OrientQueryBatch(setupConnection, select);
            var command = new Batch <List <T> >(batch, setupClient);
            var res     = await command.Execute() switch
            {
                Result <List <T>, Exception> .OkCase o => o.Payload,
                Result <List <T>, Exception> .ErrCase e => throw e.Payload,
                      _ => throw new InvalidCastException()
            };

            DbItem = res.FirstOrDefault();
        }
    }
        public GraphSetup Add <T>() where T : GraphItem
        {
            async Task <List <GraphItem> > Download()
            {
                var query       = new ReadAllQuery <T>();
                var batchQuery  = new OrientQueryBatch(Connection, query.Query);
                var batch       = new Batch <List <T> >(batchQuery, Client);
                var batchResult = await batch.Execute();

                var result = batchResult switch
                {
                    Result <List <T>, Exception> .OkCase ok => ok.Payload,
                    Result <List <T>, Exception> .ErrCase err => throw err.Payload,
                          _ => throw new InvalidOperationException()
                };

                return(result.Cast <GraphItem>().ToList());
            }

            Downloads.Add(typeof(T), Download());
            return(this);
        }
Exemple #5
0
 public Batch(OrientQueryBatch input, IRestClient client) : base(input, client)
 {
 }