select count(*) from portal_elements, portal_pages where portal_pages.page_id = :page_id and portal_pages.page_id = portal_elements.page_id and portal_elements.region = :region select portal_elements.element_id as template_element_id from portal_elements, portal_pages, portals where portal_elements.page_id = portal_pages.page_id and portal_pages.portal_id = portals.template_id and portals.portal_id = (select portal_id from portal_pages where page_id = :page_id) and portal_elements.datasource_id = :datasource_id insert into portal_element_parameters (parameter_id, element_id, config_required_p, configured_p, key, value) select portal_seq.nextval, :element_id, config_required_p, configured_p, key, value from portal_datasource_parameters where datasource_id = :datasource_id insert into portal_elements (element_id, datasource_id, name, page_id, region, sort_key, state, shadeable_p, hideable_p) select :element_id, :datasource_id, :name, :page_id, region, sort_key, state, shadeable_p, hideable_p from portal_elements where element_id = :template_element_id insert into portal_element_parameters (parameter_id, element_id, config_required_p, configured_p, key, value) select portal_seq.nextval, :element_id, config_required_p, configured_p, key, value from portal_element_parameters where element_id = :template_element_id delete from portal_elements where element_id = :element_id select * from portal_elements where element_id = :element_id update portal_elements set datasource_id = :datasource_id, name = :name, page_id = :page_id, region = :region, sort_key = :sortkey, state = :state where element_id = :element_id select portal_elements.element_id from portal_elements, portal_pages where portal_pages.portal_id = :portal_id and portal_elements.datasource_id = :datasource_id and portal_elements.page_id = portal_pages.page_id update portal_elements set sort_key = :dummy_sort_key where element_id = :element_id update portal_elements set sort_key = :sort_key where element_id = :other_element_id update portal_elements set sort_key = :other_sort_key where element_id = :element_id