/GraphQL/Implementations/SonesGraphQueryLanguage/StatementNodes/DDL/DropVertexTypeNode.cs

http://github.com/sones/sones · C# · 113 lines · 72 code · 21 blank · 20 comment · 0 complexity · d8e2ecd53fc83e339e1f6682533c0633 MD5 · raw file

  1. /*
  2. * sones GraphDB - Community Edition - http://www.sones.com
  3. * Copyright (C) 2007-2011 sones GmbH
  4. *
  5. * This file is part of sones GraphDB Community Edition.
  6. *
  7. * sones GraphDB is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, version 3 of the License.
  10. *
  11. * sones GraphDB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with sones GraphDB. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. using System;
  21. using Irony.Ast;
  22. using Irony.Parsing;
  23. using sones.GraphQL.Result;
  24. using sones.GraphDB;
  25. using sones.Library.Commons.Security;
  26. using sones.Library.Commons.Transaction;
  27. using System.Linq;
  28. using sones.GraphQL.GQL.Manager.Plugin;
  29. using sones.Library.ErrorHandling;
  30. using sones.GraphDB.Request;
  31. using System.Collections.Generic;
  32. namespace sones.GraphQL.StatementNodes.DDL
  33. {
  34. public sealed class DropVertexTypeNode : AStatement, IAstNodeInit
  35. {
  36. #region Data
  37. //the name of the type that should be dropped
  38. String _TypeName = String.Empty;
  39. String _query;
  40. #endregion
  41. #region IAstNodeInit Members
  42. public void Init(ParsingContext context, ParseTreeNode parseNode)
  43. {
  44. #region get Name
  45. _TypeName = parseNode.ChildNodes[3].Token.ValueString;
  46. #endregion
  47. }
  48. #endregion
  49. #region AStatement Members
  50. public override string StatementName
  51. {
  52. get { return "DropVertexType"; }
  53. }
  54. public override TypesOfStatements TypeOfStatement
  55. {
  56. get { return TypesOfStatements.ReadWrite; }
  57. }
  58. public override IQueryResult Execute(IGraphDB myGraphDB,
  59. IGraphQL myGraphQL,
  60. GQLPluginManager myPluginManager,
  61. String myQuery,
  62. SecurityToken mySecurityToken,
  63. Int64 myTransactionToken)
  64. {
  65. _query = myQuery;
  66. return myGraphDB.DropVertexType(mySecurityToken,
  67. myTransactionToken,
  68. new RequestDropVertexType(_TypeName),
  69. GenerateOutput);
  70. }
  71. #endregion
  72. #region helper
  73. private IQueryResult GenerateOutput(IRequestStatistics myStats,
  74. Dictionary<Int64, String> myDeletedTypeIDs)
  75. {
  76. var temp = new Dictionary<String, object>();
  77. foreach(var item in myDeletedTypeIDs)
  78. {
  79. temp.Add("RemovedTypeID", item.Key);
  80. temp.Add("RemovedTypeName", item.Value);
  81. }
  82. return QueryResult.Success(_query,
  83. SonesGQLConstants.GQL,
  84. new IVertexView[]
  85. {
  86. new VertexView( temp, null )
  87. },
  88. Convert.ToUInt64(myStats.ExecutionTime.Milliseconds));
  89. }
  90. #endregion
  91. }
  92. }