File: install.sql

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (533 lines) | stat: -rw-r--r-- 15,610 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
--
--  install.sql
--
--  $Id$
--
--  BPEL support procedures
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2012 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  

create procedure BPEL.BPEL.header (in script varchar:='', in body_arg varchar:='')
{
  declare messargs varchar;
  http (sprintf ('
    <HTML>
      <HEAD>
        <TITLE>OpenLink BPEL Process Manager</TITLE>
        <META HTTP-EQUIV="Cache-Control" content="no-cache">
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; windows-1251">
        <link rel="stylesheet" type="text/css" href="default.css" />
        %s
      </HEAD>
      <body bgcolor="#FFFFFF" topmargin="0" leftmargin="6" marginheight="0" marginwidth="6" %s>
  ', script, body_arg));
  set isolation='uncommitted';
}
;


create procedure BPEL.BPEL.footer ()
{
  http ('</body></HTML>');
}
;


create procedure BPEL.BPEL.trav_script (inout idarr any, in op_id integer)
{
	for select bg_childs from BPEL.BPEL.graph
		where bg_node_id = op_id
	do
	{
		idarr := BPEL.BPEL.vector_push (idarr, op_id);

		if (bg_childs is not null)
		{
			declare idx int;
			idx := 0;

--
			idarr := BPEL.BPEL.vector_push (idarr, -1);

			while (idx < length (bg_childs))
			{
				BPEL.BPEL.trav_script (idarr, aref (bg_childs, idx));
				idx := idx + 1;
			}
--
			idarr := BPEL.BPEL.vector_push (idarr, -2);

		}
	}
}
;

create procedure BPEL.BPEL.script_ids (in script_id int, in op_id integer)
{
	declare vec0 any;


	vec0 := lvector ();

	BPEL.BPEL.trav_script (vec0, op_id);

	return vec0;
}
;

create procedure BPEL.BPEL.get_activity (in op_id int)
{
	for select bg_activity, bg_parent from BPEL.BPEL.graph
		where bg_node_id = op_id
	do
	{
		declare activity BPEL.BPEL.activity;
                declare id int;

		activity := bg_activity;
                id := bg_parent;
                if (id = -1)
                  return 'Scope';
                else
		return activity.ba_type;
	}

}
;

create procedure BPEL.BPEL.get_wait (in inst_id int, in node_id varchar)
{

	if (exists (select * from BPEL.BPEL.wait
		where bw_instance = inst_id
		and bw_node = node_id))
	{
		http (sprintf ('<A HREF="wait.vsp?inst=%d&node=%d"> &gt; </a>', inst_id, node_id));
	}
}
;

create procedure BPEL.BPEL.spaces (in sp int)
{
	declare _inx integer;

	while (_inx < sp)
	{
		_inx := _inx + 1;
	}
        return _inx;
}
;

create procedure BPEL.BPEL.report_error (in err varchar, in _desc varchar)
{
  --http (sprintf('<report type="error"><res><![CDATA[%s]]></res><desc><![CDATA[%s]]></desc></report>',err,_desc));
  return sprintf('<report type="error"><res><![CDATA[%s]]></res><desc><![CDATA[%s]]></desc></report>',err,_desc);
}
;

create procedure BPEL.BPEL.report_result (in err varchar, in _desc varchar)
{
  --http (sprintf('<report type="result"><res><![CDATA[%s]]></res><desc><![CDATA[%s]]></desc></report>',err,_desc));
  return sprintf('<report type="result"><res><![CDATA[%s]]></res><desc><![CDATA[%s]]></desc></report>',err,_desc);
}
;

create procedure BPEL.BPEL.date_fmt (in dt datetime)
{
  declare y, m, d any;
  y := year (dt);
  m := month (dt);
  d := dayofmonth (dt);
  return sprintf ('%02d/%02d/%04d %02d:%02d', d,m,y, hour(dt), minute(dt));
}
;

create procedure BPEL.BPEL.datetime_format_parse (in str varchar)
{
	declare num int;
	num := 0;
	declare unit varchar;
	unit := null;
whenever sqlstate '22007' goto notdatetime;
	declare res datetime;
	res:= cast (str as datetime);
	return res;
notdatetime:
	declare terms any;
	terms := split_and_decode (str, 0, '\0\0 ');

	declare terms_idx int;
	terms_idx := 0;

	declare st varchar;
	st := 'DIG';
whenever sqlstate '22007' goto next;
	while (terms_idx < length (terms)) {
		if (st = 'DIG') {
			num := cast (aref (terms, terms_idx) as integer);
			st := 'PER';
		}
		if (st = 'PER') {
			if (ucase (aref (terms, terms_idx)) like 'DAY%') {
				unit := 'day';
				st := 'AGO?';
			}
			if (ucase (aref (terms, terms_idx)) like 'HOUR%') {
				unit := 'hour';
				st := 'AGO?';
			}
			if (ucase (aref (terms, terms_idx)) like 'MINUTES%') {
				unit := 'minute';
				num := num ;
				st := 'AGO?';
			}
		}
		if (st = 'AGO?')
			if (ucase (aref (terms, terms_idx)) = 'AGO') {
				num := -num;
		}
next:
		terms_idx:= terms_idx + 1;
		;
	}
	if (unit is null)
		return now();
	return dateadd (unit, num, now());
}
;


create procedure BPEL.BPEL.instances_vsp_reverse (inout nm varchar, in sort varchar)
{
	if (nm = sort) {
		if (sort like '%2') {
			nm := substring (sort, 1, length (sort) - 1);
		} else {
			nm := concat (sort, '2');
		}
	}
}
;

create procedure BPEL.BPEL.bpel_add_predifined_endpoint (in pNewPart varchar, in pEndPoint varchar, in pMode integer := 1)
{
  -- pMode = 0 called from UI

  declare
   _error,
   _errorE,
   _errorRes,
   _msg varchar;

  _errorRes := 0;
  _error := 'Empty values are not allowed';
  _errorE := 'Predefined partner link with this name already exists!';

  _msg := sprintf ('Added predefined endpoint %s for %s', pEndPoint, pNewPart);

  if ( pNewPart <> '' and pEndPoint <> '')
    {
      if ( exists (SELECT 1 FROM  BPEL.BPEL.partner_link_conf WHERE plc_name = pNewPart))
        {
          if ( pMode = 0 ){
             BPEL.BPEL.report_error ('error: ', _errorE);
             return;
          } else {
             return _errorE;
          };
        };
      insert into BPEL.BPEL.partner_link_conf values (pNewPart, pEndPoint);
    }
  else
    {
      _errorRes := 1;
    };

  if ( pMode = 0 and _errorRes = 0 )
    {
      -- UI and success action
      BPEL.BPEL.report_result ('info: ', _msg);
    }
  else if ( pMode = 0 and _errorRes = 1 )
    {
      -- UI and unsuccess action
      BPEL.BPEL.report_error ('error: ', _error);
    }
  else if ( pMode = 1 and _errorRes = 0 )
    {
      -- isql and success action
      return _msg;
    }
  else if ( pMode = 1 and _errorRes = 1 )
    {
      -- isql and unsuccess action
      return _error;
    }
  else
    {
      return 'Invalid parameters';
    };
  return;
}
;

create procedure BPEL.BPEL.bpel_update_predifined_endpoint (in pNewPart varchar, in pEndPoint varchar, in pMode integer := 1)
{
  -- pMode = 0 called from UI

  declare
   _error,
   _errorRes,
   _msg,
   _errorNE varchar;

  _errorRes := 0;
  _error := 'Empty values are not allowed';
  _errorNE := 'There is no Predifined Partner Link with such a name.';

  _msg := sprintf ('New predefined endpoint for %s is %s', pNewPart, pEndPoint);

  if ( pNewPart <> '' and pEndPoint <> '')
    {
      if ( not exists (SELECT 1 FROM  BPEL.BPEL.partner_link_conf WHERE plc_name = pNewPart))
       {
         if ( pMode = 0 ){
            BPEL.BPEL.report_error ('error: ', _errorNE);
            return;
         } else {
            return _errorNE;
         };
       };
      update BPEL.BPEL.partner_link_conf
         set plc_endpoint = pEndPoint
       where plc_name = pNewPart;
    }
  else
    {
      _errorRes := 1;
    };

  if ( pMode = 0 and _errorRes = 0 )
    {
      -- UI and success action
      BPEL.BPEL.report_result ('info: ', _msg);
    }
  else if ( pMode = 0 and _errorRes = 1 )
    {
      -- UI and unsuccess action
      BPEL.BPEL.report_error ('error: ', _error);
    }
  else if ( pMode = 1 and _errorRes = 0 )
    {
      -- isql and success action
      return _msg;
    }
  else if ( pMode = 1 and _errorRes = 1 )
    {
      -- isql and unsuccess action
      return _error;
    }
  else
    {
      return 'Invalid parameters';
    };
  return;
}
;

-- allow only dba group
create procedure BPEL.BPEL.sql_user_password_check (in name varchar, in pass varchar)
{
  declare gid, uid int;
  whenever not found goto nf;
  select U_ID, U_GROUP into uid, gid from SYS_USERS
      where U_NAME = name and U_SQL_ENABLE = 1 and U_IS_ROLE = 0 and pwd_magic_calc(U_NAME, U_PASSWORD, 1) = pass;
  if (gid = 0 or uid = 0)
    return 1;
  nf:
  return 0;
}
;

create procedure BPEL.BPEL.bpel_get_page_name ()
{
  declare path, url, elm varchar;
  declare arr any;
  path := http_path ();
  arr := split_and_decode (path, 0, '\0\0/');
  elm := arr [length (arr) - 1];
  url := xpath_eval ('//*[@url = "'|| elm ||'"]', xml_tree_doc (BPEL.BPEL.bpel_menu_tree ()));
  --dbg_obj_print (url);
  if (url is not null or elm = 'error.vspx')
    return elm;
  else
    return '';
}
;

create procedure BPEL.BPEL.bpel_menu_tree ()
{
  return concat (
'<?xml version="1.0" ?>
   <bpel_menu_tree>
     <node name="Home" url="home.vspx" id="7" allowed="bpel_hom">
       <node name="OpenLink BPEL Process Manager Home" url="home.vspx" id="71" allowed="bpel_hom_view"/>
     </node>
     <node name="Processes" url="process.vspx" id="0" allowed="bpel_web">
       <node name="Processes List" url="process.vspx" id="2" allowed="bpel_process">
         <node name="Process" url="script.vspx" id="21" place="left" allowed="bpel_process">
           <node name="Instance Audit" url="activity.vspx" id="211" place="left" allowed="bpel_process"/>
           <node name="Instance status" url="status.vspx" id="222" place="left" allowed="bpel_process"/>
           <node name="Partner Links" url="plinks.vspx" id="223" place="left" allowed="bpel_process"/>
           <node name="Partner Links Properties" url="plinks_props.vspx" id="223" place="left" allowed="bpel_process"/>
         </node>
       </node>
       <node name="Process upload" url="upload_new.vspx" id="3" allowed="bpel_upload">
         <node name="browser" url="browser.vspx" id="31" place="left" allowed="bpel_upload"/>
         <node name="confirm" url="bpel_confirm.vspx" id="32" place="left" allowed="bpel_upload"/>
       </node>
     </node>
    <node name="Instances" url="instances.vspx" id="12" allowed="bpel_inst">
      <node name="Instances" url="instances.vspx" id="13" allowed="bpel_inst1"/>
    </node>
    <node name="Debugger" url="incoming.vspx" id="4" allowed="bpel_debug">
      <node name="Debugger Console" url="incoming.vspx" id="5" allowed="bpel_debug_console">
        <node name="Invoke Service" url="message.vspx" id="51" place="left" allowed="bpel_debug_console"/>
        <node name="Debug Messages" url="imsgpr.vspx" id="52" place="left" allowed="bpel_debug_console"/>
        <node name="Debug Messages" url="omsgpr.vspx" id="53" place="left" allowed="bpel_debug_console"/>
        <node name="Debug Messages" url="rmsgpr.vspx" id="54" place="left" allowed="bpel_debug_console"/>
      </node>
    </node>
    <node name="Statistics and Reports" url="statproc.vspx" id="5" allowed="bpel_statistics">
       <node name="Statistics" url="statproc.vspx" id="6" allowed="bpel_1">
           <node name="Process Statistics" url="statproc.vspx" id="61" allowed="bpel_2"/>
           <node name="End Point Statistics" url="statendp.vspx" id="62" allowed="bpel_3"/>
       </node>
       <node name="Custom Reports" url="reports.vspx" id="9" allowed="bpel_4"/>
    </node>
    <node name="Configuration" url="configure.vspx" id="10" allowed="bpel_conf">
       <node name="Edit Configuration" url="configure.vspx" id="11" allowed="bpel_conf_edith"/>
    </node>
   </bpel_menu_tree>');
}
;


create procedure BPEL.BPEL.bpel_navigation_root (in path varchar)
{
  return xpath_eval ('/bpel_menu_tree/*', xml_tree_doc (BPEL.BPEL.bpel_menu_tree ()), 0);
}
;

create procedure BPEL.BPEL.bpel_navigation_child (in path varchar, in node any)
{
  path := concat (path, '[not @place]');
  return xpath_eval (path, node, 0);
}
;

create procedure BPEL.BPEL.check_grants (in user_name  varchar, in role_name varchar) {
  declare user_id, group_id, role_id, sql_enabled, dav_enabled integer;
  whenever not found goto nf;
  if (user_name='') return 0;
  select U_ID, U_GROUP into user_id, group_id from SYS_USERS where U_NAME=user_name;
  if (user_id = 0 OR group_id = 0)
    return 1;
  if (role_name is null or role_name = '')
    return 0;

  select U_ID into role_id from SYS_USERS where U_NAME=role_name;
  if (exists(select 1 from SYS_ROLE_GRANTS where GI_SUPER=user_id and GI_SUB=role_id))
      return 1;
nf:
  return 0;
}
;

create procedure
get_xml_meta ()
{
  declare mtd, dta any;
  exec ('select top 1 xtree_doc(''<q/>'') from db.dba.sys_users', null, null, vector (), -1, mtd, dta );
  return mtd[0];
}
;


insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('MailServer', null, 'Outgoing SMTP Server')
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('EngineMailAddress', null, 'BPEL Operator E-Mail address')
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('CommonEmailHeader',   'Subject: {SUBJECT}\r\n', 'Email header for all e-mails');
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('ErrorSubject',   'BPEL Engine error report', 'Subject for error report mail');
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('AlertSubject',   'BPEL Engine alert', 'Subject for error alert mail');
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('ErrorReportSkeleton',   'The script {SCRIPT} (instance No {INSTANCE}) was aborted with following error:\n\r{ERROR}\n\r at {DATE}.', 'E-Mail template for error notifications')
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('InstanceExpiryDelay', '24', 'Interval for instance expiration (hours)')
;


insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('ErrorAlertSkeleton',   '{ERROR}\n\rat {DATE}.',
		'E-Mail template for error alerts')
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('Statistics', 0, 'Global statistics flag')
;

insert soft BPEL..configuration (conf_name, conf_value, conf_desc)
	values ('CLRAssembliesDir', NULL, 'Directory where .NET CLR assemblies must be stored')
;

create procedure BPEL.BPEL.conf_default ()
{
  update BPEL..configuration set conf_value = null where conf_name = 'MailServer';
  update BPEL..configuration set conf_value = null where conf_name = 'EngineMailAddress';
  update BPEL..configuration set conf_value = 'Subject: {SUBJECT}\r\n' where conf_name = 'CommonEmailHeader';
  update BPEL..configuration set conf_value = 'BPEL Engine error report' where conf_name = 'ErrorSubject';
  update BPEL..configuration set conf_value = 'BPEL Engine alert' where conf_name = 'AlertSubject';
  update BPEL..configuration set conf_value = 'The script {SCRIPT} (instance No {INSTANCE}) was aborted with following error:\n\r{ERROR}\n\r at {DATE}.' where conf_name = 'ErrorReportSkeleton';
  update BPEL..configuration set conf_value = '24' where conf_name = 'InstanceExpiryDelay';
  update BPEL..configuration set conf_value = '{ERROR}\n\rat {DATE}.' where conf_name = 'ErrorAlertSkeleton';
  update BPEL..configuration set conf_value = 0 where conf_name = 'Statistics';
  update BPEL..configuration set conf_value = null where conf_name = 'CLRAssembliesDir';
}
;