rel_types::new (public)

 rel_types::new [ -supertype supertype ] [ -role_one role_one ] \
    [ -role_two role_two ] [ -table_name table_name ] \
    [ -create_table_p create_table_p ] rel_type pretty_name \
    pretty_plural object_type_one min_n_rels_one max_n_rels_one \
    object_type_two min_n_rels_two max_n_rels_two [ composable_p ]

Defined in packages/acs-subsite/tcl/rel-types-procs.tcl

Creates a new relationship type named rel_type

Switches:
-supertype
(defaults to "relationship") (optional)
-role_one
(optional)
-role_two
(optional)
-table_name
(optional)
-create_table_p
(defaults to "t") (optional)
Parameters:
rel_type
pretty_name
pretty_plural
object_type_one
min_n_rels_one
max_n_rels_one
object_type_two
min_n_rels_two
max_n_rels_two
composable_p (defaults to "t")
Author:
Michael Bryzek <mbryzek@arsdigita.com>
Created:
12/30/2000

Partial Call Graph (max 5 caller/called nodes):
%3 email_image::create_type_folder_rel email_image::create_type_folder_rel (public) rel_types::new rel_types::new email_image::create_type_folder_rel->rel_types::new install::xml::action::relation-type install::xml::action::relation-type (public) install::xml::action::relation-type->rel_types::new packages/acs-subsite/www/admin/rel-types/new-2.tcl packages/acs-subsite/ www/admin/rel-types/new-2.tcl packages/acs-subsite/www/admin/rel-types/new-2.tcl->rel_types::new db_0or1row db_0or1row (public) rel_types::new->db_0or1row db_exec_plsql db_exec_plsql (public) rel_types::new->db_exec_plsql lang::message::register lang::message::register (public) rel_types::new->lang::message::register package_recreate_hierarchy package_recreate_hierarchy (public) rel_types::new->package_recreate_hierarchy plsql_utility::generate_constraint_name plsql_utility::generate_constraint_name (public) rel_types::new->plsql_utility::generate_constraint_name

Testcases:
No testcase defined.
Source code:

        # use 29 chars to leave 1 character in the name for later dynamic
        # views

        set rel_type [plsql_utility::generate_oracle_name  -max_length 29 $rel_type]
        if {[plsql_utility::object_type_exists_p $rel_type]} {
            error "Specified relationship type, $rel_type, already exists (or another object of the same type exists)\n"
        }

        if {![db_0or1row parent_rel_type {
            select table_name as references_table,
            id_column as references_column
            from acs_object_types
            where object_type=:supertype}]} {
            error "The specified supertype \"$supertype\" does not exist"
        }

        # use 29 chars to leave 1 character in the name for later dynamic
        # views

        if {$table_name eq ""} {
            set table_name [plsql_utility::generate_oracle_name  -max_length 29 "${rel_type}_ext"]
        }
        set package_name $rel_type

        # We use rel_id for the primary key... since this is a relationship

        set pk_constraint_name [plsql_utility::generate_constraint_name $table_name rel_id "pk"]
        set fk_constraint_name [plsql_utility::generate_constraint_name $table_name rel_id "fk"]

        set plsql [list]

        # Create the actual acs object type

        lappend plsql_drop [list db_exec_plsql drop_type {}]
        lappend plsql [list db_exec_plsql create_type {}]

        # Mark the type as dynamic

        lappend plsql [list db_dml update_type FOO]

        # Force internationalization of Roles

        # Internationalising of Attributes. This is done by storing the
        # attribute with its acs-lang key

        set message_key "rel_type_${rel_type}"

        # Register the language keys

        lang::message::register en_US acs-translations $message_key $pretty_name
        lang::message::register en_US acs-translations "${message_key}_plural" $pretty_plural

        # Replace the pretty_name and pretty_plural with the message key, so
        # it is inserted correctly in the database

        set pretty_name "#acs-translations.${message_key}#"
        set pretty_plural "#acs-translations.${message_key}_plural#"

        foreach cmd $plsql {
            {*}$cmd
        }

        # The following create table statement commits the transaction. If it
        # fails, we roll back what we've done.

        if {$create_table_p == "t"} {
            if {[catch {db_exec_plsql create_table [subst {
                create table $table_name (
                     rel_id integer
                            constraint $fk_constraint_name
                            references $references_table ($references_column) on delete cascade
                            constraint $pk_constraint_name primary key
                   )}]} errmsg]} {

                # Roll back our work so far

                for {set i [expr {[llength $plsql_drop] - 1}]} {$i >= 0} {incr i -1} {
                    set drop_cmd [lindex $plsql_drop $i]
                    if {[catch $dropcmd err_msg_2]} {
                        append errmsg "\nAdditional error while trying to roll back: $err_msg_2"
                        return -code error $errmsg
                    }
                }
                return -code error $errmsg
            }
        }

        # Finally, create the PL/SQL package.

        package_recreate_hierarchy $rel_type

        return $rel_type
Generic XQL file:
<fullquery name="rel_types::new.update_type">
    <querytext>
update acs_object_types set dynamic_p='t' where object_type = :rel_type
</querytext>
</fullquery>
packages/acs-subsite/tcl/rel-types-procs.xql

PostgreSQL XQL file:
<fullquery name="rel_types::new.drop_type">
    <querytext>
	select acs_rel_type__drop_type(:rel_type, 'f')
</querytext>
</fullquery>

<fullquery name="rel_types::new.create_type">
    <querytext>
select acs_rel_type__create_type (	
	:rel_type,
	:pretty_name,
	:pretty_plural,
	:supertype,
	:table_name,
	'rel_id',
	:package_name,
	:object_type_one,
	:role_one,
	:min_n_rels_one,
	:max_n_rels_one,
	:object_type_two,
	:role_two,
	:min_n_rels_two,
	:max_n_rels_two,
    :composable_p
);
</querytext>
</fullquery>
packages/acs-subsite/tcl/rel-types-procs-postgresql.xql

Oracle XQL file:
<fullquery name="rel_types::new.drop_type">
    <querytext>
begin acs_rel_type.drop_type(:rel_type); end;
</querytext>
</fullquery>

<fullquery name="rel_types::new.create_type">
    <querytext>
	    begin
	    acs_rel_type.create_type (	
            rel_type          => :rel_type,
            supertype         => :supertype,
            pretty_name       => :pretty_name,
            pretty_plural     => :pretty_plural,
            table_name        => :table_name,
            id_column         => 'rel_id',
            package_name      => :package_name,
            object_type_one   => :object_type_one, 
            role_one          => :role_one,
            min_n_rels_one    => :min_n_rels_one,
            max_n_rels_one    => :max_n_rels_one,
            object_type_two   => :object_type_two, 
            role_two          => :role_two,
            min_n_rels_two    => :min_n_rels_two,
            max_n_rels_two    => :max_n_rels_two,
            composable_p      => :composable_p
	    );
	    end;
</querytext>
</fullquery>
packages/acs-subsite/tcl/rel-types-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: