	/*  
	
	create_views_blob.sql -	create materialized views for bad item blob (i.e. bad item serialized form) check 

	Copyright 2007, IBM Corporation

	Note: There are two kinds of (Oracle) views created below, one consisting of a one-column
		table of primary keys (a "primary key" view), and the other consisting of
		a one-column table of item ids (an "item id" view).

	*/

-- WHAT WE ARE TRYING TO BE COMPATIBLE WITH
-- CLEAN_ITEMS_OF_PK_VIEW('TOTAL_BAD_PRIMARY_KEY', clnCoaId, clnSrcCtgId, clnCoaCtgId);
-- CLEAN_CA_ITEMS_OF_IID_VIEW('TOTAL_BAD_CA_ITEM_ID', clnCoaId, clnCoaCtgId);    -- note:  COLLAB AREA CATALOG ID ONLY
	/* 
	TOTAL_BAD = All bad Entries for which we have a primary key. 
		By implication, they are bad both in source and in CA catalogs. */
create materialized view TOTAL_BAD_PRIMARY_KEY as
( 	select distinct cet_primary_key from cet_badblob where cet_ca_id = clnCoaId );


	/* 
	ADDITIONAL_CA_BAD = All bad CA orphan items and ITM-ITA cross-corruption, by item id in CA catalog. */
create materialized view ADDITIONAL_BAD_CA_ITEM_ID as
(   select distinct cet_ca_entry_id from cet_badblob where cet_ca_id = clnCoaId );

	/* 
	TOTAL_BAD_CA = All bad CA Entries, by item id. */
create materialized view TOTAL_BAD_CA_ITEM_ID as
((select distinct itm_id
  from itm x, TOTAL_BAD_PRIMARY_KEY y, coa
	where x.itm_primary_key = y.itm_primary_key
 	and coa_id = clnCoaId
        and x.itm_container_id  = coa_dst_container_id
        and x.itm_next_version_id=999999999 )
	union
 (select * from ADDITIONAL_BAD_CA_ITEM_ID));



/* end of create_views_blob script */

