Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,352 @@ +-- $Id: acs-sc-msg-types-create.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +begin + + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'acs_sc_msg_type', + pretty_name => 'ACS SC Message Type', + pretty_plural => 'ACS SC Message Types', + table_name => 'acs_sc_msg_types', + id_column => 'msg_type_id' + ); + +end; +/ +show errors + +create table acs_sc_msg_types ( + msg_type_id integer + constraint acs_sc_msg_type_id_fk + references acs_objects(object_id) + on delete cascade + constraint acs_sc_msg_type_pk + primary key, + msg_type_name varchar2(100) + constraint acs_sc_msg_type_name_un + unique +); + + +create table acs_sc_msg_type_elements ( + msg_type_id integer + constraint acs_sc_msg_type_el_mtype_id_fk + references acs_sc_msg_types(msg_type_id) + on delete cascade, + element_name varchar2(100), + element_msg_type_id integer + constraint acs_sc_msg_type_el_emti_id_fk + references acs_sc_msg_types(msg_type_id), + element_msg_type_isset_p char(1) constraint acs_msg_type_el_set_p_ck + check (element_msg_type_isset_p in ('t', 'f')), + element_pos integer +); + +create or replace package acs_sc_msg_type +as + + function new ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + msg_type_spec in varchar2 + ) return acs_sc_msg_types.msg_type_id%TYPE; + + procedure delete ( + msg_type_id in acs_sc_msg_types.msg_type_id%TYPE default null, + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE default null + ); + + function get_id ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE + ) return acs_sc_msg_types.msg_type_id%TYPE; + + + function get_name ( + msg_type_id in acs_sc_msg_types.msg_type_id%TYPE + ) return acs_sc_msg_types.msg_type_name%TYPE; + + -- ask nd about name + function parse_spec ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + msg_type_spec in varchar2 + ) return integer; + + function new_element ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + element_name in acs_sc_msg_type_elements.element_name%TYPE, + element_msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + element_msg_type_isset_p in acs_sc_msg_type_elements.element_msg_type_isset_p%TYPE, + element_pos in acs_sc_msg_type_elements.element_pos%TYPE + ) return acs_sc_msg_types.msg_type_id%TYPE; + +end acs_sc_msg_type; +/ +show errors + + +create or replace package body acs_sc_msg_type +as + + function new ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + msg_type_spec in varchar2 + ) return acs_sc_msg_types.msg_type_id%TYPE + is + v_msg_type_id integer; + v_spec_parse_level integer; + begin + v_msg_type_id := acs_object.new( + object_type => 'acs_sc_msg_type' + ); + + insert into acs_sc_msg_types ( + msg_type_id, + msg_type_name + ) values ( + v_msg_type_id, + msg_type_name + ); + + v_spec_parse_level := acs_sc_msg_type.parse_spec( + msg_type_name, + msg_type_spec); + + return v_msg_type_id; + + end new; + + procedure delete ( + msg_type_id in acs_sc_msg_types.msg_type_id%TYPE default null, + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE default null + ) + is + v_msg_type_id acs_sc_msg_types.msg_type_id%TYPE; + begin + + if msg_type_name is not NULL + then + v_msg_type_id := acs_sc_msg_type.get_id(msg_type_name); + + elsif msg_type_id is not NULL + then + v_msg_type_id := msg_type_id; + + else + raise_application_error(-20000, 'no args supplied to sc_msg_type.delete'); + + end if; + + delete from acs_sc_msg_types + where msg_type_id = v_msg_type_id; + + end delete; + + function get_id ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE + ) return acs_sc_msg_types.msg_type_id%TYPE + + is + v_msg_type_id acs_sc_msg_types.msg_type_id%TYPE; + begin + + select msg_type_id into v_msg_type_id + from acs_sc_msg_types + where msg_type_name = get_id.msg_type_name; + + return v_msg_type_id; + + end get_id; + + + function get_name ( + msg_type_id in acs_sc_msg_types.msg_type_id%TYPE + ) return acs_sc_msg_types.msg_type_name%TYPE + is + v_msg_type_name acs_sc_msg_types.msg_type_name%TYPE; + begin + + select msg_type_name into v_msg_type_name + from acs_sc_msg_types + where msg_type_id = get_name.msg_type_id; + + return v_msg_type_name; + end get_name; + + + + -- string processing in pl/sql is so much fun + -- i'm sure there is a better way to go about this + function parse_spec ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + msg_type_spec in varchar2 + ) return integer + is + v_element_pos integer; + v_str_s_idx integer; -- spec str pointers + v_str_e_idx integer; + v_elem_idx integer; -- element str pointer + v_str_len integer; + v_element varchar(200); + v_element_type varchar(200); + v_element_name varchar(200); + v_element_msg_type_name varchar(200); + v_element_msg_type_isset_p char(1); + v_junk_msg_type_id integer; + begin + + -- oracle treats empty strings as nulls + if msg_type_spec is null + then + return 0; + end if; + + + v_element_pos := 1; + v_str_e_idx := 1; + + while TRUE + loop + -- string start check + if v_element_pos = 1 + then + v_str_s_idx := 1; + else + v_str_s_idx := instr(msg_type_spec, ',', v_str_e_idx); + + if v_str_s_idx > 0 then + v_str_s_idx := v_str_s_idx + 1; + end if; + + end if; + + v_str_e_idx := instr(msg_type_spec, ',', v_str_s_idx+1)-1; + + -- end of string check + if v_str_s_idx > 0 and v_str_e_idx <= 0 + then + v_str_e_idx := length(msg_type_spec); + end if; + + -- dbms_output.put_line(v_str_s_idx || ' '|| v_str_e_idx || ' ' || v_element_pos); + -- dbms_output.new_line(); + + if v_str_s_idx > 0 + then + + v_element := substr(msg_type_spec, + v_str_s_idx, + v_str_e_idx+1 - v_str_s_idx); + + v_elem_idx := instr(v_element, ':'); + + if v_elem_idx > 0 + then + v_element_name := trim( substr(v_element, 1, v_elem_idx-1)); + v_element_type := trim( substr(v_element, v_elem_idx+1)); + + if (instr(v_element_type, '[',1,1) = length(v_element_type)-1) and + (instr(v_element_type, ']',1,1) = length(v_element_type)) + then + v_element_msg_type_isset_p := 't'; + v_element_msg_type_name := trim(substr( + v_element_type, + 1, + length(v_element_type)-2)); + + if v_element_msg_type_name = '' + then + raise_application_error (-20001, + 'Wrong Format: Message Type Specification'); + end if; + else + v_element_msg_type_isset_p := 'f'; + v_element_msg_type_name := v_element_type; + + end if; + + v_junk_msg_type_id := acs_sc_msg_type.new_element ( + msg_type_name =>parse_spec.msg_type_name, + element_name => v_element_name, + element_msg_type_name => v_element_msg_type_name, + element_msg_type_isset_p => v_element_msg_type_isset_p, + element_pos => v_element_pos + ); + + else + raise_application_error(-20001,'Wrong Format: Message Type Specification'); + end if; + else + -- yippee we're done + exit; + end if; + + v_element_pos := v_element_pos + 1; + + end loop; + + return v_element_pos - 1; + end parse_spec; + + function new_element ( + msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + element_name in acs_sc_msg_type_elements.element_name%TYPE, + element_msg_type_name in acs_sc_msg_types.msg_type_name%TYPE, + element_msg_type_isset_p in acs_sc_msg_type_elements.element_msg_type_isset_p%TYPE, + element_pos in acs_sc_msg_type_elements.element_pos%TYPE + ) return acs_sc_msg_types.msg_type_id%TYPE + is + v_msg_type_id integer; + v_element_msg_type_id integer; + begin + + v_msg_type_id := acs_sc_msg_type.get_id(msg_type_name); + + if v_msg_type_id is null + then + raise_application_error (-20001, 'Unknown Message Type: ' || msg_type_name); + end if; + + v_element_msg_type_id := acs_sc_msg_type.get_id(element_msg_type_name); + + if v_element_msg_type_id is null + then + raise_application_error (-20001, 'Unknown Message Type: ' || element_msg_type_name); + end if; + + insert into acs_sc_msg_type_elements ( + msg_type_id, + element_name, + element_msg_type_id, + element_msg_type_isset_p, + element_pos + ) values ( + v_msg_type_id, + element_name, + v_element_msg_type_id, + element_msg_type_isset_p, + element_pos + ); + + return v_msg_type_id; + + end new_element; + +end acs_sc_msg_type; +/ +show errors + + +-- +-- Primitive Message Types +-- +declare + v_msg_type_id acs_sc_msg_types.msg_type_id%TYPE; +begin + v_msg_type_id := acs_sc_msg_type.new('integer',''); + v_msg_type_id := acs_sc_msg_type.new('string',''); + v_msg_type_id := acs_sc_msg_type.new('boolean',''); + v_msg_type_id := acs_sc_msg_type.new('uri',''); + v_msg_type_id := acs_sc_msg_type.new('version',''); +end; +/ +show errors + Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-msg-types-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,17 @@ +-- $Id: acs-sc-msg-types-drop.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +drop package acs_sc_msg_type; +drop table acs_sc_msg_type_elements; +drop table acs_sc_msg_types; + + +delete from acs_objects where object_type = 'acs_sc_msg_type'; + +begin + acs_object_type.drop_type('acs_sc_msg_type'); +end; +/ +show errors + + + Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,31 @@ +-- $Id: acs-sc-object-types-create.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ +begin + acs_object_type.create_type( + object_type => 'acs_sc_contract', + pretty_name => 'ACS SC Contract', + pretty_plural => 'ACS SC Contracts', + supertype => 'acs_object', + table_name => 'ACS_SC_CONTRACTS', + id_column => 'CONTRACT_ID' + ); + + acs_object_type.create_type( + object_type => 'acs_sc_operation', + pretty_name => 'ACS SC Operation', + pretty_plural => 'ACS SC Operations', + supertype => 'acs_object', + table_name => 'ACS_SC_OPERATIONS', + id_column => 'OPERATION_ID' + ); + + acs_object_type.create_type( + object_type => 'acs_sc_implementation', + pretty_name => 'ACS SC Implementation', + pretty_plural => 'ACS SC Implementations', + supertype => 'acs_object', + table_name => 'ACS_SC_IMPLS', + id_column => 'IMPL_ID' + ); +end; +/ +show errors Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-object-types-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,14 @@ +-- $Id: acs-sc-object-types-drop.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ +begin + delete from acs_objects where object_type ='acs_sc_implementation'; + acs_object_type.drop_type('acs_sc_implementation'); + + delete from acs_objects where object_type ='acs_sc_operation'; + acs_object_type.drop_type('acs_sc_operation'); + + delete from acs_objects where object_type ='acs_sc_contract'; + acs_object_type.drop_type('acs_sc_contract'); +end; +/ +show errors + Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,568 @@ +-- $Id: acs-sc-packages-create.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +create or replace package acs_sc_contract +as + + function new ( + contract_name in acs_sc_contracts.contract_name%TYPE, + contract_desc in acs_sc_contracts.contract_desc%TYPE + ) return acs_sc_contracts.contract_id%TYPE; + + function get_id ( + contract_name in acs_sc_contracts.contract_name%TYPE + ) return acs_sc_contracts.contract_id%TYPE; + + function get_name ( + contract_id in acs_sc_contracts.contract_id%TYPE + ) return acs_sc_contracts.contract_id%TYPE; + + procedure delete ( + contract_name in acs_sc_contracts.contract_name%TYPE default null, + contract_id in acs_sc_contracts.contract_id%TYPE default null + ); +end acs_sc_contract; +/ +show errors + + +create or replace package acs_sc_operation +as + + function new ( + contract_name in acs_sc_contracts.contract_name%TYPE, + operation_name in acs_sc_operations.operation_name%TYPE, + operation_desc in acs_sc_operations.operation_desc%TYPE, + operation_iscachable_p in acs_sc_operations.operation_iscachable_p%TYPE, + operation_nargs in acs_sc_operations.operation_nargs%TYPE, + operation_inputtype in acs_sc_msg_types.msg_type_name%TYPE, + operation_outputtype in acs_sc_msg_types.msg_type_name%TYPE + ) return acs_sc_operations.operation_id%TYPE; + + function get_id ( + contract_name acs_sc_contracts.contract_name%TYPE, + operation_name acs_sc_operations.operation_name%TYPE + ) return acs_sc_operations.operation_id%TYPE; + + + procedure delete ( + operation_id acs_sc_operations.operation_id%TYPE default null, + operation_name acs_sc_operations.operation_name%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null + ); + +end acs_sc_operation; +/ +show errors + +create or replace package acs_sc_impl +as + + function new ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_owner_name acs_sc_impls.impl_owner_name%TYPE + ) return acs_sc_impls.impl_id%TYPE; + + function get_id ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ) return acs_sc_impls.impl_id%TYPE; + + function get_name ( + impl_id acs_sc_impls.impl_id%TYPE + ) return acs_sc_impls.impl_name%TYPE; + + procedure delete ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ); + + /* not sure if this should get folded into the impl package or not*/ + + function new_alias ( + impl_contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_operation_name acs_sc_operations.operation_name%TYPE, + impl_alias acs_sc_impl_alias.impl_alias%TYPE, + impl_pl acs_sc_impl_alias.impl_pl%TYPE + ) return acs_sc_impl_alias.impl_id%TYPE; + + function delete_aliases ( + impl_contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_operation_name acs_sc_operations.operation_name%TYPE + ) return acs_sc_impls.impl_id%TYPE; + +end acs_sc_impl; +/ +show error + +create or replace package acs_sc_binding +as + procedure new ( + contract_id acs_sc_operations.contract_id%TYPE default null, + impl_id acs_sc_bindings.impl_id%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null, + impl_name acs_sc_impls.impl_name%TYPE default null + ); + + procedure delete( + contract_id acs_sc_contracts.contract_id%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null, + impl_id acs_sc_impls.impl_id%TYPE default null, + impl_name acs_sc_impls.impl_name%TYPE default null + ); + + function exists_p ( + contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ) return integer; + +end acs_sc_binding; +/ +show errors + +create or replace package body acs_sc_contract +as + function new ( + contract_name in acs_sc_contracts.contract_name%TYPE, + contract_desc in acs_sc_contracts.contract_desc%TYPE + ) return acs_sc_contracts.contract_id%TYPE + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + begin + v_contract_id := acs_object.new( object_type=>'acs_sc_contract'); + + insert into acs_sc_contracts ( + contract_id, + contract_name, + contract_desc + ) values ( + v_contract_id, + contract_name, + contract_desc + ); + + return v_contract_id; + + end new; + + function get_id ( + contract_name in acs_sc_contracts.contract_name%TYPE + ) return acs_sc_contracts.contract_id%TYPE + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + begin + + select contract_id into v_contract_id + from acs_sc_contracts + where contract_name = get_id.contract_name; + + return v_contract_id; + + end get_id; + + function get_name ( + contract_id in acs_sc_contracts.contract_id%TYPE + ) return acs_sc_contracts.contract_id%TYPE + is + v_contract_name acs_sc_contracts.contract_name%TYPE; + begin + + select contract_name into v_contract_name + from acs_sc_contracts + where contract_id = get_name.contract_id; + + return v_contract_name; + + end get_name; + + procedure delete ( + contract_name in acs_sc_contracts.contract_name%TYPE default null, + contract_id in acs_sc_contracts.contract_id%TYPE default null + ) + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + begin + + if contract_name is not NULL + then + v_contract_id := acs_sc_contract.get_id(contract_name); + + elsif contract_id is not NULL + then + v_contract_id := contract_id; + + else + raise_application_error(-20001, 'Service Contracts: no valid args supplied to delete'); + end if; + + + delete from acs_sc_contracts + where contract_id = v_contract_id; + acs_object.delete(v_contract_id); + + end delete; + +end acs_sc_contract; +/ +show errors + + +create or replace package body acs_sc_operation +as + + function new ( + contract_name in acs_sc_contracts.contract_name%TYPE, + operation_name in acs_sc_operations.operation_name%TYPE, + operation_desc in acs_sc_operations.operation_desc%TYPE, + operation_iscachable_p in acs_sc_operations.operation_iscachable_p%TYPE, + operation_nargs in acs_sc_operations.operation_nargs%TYPE, + operation_inputtype in acs_sc_msg_types.msg_type_name%TYPE, + operation_outputtype in acs_sc_msg_types.msg_type_name%TYPE + ) return acs_sc_operations.operation_id%TYPE + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + v_operation_id acs_sc_operations.operation_id%TYPE; + v_operation_inputtype_id acs_sc_operations.operation_inputtype_id%TYPE; + v_operation_outputtype_id acs_sc_operations.operation_outputtype_id%TYPE; + begin + + v_contract_id := acs_sc_contract.get_id(contract_name); + v_operation_id := acs_object.new (object_type=>'acs_operation'); + v_operation_inputtype_id := acs_sc_msg_type.get_id(operation_inputtype); + v_operation_outputtype_id := acs_sc_msg_type.get_id(operation_outputtype); + + insert into acs_sc_operations ( + contract_id, + operation_id, + contract_name, + operation_name, + operation_desc, + operation_iscachable_p, + operation_nargs, + operation_inputtype_id, + operation_outputtype_id + ) values ( + v_contract_id, + v_operation_id, + contract_name, + operation_name, + operation_desc, + operation_iscachable_p, + operation_nargs, + v_operation_inputtype_id, + v_operation_outputtype_id + ); + + return v_operation_id; + + end new; + + + function get_id ( + contract_name acs_sc_contracts.contract_name%TYPE, + operation_name acs_sc_operations.operation_name%TYPE + ) return acs_sc_operations.operation_id%TYPE + as + v_operation_id acs_sc_operations.operation_id%TYPE; + begin + select operation_id into v_operation_id + from acs_sc_operations + where contract_name = get_id.contract_name + and operation_name = get_id.operation_name; + + return v_operation_id; + end get_id; + + + procedure delete ( + operation_id acs_sc_operations.operation_id%TYPE default null, + operation_name acs_sc_operations.operation_name%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null + ) + is + v_operation_id acs_sc_operations.operation_id%TYPE; + begin + + if (operation_id is NULL and operation_name is not NULL and contract_name is not NULL) + then + v_operation_id := get_id(contract_name, operation_name); + + elsif operation_id is not NULL + then + v_operation_id := operation_id; + + else + raise_application_error(-20001, 'ACS Contracts: Invalid args to operation delete'); + end if; + + delete from acs_sc_operations + where operation_id = v_operation_id; + + end delete; + + +end acs_sc_operation; +/ +show errors + + +create or replace package body acs_sc_impl +as + + function new ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_owner_name acs_sc_impls.impl_owner_name%TYPE + ) return acs_sc_impls.impl_id%TYPE + is + v_impl_id acs_sc_impls.impl_id%TYPE; + begin + v_impl_id := acs_object.new ('acs_sc_implementation'); + + insert into acs_sc_impls ( + impl_id, + impl_name, + impl_owner_name, + impl_contract_name + ) values ( + v_impl_id, + impl_name, + impl_owner_name, + impl_contract_name + ); + + return v_impl_id; + end new; + + function get_id ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ) return acs_sc_impls.impl_id%TYPE + as + v_impl_id acs_sc_impls.impl_id%TYPE; + begin + + select impl_id into v_impl_id + from acs_sc_impls + where impl_name = get_id.impl_name + and impl_contract_name = get_id.impl_contract_name; + + return v_impl_id; + + end get_id; + + + function get_name ( + impl_id acs_sc_impls.impl_id%TYPE + ) return acs_sc_impls.impl_name%TYPE + as + v_impl_name acs_sc_impls.impl_name%TYPE; + begin + + select impl_name into v_impl_name + from acs_sc_impls + where impl_id = get_name.impl_id; + + return v_impl_name; + + end get_name; + + + procedure delete ( + impl_contract_name acs_sc_impls.impl_contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ) + as + begin + + + + delete from acs_sc_impls + where impl_contract_name = impl_contract_name + and impl_name = impl_name; + + end delete; + + + /* not sure if this should get folded into the impl package */ + + function new_alias ( + impl_contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_operation_name acs_sc_operations.operation_name%TYPE, + impl_alias acs_sc_impl_alias.impl_alias%TYPE, + impl_pl acs_sc_impl_alias.impl_pl%TYPE + ) return acs_sc_impl_alias.impl_id%TYPE + is + v_impl_id acs_sc_impls.impl_id%TYPE; + begin + + v_impl_id := acs_sc_impl.get_id(impl_contract_name,impl_name); + + insert into acs_sc_impl_alias ( + impl_id, + impl_name, + impl_contract_name, + impl_operation_name, + impl_alias, + impl_pl + ) values ( + v_impl_id, + impl_name, + impl_contract_name, + impl_operation_name, + impl_alias, + impl_pl + ); + + return v_impl_id; + + end new_alias; + + function delete_alias ( + impl_contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE, + impl_operation_name acs_sc_operations.operation_name%TYPE + ) return acs_sc_impls.impl_id%TYPE + is + v_impl_id acs_sc_impls.impl_id%TYPE; + begin + v_impl_id := acs_sc_impl.get_id(impl_contract_name,impl_name); + + delete from acs_sc_impl_alias + where impl_contract_name = delete_alias.impl_contract_name + and impl_name = delete_alias.impl_name + and impl_operation_name = delete_alias.impl_operation_name; + + return v_impl_id; + + end delete_alias; + +end acs_sc_impl; +/ +show errors + + + +create or replace package body acs_sc_binding +as + -- you can pick a pair of args, either ids or names to pass in. + procedure new ( + contract_id acs_sc_operations.contract_id%TYPE default null, + impl_id acs_sc_bindings.impl_id%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null, + impl_name acs_sc_impls.impl_name%TYPE default null + ) + is + v_contract_name acs_sc_contracts.contract_name%TYPE; + v_contract_id acs_sc_contracts.contract_id%TYPE; + v_impl_name acs_sc_impls.impl_name%TYPE; + v_impl_id acs_sc_impls.impl_id%TYPE; + v_count integer; + begin + + if impl_id is not null and contract_id is not null + then + + v_contract_name := acs_sc_contract.get_name(contract_id); + v_impl_name := acs_sc_impl.get_name(impl_id); + v_contract_id := contract_id; + v_impl_id := impl_id; + + elsif contract_name is not null and impl_name is not null + then + v_contract_id := acs_sc_contract.get_id(contract_name); + v_impl_id := acs_sc_impl.get_id(contract_name,impl_name); + v_impl_name := impl_name; + v_contract_name := contract_name; + + else + raise_application_error(-20001, 'Service Contracts:Invalid args to binding new'); + end if; + + + select count(*) into v_count + from acs_sc_operations + where contract_id = new.contract_id + and operation_name not in (select impl_operation_name + from acs_sc_impl_alias + where impl_contract_name = v_contract_name + and impl_id = v_impl_id); + + if v_count > 0 + then + raise_application_error(-20001, 'Binding of ' || + v_contract_name || + ' to ' || + v_impl_name || + ' failed.'); + end if; + + insert into acs_sc_bindings ( + contract_id, + impl_id + ) values ( + v_contract_id, + v_impl_id + ); + + end new; + + procedure delete( + contract_id acs_sc_contracts.contract_id%TYPE default null, + contract_name acs_sc_contracts.contract_name%TYPE default null, + impl_id acs_sc_impls.impl_id%TYPE default null, + impl_name acs_sc_impls.impl_name%TYPE default null + ) + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + v_impl_id acs_sc_impls.impl_id%TYPE; + begin + + if impl_id is not null and contract_id is not null + then + v_impl_id := impl_id; + v_contract_id := contract_id; + + elsif impl_name is not null and contract_name is not null + then + v_impl_id := acs_sc_impl.get_id(contract_name,impl_name); + v_contract_id := acs_sc_contract.get_id(contract_name); + else + raise_application_error(-20001, 'Service contract binding delete invalid args'); + end if; + + delete from acs_sc_bindings + where contract_id = v_contract_id + and impl_id = v_impl_id; + end delete; + + function exists_p ( + contract_name acs_sc_contracts.contract_name%TYPE, + impl_name acs_sc_impls.impl_name%TYPE + ) return integer + is + v_contract_id acs_sc_contracts.contract_id%TYPE; + v_impl_id acs_sc_impls.impl_id%TYPE; + v_exists_p integer; + begin + v_contract_id := acs_sc_contract.get_id(contract_name); + v_impl_id := acs_sc_impl.get_id(contract_name,impl_name); + + select decode(count(*),0, 0, 1) into v_exists_p + from acs_sc_bindings + where contract_id = v_contract_id + and impl_id = v_impl_id; + + return v_exists_p; + end exists_p; + +end acs_sc_binding; +/ +show errors + + + + Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-packages-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,10 @@ +-- $Id: acs-sc-packages-drop.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +begin + drop package acs_sc_contract; + drop package acs_sc_operation; + drop package acs_sc_impl; + drop package acs_sc_binding; +end; +/ +show errors Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,95 @@ +-- $Id: acs-sc-tables-create.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +create table acs_sc_contracts ( + contract_id integer + constraint acs_sc_contract_id_fk + references acs_objects(object_id) + on delete cascade + constraint acs_sc_contract_pk + primary key, + contract_name varchar2(1000) + constraint acs_sc_contract_name_nn + not null + constraint acs_sc_contract_name_un + unique, + contract_desc varchar2(4000) + constraint acs_sc_contract_desc_nn + not null +); + + +create table acs_sc_operations ( + contract_id integer + constraint acs_sc_operation_cid_fk + references acs_sc_contracts(contract_id) + on delete cascade, + operation_id integer + constraint acs_sc_operation_opid_fk + references acs_objects(object_id) + on delete cascade + constraint acs_sc_operation_pk + primary key, + contract_name varchar2(1000), + operation_name varchar2(100), + operation_desc varchar2(4000) + constraint acs_sc_operation_desc_nn + not null, + operation_iscachable_p char(1) constraint acs_sc_operation_cache_p_ck + check (operation_iscachable_p in ('t', 'f')), + operation_nargs integer, + operation_inputtype_id integer + constraint acs_sc_operation_intype_fk + references acs_sc_msg_types(msg_type_id), + operation_outputtype_id integer + constraint acs_sc_operation_outtype_fk + references acs_sc_msg_types(msg_type_id) +); + + + +create table acs_sc_impls ( + impl_id integer + constraint acs_sc_impl_impl_id_fk + references acs_objects(object_id) + on delete cascade + constraint acs_sc_impl_pk + primary key, + impl_name varchar2(100), + impl_owner_name varchar2(1000), + impl_contract_name varchar2(1000) +); + +create table acs_sc_impl_alias ( + impl_id integer + constraint acs_sc_impl_proc_impl_id_fk + references acs_sc_impls(impl_id) + on delete cascade, + impl_name varchar2(100), + impl_contract_name varchar2(1000), + impl_operation_name varchar2(100), + impl_alias varchar2(100), + impl_pl varchar2(100), +constraint acs_sc_impl_alias_un unique(impl_name,impl_contract_name,impl_operation_name) +); + +create table acs_sc_bindings ( + contract_id integer + constraint acs_sc_binding_cid_fk + references acs_sc_contracts(contract_id) + on delete cascade, + impl_id integer + constraint acs_sc_binding_impl_id_fk + references acs_sc_impls(impl_id) + on delete cascade +); + + + + + + + + + + + Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-tables-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,5 @@ +drop table acs_sc_bindings; +drop table acs_sc_impl_alias; +drop table acs_sc_impls; +drop table acs_sc_operations; +drop table acs_sc_contracts; Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,48 @@ +-- $Id: acs-sc-views-create.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +create or replace view valid_uninstalled_binding as + select c.contract_id, c.contract_name, i.impl_id, i.impl_name + from acs_sc_contracts c, acs_sc_impls i + where c.contract_name = i.impl_contract_name + and not exists (select 1 + from acs_sc_bindings b + where b.contract_id = c.contract_id + and b.impl_id = i.impl_id) + and not exists (select 1 + from acs_sc_operations o + where o.contract_id = c.contract_id + and not exists (select 1 + from acs_sc_impl_alias a + where a.impl_contract_name = c.contract_name + and a.impl_id = i.impl_id + and a.impl_operation_name = o.operation_name)); + + + +create or replace view invalid_uninstalled_binding as + select c.contract_id, c.contract_name, i.impl_id, i.impl_name + from acs_sc_contracts c, acs_sc_impls i + where c.contract_name = i.impl_contract_name + and not exists (select 1 + from acs_sc_bindings b + where b.contract_id = c.contract_id + and b.impl_id = i.impl_id) + and exists (select 1 + from acs_sc_operations o + where o.contract_id = c.contract_id + and not exists (select 1 + from acs_sc_impl_alias a + where a.impl_contract_name = c.contract_name + and a.impl_id = i.impl_id + and a.impl_operation_name = o.operation_name)); + + +create or replace view orphan_implementation as + select i.impl_id, i.impl_name, i.impl_contract_name + from acs_sc_impls i + where not exists (select 1 + from acs_sc_bindings b + where b.impl_id = i.impl_id) + and not exists (select 1 + from acs_sc_contracts c + where c.contract_name = i.impl_contract_name); \ No newline at end of file Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-sc-views-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,4 @@ +-- $Id: acs-sc-views-drop.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ +drop view orphan_implementation; +drop view invalid_uninstalled_binding; +drop view valid_uninstalled_binding; \ No newline at end of file Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,5 @@ +@@ acs-sc-msg-types-create.sql +@@ acs-sc-object-types-create.sql +@@ acs-sc-tables-create.sql +@@ acs-sc-packages-create.sql +@@ acs-sc-views-create.sql \ No newline at end of file Index: openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/acs-service-contract-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,7 @@ +-- $Id: acs-service-contract-drop.sql,v 1.1 2001/09/19 22:59:01 donb Exp $ + +@@ acs-sc-views-drop.sql +@@ acs-sc-packages-drop.sql +@@ acs-sc-tables-drop.sql +@@ acs-sc-object-types-drop.sql +@@ acs-sc-msg-types-drop.sql \ No newline at end of file Index: openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-create.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,100 @@ +-- CREATE CONTRACT + +declare + sc_sample_test integer; +begin + sc_sample_test := acs_sc_contract.new( + contract_name => 'ObjectDisplay', + contract_desc => 'Object display' + ); + + sc_sample_test := acs_sc_msg_type.new( + msg_type_name => 'ObjectDisplay.Name.InputType', + msg_type_spec => 'object_id:integer' + ); + sc_sample_test := acs_sc_msg_type.new( + msg_type_name => 'ObjectDisplay.Name.OutputType', + msg_type_spec => 'object_name:string' + ); + + sc_sample_test := acs_sc_operation.new( + contract_name => 'ObjectDisplay', + operation_name => 'name', + operation_desc => 'Returns objects name', + operation_iscachable_p => 'f', + operation_nargs => 1, + operation_inputttype => 'ObjectDisplay.Name.InputType', + operation_ouputtype => 'ObjectDisplay.Name.OutputType' + ); + + + sc_sample_test := acs_sc_msg_type.new('ObjectDisplay.Url.InputType','object_id:integer'); + sc_sample_test := acs_sc_msg_type.new('ObjectDisplay.Url.OutputType','object_url:uri'); + + sc_sample_test := acs_sc_operation.new( + 'ObjectDisplay', -- contract_name + 'url', -- operation_name + 'Returns object''s url', -- operation_desc + 'f', -- operation_iscachable_p + 1, -- operation_nargs + 'ObjectDisplay.Url.InputType', -- operation_inputtype + 'ObjectDisplay.Url.OutputType' -- operation_outputtype + ); + + + sc_sample_test := acs_sc_msg_type.new ('ObjectDisplay.SampleHello.InputType', + 'object_id:integer,object_txt:string'); + sc_sample_test := acs_sc_msg_type.new ('ObjectDisplay.SampleHello.OutputType', + 'object_sample:string[],xxx_p:boolean'); + + sc_sample_test := acs_sc_operation.new ( + 'ObjectDisplay', -- contract_name + 'sample_hello', -- operation_name + 'Returns object''s url', -- operation_desc + 't', -- operation_iscachable_p + 1, -- operation_nargs + 'ObjectDisplay.SampleHello.InputType', -- operation_inputtype + 'ObjectDisplay.SampleHello.OutputType' -- operation_outputtype + ); + + + + -- CREATE IMPLEMENTATION + + + sc_sample_test := acs_sc_impl.new( + 'ObjectDisplay', -- impl_contract_name + 'bboard_message', -- impl_name + 'bboard' -- impl_owner_name + ); + + + sc_sample_test := acs_sc_impl.new_alias( + 'ObjectDisplay', -- impl_contract_name + 'bboard_message', -- impl_name + 'name', -- impl_operation_name + 'bboard_message__name', -- impl_alias + 'PLPGSQL' -- impl_pl + ); + + sc_sample_test := acs_sc_impl.new_alias( + 'ObjectDisplay', -- impl_contract_name + 'bboard_message', -- impl_name + 'url', -- impl_operation_name + 'bboard_message__url', -- impl_alias + 'PLPGSQL' -- impl_pl + ); + + sc_sample_test := acs_sc_impl.new_alias( + 'ObjectDisplay', -- impl_contract_name + 'bboard_message', -- impl_name + 'sample_hello', -- impl_operation_name + 'bboard_message__sample_hello', -- impl_alias + 'TCL' -- impl_pl + ); + + +end; +/ +show errors + Index: openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-service-contract/sql/oracle/sc-sample-drop.sql 19 Sep 2001 22:59:01 -0000 1.1 @@ -0,0 +1,24 @@ +begin + + acs_sc_impl.delete( + 'ObjectDisplay', -- impl_contract_name + 'bboard_message' -- impl_name + ); + + acs_sc_contract.delete(contract_name=>'ObjectDisplay', + operation_name=>'name'); + + acs_sc_msg_type.delete ('ObjectDisplay.Name.InputType'); + acs_sc_msg_type.delete ('ObjectDisplay.Name.OutputType'); + + acs_sc_msg_type.delete ('ObjectDisplay.Url.InputType'); + acs_sc_msg_type.delete ('ObjectDisplay.Url.OutputType'); + + acs_sc_msg_type.delete ('ObjectDisplay.SampleHello.InputType'); + acs_sc_msg_type.delete ('ObjectDisplay.SampleHello.OutputType'); + + + +end; +/ +show errors