114 lines
4.4 KiB
Text
114 lines
4.4 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 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
|