141 lines
No EOL
6.2 KiB
Text
141 lines
No EOL
6.2 KiB
Text
//***************************************************************************//
|
|
// 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 |