public DBRow AddOrReplaceRow(DBRow row) { if (row.Table == this) { throw new InvalidOperationException("Row is already in this table."); } DBRow sameRow = FindRow(row); if (sameRow != null) { if (sameRow.Element("version") != null && row.Element("version") != null) { row.Element("version").Value = sameRow.Element("version").Value; } if (sameRow.Element("_version") != null && row.Element("_version") != null) { row.Element("_version").Value = sameRow.Element("_version").Value; } sameRow.Remove(); } return(AddRow(row)); }
/// <summary> /// Adds the specified rows to table. /// </summary> /// <param name="rows">The rows to add.</param> private void AddRows(IEnumerable <XElement> rows) { foreach (XElement row in rows) { DBRow dbRow = new DBRow(row, this); this.rows.Add(dbRow); } }
/// <summary> /// Adds the empty row to table. /// </summary> /// <returns>Added row.</returns> public DBRow AddRow() { DBRow row = new DBRow(this); this.Xml.Add(row.Xml); this.rows.Add(row); return(row); }
/// <summary> /// Searches for a row with id element same as specified row id element. /// </summary> /// <param name="row">The row to search for.</param> /// <returns>First row that has id same as specified row id element.</returns> public DBRow FindRow(DBRow row) { if (this.rows.Contains(row) == true) { return(row); } return(FindRow(row.Element("id").Value)); }
/// <summary> /// Puts the communication package in outgoing queue. /// </summary> /// <param name="xml">The XML package to save.</param> /// <param name="targetBranches">The target branches.</param> public void SaveOutgoingPackage(ICommunicationPackage xml, IEnumerable <Guid> targetBranches) { if (xml == null) { throw new ArgumentNullException("xml"); } if (targetBranches == null || targetBranches.Count() == 0) { return; } DBTable outgoingXmlQueue = new DBXml().AddTable("outgoingXmlQueue"); foreach (var branchId in targetBranches) { DBRow row = outgoingXmlQueue.AddRow(); row.AddElement("id", Guid.NewGuid().ToUpperString()); row.AddElement("localTransactionId", xml.XmlData.LocalTransactionId.ToUpperString()); row.AddElement("deferredTransactionId", xml.XmlData.DeferredTransactionId.ToUpperString()); row.AddElement("databaseId", branchId.ToUpperString()); row.AddElement("type", xml.XmlData.XmlType); row.AddElement("xml", XElement.Parse(xml.XmlData.Content)); } SqlCommand cmd = this.helper.CreateCommand(StoredProcedure.communication_p_insertOutgoingPackage.ToProcedureName(), new SqlParameter("@xmlVar", SqlDbType.Xml), this.helper.CreateSqlXml(outgoingXmlQueue.Document.Xml)); using (this.Database.SynchronizeConnection()) { try { cmd.ExecuteNonQuery(); } catch (SqlException e) { if (e.Number == 2627) { throw new CommunicationPackageExistsException("Communication package with the same id already exists in the database.", xml.XmlData.Id.ToString(), e); } else { throw; } } } }
/// <summary> /// Searches for a row with id element same as specified row id element. /// </summary> /// <param name="row">The row to search for.</param> /// <param name="tableName">Name of the table.</param> /// <returns> /// First row that has id same as specified row id element. /// </returns> public DBRow FindRow(DBRow row, string tableName) { var machingRow = (from table in this.tables where table.Name.Equals(tableName, StringComparison.Ordinal) select table.FindRow(row)).FirstOrDefault(r => r != null); if (machingRow != null) { return(machingRow); } else { return(FindRow(row.Element("id").Value, tableName)); } }
/// <summary> /// Searches for a row with id element same as specified row id element. /// </summary> /// <param name="row">The row to search for.</param> /// <returns>First row that has id same as specified row id element.</returns> public DBRow FindRow(DBRow row) { var machingRow = (from table in this.tables select table.FindRow(row)).FirstOrDefault(r => r != null); //TODO -1 czy tego nie mozna wywalic? przeciez DBTable robi porownianie po id jak nie znajdzie takiej samej ref //wiec to powoduje podwojne szukanie if (machingRow != null) { return(machingRow); } else { return(FindRow(row.Element("id").Value)); } }
/// <summary> /// Adds the specified row to table. /// </summary> /// <param name="row">The row that is added.</param> /// <returns>Added row.</returns> public DBRow AddRow(DBRow row) { if (row.Table == this) { throw new InvalidOperationException("Row is already in this table."); } else if (row.Table != null) { DBRow newRow = new DBRow(new XElement(row.Xml), this); this.Xml.Add(newRow.Xml); newRow.Table = this; this.rows.Add(newRow); return(newRow); } else { this.Xml.Add(row.Xml); row.Table = this; this.rows.Add(row); return(row); } }
/// <summary> /// Removes the specified row from table. /// </summary> /// <param name="row">The row that is removed.</param> internal void RemoveRow(DBRow row) { this.rows.Remove(row); row.Xml.Remove(); }
/// <summary> /// Determines whether this row is the same as the specified row by comparing rows version element. /// </summary> /// <param name="row">The row to compare against.</param> /// <returns> /// <c>true</c> if this row is the same as the specified row; otherwise, <c>false</c>. /// </returns> public bool IsTheSameAs(DBRow row) { return(this.Element("version").Value.Equals(row.Element("version").Value, StringComparison.OrdinalIgnoreCase)); }