/// <override></override> public override void CreateDbCommands(IStoreCache storeCache) { base.CreateDbCommands(storeCache); // // === Commands to create and drop the schema === SetCreateTablesCommand(CreateCreateTablesCommand(storeCache)); SetCommand("All", RepositoryCommandType.Delete, CreateDropTablesCommand(storeCache)); // CreateProjectInfoCommands(); // CreateProjectCommands(); // CreateDesignCommands(); // CreateStyleCommands(storeCache); // CreateDiagramCommands(); // CreateLayerCommands(); // CreateShapeCommands(storeCache); // CreateModelCommands(); // CreateModelObjectCommands(storeCache); // CreateTemplateCommands(); // CreateModelMappingCommands(); }
public MessageStore(DirectoryInfo workingDirectory) { this.WorkingDirectory = workingDirectory; this.cache = new StoreCache(); this.log = new StoreLogger(); this.fileStore = new FileStore(workingDirectory); }
/// <summary> /// Closes the project store. /// </summary> /// <param name="storeCache"></param> public virtual void Close(IStoreCache storeCache) { if (storeCache == null) { throw new ArgumentNullException("storeCache"); } // Nothing to do yet. }
/// <summary> /// Loads all templates of the project into the given store cache. /// </summary> public abstract void LoadTemplates(IStoreCache cache, object projectId);
private void CreateShapeCommands(IStoreCache storeCache) { // === Generic Shape Commands === // SELECT by parent id command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; StringBuilder selectCmdText = new StringBuilder(); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { selectCmdText.Append(", S."); selectCmdText.Append(pi.Name); } else if (IsComposition(pi)) { selectCmdText.Append(", S."); selectCmdText.Append(pi.Name); } } IDbCommand selectDiagramShapeCmd = CreateCommand( string.Format("SELECT DiagramShape.Shape, Diagram{0} FROM [{1}] S JOIN DiagramShape ON S.Id = DiagramShape.Shape WHERE DiagramShape.Diagram = @Diagram", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Diagram", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectDiagramShapes, selectDiagramShapeCmd); IDbCommand selectTemplateShapeCmd = CreateCommand( string.Format("SELECT TS.Shape, TS.Template{0} FROM [{1}] S JOIN TemplateShape TS ON S.Id = TS.Shape JOIN Template T ON TS.Template = T.Id WHERE T.Project = @Project", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Project", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectTemplateShapes, selectTemplateShapeCmd); IDbCommand selectChildShapeCmd = CreateCommand( string.Format("SELECT ChildShape.Shape, Parent{0} FROM [{1}] S JOIN ChildShape ON S.Id = ChildShape.Shape WHERE ChildShape.Parent = @Parent", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Parent", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectChildShapes, selectChildShapeCmd); } // INSERT commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand insertShapeCmd = CreateCommand(); StringBuilder insertShapeCmdText1 = new StringBuilder(); StringBuilder insertShapeCmdText2 = new StringBuilder(); insertShapeCmdText1.Append("Id"); insertShapeCmdText2.Append("@Ident"); insertShapeCmd.Parameters.Add(CreateParameter("Parent", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { insertShapeCmdText1.Append(", "); insertShapeCmdText1.Append(pi.Name); insertShapeCmdText2.Append(", "); insertShapeCmdText2.Append("@" + pi.Name); insertShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { insertShapeCmdText1.Append(", "); insertShapeCmdText1.Append(pi.Name); insertShapeCmdText2.Append(", "); insertShapeCmdText2.Append("@" + pi.Name); insertShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } IDbCommand insertDiagramShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertDiagramShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO DiagramShape (Diagram, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertDiagramShape, insertDiagramShapeCmd); IDbCommand insertTemplateShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertTemplateShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO TemplateShape (Template, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertTemplateShape, insertTemplateShapeCmd); IDbCommand insertChildShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertChildShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO ChildShape (Parent, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertChildShape, insertChildShapeCmd); } // UPDATE commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand updateShapeCmd = CreateCommand(); StringBuilder cmdText = new StringBuilder(); cmdText.AppendFormat("UPDATE [{0}] SET ", SqlTableNameForEntityName(et.FullName)); // Id must be first parameter because it is written first by the writer client. updateShapeCmd.Parameters.Add(CreateParameter("Id", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } cmdText.Length -= 2; // RemoveRange last comma + space cmdText.Append(" WHERE Id = @Id"); updateShapeCmd.CommandText = cmdText.ToString(); SetCommand(et.FullName, RepositoryCommandType.Update, updateShapeCmd); } SetCommand(shapeEntityTypeName, RepositoryCommandType.UpdateOwnerDiagram, CreateCommand("DELETE FROM DiagramShape WHERE Shape = @Id; DELETE FROM ChildShape WHERE Shape = @Id; " + "INSERT INTO DiagramShape (Diagram, Shape) VALUES (@Diagram, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Diagram", DbType.Int32))); SetCommand(shapeEntityTypeName, RepositoryCommandType.UpdateOwnerShape, CreateCommand("DELETE FROM DiagramShape WHERE Shape = @Id; DELETE FROM ChildShape WHERE Shape = @Id; " + "INSERT INTO ChildShape (Parent, Shape) VALUES (@Parent, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Parent", DbType.Int32))); // // DELETE command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand deleteShapeCommand = CreateCommand( string.Format("DELETE FROM DiagramShape WHERE Shape = @Id; " + "DELETE FROM TemplateShape WHERE Shape = @Id; " + "DELETE FROM ChildShape WHERE Shape = @Id; " + "DELETE FROM Shape WHERE Id = @Id; " + "DELETE FROM [{0}] WHERE Id = @Id", SqlTableNameForEntityName(et.FullName)), CreateParameter("Id", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.Delete, deleteShapeCommand); } // // Build CheckStyleInUse and CheckTemplateInUse command const string checkShapeCmdFmt = "EXISTS(SELECT {0}.Id FROM {0} WHERE {0}.Id IN (SELECT Shape FROM DiagramShape JOIN Diagram ON DiagramShape.Diagram = Diagram.Id WHERE Diagram.Project = @Project AND Diagram.Id = @Diagram) {1})"; string styleExistsStatement = ""; string templateExistsStatement = ""; string modelObjExistsStatement = ""; foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; if (et.FullName == "Core.ShapeGroup") continue; string whereStatement = string.Empty; foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { EntityFieldDefinition fieldDef = (EntityFieldDefinition)pi; if (fieldDef.Type == typeof(object)) { if (fieldDef.ElementName == "model_object" || fieldDef.ElementName == "template") continue; if (whereStatement.Length > 0) whereStatement += " OR "; whereStatement += fieldDef.Name + " = @Style"; } } } // Build statement for checking templates, model objects and styles if (templateExistsStatement.Length > 0) templateExistsStatement += " OR "; templateExistsStatement += string.Format(checkShapeCmdFmt, SqlTableNameForEntityName(et.FullName), " AND (Template = @Template)"); if (modelObjExistsStatement.Length > 0) modelObjExistsStatement += " OR "; modelObjExistsStatement += string.Format(checkShapeCmdFmt, SqlTableNameForEntityName(et.FullName), " AND (ModelObject = @ModelObject)"); // Build statement for checking styles if (string.IsNullOrEmpty(whereStatement)) continue; if (styleExistsStatement.Length > 0) styleExistsStatement += " OR "; styleExistsStatement += string.Format(checkShapeCmdFmt, SqlTableNameForEntityName(et.FullName), " AND (" + whereStatement + ")"); } SetCommand(ProjectSettings.EntityTypeName, RepositoryCommandType.CheckTemplateInUse, CreateCommand("SELECT CASE WHEN (" + templateExistsStatement + ") THEN 1 ELSE 0 END", CreateParameter("Project", DbType.Int32), CreateParameter("Diagram", DbType.Int32), CreateParameter("Template", DbType.Int32) ) ); SetCommand(ProjectSettings.EntityTypeName, RepositoryCommandType.CheckModelObjectInUse, CreateCommand("SELECT CASE WHEN (" + modelObjExistsStatement + ") THEN 1 ELSE 0 END", CreateParameter("Project", DbType.Int32), CreateParameter("Diagram", DbType.Int32), CreateParameter("ModelObject", DbType.Int32) ) ); SetCommand(ProjectSettings.EntityTypeName, RepositoryCommandType.CheckStyleInUse, CreateCommand("SELECT CASE WHEN (" + styleExistsStatement + ") THEN 1 ELSE 0 END", CreateParameter("Project", DbType.Int32), CreateParameter("Diagram", DbType.Int32), CreateParameter("Style", DbType.Int32) ) ); // Build CheckShapeTypeInUse and CheckModelObjectTypeInUse command const string checkModelObjCmdFmt = "EXISTS(SELECT {0}.Id FROM {0} WHERE {0}.Id IN (SELECT ModelObject FROM ModelModelObject JOIN Model ON ModelModelObject.Model = Model.Id WHERE Model.Project = @Project AND Model.Id = @Model) {1})"; foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape && et.Category != EntityCategory.ModelObject) continue; SetCommand(et.FullName, RepositoryCommandType.CheckShapeTypeInUse, CreateCommand("SELECT CASE WHEN (" + string.Format((et.Category == EntityCategory.Shape) ? checkShapeCmdFmt : checkModelObjCmdFmt, SqlTableNameForEntityName(et.FullName), "") + ") THEN 1 ELSE 0 END", CreateParameter("Project", DbType.Int32), CreateParameter("Diagram", DbType.Int32) ) ); } // // === Shape Connection Commands === SetCommand(connectionEntityTypeName, RepositoryCommandType.SelectByOwnerId, CreateCommand("SELECT ActiveShape, ActivePoint, PassiveShape, PassivePoint FROM ShapeConnection " + "JOIN DiagramShape ON ActiveShape = DiagramShape.Shape WHERE DiagramShape.Diagram = @Diagram", CreateParameter("Diagram", DbType.Int32))); SetCommand(connectionEntityTypeName, RepositoryCommandType.Insert, CreateCommand("INSERT INTO ShapeConnection (ActiveShape, ActivePoint, PassiveShape, PassivePoint) " + "VALUES (@ActiveShape, @ActivePoint, @PassiveShape, @PassivePoint)", CreateParameter("ActiveShape", DbType.Int32), CreateParameter("ActivePoint", DbType.Int32), CreateParameter("PassiveShape", DbType.Int32), CreateParameter("PassivePoint", DbType.Int32))); SetCommand(connectionEntityTypeName, RepositoryCommandType.Delete, CreateCommand("DELETE FROM ShapeConnection WHERE ActiveShape = @ActiveShape AND ActivePoint = @ActivePoint", CreateParameter("ActiveShape", DbType.Int32), CreateParameter("ActivePoint", DbType.Int32) )); // // === Inner Objects Commands === SetCommand(vertexEntityTypeName, RepositoryCommandType.SelectById, CreateCommand("SELECT SeqNo, Id, X, Y FROM Vertices WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(vertexEntityTypeName, RepositoryCommandType.Delete, CreateCommand("DELETE FROM Vertices WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(vertexEntityTypeName, RepositoryCommandType.Insert, CreateCommand("INSERT INTO Vertices (Owner, SeqNo, Id, X, Y) VALUES (@Owner, @SeqNo, @Id, @X, @Y)", CreateParameter("Owner", DbType.Int32), CreateParameter("SeqNo", DbType.Int32), CreateParameter("Id", DbType.Int32), CreateParameter("X", DbType.Int32), CreateParameter("Y", DbType.Int32))); SetCommand(connectionPointEntityTypeName, RepositoryCommandType.SelectById, CreateCommand("SELECT SeqNo, Id, A, B, C FROM ConnectionPoints WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(connectionPointEntityTypeName, RepositoryCommandType.Delete, CreateCommand("DELETE FROM ConnectionPoints WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(connectionPointEntityTypeName, RepositoryCommandType.Insert, CreateCommand("INSERT INTO ConnectionPoints (Owner, SeqNo, Id, A, B, C) VALUES (@Owner, @SeqNo, @Id, @A, @B, @C)", CreateParameter("Owner", DbType.Int32), CreateParameter("SeqNo", DbType.Int32), CreateParameter("Id", DbType.Int32), CreateParameter("A", DbType.Int32), CreateParameter("B", DbType.Int32), CreateParameter("C", DbType.Int32))); }
/// <summary> /// Loads general designs or a project design. /// </summary> /// <param name="cache">Store cache to load to.</param> /// <param name="projectId">Project id for project design, null for general designs.</param> public abstract void LoadDesigns(IStoreCache cache, object projectId);
/// <summary> /// Checks whether the template associated with the given id is still in use. /// </summary> /// <param name="cache">The store cache associated with this store.</param> /// <param name="templateId">The id of the template to be checked.</param> /// <remarks>Applies only to stores that support partial loading.</remarks> public abstract bool CheckTemplateInUse(IStoreCache cache, object templateId);
/// <summary> /// Checks whether the given shape type is still in use. /// </summary> /// <param name="cache">The store cache associated with this store.</param> /// <param name="typeName">The name of the shape type to check.</param> /// <remarks>Applies only to stores that support partial loading.</remarks> public abstract bool CheckShapeTypeInUse(IStoreCache cache, string typeName);
/// <summary> /// Loads all model objects of the given template into the given store cache. /// </summary> /// <remarks> /// If the template's model objects have already been loaded, this method does nothing. /// </remarks> public abstract void LoadTemplateModelObjects(IStoreCache cache, object templateId);
/// <summary> /// Loads all child model objects of the model object with the given Id into the given store cache. /// </summary> /// <param name="cache">Store cache associated with this store.</param> /// <param name="parentModelObjectId">Id of the parent model object.</param> public abstract void LoadChildModelObjects(IStoreCache cache, object parentModelObjectId);
/// <summary> /// Loads all diagrams of the project into the given store cache. /// </summary> /// <remarks> /// If the store supports partial loading, the shapes shapes of the diagrams are not loaded. /// </remarks> public abstract void LoadDiagrams(IStoreCache cache, object projectId);
/// <summary> /// Loads all shapes of the given template into the given store cache. /// </summary> /// <remarks> /// If the template's shapes have already been loaded, this method does nothing. /// </remarks> public abstract void LoadTemplateShapes(IStoreCache cache, object templateId);
/// <ToBeCompleted></ToBeCompleted> protected IDbCommand CreateCreateTablesCommand(IStoreCache storeCache) { StringBuilder cmdText = new StringBuilder(); // cmdText.Append("CREATE TABLE ProjectInfo (Id INT IDENTITY PRIMARY KEY, Name VARCHAR(40), Version INT);" + Environment.NewLine); cmdText.Append("CREATE TABLE Project (" + "ProjectInfo INT REFERENCES ProjectInfo (Id) ON DELETE CASCADE ON UPDATE CASCADE," + "Id INT IDENTITY PRIMARY KEY, LastSavedUtc DATETIME);" + Environment.NewLine); cmdText.Append("CREATE TABLE Library (" + "Project INT REFERENCES Project (Id) ON DELETE CASCADE ON UPDATE CASCADE," + "Name VARCHAR(40), AssemblyName VARCHAR(512), Version INT);" + Environment.NewLine); cmdText.Append(CreateCreateTableCommand(storeCache.FindEntityTypeByName(Design.EntityTypeName), "Project", "Project") + ";" + Environment.NewLine); cmdText.Append("CREATE TABLE Style (Design INT REFERENCES Design (Id) ON DELETE CASCADE ON UPDATE CASCADE, Id INT IDENTITY PRIMARY KEY);" + Environment.NewLine); foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.Style) cmdText.Append(CreateCreateTableCommand(storeCache.FindEntityTypeByName(et.FullName), "Style", null) + ";" + Environment.NewLine); // cmdText.Append(CreateCreateTableCommand(storeCache.FindEntityTypeByName(Diagram.EntityTypeName), "Project", "Project") + ";" + Environment.NewLine); cmdText.Append("CREATE TABLE Layer (" + "Diagram INT REFERENCES Diagram (Id) ON DELETE CASCADE ON UPDATE CASCADE," + "Id INT, Name VARCHAR(40), Title VARCHAR(40), UpperZoomBound INT, LowerZoomBound INT);" + Environment.NewLine); cmdText.Append("CREATE TABLE Shape (Id INT IDENTITY PRIMARY KEY);" + Environment.NewLine); foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.Shape) cmdText.Append(CreateCreateTableCommand(storeCache.FindEntityTypeByName(et.FullName), "Shape", null) + ";" + Environment.NewLine); cmdText.Append("CREATE TABLE DiagramShape(Diagram INT, Shape INT PRIMARY KEY);" + Environment.NewLine); cmdText.Append("CREATE TABLE TemplateShape(Template INT, Shape INT PRIMARY KEY);" + Environment.NewLine); cmdText.Append("CREATE TABLE ChildShape(Parent INT, Shape INT PRIMARY KEY);" + Environment.NewLine); cmdText.Append("CREATE TABLE ShapeConnection (ActiveShape INT, ActivePoint INT, PassiveShape INT, PassivePoint INT);" + Environment.NewLine); // cmdText.Append("CREATE TABLE Point (Owner INT, SeqNo INT, Id INT, X INT, Y INT);" + Environment.NewLine); // cmdText.Append("CREATE TABLE Model (Project INT REFERENCES Project (Id) ON DELETE CASCADE ON UPDATE CASCADE, Id INT IDENTITY PRIMARY KEY);" + Environment.NewLine); // cmdText.Append("CREATE TABLE ModelObject (Id INT IDENTITY PRIMARY KEY);" + Environment.NewLine); foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.ModelObject) cmdText.Append(CreateCreateTableCommand(storeCache.FindEntityTypeByName(et.FullName), "ModelObject", null) + ";" + Environment.NewLine); cmdText.Append("CREATE TABLE TemplateModelObject (Template INT, ModelObject INT PRIMARY KEY);" + Environment.NewLine); cmdText.Append("CREATE TABLE ModelModelObject (Model INT, ModelObject INT PRIMARY KEY);" + Environment.NewLine); cmdText.Append("CREATE TABLE ChildModelObject (PARENT INT, ModelObject INT PRIMARY KEY);" + Environment.NewLine); // cmdText.Append("CREATE TABLE Template (" + "Project INT REFERENCES Project (Id) ON DELETE CASCADE ON UPDATE CASCADE, " + "Id INT IDENTITY PRIMARY KEY, [Name] VARCHAR(40), Title VARCHAR(40), Description VARCHAR(40), " + "ConnectionPointMappings VARCHAR(1000));" + Environment.NewLine); // cmdText.Append("CREATE TABLE ModelMapping (" + "Template INT REFERENCES TEMPLATE (id) ON DELETE CASCADE ON UPDATE CASCADE, " + "Id INT IDENTITY PRIMARY KEY);" + Environment.NewLine); cmdText.Append(string.Format("CREATE TABLE [{0}] (" + "ModelMapping INT REFERENCES ModelMapping (Id) ON DELETE CASCADE ON UPDATE CASCADE, " + "ShapePropertyId INT, ModelPropertyId INT, " + "MappingType INT, Intercept REAL, Slope REAL);" + Environment.NewLine, SqlTableNameForEntityName(NumericModelMapping.EntityTypeName))); cmdText.Append(string.Format("CREATE TABLE [{0}] (" + "ModelMapping INT REFERENCES ModelMapping (Id) ON DELETE CASCADE ON UPDATE CASCADE, " + "ShapePropertyId INT, ModelPropertyId INT, MappingType INT, Format VARCHAR(120));" + Environment.NewLine, SqlTableNameForEntityName(FormatModelMapping.EntityTypeName))); cmdText.Append(string.Format("CREATE TABLE [{0}] (" + "ModelMapping INT REFERENCES ModelMapping (Id) ON DELETE CASCADE ON UPDATE CASCADE, " + "ShapePropertyId INT, ModelPropertyId INT, MappingType INT, DefaultStyleType INT, " + "DefaultStyle INT REFERENCES Style (Id) ON DELETE NO ACTION ON UPDATE NO ACTION, " + "ValueRanges NVARCHAR(4000));" + Environment.NewLine, SqlTableNameForEntityName(StyleModelMapping.EntityTypeName))); // cmdText.Append(string.Format("CREATE TABLE SysCommand (Id INT IDENTITY PRIMARY KEY, Kind VARCHAR({0}), EntityType VARCHAR({1}), Text NVARCHAR(MAX))", ColumnSizeSysCmdKind, ColumnSizeSysCmdEntityType, ColumnSizeSysCmdCommandText)); cmdText.Append("CREATE TABLE SysParameter (Command INT REFERENCES SysCommand (Id) ON DELETE CASCADE ON UPDATE CASCADE, No INT, Name VARCHAR(40), Type VARCHAR(10))"); // return CreateCommand(cmdText.ToString()); }
private void CreateModelObjectCommands(IStoreCache storeCache) { // === Generic Shape Commands === // SELECT by parent id command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.ModelObject) continue; StringBuilder selectCmdText = new StringBuilder(); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { selectCmdText.Append(", M."); selectCmdText.Append(pi.Name); } } IDbCommand selectModelModelObjCmd = CreateCommand( string.Format("SELECT ModelModelObject.ModelObject, Model{0} FROM [{1}] M JOIN ModelModelObject ON M.Id = ModelModelObject.ModelObject WHERE ModelModelObject.Model = @Model", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Model", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectModelModelObjects, selectModelModelObjCmd); IDbCommand selectTemplateModelObjCmd = CreateCommand( string.Format("SELECT TM.ModelObject, TM.Template{0} FROM [{1}] M JOIN TemplateModelObject TM ON M.Id = TM.ModelObject JOIN Template T ON TM.Template = T.Id WHERE T.Project = @Project", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Project", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectTemplateModelObjects, selectTemplateModelObjCmd); IDbCommand selectChildModelObjCmd = CreateCommand( string.Format("SELECT ChildModelObject.ModelObject, Parent{0} FROM [{1}] M JOIN ChildModelObject ON M.Id = ChildModelObject.ModelObject WHERE ChildModelObject.Parent = @Parent", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Parent", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectChildModelObjects, selectChildModelObjCmd); } // INSERT commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.ModelObject) continue; IDbCommand insertModelObjectCmd = CreateCommand(); StringBuilder insertModelObjectCmdText1 = new StringBuilder(); StringBuilder insertModelObjectCmdText2 = new StringBuilder(); insertModelObjectCmdText1.Append("Id"); insertModelObjectCmdText2.Append("@Ident"); insertModelObjectCmd.Parameters.Add(CreateParameter("Parent", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { insertModelObjectCmdText1.Append(", "); insertModelObjectCmdText1.Append(pi.Name); insertModelObjectCmdText2.Append(", "); insertModelObjectCmdText2.Append("@" + pi.Name); insertModelObjectCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { insertModelObjectCmdText1.Append(", "); insertModelObjectCmdText1.Append(pi.Name); insertModelObjectCmdText2.Append(", "); insertModelObjectCmdText2.Append("@" + pi.Name); insertModelObjectCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } IDbCommand insertModelModelObjectCmd = (IDbCommand)((ICloneable)insertModelObjectCmd).Clone(); insertModelModelObjectCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO ModelObject DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO ModelModelObject (Model, ModelObject) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertModelObjectCmdText1.ToString(), insertModelObjectCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertModelModelObject, insertModelModelObjectCmd); IDbCommand insertTemplateModelObjectCmd = (IDbCommand)((ICloneable)insertModelObjectCmd).Clone(); insertTemplateModelObjectCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO ModelObject DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO TemplateModelObject (Template, ModelObject) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertModelObjectCmdText1.ToString(), insertModelObjectCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertTemplateModelObject, insertTemplateModelObjectCmd); IDbCommand insertChildModelObjectCmd = (IDbCommand)((ICloneable)insertModelObjectCmd).Clone(); insertChildModelObjectCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO ModelObject DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO ChildModelObject (Parent, ModelObject) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertModelObjectCmdText1.ToString(), insertModelObjectCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertChildModelObject, insertChildModelObjectCmd); } // UPDATE commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.ModelObject) continue; IDbCommand updateModelObjectCmd = CreateCommand(); StringBuilder cmdText = new StringBuilder(); cmdText.AppendFormat("UPDATE [{0}] SET ", SqlTableNameForEntityName(et.FullName)); // Id must be first parameter because it is written first by the writer client. updateModelObjectCmd.Parameters.Add(CreateParameter("Id", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateModelObjectCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateModelObjectCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } cmdText.Length -= 2; // RemoveRange last comma + space cmdText.Append(" WHERE Id = @Id"); updateModelObjectCmd.CommandText = cmdText.ToString(); SetCommand(et.FullName, RepositoryCommandType.Update, updateModelObjectCmd); } SetCommand("Core.ModelObject", RepositoryCommandType.UpdateOwnerModel, CreateCommand("DELETE FROM ModelModelObject WHERE ModelObject = @Id; DELETE FROM ChildModelObject WHERE ModelObject = @Id; " + "INSERT INTO ModelModelObject (Model, ModelObject) VALUES (@Model, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Model", DbType.Int32))); SetCommand("Core.ModelObject", RepositoryCommandType.UpdateOwnerModelObject, CreateCommand("DELETE FROM ModelModelObject WHERE ModelObject = @Id; DELETE FROM ChildModelObject WHERE ModelObject = @Id; " + "INSERT INTO ChildModelObject (Parent, ModelObject) VALUES (@Parent, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Parent", DbType.Int32))); // // DELETE command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.ModelObject) continue; IDbCommand deleteModelObjectCommand = CreateCommand( string.Format("DELETE FROM ModelModelObject WHERE ModelObject = @Id; " + "DELETE FROM TemplateModelObject WHERE ModelObject = @Id; " + "DELETE FROM ChildModelObject WHERE ModelObject = @Id; " + "DELETE FROM ModelObject WHERE Id = @Id; " + "DELETE FROM [{0}] WHERE Id = @Id", SqlTableNameForEntityName(et.FullName)), CreateParameter("Id", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.Delete, deleteModelObjectCommand); } }
private void CreateShapeCommands(IStoreCache storeCache) { // === Generic Shape Commands === // SELECT by parent id command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; StringBuilder selectCmdText = new StringBuilder(); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { selectCmdText.Append(", S."); selectCmdText.Append(pi.Name); } else if (IsComposition(pi)) { selectCmdText.Append(", S."); selectCmdText.Append(pi.Name); } } IDbCommand selectDiagramShapeCmd = CreateCommand( string.Format("SELECT DiagramShape.Shape, Diagram{0} FROM [{1}] S JOIN DiagramShape ON S.Id = DiagramShape.Shape WHERE DiagramShape.Diagram = @Diagram", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Diagram", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectDiagramShapes, selectDiagramShapeCmd); IDbCommand selectTemplateShapeCmd = CreateCommand( string.Format("SELECT TS.Shape, TS.Template{0} FROM [{1}] S JOIN TemplateShape TS ON S.Id = TS.Shape JOIN Template T ON TS.Template = T.Id WHERE T.Project = @Project", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Project", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectTemplateShapes, selectTemplateShapeCmd); IDbCommand selectChildShapeCmd = CreateCommand( string.Format("SELECT ChildShape.Shape, Parent{0} FROM [{1}] S JOIN ChildShape ON S.Id = ChildShape.Shape WHERE ChildShape.Parent = @Parent", selectCmdText.ToString(), SqlTableNameForEntityName(et.FullName)), CreateParameter("Parent", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.SelectChildShapes, selectChildShapeCmd); } // INSERT commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand insertShapeCmd = CreateCommand(); StringBuilder insertShapeCmdText1 = new StringBuilder(); StringBuilder insertShapeCmdText2 = new StringBuilder(); insertShapeCmdText1.Append("Id"); insertShapeCmdText2.Append("@Ident"); insertShapeCmd.Parameters.Add(CreateParameter("Parent", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { insertShapeCmdText1.Append(", "); insertShapeCmdText1.Append(pi.Name); insertShapeCmdText2.Append(", "); insertShapeCmdText2.Append("@" + pi.Name); insertShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { insertShapeCmdText1.Append(", "); insertShapeCmdText1.Append(pi.Name); insertShapeCmdText2.Append(", "); insertShapeCmdText2.Append("@" + pi.Name); insertShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } IDbCommand insertDiagramShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertDiagramShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO DiagramShape (Diagram, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertDiagramShape, insertDiagramShapeCmd); IDbCommand insertTemplateShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertTemplateShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO TemplateShape (Template, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertTemplateShape, insertTemplateShapeCmd); IDbCommand insertChildShapeCmd = (IDbCommand)((ICloneable)insertShapeCmd).Clone(); insertChildShapeCmd.CommandText = string.Format("DECLARE @Ident INT; " + "INSERT INTO Shape DEFAULT VALUES; SET @Ident = @@IDENTITY; " + "INSERT INTO ChildShape (Parent, Shape) VALUES (@Parent, @Ident); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT @Ident", SqlTableNameForEntityName(et.FullName), insertShapeCmdText1.ToString(), insertShapeCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.InsertChildShape, insertChildShapeCmd); } // UPDATE commands foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand updateShapeCmd = CreateCommand(); StringBuilder cmdText = new StringBuilder(); cmdText.AppendFormat("UPDATE [{0}] SET ", SqlTableNameForEntityName(et.FullName)); // Id must be first parameter because it is written first by the writer client. updateShapeCmd.Parameters.Add(CreateParameter("Id", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityFieldDefinition) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } else if (IsComposition(pi)) { cmdText.AppendFormat("[{0}] = @{0}, ", pi.Name); updateShapeCmd.Parameters.Add(CreateParameter(pi.Name, DbType.String)); } else Debug.Fail("Unexpected inner objects type in CreateDbCommands."); } cmdText.Length -= 2; // RemoveRange last comma + space cmdText.Append(" WHERE Id = @Id"); updateShapeCmd.CommandText = cmdText.ToString(); SetCommand(et.FullName, RepositoryCommandType.Update, updateShapeCmd); } SetCommand(shapeEntityTypeName, RepositoryCommandType.UpdateOwnerDiagram, CreateCommand("DELETE FROM DiagramShape WHERE Shape = @Id; DELETE FROM ChildShape WHERE Shape = @Id; " + "INSERT INTO DiagramShape (Diagram, Shape) VALUES (@Diagram, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Diagram", DbType.Int32))); SetCommand(shapeEntityTypeName, RepositoryCommandType.UpdateOwnerShape, CreateCommand("DELETE FROM DiagramShape WHERE Shape = @Id; DELETE FROM ChildShape WHERE Shape = @Id; " + "INSERT INTO ChildShape (Parent, Shape) VALUES (@Parent, @Id)", CreateParameter("Id", DbType.Int32), CreateParameter("Parent", DbType.Int32))); // // DELETE command foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Shape) continue; IDbCommand deleteShapeCommand = CreateCommand( string.Format("DELETE FROM DiagramShape WHERE Shape = @Id; " + "DELETE FROM TemplateShape WHERE Shape = @Id; " + "DELETE FROM ChildShape WHERE Shape = @Id; " + "DELETE FROM Shape WHERE Id = @Id; " + "DELETE FROM [{0}] WHERE Id = @Id", SqlTableNameForEntityName(et.FullName)), CreateParameter("Id", DbType.Int32)); SetCommand(et.FullName, RepositoryCommandType.Delete, deleteShapeCommand); } // === Shape Connection Commands === SetCommand(connectionEntityTypeName, RepositoryCommandType.SelectByOwnerId, CreateCommand("SELECT ActiveShape, ActivePoint, PassiveShape, PassivePoint FROM ShapeConnection " + "JOIN DiagramShape ON ActiveShape = DiagramShape.Shape WHERE DiagramShape.Diagram = @Diagram", CreateParameter("Diagram", DbType.Int32))); SetCommand(connectionEntityTypeName, RepositoryCommandType.Insert, CreateCommand("INSERT INTO ShapeConnection (ActiveShape, ActivePoint, PassiveShape, PassivePoint) " + "VALUES (@ActiveShape, @ActivePoint, @PassiveShape, @PassivePoint)", CreateParameter("ActiveShape", DbType.Int32), CreateParameter("ActivePoint", DbType.Int32), CreateParameter("PassiveShape", DbType.Int32), CreateParameter("PassivePoint", DbType.Int32))); SetCommand(connectionEntityTypeName, RepositoryCommandType.Delete, CreateCommand("DELETE FROM ShapeConnection WHERE ActiveShape = @ActiveShape AND ActivePoint = @ActivePoint", CreateParameter("ActiveShape", DbType.Int32), CreateParameter("ActivePoint", DbType.Int32) )); // // === Inner Objects Commands === SetCommand(pointEntityTypeName, RepositoryCommandType.SelectById, CreateCommand("SELECT SeqNo, Id, X, Y FROM Point WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(pointEntityTypeName, RepositoryCommandType.Delete, CreateCommand("DELETE FROM Point WHERE Owner = @Owner", CreateParameter("Owner", DbType.Int32))); SetCommand(pointEntityTypeName, RepositoryCommandType.Insert, CreateCommand("INSERT INTO Point (Owner, SeqNo, Id, X, Y) VALUES (@Owner, @SeqNo, @Id, @X, @Y)", CreateParameter("Owner", DbType.Int32), CreateParameter("SeqNo", DbType.Int32), CreateParameter("Id", DbType.Int32), CreateParameter("X", DbType.Int32), CreateParameter("Y", DbType.Int32))); }
private void CreateStyleCommands(IStoreCache storeCache) { // === Generic Select Style Commands === foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Style) continue; IDbCommand selectStyleCmd = CreateCommand(); StringBuilder selectStyleList = new StringBuilder(); selectStyleCmd.Parameters.Add(CreateParameter("Design", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityInnerObjectsDefinition) continue; selectStyleList.Append(", "); selectStyleList.Append(pi.Name); } selectStyleCmd.CommandText = string.Format( "SELECT Style.Id, Design{0} FROM [{1}] JOIN Style ON [{1}].Id = Style.Id WHERE Design = @Design", selectStyleList.ToString(), SqlTableNameForEntityName(et.FullName)); SetCommand(et.FullName, RepositoryCommandType.SelectByOwnerId, selectStyleCmd); } // === Specific Style Commands === foreach (IEntityType et in storeCache.EntityTypes) { if (et.Category != EntityCategory.Style) continue; string tableName = SqlTableNameForEntityName(et.FullName); // === INSERT commands === IDbCommand insertStyleCmd = CreateCommand(); StringBuilder insertStyleCmdText1 = new StringBuilder(); StringBuilder insertStyleCmdText2 = new StringBuilder(); insertStyleCmdText1.Append("Id"); insertStyleCmdText2.Append("@@IDENTITY"); insertStyleCmd.Parameters.Add(CreateParameter("Design", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityInnerObjectsDefinition) continue; insertStyleCmdText1.Append(", "); insertStyleCmdText1.Append(pi.Name); insertStyleCmdText2.Append(", "); insertStyleCmdText2.Append("@" + pi.Name); insertStyleCmd.Parameters.Add( CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } insertStyleCmd.CommandText = string.Format("INSERT INTO Style (Design) VALUES (@Design); " + "INSERT INTO [{0}] ({1}) VALUES ({2}); SELECT CAST(IDENT_CURRENT('Style') AS INT)", tableName, insertStyleCmdText1.ToString(), insertStyleCmdText2.ToString()); SetCommand(et.FullName, RepositoryCommandType.Insert, insertStyleCmd); // === UPDATE commands === IDbCommand updateStyleCmd = CreateCommand(); StringBuilder updateStyleCmdText = new StringBuilder(); updateStyleCmd.Parameters.Add(CreateParameter("Id", DbType.Int32)); foreach (EntityPropertyDefinition pi in et.PropertyDefinitions) { if (pi is EntityInnerObjectsDefinition) continue; updateStyleCmdText.Append(pi.Name); updateStyleCmdText.Append(" = @"); updateStyleCmdText.Append(pi.Name); updateStyleCmdText.Append(", "); updateStyleCmd.Parameters.Add(CreateParameter(pi.Name, DbTypeForDotNetType(((EntityFieldDefinition)pi).Type))); } updateStyleCmdText.Remove(updateStyleCmdText.Length - 2, 2); updateStyleCmd.CommandText = string.Format("UPDATE [{0}] SET {1} Where Id = @Id", tableName, updateStyleCmdText.ToString()); SetCommand(et.FullName, RepositoryCommandType.Update, updateStyleCmd); // === DELETE commands === SetCommand(et.FullName, RepositoryCommandType.Delete, CreateCommand(string.Format("DELETE FROM [{0}] WHERE Id = @Id;" + "DELETE FROM [Style] WHERE Id = @Id;", tableName), CreateParameter("@Id", DbType.Int32) ) ); } }
/// <ToBeCompleted></ToBeCompleted> protected IDbCommand CreateDropTablesCommand(IStoreCache storeCache) { string dropCommand = "IF OBJECT_ID('[{0}]') IS NOT NULL DROP TABLE [{0}];" + Environment.NewLine; StringBuilder cmdText = new StringBuilder(); // Drop inner objects cmdText.AppendFormat(dropCommand, "Point"); // Drop property mappings cmdText.AppendFormat(dropCommand, "NumericModelMapping"); cmdText.AppendFormat(dropCommand, "FormatModelMapping"); cmdText.AppendFormat(dropCommand, "StyleModelMapping"); cmdText.AppendFormat(dropCommand, "ModelMapping"); // Drop shape connections cmdText.AppendFormat(dropCommand, "ShapeConnection"); cmdText.AppendFormat(dropCommand, "ChildShape"); cmdText.AppendFormat(dropCommand, "TemplateShape"); cmdText.AppendFormat(dropCommand, "DiagramShape"); // Drop modelObject tables foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.ModelObject) cmdText.AppendFormat(dropCommand, SqlTableNameForEntityName(et.FullName)); cmdText.AppendFormat(dropCommand, "ChildModelObject"); cmdText.AppendFormat(dropCommand, "ModelModelObject"); cmdText.AppendFormat(dropCommand, "TemplateModelObject"); cmdText.AppendFormat(dropCommand, "ModelObject"); cmdText.AppendFormat(dropCommand, "Model"); // Drop shape tables foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.Shape) cmdText.AppendFormat(dropCommand, SqlTableNameForEntityName(et.FullName)); cmdText.AppendFormat(dropCommand, "Shape"); cmdText.AppendFormat(dropCommand, "Layer"); cmdText.AppendFormat(dropCommand, "Diagram"); // Drop style tables foreach (IEntityType et in storeCache.EntityTypes) if (et.Category == EntityCategory.Style) cmdText.AppendFormat(dropCommand, SqlTableNameForEntityName(et.FullName)); cmdText.AppendFormat(dropCommand, "Style"); cmdText.AppendFormat(dropCommand, "Design"); cmdText.AppendFormat(dropCommand, "Template"); cmdText.AppendFormat(dropCommand, "Library"); cmdText.AppendFormat(dropCommand, "Project"); cmdText.AppendFormat(dropCommand, "ProjectInfo"); // Drop system tables cmdText.AppendFormat(dropCommand, "SysParameter"); cmdText.AppendFormat(dropCommand, "SysCommand"); return CreateCommand(cmdText.ToString()); }
/// <summary> /// Loads all shapes of the given diagram into the given store cache. /// </summary> /// <remarks> /// Must not be called, if the diagram shapes are already loaded. /// </remarks> public abstract void LoadDiagramShapes(IStoreCache cache, Diagram diagram);
/// <summary> /// Reads the version of the project from the persistent store. /// </summary> public abstract void ReadVersion(IStoreCache cache);
/// <summary> /// Loads all child shapes of the shape with the given Id into the given store cache. /// </summary> public abstract void LoadChildShapes(IStoreCache cache, object parentShapeId);
/// <summary> /// Creates a project store in the data source. /// </summary> /// <param name="storeCache"></param> public abstract void Create(IStoreCache storeCache);
/// <summary> /// Loads all model objects of the given model into the given store cache. /// </summary> /// <remarks> /// If the model's model ojects have already been loaded, this method does nothing. /// </remarks> public abstract void LoadModelModelObjects(IStoreCache cache, object modelId);
/// <summary> /// Opens a project store in the data source. /// </summary> /// <param name="storeCache"></param> public abstract void Open(IStoreCache storeCache);
/// <summary> /// Checks whether the style associated with the given id is still in use. /// </summary> /// <param name="cache">The store cache associated with this store.</param> /// <param name="styleId">The id of the style to be checked.</param> /// <remarks>Applies only to stores that support partial loading.</remarks> public abstract bool CheckStyleInUse(IStoreCache cache, object styleId);
/// <summary> /// Loads the current project into the given store cache. /// </summary> /// <param name="cache">The store cache associated with this store.</param> /// <param name="entityType">Project entity type</param> /// <param name="parameters">Ids of the project settings to load. if null, all projects are loaded.</param> /// <remarks>Optional parameter 'parameters' is not used in the current version.</remarks> public abstract void LoadProjects(IStoreCache cache, IEntityType entityType, params object[] parameters);
/// <summary> /// Checks whether the model object associated with the given id is still in use. /// </summary> /// <param name="cache">The store cache associated with this store.</param> /// <param name="modelObjectId">The id of the model object to be checked.</param> /// <remarks>Applies only to stores that support partial loading.</remarks> public abstract bool CheckModelObjectInUse(IStoreCache cache, object modelObjectId);
/// <summary> /// Loads the model of the project into the given store cache. /// </summary> public abstract void LoadModel(IStoreCache cache, object projectId);
/// <summary> /// Commits all modifications in the cache to the data store. /// </summary> public abstract void SaveChanges(IStoreCache storeCache);
public ProductService(IProductRepository productRepository, IStoreCache cache) { _productRepository = productRepository; _cache = cache; }