//***************************************************************************// // Legenerálja a DA-hoz az insert művelet megvalósítását. // //***************************************************************************// template GenerateInsertEntity(MClass as ENTITY) #region InsertEntity private const string m_InsertCommandText = @" insert into [ConvertNameToSQLTableName([ENTITY.name])] ( [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> MAttribute as ATTRIBUTE where [ATTRIBUTE.name] != [MBaseClass.name])] [if (IsComputedAttribute([ATTRIBUTE]) == _False())] [ConvertNameToSQLColumnName([ATTRIBUTE.name])], [end if] [end loop] [end loop] [end if] [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> Role as StartRole -> MAssociation as CurrentAssoc -> MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id] != [EndRole.id]) and GetStereoType([PartnerClass]) == "Entity"))] [if (HasAssociationClass([CurrentAssoc]) == "")] [if (([EndRole.multiplicity] == "1") or (([EndRole.multiplicity] == "0..1") and (([StartRole.multiplicity] == "1..*") or ([StartRole.multiplicity] == "*") or ([StartRole.multiplicity] == "0..*"))))] [ConvertNameToSQLColumnName(ConvertRoleToName([EndRole]))], [end if] [end if] [end loop] [end loop] [end if] [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity"))] [loop (CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where([StartRole.id] < [EndRole.id] and GetStereoType([EndClass]) == "Entity" ))] [ConvertNameToSQLColumnName(ConvertRoleToName([EndRole]))], [ConvertNameToSQLColumnName(ConvertRoleToName([StartRole]))], [end loop] [end loop] [end loop] [end if] [loop (ENTITY -> MAttribute as ATTRIBUTE where [ATTRIBUTE.name] != [ENTITY.name])] [if (IsComputedAttribute([ATTRIBUTE]) == _False())] [ConvertNameToSQLColumnName([ATTRIBUTE.name])], [end if] [end loop] [loop (ENTITY -> Role as StartRole -> MAssociation as CurrentAssoc -> MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id] != [EndRole.id]) and GetStereoType([PartnerClass]) == "Entity"))] [if (HasAssociationClass([CurrentAssoc]) == "")] [if (([EndRole.multiplicity] == "1") or (([EndRole.multiplicity] == "0..1") and (([StartRole.multiplicity] == "1..*") or ([StartRole.multiplicity] == "*") or ([StartRole.multiplicity] == "0..*"))))] [ConvertNameToSQLColumnName(ConvertRoleToName([EndRole]))], [end if] [end if] [end loop] [loop (ENTITY -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity"))] [loop (CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where([StartRole.id] < [EndRole.id] and GetStereoType([EndClass]) == "Entity" ))] [ConvertNameToSQLColumnName(ConvertRoleToName([EndRole]))], [ConvertNameToSQLColumnName(ConvertRoleToName([StartRole]))], [end loop] [end loop] TOROLT, SERIAL, CREATED, [if (IsMasterEntity([ENTITY]) == "true" || GetInheritance([ENTITY]) == "tpc")] CREATOR) [else] CREATOR, ID) [end if] values ( [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> MAttribute as ATTRIBUTE where [ATTRIBUTE.name] != [MBaseClass.name])] [if (IsComputedAttribute([ATTRIBUTE]) == _False())] :[ConvertNameToCommandParameterName([ATTRIBUTE.name])], [end if] [end loop] [end loop] [end if] [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> Role as StartRole -> MAssociation as CurrentAssoc -> MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id] != [EndRole.id]) and GetStereoType([PartnerClass]) == "Entity"))] [if (HasAssociationClass([CurrentAssoc]) == "")] [if (([EndRole.multiplicity] == "1") or (([EndRole.multiplicity] == "0..1") and (([StartRole.multiplicity] == "1..*") or ([StartRole.multiplicity] == "*") or ([StartRole.multiplicity] == "0..*"))))] :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))], [end if] [end if] [end loop] [end loop] [end if] [if (GetInheritance([ENTITY]) == "tpc")] [loop (ENTITY -> SuperClass as MBaseClass)] [loop (MBaseClass -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity"))] [loop (CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where([StartRole.id] < [EndRole.id] and GetStereoType([EndClass]) == "Entity" ))] :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))], :[ConvertNameToCommandParameterName(ConvertRoleToName([StartRole]))], [end loop] [end loop] [end loop] [end if] [loop (ENTITY -> MAttribute as ATTRIBUTE where [ATTRIBUTE.name] != [ENTITY.name])] [if (IsComputedAttribute([ATTRIBUTE]) == _False())] :[ConvertNameToCommandParameterName([ATTRIBUTE.name])], [end if] [end loop] [loop (ENTITY -> Role as StartRole -> MAssociation as CurrentAssoc -> MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id] != [EndRole.id]) and GetStereoType([PartnerClass]) == "Entity"))] [if (HasAssociationClass([CurrentAssoc]) == "")] [if (([EndRole.multiplicity] == "1") or (([EndRole.multiplicity] == "0..1") and (([StartRole.multiplicity] == "1..*") or ([StartRole.multiplicity] == "*") or ([StartRole.multiplicity] == "0..*"))))] :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))], [end if] [end if] [end loop] [loop (ENTITY -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity"))] [loop (CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where([StartRole.id] < [EndRole.id] and GetStereoType([EndClass]) == "Entity" ))] :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))], :[ConvertNameToCommandParameterName(ConvertRoleToName([StartRole]))], [end loop] [end loop] :[ConvertNameToCommandParameterName("Torolt")], :[ConvertNameToCommandParameterName("Serial")], :[ConvertNameToCommandParameterName("Created")], [if (IsMasterEntity([ENTITY]) == "true" || GetInheritance([ENTITY]) == "tpc")] :[ConvertNameToCommandParameterName("Creator")]); SELECT SCOPE_IDENTITY() as ID; [else] :[ConvertNameToCommandParameterName("Creator")], :[ConvertNameToCommandParameterName("ID")] ) -- Leszármaztatott entitás ID-ja [end if] "; public override void InsertEntity([ENTITY.name] entity) { [if (IsMasterEntity([ENTITY]) == "false" && GetInheritance([ENTITY]) != "tpc")] entity.InheritedDA.InsertEntity(entity); [else] entity.Serial = 0; [if (GetTaggedValue([ENTITY], "anonymous") == "all" || GetTaggedValue([ENTITY], "anonymous") == "insert")] SetEntityCreator(entity, DateTime.Now, "??????"); [else] SetEntityCreator(entity, DateTime.Now, UserContext.Instance.UniqueIdentifier); [end if] [end if] using ([GetCSharpSQLCommandType()] command = DAUtil.CreateCommand(m_InsertCommandText)) { dbhelper.BindAttributes(entity, command); dbhelper.BindAssociations(entity, command); command.Parameters.Add("[ConvertNameToCommandParameterName("Torolt")]", [GetCSharpDatasetType("Boolean", "")]).Value = false; command.Parameters.Add("[ConvertNameToCommandParameterName("Serial")]", [GetCSharpDatasetType("Integer", "")]).Value = 0; command.Parameters.Add("[ConvertNameToCommandParameterName("Created")]", [GetCSharpDatasetType("DateTime", "")]).Value = entity.EntityCreated; command.Parameters.Add("[ConvertNameToCommandParameterName("Creator")]", [GetCSharpDatasetType("ID", "")]).Value = entity.EntityCreator; [if (IsMasterEntity([ENTITY]) == "true" || GetInheritance([ENTITY]) == "tpc")] entity.ID = Convert.ToInt32(command.ExecuteScalar()); [else] command.Parameters.Add("[ConvertNameToCommandParameterName("ID")]", [GetCSharpDatasetType("ID", "")]).Value = entity.ID; // leszármaztatott entitás ID-ja command.ExecuteNonQuery(); [end if] } } #endregion end template