init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
2056
Tools/CodeGeneration/Templates/Database/SQLGenerator.tdl
Normal file
2056
Tools/CodeGeneration/Templates/Database/SQLGenerator.tdl
Normal file
File diff suppressed because it is too large
Load diff
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
|
|
@ -0,0 +1,288 @@
|
|||
//***************************************************************************//
|
||||
// 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 Create Table Indexes script generator STARTED at \t"time()"\n";
|
||||
GenerateRenameIndexesScript();
|
||||
info = "Skeleton DB Create Table Indexes 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] = "mssql";
|
||||
break;
|
||||
|
||||
//DB2 Type
|
||||
case "DB2" :
|
||||
[dbtag] = "db2";
|
||||
break;
|
||||
end switch
|
||||
|
||||
setOutput( [OutputDir] "/" "create.rename.indexes."[dbtag]".sql" );
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja az indexeket létrehozó SQL szkriptet //
|
||||
//***************************************************************************//
|
||||
proc GenerateRenameIndexesScript()
|
||||
local tablename = "";
|
||||
local localkey = "";
|
||||
local indexname = "";
|
||||
local package = "";
|
||||
local indexnameold = "";
|
||||
|
||||
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ákhoz FK indexek
|
||||
loop (Instances -> MClass Where(GetStereoType([MClass]) == "Entity" ) )
|
||||
loop( MClass -> MAttribute Where ([MAttribute.type] == "DictionaryItem"))
|
||||
[package] = GetPackage([MClass]);
|
||||
|
||||
[tablename] = ConvertNameToSQLTableScript([MClass.name]);
|
||||
if(IsMasterEntity([MClass]) == "true")
|
||||
[localkey] = "C_INTEZMENYID, C_TANEVID, " ConvertNameToSQLColumnName([MAttribute.name]) ;
|
||||
[indexname] = ConvertNameToIndexName([MClass.name], "") "IntezmenyId_TanevId_" [MAttribute.name];
|
||||
else
|
||||
[localkey] = "C_ALINTEZMENYID, C_ALTANEVID, " ConvertNameToSQLColumnName([MAttribute.name]);
|
||||
[indexname] = ConvertNameToIndexName([MClass.name], "") "AlintezmenyId_AltanevId_" [MAttribute.name];
|
||||
end if
|
||||
[indexnameold] = ConvertNameToIndexNameOld([MClass.id]"_"[MAttribute.id]);
|
||||
|
||||
out = CreateIndexRename([tablename],[indexname],[indexnameold]);
|
||||
end loop
|
||||
end loop
|
||||
|
||||
out = "--/*Entitások egyébb FK*/\n";
|
||||
// Entitások foreign key indexei.
|
||||
// ö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")
|
||||
GenerateTableRenameIndexesForClass( [MClass] );
|
||||
end loop
|
||||
|
||||
out = "--/*kapcsoló tábla FK*/\n";
|
||||
// az asszociacios osztalyokon kivuli, csak kapcsolotablaval reprezentalhato
|
||||
// relaciok eredmenyezte indexek
|
||||
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..*")
|
||||
)
|
||||
|
||||
[indexname] = ConvertNameToIndexName(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]), ConvertRoleToName([StartRole]));
|
||||
[indexnameold] = ConvertNameToIndexNameOld([StartRole.id]"_"[StartClass.id]);
|
||||
[tablename] = ConvertNameToSQLTableScript(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]));
|
||||
out = CreateIndexRename([tablename],[indexname],[indexnameold]);
|
||||
|
||||
[indexname] = ConvertNameToIndexName(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]), ConvertRoleToName([EndRole]));
|
||||
[indexnameold] = ConvertNameToIndexNameOld([EndRole.id]"_"[EndClass.id]);
|
||||
[tablename] = ConvertNameToSQLTableScript(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]));
|
||||
out = CreateIndexRename([tablename],[indexname],[indexnameold]);
|
||||
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
end loop
|
||||
|
||||
// loop (Instances -> MClass as CLASS WHERE GetStereoType([CLASS]) == "Entity")
|
||||
// if (IsMasterEntity([CLASS]) == "true" )
|
||||
// out = CreateIndex(ConvertNameToSQLTableScript([CLASS.name]), ConvertNameToIndexName([CLASS.id]"_LSTCHNGD"), "LASTCHANGED");
|
||||
// end if
|
||||
// end loop
|
||||
|
||||
if ( [SQL_DBType] == "ORACLE")
|
||||
out = "quit\n/";
|
||||
end if
|
||||
end proc
|
||||
|
||||
|
||||
proc GenerateTableRenameIndexesForClass(MClass)
|
||||
local res = "";
|
||||
local ident = " ";
|
||||
local HasAC = "";
|
||||
|
||||
local fieldName = "";
|
||||
local functionName = "";
|
||||
local complexIndex = "";
|
||||
local attributeNames = "";
|
||||
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE], "index")) == "1")
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE.name]) ")";
|
||||
end if
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], [ATTRIBUTE.name]),ConvertNameToIndexNameOld([ATTRIBUTE.id]));
|
||||
// out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([ATTRIBUTE.id]), [fieldName] );
|
||||
// out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], [ATTRIBUTE.name]), [fieldName] );
|
||||
end loop
|
||||
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE], "index1")) == "1" )
|
||||
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [fieldName];
|
||||
[attributeNames] = [ATTRIBUTE.name];
|
||||
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE2 Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE2], "index1")) == "2" )
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE2], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE2.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE2.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [complexIndex] "," [fieldName];
|
||||
[attributeNames] = [attributeNames] "_"[ATTRIBUTE2.name];
|
||||
|
||||
end loop
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE2 Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE2], "index1")) == "3" )
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE2], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE2.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE2.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [complexIndex] "," [fieldName];
|
||||
[attributeNames] = [attributeNames] "_"[ATTRIBUTE2.name];
|
||||
end loop
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], ""),ConvertNameToIndexNameOld([MClass.id] "_1"));
|
||||
//out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], "") toUpper([attributeNames]), [complexIndex] );
|
||||
end loop
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE], "index2")) == "1" )
|
||||
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [fieldName];
|
||||
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE2 Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE2], "index2")) == "2" )
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE2], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE2.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE2.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [complexIndex] "," [fieldName];
|
||||
end loop
|
||||
loop ( MClass -> MAttribute as ATTRIBUTE2 Where toLower(GetTaggedValueOfAttribute([ATTRIBUTE2], "index2")) == "3" )
|
||||
[functionName] = GetTaggedValueOfAttribute([ATTRIBUTE2], "index_function");
|
||||
if ([functionName] == "")
|
||||
[fieldName] = ConvertNameToSQLColumnName([ATTRIBUTE2.name]);
|
||||
else
|
||||
[fieldName] = [functionName] "(" ConvertNameToSQLColumnName([ATTRIBUTE2.name]) ")";
|
||||
end if
|
||||
|
||||
[complexIndex] = [complexIndex] "," [fieldName];
|
||||
end loop
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], [MClass.id] "_2"),ConvertNameToIndexNameOld([MClass.id] "_2"));
|
||||
// out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], [MClass.id] "_2"), [complexIndex] );
|
||||
end loop
|
||||
|
||||
loop (MClass->Role as StartRole ->MAssociation as CurentAssoc ->MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id]!=[EndRole.id]) and GetStereoType([PartnerClass]) == "Entity"))
|
||||
[HasAC] = HasAssociationClass([CurentAssoc]);
|
||||
// csak ha nincs a relaciohoz asszociacios osztaly rendelve
|
||||
// akkor kell ennel az osztalynal felvenni az oszlopokat.
|
||||
if ([HasAC] == "")
|
||||
|
||||
if (
|
||||
//0..1-1
|
||||
([StartRole.multiplicity]=="0..1" and [EndRole.multiplicity]=="1") or
|
||||
//1..*-1
|
||||
([StartRole.multiplicity]=="1..*" and [EndRole.multiplicity]=="1") or
|
||||
//*-1
|
||||
([StartRole.multiplicity]=="*" and [EndRole.multiplicity]=="1") or
|
||||
([StartRole.multiplicity]=="0..*" and [EndRole.multiplicity]=="1") or
|
||||
//1..*-0..1
|
||||
([StartRole.multiplicity]=="1..*" and [EndRole.multiplicity]=="0..1") or
|
||||
//*-0..1
|
||||
([StartRole.multiplicity]=="*" and [EndRole.multiplicity]=="0..1") or
|
||||
([StartRole.multiplicity]=="0..*" and [EndRole.multiplicity]=="0..1")
|
||||
)
|
||||
//tablename,indexname,localkey
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], ConvertRoleToName([EndRole])),ConvertNameToIndexNameOld([EndRole.id]"_"[CurentAssoc.id]));
|
||||
// out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], ConvertRoleToName([EndRole])), ConvertNameToSQLColumnName(ConvertRoleToName([EndRole])));
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
//Asszociacios osztaly relaciok
|
||||
loop (MClass -> 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" ))
|
||||
// foreign kulcsokra index
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], ConvertRoleToName([StartRole])),ConvertNameToIndexNameOld([StartRole.id]"_"[CurrentAssoc.id]));
|
||||
//out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], ConvertRoleToName([StartRole])), ConvertNameToSQLColumnName(ConvertRoleToName([StartRole])) );
|
||||
|
||||
out = CreateIndexRename(ConvertNameToSQLTableScript([MClass.name]),ConvertNameToIndexName([MClass.name], ConvertRoleToName([EndRole])),ConvertNameToIndexNameOld([EndRole.id]"_"[CurrentAssoc.id]));
|
||||
//out = CreateIndex(GetPackage([MClass]), ConvertNameToSQLTableScript([MClass.name]), ConvertNameToIndexName([MClass.name], ConvertRoleToName([EndRole])), ConvertNameToSQLColumnName(ConvertRoleToName([EndRole])) );
|
||||
end loop
|
||||
end loop
|
||||
|
||||
return [res];
|
||||
end proc
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
//***************************************************************************//
|
||||
// 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 Create Table Indexes script generator STARTED at \t"time()"\n";
|
||||
GenerateCreateTableIndexesScript();
|
||||
info = "Skeleton DB Create Table Indexes 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] "/" "create.indexes"[dbtag]".sql" );
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja az indexeket létrehozó SQL szkriptet //
|
||||
//***************************************************************************//
|
||||
proc GenerateCreateTableIndexesScript()
|
||||
local tablename = "";
|
||||
local localkey = "";
|
||||
local indexname = "";
|
||||
local package = "";
|
||||
|
||||
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ákhoz FK indexek
|
||||
loop (Instances -> MClass Where(GetStereoType([MClass]) == "Entity" ) )
|
||||
loop( MClass -> MAttribute Where ([MAttribute.type] == "DictionaryItem"))
|
||||
[package] = GetPackage([MClass]);
|
||||
|
||||
[tablename] = ConvertNameToSQLTableScript([MClass.name]);
|
||||
if(IsMasterEntity([MClass]) == "true")
|
||||
[localkey] = "C_INTEZMENYID, C_TANEVID, " ConvertNameToSQLColumnName([MAttribute.name]) ;
|
||||
[indexname] = ConvertNameToIndexName([MClass.name], "") "IntezmenyId_TanevId_" [MAttribute.name];
|
||||
else
|
||||
[localkey] = "C_ALINTEZMENYID, C_ALTANEVID, " ConvertNameToSQLColumnName([MAttribute.name]);
|
||||
[indexname] = ConvertNameToIndexName([MClass.name], "") "AlintezmenyId_AltanevId_" [MAttribute.name];
|
||||
end if
|
||||
|
||||
out = CreateIndex([package], [tablename],[indexname],[localkey]);
|
||||
end loop
|
||||
end loop
|
||||
|
||||
out = "--/*Entitások egyébb FK*/\n";
|
||||
// Entitások foreign key indexei.
|
||||
// ö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")
|
||||
GenerateTableIndexesForClass( [MClass] );
|
||||
end loop
|
||||
|
||||
out = "--/*kapcsoló tábla FK*/\n";
|
||||
// az asszociacios osztalyokon kivuli, csak kapcsolotablaval reprezentalhato
|
||||
// relaciok eredmenyezte indexek
|
||||
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..*")
|
||||
)
|
||||
|
||||
[package] = GetPackage([StartClass]);
|
||||
out = CreateIndex([package],ConvertNameToSQLTableScript(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole])), ConvertNameToIndexName(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]), ConvertRoleToName([StartRole])), ConvertNameToSQLColumnName(ConvertRoleToName([StartRole])));
|
||||
out = CreateIndex([package],ConvertNameToSQLTableScript(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole])), ConvertNameToIndexName(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]), ConvertRoleToName([EndRole])), ConvertNameToSQLColumnName(ConvertRoleToName([EndRole])));
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
end loop
|
||||
|
||||
// loop (Instances -> MClass as CLASS WHERE GetStereoType([CLASS]) == "Entity")
|
||||
// if (IsMasterEntity([CLASS]) == "true" )
|
||||
// out = CreateIndex(ConvertNameToSQLTableScript([CLASS.name]), ConvertNameToIndexName([CLASS.id]"_LSTCHNGD"), "LASTCHANGED");
|
||||
// end if
|
||||
// end loop
|
||||
|
||||
if ( [SQL_DBType] == "ORACLE")
|
||||
out = "quit\n/";
|
||||
end if
|
||||
end proc
|
|
@ -0,0 +1,114 @@
|
|||
//***************************************************************************//
|
||||
// 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 Create Table script generator STARTED at \t"time()"\n";
|
||||
GenerateCreateTableScript();
|
||||
info = "Skeleton DB Create Table 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] = "";
|
||||
[CimbyTest_MSSQL] = "true";
|
||||
break;
|
||||
|
||||
//DB2 Type
|
||||
case "DB2" :
|
||||
[dbtag] = ".db2";
|
||||
break;
|
||||
end switch
|
||||
|
||||
setOutput( [OutputDir] "/" "create.tables"[dbtag]".sql" );
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja a táblákat létrehozó SQL szkriptet. //
|
||||
//***************************************************************************//
|
||||
proc GenerateCreateTableScript()
|
||||
|
||||
out = [BOM];
|
||||
// sémák generálása
|
||||
loop (Instances -> MPackage WHERE IsPackageAllowed([MPackage.name]) == "True" and [MPackage.name] != [ProjectName])
|
||||
out = CreateExtendedSchema([MPackage.name]);
|
||||
end loop
|
||||
|
||||
// az entity stereotipiaval ellatott osztalyok
|
||||
// tabla szerkezetenek elkeszitese
|
||||
loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity")
|
||||
out = ConvertClassToTable( [MClass] );
|
||||
end loop
|
||||
|
||||
// az asszociacios osztalyokon kivuli, csak kapcsolotablaval reprezentalhato
|
||||
// relaciok eredmenyezte tabla definiciok.
|
||||
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..*")
|
||||
)
|
||||
out = ConvertAssociationToSwitchTable([StartRole],[EndRole],[StartClass],[EndClass]);
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
end loop
|
||||
|
||||
if ( [SQL_DBType] == "ORACLE")
|
||||
out = "quit\n/";
|
||||
end if
|
||||
|
||||
// view szerkezetenek elkeszitese
|
||||
// loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity")
|
||||
// out = ConvertClassToView( [MClass] );
|
||||
// end loop
|
||||
end proc
|
134
Tools/CodeGeneration/Templates/Database/SQL_CreateViewScript.tdl
Normal file
134
Tools/CodeGeneration/Templates/Database/SQL_CreateViewScript.tdl
Normal file
|
@ -0,0 +1,134 @@
|
|||
//***************************************************************************//
|
||||
// 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 Create View script generator STARTED at \t"time()"\n";
|
||||
GenerateCreateViewScript();
|
||||
info = "Skeleton DB Create View script generator STOPPED at \t"time()"\n";
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Általános inicializálás //
|
||||
//***************************************************************************//
|
||||
proc Init()
|
||||
local dbtag = "";
|
||||
//current language
|
||||
setLanguage("SQL");
|
||||
|
||||
switch( [SQL_DBType] )
|
||||
//ORACLE Type
|
||||
case "ORACLE" :
|
||||
[dbtag] = "ora";
|
||||
break;
|
||||
|
||||
//MSSQL Type
|
||||
case "MSSQL" :
|
||||
[dbtag] = "mssql";
|
||||
break;
|
||||
|
||||
//DB2 Type
|
||||
case "DB2" :
|
||||
[dbtag] = "db2";
|
||||
break;
|
||||
end switch
|
||||
|
||||
setOutput( [OutputDir] "/" "sp_Global_CreateSchemaViews.sql" );
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
//***************************************************************************//
|
||||
// Legenerálja a view-kat létrehozó SQL szkriptet. //
|
||||
//***************************************************************************//
|
||||
proc GenerateCreateViewScript()
|
||||
|
||||
out = [BOM];
|
||||
out = "-- =============================================\n";
|
||||
out = "-- Description: Schema View-kat generáló script\n";
|
||||
out = "-- =============================================\n";
|
||||
out = "\n";
|
||||
out = "SET ANSI_NULLS ON\n";
|
||||
out = "GO\n";
|
||||
out = "SET QUOTED_IDENTIFIER ON\n";
|
||||
out = "GO\n";
|
||||
out = "\n";
|
||||
out = "IF OBJECT_ID('dbo.sp_Global_CreateSchemaViews') IS NOT NULL\n";
|
||||
out = "BEGIN\n";
|
||||
out = " DROP PROCEDURE [dbo].[sp_Global_CreateSchemaViews]\n";
|
||||
out = "END\n";
|
||||
out = "GO\n";
|
||||
out = "\n";
|
||||
out = "CREATE PROCEDURE [dbo].[sp_Global_CreateSchemaViews]\n";
|
||||
out = " @IntezmenyId int,\n";
|
||||
out = " @IntezmenyAzonosito nvarchar(30),\n";
|
||||
out = " @TanevId int\n";
|
||||
out = "AS\n";
|
||||
out = "BEGIN\n";
|
||||
out = "DECLARE @IntezmenyTemplate nvarchar(50) = 'KR_'+@IntezmenyAzonosito\n";
|
||||
out = "DECLARE @Schema nvarchar(50) = @IntezmenyTemplate+'_Schema'\n";
|
||||
out = "DECLARE @SchemaUser nvarchar(50) = @IntezmenyTemplate + '_user'\n";
|
||||
out = "DECLARE @AktivTanev nvarchar(500)\n";
|
||||
out = "DECLARE @Sql nvarchar(max)\n";
|
||||
|
||||
// az entity stereotipiaval ellatott osztalyok
|
||||
// tabla szerkezetenek elkeszitese
|
||||
loop (Instances->MClass WHERE GetStereoType([MClass]) == "Entity" )
|
||||
if(GetPackage([MClass]) != "stage")
|
||||
out = ConvertClassToView( [MClass] );
|
||||
end if
|
||||
end loop
|
||||
|
||||
// az asszociacios osztalyokon kivuli, csak kapcsolotablaval reprezentalhato
|
||||
// relaciok eredmenyezte tabla definiciok.
|
||||
local AssocClassCount = "";
|
||||
local tableName = "";
|
||||
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..*")
|
||||
)
|
||||
|
||||
if(GetPackage([StartClass]) != "stage")
|
||||
[tableName] = ConvertNameToSQLTableScript(ConvertAssociationRolesToSwitchTableName([StartRole],[EndRole]));
|
||||
out = "/* VIEW: " [tableName] " */\n";
|
||||
out = ConvertAssociatedClassToView([tableName]);
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
end loop
|
||||
end loop
|
||||
out = "END\n";
|
||||
end proc
|
|
@ -0,0 +1,184 @@
|
|||
//***************************************************************************//
|
||||
// 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;
|
||||
|
||||
proc main()
|
||||
Init();
|
||||
// info = "";
|
||||
if ([SQL_DBType] == "MSSQL")
|
||||
out = MultiLanguageViews_Mssql();
|
||||
else
|
||||
if ([SQL_DBType] == "ORACLE")
|
||||
out = MultiLanguageViews_Oracle();
|
||||
end if
|
||||
end if
|
||||
// info = "";
|
||||
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] = "mssql";
|
||||
break;
|
||||
|
||||
//DB2 Type
|
||||
case "DB2" :
|
||||
[dbtag] = "db2";
|
||||
break;
|
||||
end switch
|
||||
|
||||
setOutput( [OutputDir] "/" "create.multilang." [dbtag] ".sql");
|
||||
|
||||
// UTF-8 BOM bájtok
|
||||
setVar("BOM", "\xEF\xBB\xBF");
|
||||
end proc
|
||||
|
||||
|
||||
|
||||
template MultiLanguageViews_Oracle()
|
||||
[BOM]
|
||||
[loop (Instances -> MClass as ENTITY where GetStereoType([ENTITY]) == "Entity" and HasMultiLanguageAttributes([ENTITY]) == _True())]
|
||||
[GenerateMultiLanguageView_Oracle([ENTITY], 1)]
|
||||
/
|
||||
|
||||
[GenerateMultiLanguageView_Oracle([ENTITY], 2)]
|
||||
/
|
||||
|
||||
[GenerateMultiLanguageView_Oracle([ENTITY], 3)]
|
||||
/
|
||||
|
||||
[GenerateMultiLanguageView_Oracle([ENTITY], 4)]
|
||||
/
|
||||
|
||||
[end loop]
|
||||
QUIT
|
||||
|
||||
end template
|
||||
|
||||
|
||||
template GenerateMultiLanguageView_Oracle(MClass as ENTITY, LANGUAGEINDEX)
|
||||
create or replace view [ConvertNameToSQLTableName([ENTITY.name])]_[LANGUAGEINDEX] as
|
||||
select
|
||||
[loop (ENTITY -> MAttribute as ATTRIBUTE)]
|
||||
[if (IsMultiLanguage([ATTRIBUTE]) == _True() and GetLanguageIndex([ATTRIBUTE]) == 0)]
|
||||
nvl([ConvertNameToSQLColumnName([ATTRIBUTE.name])]_[LANGUAGEINDEX], [ConvertNameToSQLColumnName([ATTRIBUTE.name])]) "[ConvertNameToSQLColumnName([ATTRIBUTE.name])]",
|
||||
[else]
|
||||
[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]
|
||||
[if (IsMasterEntity([ENTITY]) == "true")]
|
||||
SERIAL,
|
||||
LASTCHANGED,
|
||||
MODIFIER,
|
||||
CREATED,
|
||||
CREATOR,
|
||||
[end if]
|
||||
ID
|
||||
from
|
||||
[ConvertNameToSQLTableName([ENTITY.name])]
|
||||
end template
|
||||
|
||||
|
||||
template MultiLanguageViews_Mssql()
|
||||
[BOM]
|
||||
[loop (Instances -> MClass as ENTITY where GetStereoType([ENTITY]) == "Entity" and HasMultiLanguageAttributes([ENTITY]) == _True())]
|
||||
[GenerateMultiLanguageView_Mssql([ENTITY], 1)]
|
||||
go
|
||||
|
||||
[GenerateMultiLanguageView_Mssql([ENTITY], 2)]
|
||||
go
|
||||
|
||||
[GenerateMultiLanguageView_Mssql([ENTITY], 3)]
|
||||
go
|
||||
|
||||
[GenerateMultiLanguageView_Mssql([ENTITY], 4)]
|
||||
go
|
||||
|
||||
[end loop]
|
||||
end template
|
||||
|
||||
|
||||
template GenerateMultiLanguageView_Mssql(MClass as ENTITY, LANGUAGEINDEX)
|
||||
if exists ( select name from sysobjects where name = '[ConvertNameToSQLTableName([ENTITY.name])]_[LANGUAGEINDEX]' and type = 'V')
|
||||
drop view [ConvertNameToSQLTableName([ENTITY.name])]_[LANGUAGEINDEX]
|
||||
go
|
||||
|
||||
create view [ConvertNameToSQLTableName([ENTITY.name])]_[LANGUAGEINDEX] as
|
||||
select
|
||||
[loop (ENTITY -> MAttribute as ATTRIBUTE)]
|
||||
[if (IsMultiLanguage([ATTRIBUTE]) == _True() and GetLanguageIndex([ATTRIBUTE]) == 0)]
|
||||
isnull([ConvertNameToSQLColumnName([ATTRIBUTE.name])]_[LANGUAGEINDEX], [ConvertNameToSQLColumnName([ATTRIBUTE.name])]) "[ConvertNameToSQLColumnName([ATTRIBUTE.name])]",
|
||||
[else]
|
||||
[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]
|
||||
[if (IsMasterEntity([ENTITY]) == "true")]
|
||||
SERIAL,
|
||||
LASTCHANGED,
|
||||
MODIFIER,
|
||||
CREATED,
|
||||
CREATOR,
|
||||
[end if]
|
||||
ID
|
||||
from
|
||||
[ConvertNameToSQLTableName([ENTITY.name])]
|
||||
end template
|
||||
|
||||
|
||||
proc HasMultiLanguageAttributes(MClass as ENTITY)
|
||||
loop (ENTITY -> MAttribute as ATTRIBUTE where IsMultiLanguage([ATTRIBUTE]) == _True())
|
||||
return _True();
|
||||
end loop
|
||||
return _False();
|
||||
end proc
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue