internal InternalRoot(DbNode node) { IsMapper = true; Name = node.Name; IsEmbeddedTransaction = false; Node = node; }
// Updates.Apply() -> Database.Update() -> Node.Validate() internal bool Validate() { // If no ANode, then we're invalid if (_aNode == null) { return(false); } // If we're not a database node, then always valid if (DbNode == null) { return(true); } // First check if the pre value is too large (the database shrunk), // then check if the current pre still refers to the same id // (do second since it requires disk access and is thus a little slower) if (DbNode.pre >= DbNode.data().meta.size || _id != DbNode.data().id(DbNode.pre)) { int pre = DbNode.data().pre(_id); if (pre == -1) { Invalidate(); return(false); } DbNode.set(pre, _kind); // Assume that the kind is the same since we found the same ID } return(true); }
private static void CheckSynonymAndThrow(DbNode synonym) { if (!synonym.IsTable()) { throw new QueryTalkException(".UseAs", QueryTalkExceptionType.InvalidSynonym, String.Format("synonym = {0}", synonym), Text.Method.JoinSynonym); } }
private static Chainer _Translate(DbNode node) { var subject = node.Root; var context = new SemqContext(subject); var query = ((ISemantic)subject).Translate(context, null); return(((ISelect)query).Select().Top(subject.Top, 0)); }
/// <summary> /// Returns the identifier of a specified node. /// </summary> /// <param name="node">Is the node object.</param> public static Identifier I(this DbNode node) { // check null if (node == null) { throw new QueryTalkException("I", QueryTalkExceptionType.ArgumentNull, "node = null", Text.Method.I); } return(DbMapping.GetNodeName(node.NodeID)); }
/// <summary> /// Implementation of the Translate method. /// </summary> Chainer ISemantic.Translate(SemqContext context, DbNode predecessor) { if (_dbColumn != null && (ISemantic)_dbColumn.Parent != null) { return(((ISemantic)_dbColumn.Parent).Translate(context, predecessor)); } else { return(null); } }
public ClientNode CreateNode(ClientNode clientNode) { DbNode dbNode = new DbNode(); // mapping dbNode = Post("api/graph/node", dbNode).Result; // mapping return(clientNode); }
public static async Task InitializeData(TreeContext context) { context.Database.Migrate(); if (!context.Nodes.Any()) { var node = new DbNode[] { new DbNode { Level = 0, Name = "root", ParentId = null } }; context.Nodes.AddRange(node); await context.SaveChangesAsync(); var rootId = context.Nodes.FirstOrDefault().IdNode; var nodes = new DbNode[] { new DbNode { Level = 1, Name = "First", ParentId = rootId }, new DbNode { Level = 1, Name = "Second", ParentId = rootId }, new DbNode { Level = 1, Name = "Text", ParentId = rootId }, new DbNode { Level = 1, Name = "Any", ParentId = rootId } }; context.Nodes.AddRange(nodes); await context.SaveChangesAsync(); } }
public async Task <int> Post([FromBody] CoordinatesArg arg) { _log.Information("create node {coordinates}", arg); using (var dbGraphContext = new DbGraphContext(_options)) { var node = new DbNode { Latitude = arg.Latitude, Longitude = arg.Longitude }; dbGraphContext.Add(node); await dbGraphContext.SaveChangesAsync(); return(node.Id); } }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { int result = 17; if (DbNode != null) { result = 37 * result + _id.GetHashCode(); result = 37 * result + DbNode.data().GetHashCode(); } else if (ANode != null) { result = 37 * ANode.id; } return(result); }
private DbNode <T> GetNodeByIndex(int index) { if (index < 0 || index > count) { throw new ArgumentOutOfRangeException("index", "索引超出范围"); } DbNode <T> tempNode = this.head; for (int i = 0; i < index; i++) { tempNode = tempNode.Next; } return(tempNode); }
/// <summary> /// Implicitly converts an argument into the object of TableArgument type. /// </summary> /// <param name="arg">An argument to convert.</param> public TableArgument(DbNode arg) : base(arg) { if (CheckNull(Arg(() => arg, arg))) { Sql = arg.Name; } Build = (buildContext, buildArgs) => { buildContext.TryTakeException(chainException); return(Sql); }; SetArgType(arg); }
public void Display() { if (head == null) { Console.WriteLine("List is empty"); return; } DbNode <T> p = head; while (p != null) { Console.WriteLine(p.Data); p = p.Next; } }
public void AddAfter(T value) { DbNode <T> newNode = new DbNode <T>(value); if (this.head == null) { // 如果链表当前为空则置为头结点 this.head = newNode; } else { DbNode <T> lastNode = this.GetNodeByIndex(this.count - 1); // 调整插入节点与前驱节点指针关系 lastNode.Next = newNode; newNode.Prev = lastNode; } this.count++; }
public async Task <List <VMDeleteNodeResult> > DeleteAsync(Guid id) { List <DbNode> deletedNodes = new List <DbNode>(); var node = new DbNode { IdNode = id }; try { var result = _context.Nodes.Remove(node); deletedNodes.Add(result.Entity); var childs = await _context.Nodes.Where(x => x.ParentId == result.Entity.IdNode).Select(x => x.IdNode).ToListAsync(); foreach (var childId in childs) { node = new DbNode { IdNode = childId }; result = _context.Nodes.Remove(node); deletedNodes.Add(result.Entity); } } catch (ArgumentException) { return(null); } await _context.SaveChangesAsync(); var viewModels = new List <VMDeleteNodeResult>(); foreach (var deletedNode in deletedNodes) { var viewModel = new VMDeleteNodeResult(); viewModel.IdNode = deletedNode.IdNode; viewModels.Add(viewModel); } return(viewModels); }
public T Delete(int i) { if (IsEmpty() || i < 0) { Console.WriteLine("Link is empty or Position is error"); return(default(T)); } DbNode <T> q = new DbNode <T>(); if (i == 1) { q = head; head = head.Next; return(q.Data); } return(default(T)); }
/// <summary> /// /// </summary> /// <param name="value"></param> public void AddBefore(T value) { DbNode <T> newNode = new DbNode <T>(value); if (this.head == null) { // 如果链表当前为空则置为头结点 this.head = newNode; } else { DbNode <T> lastNode = this.GetNodeByIndex(this.count - 1); DbNode <T> prevNode = lastNode.Prev; // 调整倒数第2个节点与插入节点的关系 prevNode.Next = newNode; newNode.Prev = prevNode; // 调整倒数第1个节点与插入节点的关系 lastNode.Prev = newNode; newNode.Next = lastNode; } this.count++; }
public void Append(T item) { DbNode <T> q = new DbNode <T>(item); DbNode <T> p = new DbNode <T>(); //如果双向链表是空表 if (head == null) { head = q; return; } //如果双向链表不为空,尾插法 p = head; while (p.Next != null) { p = p.Next; } p.Next = q; q.Prev = p; q.Next = null; }
public async Task MoveNode(VMMoveNodeData node, Guid id) { var nodeList = new List <DbNode>(); var destinationLevel = _context.Nodes.Where(x => x.IdNode == node.DestinationId).Select(x => x.Level).FirstOrDefault(); var slectedName = _context.Nodes.Where(x => x.IdNode == id).Select(x => x.Name).FirstOrDefault(); var newNode = new DbNode { IdNode = id, Name = slectedName, Level = destinationLevel + 1, ParentId = node.DestinationId }; nodeList.Add(newNode); var childsList = _context.Nodes.Where(x => x.ParentId == id).ToList(); foreach (var child in childsList) { newNode = new DbNode { IdNode = child.IdNode, Name = child.Name, Level = destinationLevel + 2, ParentId = child.ParentId }; nodeList.Add(newNode); } await DeleteAsync(id); foreach (var createdNode in nodeList) { var result = await _context.Nodes.AddAsync(createdNode); } _context.SaveChanges(); }
public DbNode(T val) { data = val; next = null; }
internal static void ThrowInvalidPredicateGroupingException(DbNode subject) { throw new QueryTalkException("PredicateGroup.ThrowInvalidPredicateGroupingException", QueryTalkExceptionType.InvalidPredicateGrouping, null, Text.Method.PredicateGrouping).SetObjectName(subject.Name); }
public DbNode() { _data = default(T); _next = null; }
public DbNode(T val) { _data = val; _next = null; }
public DbNode(DbNode <T> p) { _next = p; }
private DbNode <T> _next; //后驱引用域 public DbNode(T val, DbNode <T> p) { _data = val; _next = p; }
public DbNode(DbNode <T> p) { this.next = p; }
internal static DB3 GetFK(this DbNode table) { return(((IRelation)table).FK); }
public DbNode() { data = default(T); next = null; }
private XElement GetItemByNode(DbNode node, XElement format) { XElement xel = node.xel; if (xel == null) { return(null); } string type = xel.Name.NamespaceName + xel.Name.LocalName; //var ft = format.Attribute("type")?.Value; //if (ft != null && type != ft) return null; return(new XElement("record", new XAttribute("id", xel.Attribute(Cassettes.ONames.rdfabout).Value), new XAttribute("type", type), format.Elements().Where(fel => fel.Name == "field" || fel.Name == "direct" || fel.Name == "inverse") .SelectMany(fel => { string prop = fel.Attribute("prop").Value; if (fel.Name == "field") { return xel.Elements() .Where(el => el.Name.NamespaceName + el.Name.LocalName == prop) .Select(el => new XElement("field", new XAttribute("prop", prop), el.Value)); } else if (fel.Name == "direct") { return xel.Elements() .Where(el => el.Name.NamespaceName + el.Name.LocalName == prop) .Select <XElement, XElement>(el => { if (!records.TryGetValue(el.Attribute(Cassettes.ONames.rdfresource).Value, out DbNode node2) || node2.xel == null) { return null; } string t = node2.xel.Name.NamespaceName + node2.xel.Name.LocalName; XElement f = fel.Elements("record") .FirstOrDefault(fr => { XAttribute t_att = fr.Attribute("type"); if (t_att == null) { return true; } return t_att.Value == t; }); if (f == null) { return null; } return new XElement("direct", new XAttribute("prop", prop), GetItemByNode(node2, f)); }); } else if (fel.Name == "inverse") { //return node.inverse // .Where(el => el.Name.NamespaceName + el.Name.LocalName == prop) // .Select(el => new XElement("inverse", new XAttribute("prop", prop), // fel.Element("record") == null ? null : // GetItemById(el.Parent.Attribute(Cassettes.ONames.rdfabout).Value, fel.Element("record")))); return node.inverse .Where(el => el.Name.NamespaceName + el.Name.LocalName == prop) .Select <XElement, XElement>(el => { if (!records.TryGetValue(el.Parent.Attribute(Cassettes.ONames.rdfabout).Value, out DbNode node2) || node2.xel == null) { return null; } string t = node2.xel.Name.NamespaceName + node2.xel.Name.LocalName; XElement f = fel.Elements("record") .FirstOrDefault(fr => { XAttribute t_att = fr.Attribute("type"); if (t_att == null) { return true; } return t_att.Value == t; }); if (f == null) { return null; } return new XElement("inverse", new XAttribute("prop", prop), GetItemByNode(node2, f)); }); } else { return null; } }))); }
private DbNode <T> next; //后继应用域 public DbNode(T val, DbNode <T> p) { this.data = val; this.next = p; }