Пример #1
0
        public override QueryResult Import(IEnumerable<String> myLines, IGraphDBSession myIGraphDBSession, DBContext myDBContext, UInt32 parallelTasks = 1, IEnumerable<String> comments = null, ulong? offset = null, ulong? limit = null, VerbosityTypes verbosityTypes = VerbosityTypes.Errors)
        {
            var gqlQuery = new GraphQLQuery(myDBContext.DBPluginManager);

            #region Evaluate Limit and Offset

            if (offset != null)
            {
                myLines = myLines.SkipULong(offset.Value);
            }
            if (limit != null)
            {
                myLines = myLines.TakeULong(limit.Value);
            }

            #endregion

            var queryResult = new QueryResult();

            #region Import queries

            if (parallelTasks > 1)
            {
                queryResult = ExecuteAsParallel(myLines, myIGraphDBSession, gqlQuery, verbosityTypes, parallelTasks, comments);
            }
            else
            {
                queryResult = ExecuteAsSingleThread(myLines, myIGraphDBSession, gqlQuery, verbosityTypes, comments);
            }

            #endregion

            return queryResult;
        }
Пример #2
0
        protected QueryResult QueryDB(AGraphDSSharp myGraphDSSharp, String myQueryString, Boolean myWithOutput = true)
        {
            if (myWithOutput)
                Write(myQueryString + " => ");

            var GQLQuery = new GraphQLQuery(myGraphDSSharp.IGraphDBSession.DBPluginManager);
            var _QueryResult = GQLQuery.Query(myQueryString, myGraphDSSharp.IGraphDBSession);

            if (myWithOutput)
                WriteLine(_QueryResult.ResultType.ToString());

            if (_QueryResult == null)
                WriteLine("The QueryResult is invalid!\n\n");

            else if (_QueryResult.ResultType != ResultType.Successful)
                foreach (var aError in _QueryResult.Errors)
                    WriteLine(aError.GetType().ToString() + ": " + aError.ToString() + "\n\n");

            return _QueryResult;
        }
Пример #3
0
        public override QueryResult Import(System.IO.Stream myInputStream, IGraphDBSession myIGraphDBSession, DBContext myDBContext, UInt32 myParallelTasks = 1, IEnumerable<String> myComments = null, ulong? myOffset = null, ulong? myLimit = null, VerbosityTypes myVerbosityType = VerbosityTypes.Errors)
        {
            var gqlQuery = new GraphQLQuery(myDBContext.DBPluginManager);

            var lines = ReadLinesFromStream(myInputStream);

            #region Evaluate Limit and Offset

            if (myOffset != null)
            {
                lines = lines.SkipULong(myOffset.Value);
            }
            if (myLimit != null)
            {
                lines = lines.TakeULong(myLimit.Value);
            }

            #endregion

            var queryResult = new QueryResult();

            #region Import queries

            if (myParallelTasks > 1)
            {
                queryResult = ExecuteAsParallel(lines, myIGraphDBSession, gqlQuery, myVerbosityType, myParallelTasks, myComments);
            }
            else
            {
                queryResult = ExecuteAsSingleThread(lines, myIGraphDBSession, gqlQuery, myVerbosityType, myComments);
            }

            #endregion

            return queryResult;
        }
Пример #4
0
        public override Exceptional Execute(AGraphDSSharp myAGraphDSSharp, ref String myCurrentPath, Dictionary<String, List<AbstractCLIOption>> myOptions, String myInputString)
        {
            if (myAGraphDSSharp == null)
                return new Exceptional(new GraphDSError("myAGraphDSSharp must not be null!"));

            var gqlQuery = new GraphQLQuery(myAGraphDSSharp.IGraphDBSession.DBPluginManager);

            Boolean isSuccessful = true;
            int numberOfStatement = 1;
            Stopwatch sw = new Stopwatch();
            String ScriptFile = myOptions.ElementAt(1).Value[0].Option;

            //((FSSessionInfo)_IGraphFS2Session.SessionToken.SessionInfo).FSSettings.AutoCommitAfterNumberOfPendingTransactions = 1000;

            String line = "";
            try
            {
                StreamReader reader = new StreamReader(ScriptFile);

                //_IGraphFS2Session.BeginTransaction();

                sw.Start();
                while ((line = reader.ReadLine()) != null)
                {
                    if (!ExecuteAQuery(line.Trim(), myAGraphDSSharp.IGraphDBSession, gqlQuery))
                    {
                        WriteLine("Error while executing query: \"" + line + "\"");

                        isSuccessful= false;
                        break;
                    }

                    if (line.Length != 0)
                    {
                        numberOfStatement++;
                    }

                    if (_CancelCommand)
                    {
                        Console.WriteLine("... parsing stopped.");
                        break;
                    }

                }

                sw.Stop();
                reader.Close();

            }
            catch
            {
                // Fehler beim Öffnen der Datei
            }

            if (isSuccessful)
            {
                WriteLine("\nSuccessfully executed " + numberOfStatement + " statements in " + sw.Elapsed.Seconds + " seconds.");
                //_IGraphFS2Session.CommitTransaction();
            }
            else
            {
                //_IGraphFS2Session.RollbackTransaction();
            }

            return Exceptional.OK;
        }
Пример #5
0
        private bool ExecuteAQuery(string query, IGraphDBSession dbSession, GraphQLQuery myGQLQuery)
        {
            if (query.Length != 0)
            {
                //execute query
                QueryResult myQueryResult = myGQLQuery.Query(query, dbSession);

                WriteLine(query);

                HandleQueryResult(myQueryResult, false);

                if (myQueryResult.ResultType != ResultType.Successful)
                {
                    WriteLine(myQueryResult.GetIErrorsAsString());
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return true;
            }
        }
Пример #6
0
        private QueryResult ExecuteAsParallel(IEnumerable<String> myLines, IGraphDBSession myIGraphDBSession, GraphQLQuery myGQLQuery, VerbosityTypes verbosityTypes, UInt32 parallelTasks = 1, IEnumerable<String> comments = null)
        {
            var queryResult       = new QueryResult();
            var aggregatedResults = new List<IEnumerable<Vertex>>();

            #region Create parallel options

            var parallelOptions = new ParallelOptions()
            {
                MaxDegreeOfParallelism = (int)parallelTasks
            };

            #endregion

            Int64 numberOfLine = 0;

            Parallel.ForEach(myLines, parallelOptions, (line, state) =>
            {

                if (!IsComment(line, comments))
                {

                    Interlocked.Add(ref numberOfLine, 1L);

                    if (!IsComment(line, comments)) // Skip comments
                    {

                        var qresult = ExecuteQuery(line, myIGraphDBSession, myGQLQuery);

                        #region VerbosityTypes.Full: Add result

                        if (verbosityTypes == VerbosityTypes.Full)
                        {
                            lock (aggregatedResults)
                            {
                                aggregatedResults.Add(qresult.Vertices);
                            }
                        }

                        #endregion

                        #region !VerbosityTypes.Silent: Add errors and break execution

                        if (qresult.ResultType != ResultType.Successful && verbosityTypes != VerbosityTypes.Silent)
                        {
                            lock (queryResult)
                            {
                                queryResult.PushIErrors(new[] { new Errors.Error_ImportFailed(line, numberOfLine) });
                                queryResult.PushIErrors(qresult.Errors);
                                queryResult.PushIWarnings(qresult.Warnings);
                            }
                            state.Break();
                        }

                        #endregion

                    }

                }

            });

            //add the results of each query into the queryResult
            queryResult.Vertices = AggregateListOfListOfVertices(aggregatedResults);

            return queryResult;
        }
Пример #7
0
 private QueryResult ExecuteQuery(String myQuery, IGraphDBSession myIGraphDBSession, GraphQLQuery myGQLQuery)
 {
     return myGQLQuery.Query(myQuery, myIGraphDBSession);
 }
Пример #8
0
        private QueryResult ExecuteAsSingleThread(IEnumerable<String> myLines, IGraphDBSession myIGraphDBSession, GraphQLQuery myGQLQuery, VerbosityTypes verbosityTypes, IEnumerable<String> comments = null)
        {
            var queryResult1 = new QueryResult();
            Int64 numberOfLine = 0;
            var query = String.Empty;
            var aggregatedResults = new List<IEnumerable<Vertex>>();

            foreach (var _Line in myLines)
            {

                numberOfLine++;

                #region Skip comments

                if (IsComment(_Line, comments))
                {
                    continue;
                }

                #endregion

                query += _Line;

                var qresult = ExecuteQuery(query, myIGraphDBSession, myGQLQuery);

                #region VerbosityTypes.Full: Add result

                if (verbosityTypes == VerbosityTypes.Full)
                {
                    aggregatedResults.Add(qresult.Vertices);
                }

                #endregion

                #region !VerbosityTypes.Silent: Add errors and break execution

                if (qresult.ResultType == ResultType.Failed)
                {

                    if (qresult.Errors.Any(e => (e is Error_GqlSyntax) && (e as Error_GqlSyntax).SyntaxErrorMessage.Equals("Mal-formed  string literal - cannot find termination symbol.")))
                    {
                        Debug.WriteLine("Query at line [" + numberOfLine + "] [" + query + "] failed with " + qresult.GetIErrorsAsString() + " add next line...");
                        continue;
                    }

                    if (verbosityTypes != VerbosityTypes.Silent)
                    {
                        queryResult1.PushIError(new Error_ImportFailed(query, numberOfLine));
                        queryResult1.PushIErrors(qresult.Errors);
                        queryResult1.PushIWarnings(qresult.Warnings);
                    }

                    break;

                }
                else if (qresult.ResultType == ResultType.PartialSuccessful && verbosityTypes != VerbosityTypes.Silent)
                {
                    queryResult1.PushIWarning(new Warning_ImportWarning(query, numberOfLine));
                    queryResult1.PushIWarnings(qresult.Warnings);
                }

                #endregion

                query = String.Empty;

            }

            //add the results of each query into the queryResult
            queryResult1.Vertices = AggregateListOfListOfVertices(aggregatedResults);

            return queryResult1;
        }
Пример #9
0
 public GraphDSREST_Service(AGraphDSSharp myAGraphDSSharp)
 {
     _AGraphDSSharp    = myAGraphDSSharp;
     _GraphQLQuery     = new GraphQLQuery(_AGraphDSSharp.IGraphDBSession.DBPluginManager);
     //            _SessionSonesCLIs = new Dictionary<String, sonesCLI>();
 }