89 lines
4.9 KiB
Text
89 lines
4.9 KiB
Text
//***************************************************************************//
|
|
// Legenerálja egy entitás asszociációinak módosítóműveletét a DA-ban //
|
|
//***************************************************************************//
|
|
template GenerateUpdateAssociations(MClass as ENTITY)
|
|
#region UpdateAssociations
|
|
|
|
private const string m_UpdateAssociationCommandText = @"
|
|
update [ConvertNameToSQLTableName([ENTITY.name])]
|
|
set
|
|
[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]))] = :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))],
|
|
[end if]
|
|
[end if]
|
|
[end loop]
|
|
[end loop]
|
|
[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]))] = :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))],
|
|
[ConvertNameToSQLColumnName(ConvertRoleToName([StartRole]))] = :[ConvertNameToCommandParameterName(ConvertRoleToName([StartRole]))],
|
|
[end loop]
|
|
[end loop]
|
|
[end loop]
|
|
[end if]
|
|
[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]))] = :[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" ))]
|
|
[ConvertNameToSQLColumnName(ConvertRoleToName([EndRole]))] = :[ConvertNameToCommandParameterName(ConvertRoleToName([EndRole]))],
|
|
[ConvertNameToSQLColumnName(ConvertRoleToName([StartRole]))] = :[ConvertNameToCommandParameterName(ConvertRoleToName([StartRole]))],
|
|
[end loop]
|
|
[end loop]
|
|
SERIAL = ISNULL(SERIAL,0) + 1,
|
|
LASTCHANGED = :[ConvertNameToCommandParameterName("LastChanged")],
|
|
MODIFIER = :[ConvertNameToCommandParameterName("Modifier")]
|
|
where
|
|
[if (IsMasterEntity([ENTITY]) == "true")]
|
|
(ID = :[ConvertNameToCommandParameterName("ID")]) and (ISNULL(SERIAL,0) = :[ConvertNameToCommandParameterName("Serial")])
|
|
[else]
|
|
(ID = :[ConvertNameToCommandParameterName("ID")])
|
|
[end if]
|
|
";
|
|
|
|
public override bool UpdateAssociations([ENTITY.name] entity)
|
|
{
|
|
[if (IsMasterEntity([ENTITY]) == "false")]
|
|
if (entity.InheritedDA.UpdateAssociations(entity) == false)
|
|
{
|
|
return false;
|
|
}
|
|
[end if]
|
|
|
|
using ([GetCSharpSQLCommandType()] command = DAUtil.CreateCommand(m_UpdateAssociationCommandText))
|
|
{
|
|
dbhelper.BindAssociations(entity, command);
|
|
|
|
DateTime lastchanged = DateTime.Now;
|
|
var modifier = UserContext.Instance.UniqueIdentifier;
|
|
|
|
command.Parameters.Add("[ConvertNameToCommandParameterName("ID")]", [GetCSharpDatasetType("ID", "")]).Value = entity.ID;
|
|
[if (IsMasterEntity([ENTITY]) == "true")]
|
|
command.Parameters.Add("[ConvertNameToCommandParameterName("Serial")]", [GetCSharpDatasetType("Integer", "")]).Value = entity.Serial;
|
|
[end if]
|
|
command.Parameters.Add("[ConvertNameToCommandParameterName("LastChanged")]", [GetCSharpDatasetType("DateTime", "")]).Value = lastchanged;
|
|
command.Parameters.Add("[ConvertNameToCommandParameterName("Modifier")]", [GetCSharpDatasetType("ID", "")]).Value = modifier;
|
|
|
|
bool result = (command.ExecuteNonQuery() == 1);
|
|
[if (IsMasterEntity([ENTITY]) == "true")]
|
|
if (result == true)
|
|
{
|
|
entity.Serial++;
|
|
SetEntityModifier(entity, lastchanged, modifier);
|
|
}
|
|
[end if]
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
end template
|