File: bpel_ddl.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 (991 lines) | stat: -rw-r--r-- 35,537 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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
--
--  bpel_ddl.sql
--
--  $Id$
--
--  BPEL DB Schema
--  
--  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 exec_no_error(in expr varchar) {
  declare state, message, meta, result any;
  exec(expr, state, message, vector(), 0, meta, result);
}
;

exec_no_error ('
create type BPEL.BPEL.node as (
	bn_id		int,			      -- node id
	bn_parent	int,			      -- parent node id
	bn_top_node 	BPEL.BPEL.node default null,  -- the top-most node
	bn_parent_node 	BPEL.BPEL.node default null,  -- the parent node
	bn_activity	BPEL.BPEL.activity,	      -- activity representing the node
	bn_childs	any,			      -- lvector of node ids of the children nodes
	bn_scope	int,
	bn_script_id 	int,			      -- the script
	bn_cnt		int default 0 -- last activity serial no; valid on top node only
	)
	SELF AS REF
	constructor method node (act BPEL.BPEL.activity, inst int, top_node BPEL.BPEL.node),
	static method new_node (parent BPEL.BPEL.node, act BPEL.BPEL.activity, inst int) returns BPEL.BPEL.node,
	static method new_flow (parent BPEL.BPEL.node, inst int) returns BPEL.BPEL.node,
	static method new_compensation_handler (parent BPEL.BPEL.node, inst int) returns BPEL.BPEL.node,
	static method new_fault_handlers (parent BPEL.BPEL.node, inst int) returns BPEL.BPEL.node,
	static method new_activity (parent BPEL.BPEL.node, inst int) returns BPEL.BPEL.node,
	static method new_sequence (parent BPEL.BPEL.node, inst int) returns BPEL.BPEL.node,
	static method new_invoke (parent BPEL.BPEL.node, inst int,
		_partnerLink varchar,
		_portType varchar,
		_operation varchar,
		_inputVariable varchar,
		_outputVariable varchar,
		_corrs any
		) returns BPEL.BPEL.node,
	static method new_compensate (parent BPEL.BPEL.node, inst int,
		_scope varchar) returns BPEL.BPEL.node,
	static method new_scope (parent BPEL.BPEL.node, inst int, in nm varchar) returns BPEL.BPEL.node,
	method add_child (child BPEL.BPEL.node) returns int')
;

-- Activity Base UDT
exec_no_error('
create type BPEL.BPEL.activity as (
		ba_type 	  varchar,
		ba_id		  int,	-- serial no
		ba_preds_bf varbinary default \'\\x0\\x0\', 	-- bitmask for predecesors to be completed
		ba_init_bf 	  varbinary default \'\\x0\\x0\',	-- bitmask for initialization of loops
		ba_parent_id	  int,
		ba_scope_idx 	  int,	-- index of the current scope"s number in the instance scope no vector
		ba_pscope_idx 	  int,	-- index of the parent scope"s number in the instance scope no vector
		ba_join_cond 	  varchar default NULL,
		ba_suppress_join_fail int default 0,
		ba_scope 	  int default 0,
		ba_fault_hdl 	  int default 0,
		ba_fault_hdl_bit  int default 0,
		ba_src_links	  any,
		ba_tgt_links 	  any,
		ba_enc_scps 	  any,
		ba_succ		  any,
		ba_src_line	  int default null,
		ba_is_event	  int,
		ba_in_comp	  int
		)
	method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int,
	method http_output (mode varchar) returns varchar,
	method add_audit_entry(inst int, node int, in info any) returns int')
;

exec_no_error ('
create type BPEL.BPEL.place as (
	bp_id	int,
	bp_query_prefix varchar
	)
	method get_value (in inst int, in scope int, in scope_inst int) returns any,
	method set_value (in inst int, in scope int, in scope_inst int, in val any) returns int,
	method get_info () returns varchar')
;

exec_no_error ('
create type BPEL.BPEL.place_vpa under BPEL.BPEL.place as (
	ba_var	varchar,
	ba_part varchar,
	ba_query varchar
	)
	overriding method get_value (in inst int, in scope int, in scope_inst int) returns any,
	overriding method set_value (in inst int, in scope int, in scope_inst int, in val any) returns int,
	overriding method get_info () returns varchar,
	constructor method place_vpa (v varchar, part varchar, q varchar)')
;

exec_no_error ('
create type BPEL.BPEL.place_vq under BPEL.BPEL.place as (
	ba_var	varchar,
	ba_query varchar
	)
	overriding method get_value (in inst int, in scope int, in scope_inst int) returns any,
	overriding method set_value (in inst int, in scope int, in scope_inst int, in val any) returns int,
	overriding method get_info () returns varchar,
	constructor method place_vq (v varchar, q varchar)')
;

exec_no_error ('
create type BPEL.BPEL.place_vpr under BPEL.BPEL.place as (
	ba_var	varchar,
	ba_property	varchar
	)
	overriding method get_info () returns varchar,
	constructor method place_vpr (v varchar, prop varchar)')
;

exec_no_error ('
create type BPEL.BPEL.place_plep under BPEL.BPEL.place as (
	ba_pl	varchar,
	ba_ep	varchar
	)
	overriding method get_value (in inst int, in scope int, in scope_inst int) returns any,
	overriding method set_value (in inst int, in scope int, in scope_inst int, in val any) returns int,
	overriding method get_info () returns varchar,
	constructor  method place_plep (pl varchar, ep any)')
;

exec_no_error ('
create type BPEL.BPEL.place_expr under BPEL.BPEL.place as (
	ba_exp	varchar
	)
	overriding method get_value (in inst int, in scope int, in scope_inst int) returns any,
	overriding method set_value (in inst int, in scope int, in scope_inst int, in val any) returns int,
	overriding method get_info () returns varchar,
	constructor method  place_expr (expr varchar)')
;

exec_no_error ('
create type BPEL.BPEL.place_text under BPEL.BPEL.place as (
	ba_text	varchar
	)
	overriding method get_value (in inst int, in scope int, in scope_inst int) returns any,
	overriding method get_info () returns varchar,
	constructor method  place_text (_text varchar)')
;

-- Wait

exec_no_error ('
create type BPEL.BPEL.wait under BPEL.BPEL.activity as (
		ba_seconds	int
	)
	constructor method wait (dt varchar),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;



-- Virtuoso PL extension
exec_no_error ('
create type BPEL.BPEL.sql_exec under BPEL.BPEL.activity as (
	ba_proc_name	varchar,
	ba_sql_text	varchar
	)
	constructor method sql_exec (_text varchar),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- Java extension
exec_no_error ('
create type BPEL.BPEL.java_exec under BPEL.BPEL.activity as (
	ba_class_name	varchar
	)
	constructor method java_exec (name varchar, _text varchar, _imports varchar),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- .NET extension
exec_no_error ('
create type BPEL.BPEL.clr_exec under BPEL.BPEL.activity as (
	ba_class_name	varchar,
	ba_assemblies	any
	)
	constructor method clr_exec (name varchar, _text varchar, _imports varchar, refs any),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;


-- Switch
exec_no_error ('
create type BPEL.BPEL.switch under BPEL.BPEL.activity
	constructor method switch (),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- Case
exec_no_error ('
create type BPEL.BPEL.case1 under BPEL.BPEL.activity as
        (
	  ba_condition	varchar
	)
	constructor method case1 (expr varchar),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- Otherwise
exec_no_error ('
create type BPEL.BPEL.otherwise under BPEL.BPEL.activity
	constructor method otherwise (),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- While
exec_no_error ('
create type BPEL.BPEL.while_st under BPEL.BPEL.activity as
	(
	  ba_condition  varchar
	)
	constructor method while_st (cond varchar),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int')
;

-- Assign (one per copy)
exec_no_error ('create type BPEL.BPEL.assign under BPEL.BPEL.activity as (
	ba_from	BPEL.BPEL.place,
	ba_to	BPEL.BPEL.place
	)
	constructor method assign (_from BPEL.BPEL.place),
	method add_to (_to BPEL.BPEL.place) returns int,
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Flow
exec_no_error ('create type BPEL.BPEL.flow under BPEL.BPEL.activity
	constructor method flow (),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Receive
exec_no_error ('create type BPEL.BPEL.receive under BPEL.BPEL.activity as (
		ba_name		varchar,
		ba_partner_link	varchar, -- id
		ba_port_type	varchar, -- id
		ba_operation	varchar, -- id
		ba_var		varchar, -- inputVariable
		ba_create_inst	int default 0, -- 0 == FALSE
		ba_correlations	any,
		ba_one_way	int
	)
	constructor method receive (_name		varchar,
			_partner_link	varchar,
		        _port_type	varchar,
			_operation	varchar,
			_var		varchar,
			_create_inst	varchar,
			_corrs	any,
			_one_way int
			),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int,
	overriding method http_output (mode varchar) returns varchar,
	--method register_wait_object (inst int, node int, scope int) returns int,
	method register_wait_object (in inst int, in node int, in scope int, in scope_inst int, inout ctx BPEL..ctx) returns int,
	method check_correlation (in msg any, in inst int, in scope int, in scope_inst int, inout ctx BPEL..ctx) returns int,
	method unregister_wait_object (inst int, node int, scope int) returns int');

-- Reply
exec_no_error ('create type BPEL.BPEL.reply under BPEL.BPEL.activity as (
             ba_partnerLink varchar,
             ba_portType varchar,
             ba_operation varchar,
             ba_variable varchar,
             ba_name varchar,
	     ba_fault varchar default null,
	     ba_correlations		any -- correlation
	)
	constructor method reply (
             _partnerLink varchar,
             _portType varchar,
             _operation varchar,
             _variable varchar,
             _name varchar,
	     _corrs any,
	     _fault any
	     ),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int,
	overriding method http_output (mode varchar) returns varchar');

-- Invoke (sync or async)
exec_no_error ('create type BPEL.BPEL.invoke under BPEL.BPEL.activity as (
	ba_name		varchar,
	ba_partner_link	varchar, -- id
        ba_port_type		varchar, -- id
	ba_operation		varchar, -- id
	ba_input_var		varchar, -- inputVariable
	ba_output_var		varchar,
	ba_correlations		any, -- correlation
	is_sync			int default 0
	)
	constructor method invoke ( _partnerLink varchar,
                _portType varchar,
                _operation varchar,
                _inputVariable varchar,
		_outputVariable varchar,
		_corrs any
		),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Sequence
exec_no_error ('create type BPEL.BPEL.sequence under BPEL.BPEL.activity as (
	ba_childs	any -- vector
	)
	constructor method sequence (),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- CompensationHandler
exec_no_error ('create type BPEL.BPEL.compensation_handler under BPEL.BPEL.activity as (
	bch_parent_scope	int,
	bch_node_id	int -- reference to graph
	)
	constructor method compensation_handler (),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int,
	overriding method compensate (in inst int, inout node int, inout amask varbinary) returns int');

exec_no_error ('create type BPEL.BPEL.compensation_handler_end under BPEL.BPEL.activity
	constructor method compensation_handler_end (),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Catch (obsoleted)
exec_no_error ('create type BPEL.BPEL.catch_fault as (
	cf_name		varchar,
	cf_var		varchar,
	cf_node_id	int
	)
	constructor method catch_fault (
		nm varchar,
		vr varchar,
		nd int)');

-- FaultHandler
exec_no_error ('create type BPEL.BPEL.fault_handlers under BPEL.BPEL.activity as (
	bfh_parent_scope	int,
	bfh_cfs			any -- array of BPEL.BPEL.catch_fault
	)
	constructor method fault_handlers (),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

exec_no_error ('create type BPEL.BPEL.scope_end under BPEL.BPEL.activity as
	(
	  se_events any,
	  se_scope_name varchar,
	  se_comp_act int default 0
	)
	constructor method scope_end (inout events any, in scope_name any, in comps int),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Scope
exec_no_error ('create type BPEL.BPEL.scope under BPEL.BPEL.activity as (
	ba_parent_scope	int,
	ba_name	varchar,
	ba_exception any, -- array of fault description, handler node id ref to BPEL.BPEL.graph
	ba_compensation int,  --ref to BPEL.BPEL.graph
	ba_vars any,  -- array of (vars idx -- look at BPEL.BPEL.var
	ba_childs any, -- array
	ba_corrs any -- array of correlation set refs
	)
	constructor method scope (in nm varchar),
	constructor method scope (),
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');


-- Compensate
exec_no_error ('create type BPEL.BPEL.compensate under BPEL.BPEL.activity as (
	ba_scope_name varchar
	)
	constructor method compensate (in _scope varchar),
	method handle_scope (in inst int, in curr_scope int,
		in compensation_scope int,
		in compensation_node int) returns int,
	overriding method http_output (mode varchar) returns varchar,
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- pseudo activity Jump
exec_no_error ('create type BPEL.BPEL.jump under BPEL.BPEL.activity as
	(
	  ba_act_id int,
	  ba_node_id int default 0
	)
	constructor method jump (in act_id int, in node_id int),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- pseudo activity Link
exec_no_error ('create type BPEL.BPEL.link under BPEL.BPEL.activity as
	(
	  ba_name varchar
	)
	constructor method link (in name varchar),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Empty
exec_no_error ('create type BPEL.BPEL.empty under BPEL.BPEL.activity
	constructor method empty ()');

-- Throw
exec_no_error ('create type BPEL.BPEL.throw under BPEL.BPEL.activity as
	(
	  ba_fault varchar
	)
	constructor method throw (in fault varchar),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Catch
exec_no_error ('create type BPEL.BPEL.catch under BPEL.BPEL.activity as
	(
	  ba_fault varchar,
	  ba_var varchar
	)
	constructor method catch (in fault varchar, in var varchar),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Pick
exec_no_error ('create type BPEL.BPEL.pick under BPEL.BPEL.activity as
	(
	  ba_create_inst int
	)
	constructor method pick (in flag varchar),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- onMessage
exec_no_error ('create type BPEL.BPEL.onmessage under BPEL.BPEL.receive
	constructor method onmessage
	(
	 _partner_link	varchar,
	 _port_type	varchar,
	 _operation	varchar,
	 _var		varchar,
	 _create_inst	varchar,
	 _corrs		any,
	 _one_way       int
	),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- onAlarm
exec_no_error ('create type BPEL.BPEL.onalarm under BPEL.BPEL.activity as
	(
	  ba_for_exp varchar,
	  ba_until_exp varchar,
	  ba_seconds int
	)
	constructor method onalarm (in for_exp varchar, in until_exp varchar),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- Terminate
exec_no_error ('create type BPEL.BPEL.terminate under BPEL.BPEL.activity
	constructor method terminate (),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

-- XXX: for testing only : serverFailure
exec_no_error ('create type BPEL.BPEL.server_failure under BPEL.BPEL.activity
	constructor method server_failure (),
	overriding method eval (in inst int, inout scp_inst int, inout node int, inout amask varbinary, inout links varbinary, inout stack any, inout ctx BPEL..ctx) returns int');

--
-- Tables; IMPORTANT: please keep descriptions up-to date
-- the following goes to the documentation
--


-- Scripts table, keeps one record per version
exec_no_error ('create table BPEL.BPEL.script (
	bs_id integer identity, 	-- unique id identifying the process
	bs_uri varchar,			-- obsoleted: script source URI
	bs_name varchar,		-- process name, all versions have same name
	bs_state int, 			-- 0 on, current version, 1 obsolete, 2 edit mode
	bs_date	datetime,		-- date of registration
	bs_audit int default 0, 	-- audit flag : 1 on, 0 off
	bs_debug int default 0,		-- debug flag
	bs_version int default 0,	-- process version
	bs_parent_id int default null,	-- fk to bs_id of previous process version
	bs_first_node_id int,  		-- the first node id in the graph
	bs_pickup_bf varbinary default \'\\x0\',	-- bitmask for resume nodes
	bs_act_num	int, 		-- stores the total number of activities
	bs_lpath	varchar default null, -- virtual directory
	bs_scopes	any,		-- initial copy of scopes array
	bs_step_mode    int default 0,	-- stepping mode flag

	-- process statistics
	bs_n_completed int default 0,
	bs_n_errors int default 0,
	bs_n_create int default 0,
	bs_cum_wait int default 0,
	primary key (bs_id))');

exec_no_error ('create index bs_name on BPEL.BPEL.script (bs_name, bs_state)');

-- BPEL and WSDL sources
exec_no_error ('create table BPEL..script_source
	(
	 bsrc_script_id int, -- script id, fk to bs_id of scripts table.
	 bsrc_role varchar,  -- one of bpel, bpel-ext, wsdl, deploy, partner-1... partner-n
	 bsrc_text long xml, -- source text
	 bsrc_url varchar,   -- if this comes from an uri
	 bsrc_temp varchar,  -- contains the namespaces info
	 primary key (bsrc_script_id, bsrc_role)
)
');



-- Process instances
exec_no_error ('create table BPEL.BPEL.instance (
	bi_id int identity,   		-- global immutable id of instance
	bi_script int,  		-- fk to bs_id from BPEL.BPEL.script
	bi_scope_no int default 0,  	-- sequence counter for scope numbers in instance
	bi_state int default 0,
		-- 0, started
		-- 1, suspended (wait for signal)
		-- 2, finished
		-- 3, aborted
	bi_error any,			-- error
	bi_lerror_handled int,
	bi_last_act	datetime,	-- last activity execution
	bi_started	datetime,	-- start time
	bi_init_oper	varchar,	-- operation that made the instance
	bi_host		varchar,
	bi_wsa		long xml,	-- WS-Addressing headers
	bi_activities_bf varbinary default \'\\x0\\x0\', -- bitmask for each activity is completed or not
	bi_link_status_bf varbinary default \'\\x0\\x0\', -- bitmask for link status
	bi_prefix_info varchar default \'\', -- xpath prefix string
	bi_scopes any,			-- array containing current compensation scopes
	bi_comp_stack any,
	primary key (bi_id))');


-- Initial values (URL etc.) for partner links
exec_no_error ('create table BPEL.BPEL.partner_link_init (
	bpl_script int, 	-- script instance id
	bpl_name varchar,	-- partner link name
	bpl_partner any,  	-- url, end point etc serialized
	bpl_role varchar,
	bpl_myrole varchar,
	bpl_type varchar,
	bpl_endpoint varchar,	-- partner service endpoint URL
	bpl_backup_endpoint varchar,
	bpl_wsdl_uri varchar,
	bpl_debug int default 0,-- debug flag
	bpl_opts long xml,	-- partner link options (WS-Security, WS-RM etc.)
	primary key (bpl_script,bpl_name))');

-- Runtime values for partner links (run time copy of partner_link_init table)
exec_no_error ('create table BPEL..partner_link (
	pl_inst int, 		-- instance id
	pl_name varchar, 	-- partner link name
	pl_scope_inst int, 	-- scope instance id
	pl_role int, 		-- flag 0 - myRole, 1 - partnerRole
	pl_endpoint varchar, 	-- current URL to the partner service
	pl_backup_endpoint varchar, -- second URL to the service for connection error
	pl_debug int default 0,	-- debug flag
	pl_opts long xml,	-- partner link options (WS-Security, WS-RM etc.)
	primary key (pl_inst, pl_name, pl_scope_inst, pl_role))');

-- Script compilation
exec_no_error ('create table BPEL.BPEL.graph (
	bg_script_id int,  	-- FK to bs_id of BPEL.BPEL.script
	bg_node_id int , 	-- running id in the script, referenced from BPEL.BPEL.waits etc.
	bg_activity BPEL.BPEL.activity, -- UDT representing activity
	bg_childs any,
	bg_parent int,
        bg_src_id varchar,	-- internal use
	primary key (bg_script_id, bg_node_id))');

sequence_set ('BPEL_NODE_ID', 1, 1);

-- Receive activities waiting for incoming message
exec_no_error ('create table BPEL.BPEL.wait (
	bw_uid varchar,
	bw_instance integer,  -- instance id
	bw_script varchar,    -- FK reference to bs_name of script table
	bw_script_id int,     -- FK reference to bs_id of script table
	bw_node int,	      -- FK reference to bg_node_id of the graph table
	bw_scope  int,
	bw_partner_link varchar, -- the party from which instance waiting a message
	bw_port varchar,  	 -- the name of the operation which instance wait to receive
	bw_deadline datetime,
	bw_message long varchar default null, -- if instance is occupied and message is already arrived
	bw_state int default 0,		      -- flag that bw_message is not null (0 or 1)
	bw_correlation_exp varchar, 	      -- XPath expression for computing the correlation value from message
	bw_expected_value long varbinary,     -- value of the expected correlation
	bw_message_type int default 0,	      -- where to expect the data : 0 - SOAP:Body 1 - SOAP:Header
	bw_start_date datetime,
	bw_from_comp int default 0,
	bw_security any,
	primary key (bw_instance, bw_node))');

exec_no_error ('create index wait_sp on BPEL.BPEL.wait (bw_port, bw_script, bw_message_type)');

exec_no_error ('create index wait_st on BPEL.BPEL.wait (bw_instance, bw_state)');

exec_no_error ('create index wait_uid on BPEL.BPEL.wait (bw_uid)');

-- Messages which have been arrived but not correlated yet
exec_no_error ('create table BPEL.BPEL.queue (
	bq_id int identity,	-- unique id
	bq_script int,		-- FK references bs_id from the script table
	bq_ts timestamp,
	bq_state int,		-- state of the Queue item; 0 - not processed
	bq_endpoint varchar,	-- not used
	bq_op varchar,		-- Operation name
	bq_mid varchar,		-- mot used
	bq_message long varchar, -- The incoming message text
	bq_header long varchar,  -- SOAP:Header
	bq_security any,
	primary key (bq_op, bq_ts)
	)');


-- Initial values for SOAP Messages and XMLSchema types
exec_no_error ('create table BPEL..types_init (
	vi_script int,	   -- FK reference to bs_id to the script table
	vi_name   varchar, -- message name, element name etc.
	vi_type   int, 	   -- 0 - message, 1 - element, 2 - XMLSchema type
	vi_value  long xml,-- Initial value
	primary key (vi_script, vi_name, vi_type)
)
')
;

-- Matching XPath expressions for the SOAP message parts
exec_no_error ('create table BPEL.BPEL.message_parts
	(
	mp_script int,	    -- FK reference to bs_id to the script table
	mp_message varchar, -- message name
	mp_part varchar,    -- part name
	mp_xp   varchar,    -- location XPath expression
	primary key (mp_script, mp_message, mp_part)
	)
')
;

-- Operations which are invoked by process (used in invoke activities)
exec_no_error ('create table BPEL.BPEL.remote_operation (
	ro_script int,		-- FK reference to bs_id to the script table
	ro_partner_link varchar,-- name of the partner link
	ro_role varchar,	-- not used
	ro_operation varchar,	-- operation name
	ro_port_type varchar,	-- port type
	ro_input varchar,	-- input message name
	ro_output varchar,	-- output message name
	ro_endpoint_uri varchar,-- not used
	ro_style int,		-- messages encoding style : 1 - literal, 0 - RPC like
	ro_action varchar default \'\', -- SOAP Action value
	ro_target_namespace varchar,  -- for RPC encoding the namespace to be used for wrapper elements
	ro_use_wsa int default 0, -- WS-Addressing capabilities flag
	ro_reply_service varchar, -- for one-way operations: reply service name
	ro_reply_port varchar,    -- for one-way operations: reply port type
	primary key (ro_script, ro_partner_link, ro_operation)
)
')
;

-- Operations which process defines (can receive and reply)
exec_no_error ('create table BPEL.BPEL.operation (
	bo_script int,		-- FK reference to bs_id to the script table
	bo_name	varchar,	-- operation name
	bo_action varchar,	-- SOAP Action value
	bo_port_type	varchar,-- port type
	bo_partner_link varchar,-- name of the partner link
	bo_input	varchar,-- input message name
	bo_input_xp	varchar,-- XPath expression to match the input message
	bo_small_input	varchar,-- not used
	bo_output	varchar,-- output message name
	bo_style	int default 0,-- messages encoding style : 1 - literal, 0 - RPC like
	bo_init		int,	-- process instantiation flag: 1 - can make new instances
	primary key (bo_script, bo_name, bo_partner_link)
)')
;

exec_no_error ('create index bo_name on BPEL.BPEL.operation (bo_name)')
;

-- Predefined endpoint URLs for partner links
exec_no_error ('create table BPEL.BPEL.partner_link_conf (
	plc_name	varchar,
	plc_endpoint	varchar,
	primary key (plc_name)
)
')
;

-- Properties
exec_no_error ('create table BPEL.BPEL.property
(
  bpr_script int, 	-- FK reference to bs_id to the script table
  bpr_name varchar,	-- property name
  bpr_type varchar,	-- property type
  primary key (bpr_script, bpr_name)
)
')
;

-- Aliases
exec_no_error ('create table BPEL.BPEL.property_alias (
	pa_script	int,		-- FK reference to bs_id to the script table
	pa_prop_id	int identity,
	pa_prop_name	varchar,	-- property name
	pa_message	varchar,	-- message name
	pa_part		varchar,	-- part name
	pa_query	varchar,	-- XPath query to set the property value
	pa_type		varchar,
	primary key (pa_script, pa_prop_name, pa_message))
')
;

-- Correlation properties
exec_no_error ('create table BPEL.BPEL.correlation_props (
	cpp_id 		int identity (start with 1),
	cpp_script	int,		-- FK reference to bs_id to the script table
	cpp_corr	varchar,	-- correlation name
	cpp_prop_name	varchar,	-- property name
	primary key (cpp_id, cpp_script, cpp_corr, cpp_prop_name))
')
;

-- Variables
exec_no_error ('create table BPEL..variables (
	v_inst 		int,		-- instance id, FK reference bi_id of the instance table
	v_scope_inst   	int,		-- scope instance id; different than 0 for compensation scope
	v_name 		varchar,	-- variable name
	v_type 		varchar,	-- variable type
	v_s1_value	any, 		-- string, numeric
	v_s2_value	varchar, 	-- XML entities
	v_b1_value	long varchar,	-- long strings
	v_b2_value	long varchar, 	-- XML entities
	primary key (v_inst, v_scope_inst, v_name))
')
;

-- Links
exec_no_error ('create table BPEL..links
	(
	  bl_script int,	-- FK reference to bs_id to the script table
	  bl_name   varchar,	-- link name
	  bl_act_id int,	-- corresponding link activity bit number
	  primary key (bl_act_id, bl_script)
	)
')
;

sequence_set ('bpel_scope_id', 1, 1);

-- Compensation scopes
exec_no_error ('create table BPEL..compensation_scope
	(tc_inst int,
	 tc_seq	 int,
	 tc_scope_name varchar default null,
	 tc_scopes long varbinary,
	 tc_head_node int,
	 tc_head_node_bit int,
	 tc_compensating_from int default null,
	 tc_seq_parent	int default null,
	 primary key (tc_inst, tc_seq)
	)
')
;

-- Messages are correlated via WS-Addressing
exec_no_error ('create table BPEL..wsa_messages
	(
	wa_inst int,
	wa_pl	varchar,
	wa_mid  varchar,
	primary key (wa_inst, wa_pl, wa_mid)
	)
')
;

exec_no_error ('create table BPEL..lock
	(
	lck int primary key
	)
')
;

insert soft BPEL..lock (lck) values (1)
;

-- Accepted connections which are waiting for reply
exec_no_error ('create table BPEL..reply_wait
	(
	rw_inst int,
	rw_id int, -- identity (start with 1),
	rw_partner varchar,
	rw_port varchar,
	rw_operation varchar,
	rw_query varchar,
	rw_expect varchar,
	rw_started datetime,
	primary key (rw_inst, rw_id)
	)
')
;

sequence_set ('connection_id', 1, 1);

-- Registered alarm events
exec_no_error ('create table BPEL..time_wait
	(
	  tw_inst 	int,
	  tw_node 	int,
	  tw_scope_inst int,
	  tw_script	varchar,
	  tw_script_id	int,
	  tw_sec  	int,
	  tw_until 	datetime,
	  primary key (tw_inst, tw_node)
	)
')
;

exec_no_error ('create type BPEL..comp_ctx as
	(
	  c_tgtlinks any,
	  c_srclinks any,
	  c_join_cond varchar,
	  c_supp_join varchar,
	  c_current_scope int,
	  c_current_fault int,
	  c_current_fault_bit int,
	  c_enc_scps	any,
          c_internal_id varchar,
	  c_src_line int,
	  c_scopes any,
	  c_event int default 0,
	  c_in_comp int default 0
	)
	self as ref
')
;


exec_no_error ('create type BPEL..ctx as
	(
          c_fault    varchar default null,
	  c_full_err varchar default null,
	  c_comp     int default 0,
	  c_jumps    any,
	  c_flushed  int default 0,
	  c_hdr	     any default null,
	  c_script_id int default null,
	  c_script varchar default null,
	  c_debug int default 0,
	  c_init_oper varchar default null,
	  c_first_node int default 0,
	  c_scope_id int,
	  c_pscope_id int,
	  c_host varchar
	)
       self as ref
')
;

-- BPEL message debugging queue
exec_no_error ('create table BPEL..dbg_message (
	bdm_text long varchar,		-- message text
	bdm_id int identity (start with 1),
	bdm_ts datetime,
	bdm_inout int, 			-- 1 for in, 0 for out
	bdm_sender_inst int, 		-- instance id of sender if outbound message
	bdm_receiver int, 		-- if inbound, inst id of receiving inst
	bdm_plink varchar, 		-- name of partner link in the script in question
	bdm_recipient varchar, 		-- partner link value for outbound message, URL.
	bdm_activity int, 		-- activity id of activity that either sent the message or would receive the message in the sender/receiver instance.
	bdm_oper varchar,		-- operation name
	bdm_script int,			-- process id, FK reference bs_id from script table
	bdm_action varchar,		-- SOAP Action value
	bdm_conn int,			-- client connection id
	primary key (bdm_id)
)
')
;

-- BPEL engine configuration
exec_no_error ('create table BPEL..configuration (
	conf_name	varchar not null,
	conf_desc 	varchar,
	conf_value	any, -- not blob
	conf_long_value	long varchar,
	primary key (conf_name)
)
')
;

exec_no_error ('create trigger dbg_wait_del after delete on BPEL.BPEL.wait {
  delete from BPEL..dbg_message where bdm_sender_inst = bw_instance and bdm_activity = bw_node;
}
')
;

exec_no_error ('create type BPEL.BPEL.partner_link_opts as
	(
	  pl_auth varchar default \'none\',
          pl_keyinst any default null,
	  pl_sec varchar default \'sign\',
	  pl_signature varchar default null,
	  pl_delivery varchar default null,
	  pl_wsa_version varchar default \'http://schemas.xmlsoap.org/ws/2003/03/addressing\',
	  pl_uid varchar default null,
	  pl_pwd varchar default null,
	  pl_in_enc varchar default null,
	  pl_in_sign varchar default null,
	  pl_in_tokens any default null
	)
	self as ref
')
;

exec_no_error ('create table BPEL.BPEL.op_stat
	(
	 bos_process int,
	 bos_plink varchar,
	 bos_op varchar,
	 bos_n_invokes int default 0,
	 bos_n_receives int default 0,
	 bos_cum_wait numeric default 0, -- miliseconds total time wait at the partner link/operation
	 bos_data_in numeric default 0,
	 bos_data_out numeric default 0,
	 bos_n_errors int default 0,
	 primary key (bos_process, bos_plink, bos_op)
)
')
;


exec_no_error ('create table BPEL.BPEL.error_log
	(
	 bel_ts timestamp,
	 bel_seq int identity,
	 bel_level int, -- bel_level is 1. fatal 2. network, 3 instance.
	 bel_notice_sent datetime,  -- time the email was sent, null if none
	 bel_text varchar,
	 primary key (bel_ts, bel_seq)
)
')
;

exec_no_error ('create table BPEL.BPEL.hosted_classes
	(
	 hc_script	int,
	 hc_type	varchar default \'java\',
	 hc_name	varchar,
	 hc_text	long varbinary, -- compiled class
	 hc_path	varchar, -- path to class if it is stored in file system
	 hc_load_method	varchar,
	 primary key (hc_script, hc_type,  hc_name)
)
')
;