init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
190
Tools/CodeGeneration/Templates/Database/SQL_AlterTableScript.tdl
Normal file
190
Tools/CodeGeneration/Templates/Database/SQL_AlterTableScript.tdl
Normal file
|
@ -0,0 +1,190 @@
|
|||
//***************************************************************************//
|
||||
// A használt fájlok //
|
||||
//***************************************************************************//
|
||||
USES Common/std;
|
||||
USES Common/Converters;
|
||||
USES Common/CommonUtil;
|
||||
USES Common/StringUtil;
|
||||
USES Common/ModelDataRetreive;
|
||||
USES Common/DBUtil;
|
||||
|
||||
USES Database/SQLGenerator;
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Belépési pont //
|
||||
//***************************************************************************//
|
||||
proc main()
|
||||
// initialize the output and other context information
|
||||
Init();
|
||||
info = "Skeleton DB Alter Table script generator STARTED at \t"time()"\n";
|
||||
GenerateAlterTableScript();
|
||||
info = "Skeleton DB Alter Table script generator STOPPED at \t"time()"\n";
|
||||
|
||||
info = "Skeleton DB Alter Table Check Constraint script generator STARTED at \t"time()"\n";
|
||||
GenerateAlterTableCheckScript();
|
||||
info = "Skeleton DB Alter Table Check Constraint script generator STOPPED at \t"time()"\n";
|
||||
|
||||
info = "Skeleton DB Alter Table Unique Constraint script generator STARTED at \t"time()"\n";
|
||||
GenerateAlterTableUniqueScript();
|
||||
info = "Skeleton DB Alter Table Unique Constraint script generator STOPPED at \t"time()"\n";
|
||||
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Általános inicializálás //
|
||||
//***************************************************************************//
|
||||
proc Init()
|
||||
local dbtag = "";
|
||||
//current language
|
||||
setLanguage("SQL");
|
||||
//mkdir([OutputDir]);
|
||||
|
||||
switch( [SQL_DBType] )
|
||||
//ORACLE Type
|
||||
case "ORACLE" :
|
||||
[dbtag] = ".ora";
|
||||
break;
|
||||
|
||||
//MSSQL Type
|
||||
case "MSSQL" :
|
||||
[dbtag] = "";
|
||||
break;
|
||||
|
||||
//DB2 Type
|
||||
case "DB2" :
|
||||
[dbtag] = ".db2";
|
||||
break;
|
||||
end switch
|
||||
|
||||
setOutput( [OutputDir] "/" "alter.tables"[dbtag]".sql" );
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja a kényszereket létrehozó SQL szkriptet: foreign key, unique //
|
||||
// key, check constraint //
|
||||
//***************************************************************************//
|
||||
proc GenerateAlterTableScript()
|
||||
local tablename = "";
|
||||
local localkey = "";
|
||||
local foreigntablename = "";
|
||||
local pkcname = "";
|
||||
local package = "";
|
||||
local fkname = "";
|
||||
local fknamepartial = "";
|
||||
local foreignschema = "dbo";
|
||||
local tpc = "false";
|
||||
|
||||
out = [BOM];
|
||||
out = "--/* Modell verzio: " GetModelVersion() " */\n\n\n";
|
||||
|
||||
out = "--/*DictionaryItemType és Entitás attributuma közötti FK*/\n";
|
||||
// A DictItemType és entitás táblák közötti
|
||||
// foreign key constraintek
|
||||
loop (Instances -> MClass Where(GetStereoType([MClass]) == "Entity" ) )
|
||||
loop( MClass -> MAttribute Where ([MAttribute.type] == "DictionaryItem"))
|
||||
// info = "Entity alter table script for DictItemTypeTranslatoin : "[MClass.name]" at \t"time()"\n";
|
||||
|
||||
[tablename] = ConvertNameToSQLTableScript([MClass.name]);
|
||||
if(IsMasterEntity([MClass]) == "true")
|
||||
[localkey] = ConvertNameToSQLColumnName([MAttribute.name]) ", C_INTEZMENYID, C_TANEVID";
|
||||
[fknamepartial] = [MAttribute.name] "_IntezmenyId_TanevId";
|
||||
else
|
||||
[localkey] = ConvertNameToSQLColumnName([MAttribute.name]) ", C_ALINTEZMENYID, C_ALTANEVID";
|
||||
[fknamepartial] = [MAttribute.name] "_AlintezmenyId_AltanevId";
|
||||
end if
|
||||
[pkcname] = ConvertNameToForeignKeyConstraint([MClass.name], "");
|
||||
[foreigntablename] = ConvertDictItemTypeToItemTableName([MAttribute.defaultValue]);
|
||||
if (TruncateString([foreigntablename], 4) == "T_DKT")
|
||||
[tpc] = "true";
|
||||
end if
|
||||
[package] = GetSchemaName([MClass]);
|
||||
[fkname] = ConvertNameToForeignKeyName([MClass.name], [fknamepartial], [MAttribute.defaultValue]);
|
||||
out = AddForeignKeyConstraint([package], [foreignschema], [tablename],[pkcname],[localkey], [foreigntablename], [fkname], "true", [tpc]);
|
||||
[tpc] = "false";
|
||||
end loop
|
||||
end loop
|
||||
|
||||
|
||||
out = "--/*Entitások egyébb FK*/\n";
|
||||
// Entitások foreign key konstraintjei.
|
||||
// öröklődés
|
||||
// asszociácios osztály nélküli asszociációk
|
||||
// ha ez az osztály maga asszociációs osztály
|
||||
loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity")
|
||||
// info = "Entity alter table script: "[MClass.name]" at \t"time()"\n";
|
||||
GenerateAlterDefinitionsForClass( [MClass] );
|
||||
end loop
|
||||
|
||||
out = "--/*kapcsoló tábla FK*/\n";
|
||||
// az asszociacios osztalyokon kivuli, csak kapcsolotablaval reprezentalhato
|
||||
// relaciok eredmenyezte constraintek
|
||||
local AssocClassCount = "";
|
||||
loop (Instances -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass])=="Entity" ))
|
||||
loop ( CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where (GetStereoType([EndClass])=="Entity" and [StartRole.id]<[EndRole.id]) )
|
||||
[AssocClassCount] = HasAssociationClass([CurrentAssoc]);
|
||||
if ( [AssocClassCount] == "" )
|
||||
if (
|
||||
//0..1-0..1
|
||||
([StartRole.multiplicity]=="0..1" and [EndRole.multiplicity]=="0..1") or
|
||||
//1..*-1..*
|
||||
([StartRole.multiplicity]=="1..*" and [EndRole.multiplicity]=="1..*") or
|
||||
//1..*-*
|
||||
([StartRole.multiplicity]=="1..*" and [EndRole.multiplicity]=="*") or
|
||||
([StartRole.multiplicity]=="1..*" and [EndRole.multiplicity]=="0..*") or
|
||||
([StartRole.multiplicity]=="*" and [EndRole.multiplicity]=="1..*") or
|
||||
([StartRole.multiplicity]=="0..*" and [EndRole.multiplicity]=="1..*") or
|
||||
//*-*
|
||||
([StartRole.multiplicity]=="*" and [EndRole.multiplicity]=="*") or
|
||||
([StartRole.multiplicity]=="*" and [EndRole.multiplicity]=="0..*") or
|
||||
([StartRole.multiplicity]=="0..*" and [EndRole.multiplicity]=="*") or
|
||||
([StartRole.multiplicity]=="0..*" and [EndRole.multiplicity]=="0..*")
|
||||
)
|
||||
// info = "Switch table alter table script for: ["[StartClass.name] "][" [EndClass.name]"] at \t"time()"\n";
|
||||
out = GenerateAlterDefinitonsForSwitchTable([StartClass],[StartRole],[EndClass],[EndRole], [CurrentAssoc]);
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
end loop
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja a check constraint-eket létrehozó SQL szkriptet. //
|
||||
//***************************************************************************//
|
||||
proc GenerateAlterTableCheckScript()
|
||||
out = "\n--/*Entitások check constraintjei CK*/\n";
|
||||
// Entitások check konstraintjei.
|
||||
// öröklődés
|
||||
// asszociácios osztály nélküli asszociációk
|
||||
// ha ez az osztály maga asszociációs osztály
|
||||
loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity")
|
||||
// info = "Entity alter table check constraint script: "[MClass.name]" at \t"time()"\n";
|
||||
GenerateAlterCheckDefinitionsForClass( [MClass] );
|
||||
end loop
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja a unique key constraint-eket létrehozó SQL szkriptet. //
|
||||
//***************************************************************************//
|
||||
proc GenerateAlterTableUniqueScript()
|
||||
out = "\n--/*Entitások unique constraintjei UK*/\n";
|
||||
// Entitások unique konstraintjei.
|
||||
// öröklődés
|
||||
// asszociácios osztály nélküli asszociációk
|
||||
// ha ez az osztály maga asszociációs osztály
|
||||
loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity")
|
||||
// info = "Entity alter table unique constraint script: "[MClass.name]" at \t"time()"\n";
|
||||
GenerateAlterUniqueDefinitionsForClass( [MClass] );
|
||||
end loop
|
||||
|
||||
if ( [SQL_DBType] == "ORACLE")
|
||||
out = "quit\n/";
|
||||
end if
|
||||
end proc
|
Loading…
Add table
Add a link
Reference in a new issue