package_create_attribute_list (private)

 package_create_attribute_list [ -supertype supertype ] \
    [ -object_name object_name ] [ -limit_to limit_to ] \
    [ -table table ] [ -column column ] [ -column_value column_value ] \
    object_type

Defined in packages/acs-subsite/tcl/package-procs.tcl

Generates the list of attributes for this object type. Each element in the list is (table_name, column_name, default_value, column_value) where default_value and column_value are optional. Note that if either of table_name, id_column is unspecified, we retrieve the values for both from the acs_object_types table

Switches:
-supertype (optional)
The supertype of the object we are creating. If specified, along with object_name, we lookup the parameters to supertype.object_name and include any missing parameters in our argument list.
-object_name (optional)
The name of the function / procedure we are creating. See supertype for explanation.
-limit_to (optional)
If empty, this argument is ignored. Otherwise, it is a list of all the columns to be included in the attribute list. Any attribute whose column_name is not in this list is then ignored.
-table (optional)
The table_name for this object_type (from the acs_object_types tables)
-column (optional)
The id_column for this object_type (from the acs_object_types tables)
-column_value (optional)
The value for this column in the present calling function. Useful when you are calling supertype function and need to refer to the supertype argument by a different name locally.
Parameters:
object_type (required)
The object type for which we are generating attributes
Author:
Michael Bryzek <mbryzek@arsdigita.com>
Created:
12/2000

Partial Call Graph (max 5 caller/called nodes):
%3 package_generate_body package_generate_body (private) package_create_attribute_list package_create_attribute_list package_generate_body->package_create_attribute_list acs_object_type::get acs_object_type::get (public) package_create_attribute_list->acs_object_type::get db_foreach db_foreach (public) package_create_attribute_list->db_foreach package_attribute_default package_attribute_default (private) package_create_attribute_list->package_attribute_default package_table_columns_for_type package_table_columns_for_type (private) package_create_attribute_list->package_table_columns_for_type util_memoize util_memoize (public) package_create_attribute_list->util_memoize

Testcases:
No testcase defined.
Source code:
    if { $table eq "" || $column eq "" } {
        # pull out the table and column names based on the object type
        acs_object_type::get -object_type $object_type -array acs_type
        set table  $acs_type(table_name)
        set column $acs_type(id_column)
    }

    # set toupper for case-insensitive searching
    set limit_to [string toupper $limit_to]

    # For the actual package spec and body, we build up a list of
    # the arguments and use a helper proc to generate the actual
    # pl/sql code. Note that the helper procs also return nicely
    # formatted pl/sql code

    set attr_list [list]

    # Start with the primary key for this object type. Continuing with
    # convention that id_column can be null (will default to new
    # object_id)
    lappend attr_list [list $table "$column" NULL $column_value]

    # the all_attributes array is used to ensure we do not have
    # duplicate column names
    set all_attributes([string toupper $column]) 1

    if { $column_value ne "" } {
        # column value is the same physical column as $column - just
        # named differently in the attribute list. We still don't want
        # duplicates
        set all_attributes([string toupper $column_value]) 1
    }

    # Now, loop through and gather all the attributes for this object
    # type and all its supertypes in order starting with this object
    # type up the type hierarchy

    db_foreach select_all_attributes {} {
        # First make sure the attribute is okay
        if { $limit_to ne "" } {
            # We have a limited list of arguments to use. Make sure
            # this attribute is one of them
            if {$attr_column_name ni $limit_to} {
                # This column is not in the list of allowed
                # columns... ignore
                continue
            }
        }
        set default [package_attribute_default  -min_n_values $min_n_values  -attr_default $default_value  $object_type $attr_table_name $attr_column_name]
        lappend attr_list [list $attr_table_name $attr_column_name $default]
        set all_attributes($attr_column_name) 1
    }

    if { $supertype ne "" && $object_name ne "" } {
        foreach row [util_memoize [list package_table_columns_for_type $supertype]] {
            lassign $row table_name column_name

            # Note that limit_to doesn't apply here as we always need
            # to include these arguments else the call will fail

            if { [info exists all_attributes($column_name)] } {
                continue
            }
            set all_attributes($column_name) 1
            set default [package_attribute_default $object_type $table_name $column_name]
            lappend attr_list [list $table_name $column_name $default]
        }
    }

    return $attr_list
Generic XQL file:
packages/acs-subsite/tcl/package-procs.xql

PostgreSQL XQL file:
<fullquery name="package_create_attribute_list.select_all_attributes">
    <querytext>

        select upper(coalesce(attr.table_name,t.table_name)) as attr_table_name,
               upper(coalesce(attr.column_name, attr.attribute_name)) as attr_column_name,
               attr.ancestor_type, attr.min_n_values, attr.default_value
          from acs_object_type_attributes attr,
               (select t2.object_type, t2.table_name, (tree_level(t1.tree_sortkey) - tree_level(t2.tree_sortkey)) + 1 as type_level
                  from acs_object_types t1, acs_object_types t2
                 where t1.tree_sortkey between t2.tree_sortkey and tree_right(t2.tree_sortkey)
                   and t1.object_type = :object_type) t
         where attr.ancestor_type = t.object_type
           and attr.object_type = :object_type
        order by t.type_level

      </querytext>
</fullquery>
packages/acs-subsite/tcl/package-procs-postgresql.xql

Oracle XQL file:
<fullquery name="package_create_attribute_list.select_all_attributes">
    <querytext>
      
	select upper(nvl(attr.table_name,t.table_name)) as attr_table_name, 
	       upper(nvl(attr.column_name, attr.attribute_name)) as attr_column_name, 
	       attr.ancestor_type, attr.min_n_values, attr.default_value
	  from acs_object_type_attributes attr, 
	       (select t.object_type, t.table_name, level as type_level
	          from acs_object_types t
	         start with t.object_type = :object_type
	       connect by prior t.supertype = t.object_type) t
         where attr.ancestor_type = t.object_type
           and attr.object_type = :object_type
        order by t.type_level 
    
      </querytext>
</fullquery>
packages/acs-subsite/tcl/package-procs-oracle.xql

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