CREATE OR REPLACE PACKAGE BODY SnapshotGenerated AS

FCOPARENTS    NUMBER(1):= 0;
FCOCHILDREN   NUMBER(1):= 1;

PROCEDURE takeSnapshot(idTable IN SnapshotCreateRestore.elemidType,
                  snap IN NUMBER) IS

  vCounter BINARY_INTEGER;
  tcount NUMBER;
  BEGIN
    Snapshot.debug('SnapshotGenerated.takeSnapshot: ','Insert parentage of objects');
    if (idTable.COUNT > 0) then
      vCounter:= idTable.FIRST;
      loop
        BEGIN
          insert into CMPFCOStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s2_16,
               s2_17,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               cl_1,
               cl_2,
               cl_3,
               cl_4,
               cl_5,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
            from CMPFCOClasses cmp
            where cmp.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
              and cmp.i_1 = idTable(vCounter)
          );
          insert into CMPSCOStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               b_20,
               b_21,
               b_22,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18
            from CMPSCOClasses cmp
            where cmp.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
              and cmp.i_1 = idTable(vCounter)
          );
          insert into CMPSCOCfgStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               i_21,
               i_22,
               i_23,
               d_1,
               d_2,
               d_3,
               d_4,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               t_16,
               t_17,
               t_18,
               t_19,
               t_20,
               t_21,
               t_22,
               t_23,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s1_16,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               s3_13,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19,
               r_20,
               r_21,
               r_22,
               r_23
            from CMPSCOCfgClasses cmp
            where cmp.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
              and cmp.i_1 = idTable(vCounter)
          );
          insert into CMPSCOMapStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               cl_1,
               cl_2,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
            from CMPSCOMapClasses cmp
            where cmp.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
              and cmp.i_1 = idTable(vCounter)
          );
          insert into CMPSCOPrpStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16
            from CMPSCOPrpClasses cmp
            where cmp.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
              and cmp.i_1 = idTable(vCounter)
          );
          insert into CMPSYSStorage
          (
            select
               WorkspaceID,
               snap,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               cl_1,
               cl_2,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15
            from CMPSYSClasses cmp
            where cmp.workspaceID = 1
              and cmp.i_1 = idTable(vCounter)
          );
          Snapshot.debug('SnapshotGenerated.takeSnapshot: ','Inserting parentage into association tables');
          insert into pctreestorage
            select p.workspaceID, snap, ' ', p.parentID, p.childID, p.parentRole, p.childRole
            from pctree p
            where p.childid = idTable(vCounter);
          insert into interlinkstorage
            select i.workspaceID, snap, ' ', i.linkfrom, i.linkto, i.linkfromrole, i.linktorole
            from interlink i
            where i.linkfrom = idTable(vCounter);
          insert into intralinkstorage
            select i.workspaceID, snap, ' ', i.linkFrom, i.linkTo, i.linkFromRole, i.linkToRole
            from intralink i
            where i.linkfrom = idTable(vCounter);
          Snapshot.debug('SnapshotGenerated.takeSnapshot: ','Inserting parentage into namespace storage table');
          insert into fcofoldernamespacestorage
            select cmp.workspaceID, snap, 1, 1,
            cmp.parentID,
            cmp.domain,
      	    cmp.name,
      	    cmp.isPhys,
      	    cmp.elementid,
            cmp.aggregateParent,
      	    cmp.languageISOID
            from cmpallfolderfconames cmp
            where cmp.elementid = idTable(vCounter);
        EXCEPTION when DUP_VAL_ON_INDEX then
          null;
        END;
        exit when vCounter = idTable.LAST;
        vCounter:= idTable.NEXT(vCounter);
      end loop;
    end if;

    Snapshot.debug('SnapshotGenerated.takeSnapshot: ','Insert actual repository objects');
    delete from temptable t
    where exists
    ((
      select 1 from CMPFCOStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
     ) union all (
      select 1 from CMPSCOStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
     ) union all (
      select 1 from CMPSCOCfgStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
     ) union all (
      select 1 from CMPSCOMapStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
     ) union all (
      select 1 from CMPSCOPrpStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
     ) union all (
      select 1 from CMPSYSStorage cmp
      where cmp.workspaceID = t.workspaceID
        and cmp.i_1 = t.elementid and snapshotid = snap
    ));
    insert into CMPFCOStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_FCOELEMENTID) */
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s2_16,
               s2_17,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               cl_1,
               cl_2,
               cl_3,
               cl_4,
               cl_5,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
          from temptable t, CMPFCOClasses cmp
          where cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
    insert into CMPSCOStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_SCOELEMENTID) */
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               b_20,
               b_21,
               b_22,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18
          from temptable t, CMPSCOClasses cmp
          where cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
    insert into CMPSCOCfgStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_SCOCFGELEMENTID)*/
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               i_21,
               i_22,
               i_23,
               d_1,
               d_2,
               d_3,
               d_4,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               t_16,
               t_17,
               t_18,
               t_19,
               t_20,
               t_21,
               t_22,
               t_23,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s1_16,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               s3_13,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19,
               r_20,
               r_21,
               r_22,
               r_23
          from temptable t, CMPSCOCfgClasses cmp
          where cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
    insert into CMPSCOMapStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_SCOMAPELEMENTID) */
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               cl_1,
               cl_2,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
          from temptable t, CMPSCOMapClasses cmp
          where cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
    insert into CMPSCOPrpStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_SCOPRPELEMENTID) */
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16
          from temptable t, CMPSCOPrpClasses cmp
          where cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
    insert into CMPSYSStorage
      (
          select /*+ LEADING(t) USE_NL_WITH_INDEX(cmp IDX_SYSELEMENTID) */
               t.WorkspaceID,
               snap,
               t.compuoid,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               cl_1,
               cl_2,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15
          from temptable t, CMPSYSClasses cmp
          where t.workspaceID = 1
            and cmp.workspaceID = t.workspaceID
            and cmp.i_1 = t.elementid
      );
  END takeSnapshot;


PROCEDURE reconcileAssociations(hashTable IN SnapshotCreateRestore.elemidType,
  snap IN NUMBER) IS

  BEGIN
               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15,r_16,r_17,r_18,r_19
               from AssocTable a, CMPFCOStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPFCOStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPFCOStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPFCOStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPFCOStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPFCOStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPFCOStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPFCOStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPFCOStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPFCOStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPFCOStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPFCOStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPFCOStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPFCOStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPFCOStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPFCOStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPFCOStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_16)) then
                     update CMPFCOStorage set r_16 = hashTable(c.r_16)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_17)) then
                     update CMPFCOStorage set r_17 = hashTable(c.r_17)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_18)) then
                     update CMPFCOStorage set r_18 = hashTable(c.r_18)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_19)) then
                     update CMPFCOStorage set r_19 = hashTable(c.r_19)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6
               from AssocTable a, CMPMMMStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPMMMStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPMMMStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPMMMStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPMMMStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPMMMStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPMMMStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPMMMStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15,r_16,r_17,r_18
               from AssocTable a, CMPSCOStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPSCOStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPSCOStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPSCOStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPSCOStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPSCOStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPSCOStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPSCOStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPSCOStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPSCOStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPSCOStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPSCOStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPSCOStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPSCOStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPSCOStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPSCOStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPSCOStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_16)) then
                     update CMPSCOStorage set r_16 = hashTable(c.r_16)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_17)) then
                     update CMPSCOStorage set r_17 = hashTable(c.r_17)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_18)) then
                     update CMPSCOStorage set r_18 = hashTable(c.r_18)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15,r_16,r_17,r_18,r_19,r_20,r_21,r_22,r_23
               from AssocTable a, CMPSCOCfgStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPSCOCfgStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPSCOCfgStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPSCOCfgStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPSCOCfgStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPSCOCfgStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPSCOCfgStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPSCOCfgStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPSCOCfgStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPSCOCfgStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPSCOCfgStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPSCOCfgStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPSCOCfgStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPSCOCfgStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPSCOCfgStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPSCOCfgStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPSCOCfgStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_16)) then
                     update CMPSCOCfgStorage set r_16 = hashTable(c.r_16)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_17)) then
                     update CMPSCOCfgStorage set r_17 = hashTable(c.r_17)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_18)) then
                     update CMPSCOCfgStorage set r_18 = hashTable(c.r_18)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_19)) then
                     update CMPSCOCfgStorage set r_19 = hashTable(c.r_19)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_20)) then
                     update CMPSCOCfgStorage set r_20 = hashTable(c.r_20)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_21)) then
                     update CMPSCOCfgStorage set r_21 = hashTable(c.r_21)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_22)) then
                     update CMPSCOCfgStorage set r_22 = hashTable(c.r_22)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_23)) then
                     update CMPSCOCfgStorage set r_23 = hashTable(c.r_23)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15,r_16,r_17,r_18,r_19
               from AssocTable a, CMPSCOMapStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPSCOMapStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPSCOMapStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPSCOMapStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPSCOMapStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPSCOMapStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPSCOMapStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPSCOMapStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPSCOMapStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPSCOMapStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPSCOMapStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPSCOMapStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPSCOMapStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPSCOMapStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPSCOMapStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPSCOMapStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPSCOMapStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_16)) then
                     update CMPSCOMapStorage set r_16 = hashTable(c.r_16)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_17)) then
                     update CMPSCOMapStorage set r_17 = hashTable(c.r_17)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_18)) then
                     update CMPSCOMapStorage set r_18 = hashTable(c.r_18)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_19)) then
                     update CMPSCOMapStorage set r_19 = hashTable(c.r_19)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15,r_16
               from AssocTable a, CMPSCOPrpStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPSCOPrpStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPSCOPrpStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPSCOPrpStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPSCOPrpStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPSCOPrpStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPSCOPrpStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPSCOPrpStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPSCOPrpStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPSCOPrpStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPSCOPrpStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPSCOPrpStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPSCOPrpStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPSCOPrpStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPSCOPrpStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPSCOPrpStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPSCOPrpStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_16)) then
                     update CMPSCOPrpStorage set r_16 = hashTable(c.r_16)
                      where rowid = c.rowid;
                   end if;
               end loop;

               for c in (select /*+full (a) */ cmp.rowid, i_1,r_1,r_2,r_3,r_4,r_5,r_6,r_7,r_8,r_9,r_10,r_11,r_12,r_13,r_14,r_15
               from AssocTable a, CMPSYSStorage cmp where cmp.workspaceID = a.workspaceId and cmp.i_1 = a.oldID and snapshotid = snap) 
               loop
                   if (hashTable.EXISTS(c.i_1)) then
                     update CMPSYSStorage set i_1 = hashTable(c.i_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_1)) then
                     update CMPSYSStorage set r_1 = hashTable(c.r_1)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_2)) then
                     update CMPSYSStorage set r_2 = hashTable(c.r_2)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_3)) then
                     update CMPSYSStorage set r_3 = hashTable(c.r_3)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_4)) then
                     update CMPSYSStorage set r_4 = hashTable(c.r_4)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_5)) then
                     update CMPSYSStorage set r_5 = hashTable(c.r_5)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_6)) then
                     update CMPSYSStorage set r_6 = hashTable(c.r_6)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_7)) then
                     update CMPSYSStorage set r_7 = hashTable(c.r_7)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_8)) then
                     update CMPSYSStorage set r_8 = hashTable(c.r_8)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_9)) then
                     update CMPSYSStorage set r_9 = hashTable(c.r_9)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_10)) then
                     update CMPSYSStorage set r_10 = hashTable(c.r_10)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_11)) then
                     update CMPSYSStorage set r_11 = hashTable(c.r_11)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_12)) then
                     update CMPSYSStorage set r_12 = hashTable(c.r_12)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_13)) then
                     update CMPSYSStorage set r_13 = hashTable(c.r_13)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_14)) then
                     update CMPSYSStorage set r_14 = hashTable(c.r_14)
                      where rowid = c.rowid;
                   end if;
                   if (hashTable.EXISTS(c.r_15)) then
                     update CMPSYSStorage set r_15 = hashTable(c.r_15)
                      where rowid = c.rowid;
                   end if;
               end loop;

  END reconcileAssociations;

PROCEDURE insertIntoCurrentRepos(snap IN NUMBER,compId IN NUMBER) IS
  BEGIN
    Snapshot.debug('SnapshotGenerated.insertIntoCurrentRepos: ','');
    if (Snapshot.isDebug()) then
      for c in (select * from tempfco where type = FCOCHILDREN) loop
        Snapshot.debug('SnapshotGenerated.insertIntoCurrentRepos: uoid = ',c.uoid);
      end loop;
    end if;
    insert into CMPFCOClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s2_16,
               s2_17,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               cl_1,
               cl_2,
               cl_3,
               cl_4,
               cl_5,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
          from CMPFCOStorage a
          where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
    insert into CMPSCOClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               b_20,
               b_21,
               b_22,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18
          from CMPSCOStorage a
          where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
    insert into CMPSCOCfgClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               i_21,
               i_22,
               i_23,
               d_1,
               d_2,
               d_3,
               d_4,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               t_16,
               t_17,
               t_18,
               t_19,
               t_20,
               t_21,
               t_22,
               t_23,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s1_16,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               s3_13,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19,
               r_20,
               r_21,
               r_22,
               r_23
          from CMPSCOCfgStorage a
          where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
    insert into CMPSCOMapClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               cl_1,
               cl_2,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
          from CMPSCOMapStorage a
          where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
    insert into CMPSCOPrpClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16
          from CMPSCOPrpStorage a
          where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
    insert into CMPSYSClasses
      (
          select
               WorkspaceID,
               0,
               null,
               1,
               0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               cl_1,
               cl_2,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15
          from CMPSYSStorage a
          where a.workspaceID = 1
          and
          (
            a.compuoid in (select uoid from tempfco where type = FCOCHILDREN) or
	          a.i_1 = compid
          )
          and
          a.snapshotID = snap
      );
  END insertIntoCurrentRepos;

PROCEDURE restoreParentage(snap IN NUMBER) IS
  BEGIN
    Snapshot.debug('SnapshotGenerated.restoreParentage:','');
    /*
    for c in (select elementid from tempfco where type = FCOPARENTS) loop
      Snapshot.debug('SnapshotGenerated.restoreParentage: elementid = ',c.elementid);
    end loop;
    */
    insert into CMPFCOClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s2_16,
               s2_17,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               cl_1,
               cl_2,
               cl_3,
               cl_4,
               cl_5,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
        from CMPFCOStorage a,tempfco t
        where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
    insert into CMPSCOClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               b_20,
               b_21,
               b_22,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s2_10,
               s2_11,
               s2_12,
               s2_13,
               s2_14,
               s2_15,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18
        from CMPSCOStorage a,tempfco t
        where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
    insert into CMPSCOCfgClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               b_13,
               b_14,
               b_15,
               b_16,
               b_17,
               b_18,
               b_19,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               i_14,
               i_15,
               i_16,
               i_17,
               i_18,
               i_19,
               i_20,
               i_21,
               i_22,
               i_23,
               d_1,
               d_2,
               d_3,
               d_4,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               t_14,
               t_15,
               t_16,
               t_17,
               t_18,
               t_19,
               t_20,
               t_21,
               t_22,
               t_23,
               f_1,
               f_2,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s1_12,
               s1_13,
               s1_14,
               s1_15,
               s1_16,
               s2_1,
               s2_2,
               s2_3,
               s2_4,
               s2_5,
               s2_6,
               s2_7,
               s2_8,
               s2_9,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               s3_13,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19,
               r_20,
               r_21,
               r_22,
               r_23
        from CMPSCOCfgStorage a,tempfco t
        where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
    insert into CMPSCOMapClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               i_8,
               i_9,
               i_10,
               i_11,
               i_12,
               i_13,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               t_12,
               t_13,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               s3_8,
               s3_9,
               s3_10,
               s3_11,
               s3_12,
               cl_1,
               cl_2,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16,
               r_17,
               r_18,
               r_19
        from CMPSCOMapStorage a,tempfco t
        where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
    insert into CMPSCOPrpClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               t_10,
               t_11,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               s3_7,
               cl_1,
               cl_2,
               cl_3,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15,
               r_16
        from CMPSCOPrpStorage a,tempfco t
        where a.workspaceID = (select sys_context('owb_workspace','workspaceID') from dual)
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
    insert into CMPSYSClasses
      (
        select
              WorkspaceID,
	      0,
	      null,
              1,
              0,
               DeletionParent,
               LoadingParent,
               b_1,
               b_2,
               b_3,
               b_4,
               b_5,
               b_6,
               b_7,
               b_8,
               b_9,
               b_10,
               b_11,
               b_12,
               i_1,
               i_2,
               i_3,
               i_4,
               i_5,
               i_6,
               i_7,
               d_1,
               d_2,
               d_3,
               t_1,
               t_2,
               t_3,
               t_4,
               t_5,
               t_6,
               t_7,
               t_8,
               t_9,
               s1_1,
               s1_2,
               s1_3,
               s1_4,
               s1_5,
               s1_6,
               s1_7,
               s1_8,
               s1_9,
               s1_10,
               s1_11,
               s2_1,
               s2_2,
               s2_3,
               s4_1,
               s4_2,
               s3_1,
               s3_2,
               s3_3,
               s3_4,
               s3_5,
               s3_6,
               cl_1,
               cl_2,
               bl_1,
               r_1,
               r_2,
               r_3,
               r_4,
               r_5,
               r_6,
               r_7,
               r_8,
               r_9,
               r_10,
               r_11,
               r_12,
               r_13,
               r_14,
               r_15
        from CMPSYSStorage a,tempfco t
        where a.workspaceID = 1
          and a.i_1 = t.elementid and a.snapshotID = snap and t.type = FCOPARENTS
        );
  END restoreParentage;
 
FUNCTION getClassBasedSet(class IN VARCHAR) RETURN NUMBER IS
  result NUMBER;
  BEGIN
    if    ('CMPRelationalDBItem'         = class) then result := 1;
    elsif ('CMPBusinessRuleItemParam'    = class) then result := 1;
    elsif ('CMPProfileAttribute'         = class) then result := 1;
    elsif ('CMPWBField'                  = class) then result := 1;
    elsif ('CMPFunctionArgument'         = class) then result := 1;
    elsif ('CMPRecordField'              = class) then result := 1;
    elsif ('CMPExternalTableItem'        = class) then result := 1;
    elsif ('CMPItem'                     = class) then result := 1;
    elsif ('CMPDimensionAttribute'       = class) then result := 2;
    elsif ('CMPCubeMeasure'              = class) then result := 2;
    elsif ('CMPProcessActivityParameter' = class) then result := 3;
    elsif ('CMPVariable'                 = class) then result := 3;
    elsif ('CMPBaseVariable'             = class) then result := 3;
    else result := null;
    end if;
    return result;
  END getClassBasedSet;

FUNCTION getSetBasedValue(set IN NUMBER, v1 IN NUMBER,
                           v2 IN NUMBER, v3 IN NUMBER) RETURN NUMBER IS
  result NUMBER;
  BEGIN
    if    (set = 1) then result := v1;
    elsif (set = 2) then result := v2;
    elsif (set = 3) then result := v3;
    else result := null;
    end if;
    return result;
  END getSetBasedValue;

PROCEDURE resetDataTypes(elemID IN NUMBER, platformId IN NUMBER) IS
  targetDataType NUMBER;
  targetDataSet  NUMBER;
  propertyValues SnapshotDataTypeService.mappedPairType;
  BEGIN
    for fco in (
      select elementid
      from firstclassobject_v
      start with elementid = elemID
      connect by prior elementid = owningfolder
    )
    loop
      for dt in (
        select rowid, r_10, s2_1, i_7, i_8, i_9, i_10, i_11, i_12, i_13, i_15, i_16
        from CMPSCOCfgClasses
        where r_7 = fco.elementid and r_10 is not null
      )
      loop
        targetDataSet               := getClassBasedSet(dt.s2_1);
        propertyValues('size')      := getSetBasedValue(targetDataSet, dt.i_13, dt.i_10, dt.i_7);
        propertyValues('precision') := getSetBasedValue(targetDataSet, dt.i_15, dt.i_11, dt.i_8);
        propertyValues('scale')     := getSetBasedValue(targetDataSet, dt.i_16, dt.i_12, dt.i_9);
        targetDataType := SnapshotDataTypeService.getMappedDataType(dt.r_10, platformId, propertyValues);
        if (targetDataType is not null) then
          update CMPSCOCfgClasses set
            r_10 = targetDataType
           ,s3_5 = SnapshotDataTypeService.getMappedDataTypeFQN(targetDataType)
           ,s1_7 = SnapshotDataTypeService.getMappedDataTypeUOID(targetDataType)
           ,i_7  = decode(targetDataSet,3,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_7),i_7)
           ,i_8  = decode(targetDataSet,3,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_8),i_8)
           ,i_9  = decode(targetDataSet,3,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_9),i_9)
           ,i_10 = decode(targetDataSet,2,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_10),i_10)
           ,i_11 = decode(targetDataSet,2,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_11),i_11)
           ,i_12 = decode(targetDataSet,2,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_12),i_12)
           ,i_13 = decode(targetDataSet,1,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_13),i_13)
           ,i_15 = decode(targetDataSet,1,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_15),i_15)
           ,i_16 = decode(targetDataSet,1,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_16),i_16)
          where rowid = dt.rowid;
        end if;
      end loop;
    end loop;
  END resetDataTypes;

PROCEDURE resetDataTypes(uoidStr IN VARCHAR2, snap IN NUMBER, platformId IN NUMBER) IS
  targetDataType NUMBER;
  targetDataSet  NUMBER;
  propertyValues SnapshotDataTypeService.mappedPairType;
  BEGIN
    for fco in (
      select elementid
      from firstclassobject_x
      where snapshotid = snap
      start with uoid = uoidStr
      connect by prior elementid = owningfolder
    )
    loop
      for dt in (
        select rowid, r_10, s2_1, i_7, i_8, i_9, i_10, i_11, i_12, i_13, i_15, i_16
        from CMPSCOCfgStorage
        where snapshotid = snap and r_7 = fco.elementid and r_10 is not null
      )
      loop
        targetDataSet               := getClassBasedSet(dt.s2_1);
        propertyValues('size')      := getSetBasedValue(targetDataSet, dt.i_13, dt.i_10, dt.i_7);
        propertyValues('precision') := getSetBasedValue(targetDataSet, dt.i_15, dt.i_11, dt.i_8);
        propertyValues('scale')     := getSetBasedValue(targetDataSet, dt.i_16, dt.i_12, dt.i_9);
        targetDataType := SnapshotDataTypeService.getMappedDataType(dt.r_10, platformId, propertyValues);
        if (targetDataType is not null) then
          update CMPSCOCfgStorage set
            r_10 = targetDataType
           ,s3_5 = SnapshotDataTypeService.getMappedDataTypeFQN(targetDataType)
           ,s1_7 = SnapshotDataTypeService.getMappedDataTypeUOID(targetDataType)
           ,i_7  = decode(targetDataSet,3,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_7),i_7)
           ,i_8  = decode(targetDataSet,3,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_8),i_8)
           ,i_9  = decode(targetDataSet,3,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_9),i_9)
           ,i_10 = decode(targetDataSet,2,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_10),i_10)
           ,i_11 = decode(targetDataSet,2,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_11),i_11)
           ,i_12 = decode(targetDataSet,2,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_12),i_12)
           ,i_13 = decode(targetDataSet,1,SnapshotDataTypeService.resetLength(dt.r_10,targetDataType,i_13),i_13)
           ,i_15 = decode(targetDataSet,1,SnapshotDataTypeService.resetPrecision(dt.r_10,targetDataType,i_15),i_15)
           ,i_16 = decode(targetDataSet,1,SnapshotDataTypeService.resetScale(dt.r_10,targetDataType,i_16),i_16)
          where rowid = dt.rowid;
        end if;
      end loop;
    end loop;
  END resetDataTypes;

END SnapshotGenerated;
/