init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue