/* Sample queries to retrieve data from the Semarchy Repository */

/*
 * Query to retrieve all LOV Values
 * in all LOVs
 * in the model 'CustomerB2CDemo'
 */
select 
  /* VAL.UUID  This is the internal ID of the value, but it is unlikely that you want to retrieve it. */
  RM.NAME       MODEL_NAME,
  LOV.NAME      LIST_NAME,
  VAL.CODE      VALUE_CODE,
  VAL.LABEL     VALUE_LABEL
from
             MTA_ROOT_MODEL RM
  inner join MTA_TYPE      LOV on (LOV.O_MODEL = RM.UUID and LOV.CLASSNAME = 'LOVType')
  inner join MTA_LOV_VAL   VAL on (VAL.O_TYPE = LOV.UUID and VAL.BRANCHID = LOV.BRANCHID and VAL.EDITIONID = LOV.EDITIONID)
where 
  RM.NAME = 'CustomerB2CDemo'
  and LOV.BRANCHID = 0
  and LOV.EDITIONID = 0
order by LOV.NAME, VAL.CODE
;


/*
 * Query to retrieve all Attributes
 * in all ComplexTypes
 * in the model 'CustomerB2CDemo'
 */
select 
  /* ATT.UUID  This is the internal ID of the Attribute, but it is unlikely that you want to retrieve it. */
  RM.NAME       MODEL_NAME,
  TYP.NAME      COMPLEX_TYPE_NAME,
  ATT.NAME      ATT_NAME,
  ATT.LABEL     ATT_LABEL
from
             MTA_ROOT_MODEL RM
  inner join MTA_CPLXTYPE  TYP on (TYP.O_MODEL = RM.UUID and TYP.CLASSNAME = 'ComplexType')
  inner join MTA_ATTRIBUTE ATT on (ATT.O_CPLXTYPE = TYP.UUID and ATT.BRANCHID = TYP.BRANCHID and ATT.EDITIONID = TYP.EDITIONID)
where 
  RM.NAME = 'CustomerB2CDemo'
  and TYP.BRANCHID = 0
  and TYP.EDITIONID = 0
order by TYP.NAME, ATT.POS_IN_PARENT
;


/*
 * Query to retrieve all Attributes
 * in all Entities
 * in the model 'CustomerB2CDemo'
 */
select 
  RM.NAME       MODEL_NAME,
  ENT.NAME      ENTITY_NAME,
  ATT.NAME      ATT_NAME,
  ATT.LABEL     ATT_LABEL,
  ATT.DOCUMENTATION ATT_DOCS
from
             MTA_ROOT_MODEL RM
  inner join MTA_ENTITY    ENT on (ENT.O_MODEL = RM.UUID)
  inner join MTA_ATTRIBUTE ATT on (ATT.O_ENTITY = ENT.UUID)
where 
  RM.NAME = 'CustomerB2CDemo'
  and ENT.BRANCHID = 0
  and ENT.EDITIONID = 0
order by ENT.NAME, ATT.POS_IN_PARENT
;

