private void LoadObjects(XmlReader reader) { var metaObjectIdString = reader.GetAttribute(Serialization.Id); var metaObjectId = new Guid(metaObjectIdString); var objectType = (IObjectType)this.ObjectFactory.MetaPopulation.Find(metaObjectId); if (!reader.IsEmptyElement) { var oidsString = reader.ReadString(); var oids = oidsString.Split(Serialization.ObjectsSplitterCharArray); for (var i = 0; i < oids.Length; i++) { var objectArray = oids[i].Split(Serialization.ObjectSplitterCharArray); var objectId = new ObjectIdLong(long.Parse(objectArray[0])); var cacheId = new ObjectVersionLong(objectArray[1]); if (!(objectType is IClass)) { this.OnObjectNotLoaded(metaObjectId, objectId.ToString()); } else { // Objects var cmdText = @" INSERT INTO " + Mapping.TableNameForObjects + " (" + Mapping.ColumnNameForObject + "," + Mapping.ColumnNameForType + "," + Mapping.ColumnNameForCache + @") VALUES (" + Mapping.ParameterNameForObject + "," + Mapping.ParameterNameForType + "," + Mapping.ParameterNameForCache + ")"; using (var command = this.CreateCommand(cmdText)) { command.Parameters.Add(Mapping.ParameterNameForObject, Mapping.DbTypeForId).Value = objectId.Value; command.Parameters.Add(Mapping.ParameterNameForType, Mapping.DbTypeForType).Value = objectType.Id; command.Parameters.Add(Mapping.ParameterNameForCache, Mapping.DbTypeForCache).Value = cacheId.Value; command.ExecuteNonQuery(); } } } } }
protected void SaveObjects(ManagementSession session) { var concreteCompositeType = new List<IClass>(this.database.MetaPopulation.Classes); concreteCompositeType.Sort(); foreach (var type in concreteCompositeType) { var atLeastOne = false; var sql = "SELECT " + Mapping.ColumnNameForObject + ", " + Mapping.ColumnNameForCache + "\n"; sql += "FROM " + this.database.Mapping.TableNameForObjects + "\n"; sql += "WHERE " + Mapping.ColumnNameForType + "=" + Mapping.ParamNameForType+ "\n"; sql += "ORDER BY " + Mapping.ColumnNameForObject; using (var command = session.CreateCommand(sql)) { command.AddInParameter(Mapping.ParamNameForType, type.Id); using (var reader = command.ExecuteReader()) { while (reader.Read()) { if (atLeastOne == false) { atLeastOne = true; this.writer.WriteStartElement(Serialization.ObjectType); this.writer.WriteAttributeString(Serialization.Id, type.Id.ToString()); } else { this.writer.WriteString(Serialization.ObjectsSplitter); } var objectId = this.database.ObjectIds.Parse(reader[0].ToString()); var cacheId = new ObjectVersionLong(reader[1].ToString()); this.writer.WriteString(objectId.Value + Serialization.ObjectSplitter + cacheId.Value); } reader.Close(); } } if (atLeastOne) { this.writer.WriteEndElement(); } } }
private void LoadObjects(XmlReader reader) { var metaObjectIdString = reader.GetAttribute(Serialization.Id); var metaObjectId = new Guid(metaObjectIdString); var objectType = (IObjectType)this.ObjectFactory.MetaPopulation.Find(metaObjectId); if (!reader.IsEmptyElement) { var oidsString = reader.ReadString(); var oids = oidsString.Split(Serialization.ObjectsSplitterCharArray); for (var i = 0; i < oids.Length; i++) { var objectArray = oids[i].Split(Serialization.ObjectSplitterCharArray); var objectId = new ObjectIdLong(long.Parse(objectArray[0])); var cacheId = new ObjectVersionLong(objectArray[1]); if (!(objectType is IClass)) { this.OnObjectNotLoaded(metaObjectId, objectId.ToString()); } else { // Objects var cmdText = @" INSERT INTO " + this.SchemaName + "." + Mapping.TableNameForObjects + " (" + Mapping.ColumnNameForObject + "," + Mapping.ColumnNameForType + "," + Mapping.ColumnNameForCache + @") VALUES (" + Mapping.ParameterNameForObject + "," + Mapping.ParameterNameForType + "," + Mapping.ParameterNameForCache + ")"; using (var command = this.CreateCommand(cmdText)) { command.Parameters.Add(Mapping.ParameterNameForObject, this.mapping.SqlDbTypeForObject).Value = objectId.Value; command.Parameters.Add(Mapping.ParameterNameForType, Mapping.SqlDbTypeForType).Value = objectType.Id; command.Parameters.Add(Mapping.ParameterNameForCache, Mapping.SqlDbTypeForCache).Value = cacheId.Value; command.ExecuteNonQuery(); } } } } }