MINI MINI MANI MO
<?xml version="1.0"?>
<!--
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
NAME
kusilmd.xsl
DESCRIPTION
Convert ILM (SXML) to DDL.
MODIFIED MM/DD/YY
rapayne 08/24/16 - Bug 24490693: generate IM clause for ILM policies.
jjanosik 10/12/15 - Fix ILM POLICIES for partitioned tables
tbhukya 01/05/15 - Bug 20319428: Declare referred params and import
xsl files for referred templates
lbarton 05/23/13 - bug 15872712: ILM policies
-->
<xsl:stylesheet version="1.0" xmlns:sxml="http://xmlns.oracle.com/ku" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Needed for Template DoCompressDDL -->
<xsl:import href="kuscommc.xsl"/>
<!-- Top-level parameters -->
<xsl:param name="PRETTY">1</xsl:param>
<xsl:param name="VERSION">9999999999</xsl:param>
<!-- Templates -->
<xsl:template name="DoAllILMPolicies">
<xsl:param name="ParentNode" select="''"/>
<!-- *******************************************************************
Template: DoAllILMPolicies - generate ALTER TABLE [MODIFY (SUB)PARTITION]
for all ILM policies for a table
Parameters:
ParentNode - parent of SCHEMA and NAME and RELATIONAL_TABLE
******************************************************************** -->
<!-- ALTER TABLE [MODIFY PARTITION] statement for ILM policies -->
<xsl:if test="$VERSION>=1200000000">
<!-- ALTER Table statment for ILM POLICIES. Get the ILM starting point from
the table physical properties if the table has no partitions and from
the default physical properties if it has partitions -->
<xsl:call-template name="DoILMPolicies">
<xsl:with-param name="ILMParentNode" select="$ParentNode/sxml:RELATIONAL_TABLE/sxml:PHYSICAL_PROPERTIES/sxml:HEAP_TABLE |
$ParentNode/sxml:RELATIONAL_TABLE/sxml:TABLE_PROPERTIES//sxml:DEFAULT_PHYSICAL_PROPERTIES/sxml:HEAP_TABLE"/>
<xsl:with-param name="SchemaParentNode" select="$ParentNode"/>
</xsl:call-template>
<!-- ALTER TABLE MODIFY PARTITION statement(s) for ILM policies -->
<xsl:for-each select="$ParentNode//sxml:PARTITION_LIST_ITEM">
<xsl:call-template name="DoILMPolicies">
<xsl:with-param name="ILMParentNode" select="sxml:PHYSICAL_PROPERTIES/sxml:HEAP_TABLE"/>
<xsl:with-param name="SchemaParentNode" select="$ParentNode"/>
<xsl:with-param name="SubType">PARTITION</xsl:with-param>
</xsl:call-template>
<xsl:for-each select="sxml:SUBPARTITION_LIST/sxml:SUBPARTITION_LIST_ITEM">
<xsl:call-template name="DoILMPolicies">
<xsl:with-param name="ILMParentNode" select="."/>
<xsl:with-param name="SchemaParentNode" select="$ParentNode"/>
<xsl:with-param name="SubType">SUBPARTITION</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="DoILMPolicies">
<xsl:param name="ILMParentNode" select="''"/>
<xsl:param name="SchemaParentNode" select="''"/>
<xsl:param name="SubType" select="''"/>
<!-- *******************************************************************
Template: DoILMPolicies - generate ALTER TABLE [MODIFY (SUB)PARTITION]
for ILM policies.
Parameters:
ILMParentNode - parent of ILM_POLICIES
SchemaParentNode - parent of SCHEMA and NAME
SubType - PARTITION or SUBPARTITION or null
Current node: TABLE or PARTITION_LIST_ITEM or SUBPARTITION_LIST_ITEM
******************************************************************** -->
<xsl:variable name="PartName" select="sxml:NAME"/>
<xsl:for-each select="$ILMParentNode/sxml:ILM_POLICIES/sxml:ILM_POLICIES_ITEM">
<xsl:variable name="Inherited">
<xsl:choose>
<xsl:when test="sxml:INHERITED_FROM='TABLESPACE'">TRUE</xsl:when>
<xsl:when test="$SubType='PARTITION' and sxml:INHERITED_FROM='TABLE'">TRUE</xsl:when>
<xsl:when test="$SubType='SUBPARTITION' and sxml:INHERITED_FROM='PARTITION'">TRUE</xsl:when>
<xsl:otherwise>FALSE</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="sxml:DISABLED_NAME or $Inherited='FALSE'">
<xsl:call-template name="DoAnILMPolicy">
<xsl:with-param name="SchemaParentNode" select="$SchemaParentNode"/>
<xsl:with-param name="SubType" select="$SubType"/>
<xsl:with-param name="PartName" select="$PartName"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="DoAnILMPolicy">
<xsl:param name="SchemaParentNode" select="''"/>
<xsl:param name="SubType" select="''"/>
<xsl:param name="PartName" select="''"/>
<!-- *******************************************************************
Template: DoAnILMPolicy - generate ALTER TABLE [MODIFY (SUB)PARTITION]
for one ILM policy
Parameters:
SchemaParentNode - parent of SCHEMA and NAME
SubType - PARTITION or SUBPARTITION or null
PartName - [sub]partition name
Current node: ILM_POLICIES_ITEM
******************************************************************** -->
<xsl:variable name="ilmClause">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:if test="string-length($ilmClause)>0">
<xsl:call-template name="ParseDDL"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ALTER TABLE </xsl:text>
<xsl:call-template name="SchemaName">
<xsl:with-param name="ParentNode" select="$SchemaParentNode"/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="$SubType='PARTITION'">
<xsl:text> MODIFY PARTITION </xsl:text>
<xsl:call-template name="QuotedName">
<xsl:with-param name="NameNode" select="$PartName"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$SubType='SUBPARTITION'">
<xsl:text> MODIFY SUBPARTITION </xsl:text>
<xsl:call-template name="QuotedName">
<xsl:with-param name="NameNode" select="$PartName"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:value-of select="$ilmClause"/>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:ILM_POLICIES">
<xsl:param name="SubType" select="''"/>
<!-- *******************************************************************
Template: ILM_POLICIES -
Parameters:
SubType - PARTITION or SUBPARTITION or null
******************************************************************** -->
<xsl:for-each select="sxml:ILM_POLICIES_ITEM">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="sxml:ILM_POLICIES_ITEM">
<xsl:param name="SubType" select="''"/>
<!-- *******************************************************************
Template: ILM_POLICIES_ITEM -
Parameters:
SubType - PARTITION or SUBPARTITION or null
******************************************************************** -->
<xsl:variable name="IlmPolicyAction">
<xsl:call-template name="DoILMPolicyAction"/>
</xsl:variable>
<xsl:if test="string-length($IlmPolicyAction)>0">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="sxml:DISABLED_NAME">
<xsl:text> ILM DISABLE POLICY </xsl:text>
<xsl:value-of select="sxml:DISABLED_NAME"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> ILM ADD POLICY</xsl:text>
<xsl:value-of select="$IlmPolicyAction"/>
<xsl:apply-templates select="sxml:SEGMENT[not(@src='1')]"/>
<xsl:apply-templates select="sxml:GROUP[not(@src='1')]"/>
<xsl:apply-templates select="sxml:ROW[not(@src='1')]"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:ON[not(@src='1')]"/>
<xsl:apply-templates select="sxml:AFTER[not(@src='1')]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="DoILMPolicyAction">
<!-- ************************************************************
Template: DoILMPolicyAction
Description: generate ILM policy action portion of the policy clause
**************************************************************** -->
<xsl:choose>
<xsl:when test="sxml:COMPRESS[not(@src='1')]">
<xsl:call-template name="DoCompressDDL">
<xsl:with-param name="Compress" select="sxml:COMPRESS"/>
<xsl:with-param name="CompressLevel" select="sxml:COMPRESS_LEVEL"/>
<xsl:with-param name="OmitRowLevelLocking" select="true()"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="sxml:INMEMORY[not(@src='1')] and $VERSION>=1202000000">
<xsl:if test="sxml:INMEMORY/sxml:SET">
<xsl:text> SET </xsl:text>
<xsl:value-of select="normalize-space(sxml:INMEMORY/sxml:SET)"/>
</xsl:if>
<xsl:if test="sxml:INMEMORY/sxml:MODIFY">
<xsl:text> MODIFY </xsl:text>
<xsl:value-of select="normalize-space(sxml:INMEMORY/sxml:MODIFY)"/>
</xsl:if>
<xsl:if test="sxml:INMEMORY/sxml:NO_INMEMORY">
<xsl:text> NO INMEMORY</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="sxml:TIER[not(@src='1')]">
<xsl:apply-templates select="sxml:TIER"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="sxml:TIER">
<!-- *******************************************************************
Template: TIER - Tiering clause
******************************************************************** -->
<xsl:text> TIER TO </xsl:text>
<xsl:value-of select="sxml:TABLESPACE"/>
<xsl:if test="sxml:READ_ONLY[not(@src='1')]"> READ ONLY </xsl:if>
</xsl:template>
<xsl:template match="sxml:SEGMENT | sxml:GROUP | sxml:ROW">
<!-- *******************************************************************
Template: SEGMENT, GROUP, ROW
******************************************************************** -->
<xsl:text> </xsl:text>
<xsl:value-of select="local-name(.)"/>
</xsl:template>
<xsl:template match="sxml:ON[not(@src='1')]">
<!-- *******************************************************************
Template: ON function-name
******************************************************************** -->
<xsl:text> ON </xsl:text>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="sxml:AFTER">
<!-- *******************************************************************
Template: AFTER n DAYS OF
******************************************************************** -->
<xsl:text> AFTER </xsl:text>
<xsl:value-of select="sxml:DAYS"/>
<xsl:text> DAYS OF </xsl:text>
<xsl:apply-templates select="sxml:ACCESS[not(@src='1')]"/>
<xsl:apply-templates select="sxml:MODIFICATION[not(@src='1')]"/>
<xsl:apply-templates select="sxml:CREATION[not(@src='1')]"/>
</xsl:template>
<xsl:template match="sxml:ACCESS | sxml:MODIFICATION | sxml:CREATION">
<!-- *******************************************************************
Template: ACCESS | MODIFICATION | CREATION
******************************************************************** -->
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
<xsl:value-of select="local-name(.)"/>
</xsl:template>
</xsl:stylesheet>
OHA YOOOO