//***************************************************************************// // 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