MINI MINI MANI MO
<?xml version="1.0"?>
<!--
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
NAME
kuilm.xsl
DESCRIPTION
XSLT stylesheet for XML => DDL conversion of ILM attributes in table UDTs
NOTES
Do NOT modify this file under any circumstance. Copy the file
if you wish to use this stylesheet with an external XML/XSL parser
MODIFIED MM/DD/YY
sdavidso 03/28/17 - bug25509879 ILM "TIER TO" quoted tablespace
rapayne 08/09/16 - bug 24435630: generate IM clause for ILM policies.
dvekaria 09/25/15 - Bug 21865888: Incorrect DDL for disabled ILM.
sogugupt 07/13/15 - Bug 21312469 - Incorrect ILM policy
lbarton 10/14/14 - bug 19164768: temporal validity + row archival
dvekaria 05/22/14 - Bug 18381016: ILM include ACTIONC value.
lbarton 11/05/13 - bug 17654567: row archival
lbarton 10/03/12 - bug 10350062: ILM compression and storage tiering
lbarton 02/09/12 - project 37414: ILM support
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Import required scripts -->
<xsl:import href="kucommon.xsl"/>
<!-- Top-level parameters -->
<xsl:param name="PRETTY">1</xsl:param>
<xsl:param name="SQLTERMINATOR">0</xsl:param>
<!-- params for parse -->
<xsl:param name="PRS_DDL">0</xsl:param>
<xsl:param name="PRS_DELIM">\{]`</xsl:param>
<xsl:param name="PRS_VERB">0</xsl:param>
<xsl:param name="PRS_OBJECT_TYPE">0</xsl:param>
<xsl:param name="PRS_SCHEMA">0</xsl:param>
<xsl:param name="PRS_NAME">0</xsl:param>
<xsl:param name="PRS_TABLESPACE">0</xsl:param>
<xsl:param name="PRS_GRANTEE">0</xsl:param>
<xsl:param name="PRS_GRANTOR">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_SCHEMA">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_NAME">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_TYPE">0</xsl:param>
<xsl:param name="PRS_ALT_CONNECT_TYPE">0</xsl:param>
<!-- Templates -->
<xsl:template name="DoILMClause">
<!-- *******************************************************************
Template: DoILMClause
Description: generate ILM clause
Current node: TABLE_T
The relevant bits are in PROPERTY2:
x08000 (32768) row archival (formerly lifecycle management)
The following bits are no longer valid
x10000 (65536) tracking (write time)
x20000 (131072) tracking (create time)
x40000 (262144) tracking (read time)
x80000 (524288) tracking segment access
******************************************************************** -->
<xsl:if test="(PROPERTY2 mod 65536) >= 32768">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ROW ARCHIVAL </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="DoILMPolicies">
<xsl:param name="SubType" select="''"/>
<!-- *******************************************************************
Template: DoILMPolicies - generate ALTER TABLE [MODIFY (SUB)PARTITION]
for ILM policies
Parameters:
SubType - PARTITION or SUBPARTITION or null
******************************************************************** -->
<xsl:variable name="SchemaNode" select="SCHEMA_OBJ/OWNER_NAME"/>
<xsl:variable name="NameNode" select="SCHEMA_OBJ/NAME"/>
<xsl:variable name="SchemaObj" select="SCHEMA_OBJ"/>
<xsl:for-each select="ILM_POLICIES/ILM_POLICIES_ITEM">
<xsl:variable name="IlmPolicy">
<xsl:call-template name="DoILMPolicy"/>
</xsl:variable>
<!-- INHERITED represents
1 - inherited from tablespace or inherited from table or inherited from table partition
0 - not inherited -->
<xsl:variable name="INHERITED">
<xsl:choose>
<xsl:when test="((ILMOBJ_FLAG mod 16)= 8) or
(OBJ_TYP != OBJ_TYP_ORIG and OBJ_TYP_ORIG = 2) or
(OBJ_TYP != OBJ_TYP_ORIG and OBJ_TYP_ORIG = 19)">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$INHERITED = 0 and string-length($IlmPolicy)>0 or ILMOBJ_FLAG mod 2 =1">
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaNode"/>
<xsl:with-param name="NameNode" select="$NameNode"/>
</xsl:call-template>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ALTER TABLE </xsl:text>
<xsl:apply-templates select="$SchemaObj"/>
<xsl:if test="string-length($SubType)!=0">
<xsl:text> MODIFY </xsl:text>
<xsl:value-of select="$SubType"/>
<xsl:text> "</xsl:text>
<xsl:value-of select="$SchemaObj/SUBNAME"/>
<xsl:text>" </xsl:text>
</xsl:if>
<xsl:choose>
<!-- if policy is disabled on the non inherited object then call disable policy template -->
<xsl:when test="ILMOBJ_FLAG mod 2 =1">
<xsl:call-template name="DisablePolicy"/>
</xsl:when>
<xsl:otherwise>
<!-- otherwise we are adding a ILM policy -->
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ILM ADD POLICY </xsl:text>
<xsl:value-of select="$IlmPolicy"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="$INHERITED = 1 and ILMOBJ_FLAG = 1">
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="$SchemaNode"/>
<xsl:with-param name="NameNode" select="$NameNode"/>
</xsl:call-template>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ALTER TABLE </xsl:text>
<xsl:apply-templates select="$SchemaObj"/>
<xsl:if test="string-length($SubType)!=0">
<xsl:text> MODIFY </xsl:text>
<xsl:value-of select="$SubType"/>
<xsl:text> "</xsl:text>
<xsl:value-of select="$SchemaObj/SUBNAME"/>
<xsl:text>" </xsl:text>
</xsl:if>
<xsl:call-template name="DisablePolicy"/>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="DoILMPolicyAction">
<!-- *******************************************************************
Template: DoILMPolicyAction
Description: generate ILM policy action portion of the policy clause
******************************************************************** -->
<!-- ACTIONC_CLOB is only valid in 12.2 and is used to track IM
attributes used in ILM policies.
-->
<xsl:if test="(not(ACTIONC_CLOB) and ACTION != '4') or
$VERSION>=1202000000">
<xsl:choose>
<xsl:when test="ACTION='2'">
<xsl:text>TIER TO "</xsl:text>
<xsl:value-of select="TIER_TBS"/>
<xsl:text>" </xsl:text>
<xsl:if test="FLAG='1'">READ ONLY </xsl:if>
</xsl:when>
<xsl:when test="ACTION='1'">
<xsl:choose>
<xsl:when test="CTYPE='1'">
<xsl:value-of select="ACTIONC"/>
</xsl:when>
<xsl:when test="CTYPE='2'">
<xsl:text>ROW STORE COMPRESS ADVANCED </xsl:text>
<xsl:if test="FLAG='4'">INPLACE </xsl:if>
</xsl:when>
<xsl:when test="CTYPE='3'">
<xsl:text>COLUMN STORE COMPRESS FOR </xsl:text>
<xsl:choose>
<xsl:when test="CLEVEL='1'">QUERY LOW </xsl:when>
<xsl:when test="CLEVEL='2'">QUERY HIGH </xsl:when>
<xsl:when test="CLEVEL='3'">ARCHIVE LOW </xsl:when>
<xsl:when test="CLEVEL='4'">ARCHIVE HIGH </xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="POL_SUBTYPE='1'">
<xsl:text>MODIFY </xsl:text>
<xsl:value-of select="ACTIONC_CLOB"/>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="ACTION='4'">
<xsl:text>NO INMEMORY </xsl:text>
</xsl:when>
<xsl:when test="ACTION='5'">
<xsl:text>SET </xsl:text>
<xsl:value-of select="ACTIONC_CLOB"/>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name="DoILMPolicy">
<!-- *******************************************************************
Template: DoILMPolicy
Description: generate ILM policy clause
******************************************************************** -->
<xsl:variable name="IlmPolicyAction">
<xsl:call-template name="DoILMPolicyAction"/>
</xsl:variable>
<xsl:if test="string-length($IlmPolicyAction)>0">
<xsl:value-of select="$IlmPolicyAction"/>
<xsl:choose>
<xsl:when test="SCOPE='1'">SEGMENT </xsl:when>
<xsl:when test="SCOPE='2'">GROUP </xsl:when>
<xsl:when test="SCOPE='3'">ROW </xsl:when>
</xsl:choose>
<!-- condition clause -->
<xsl:choose>
<xsl:when test="FLAG=8">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ON </xsl:text>
<xsl:value-of select="CUSTFUNC"/>
</xsl:when>
<xsl:when test="DAYS > 0">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> AFTER </xsl:text>
<xsl:value-of select="DAYS"/>
<xsl:text> DAYS OF </xsl:text>
<xsl:choose>
<xsl:when test="CONDITION='0'">NO ACCESS</xsl:when>
<xsl:when test="CONDITION='1'">LOW ACCESS</xsl:when>
<xsl:when test="CONDITION='2'">NO MODIFICATION</xsl:when>
<xsl:when test="CONDITION='3'">CREATION</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="TABLESPACE_ILM_POLICY_T">
<!-- *******************************************************************
Template: TABLESPACE_ILM_POLICY_T - default ILM policies for tablespace
******************************************************************** -->
<xsl:variable name="NameNode" select="NAME"/>
<xsl:for-each select="ILM_POLICIES/ILM_POLICIES_ITEM">
<xsl:variable name="IlmPolicy">
<xsl:call-template name="DoILMPolicy"/>
</xsl:variable>
<xsl:if test="string-length($IlmPolicy)>0">
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLESPACE_ILM_POLICY</xsl:with-param>
<xsl:with-param name="NameNode" select="$NameNode"/>
</xsl:call-template>
<xsl:text> ALTER TABLESPACE "</xsl:text>
<xsl:value-of select="$NameNode"/>
<xsl:text>" DEFAULT</xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ILM ADD POLICY </xsl:text>
<xsl:value-of select="$IlmPolicy"/>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
</xsl:if>
<xsl:if test="$PRETTY=1 and position()!=last()">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="DisablePolicy">
<!-- ************************************************************************
Template:DisablePolicy
Description:Generate disable ILM policy clause
*************************************************************************** -->
<xsl:variable name="PolicyName" select="POLICY_NUM"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ILM DISABLE POLICY P</xsl:text>
<xsl:value-of select="$PolicyName"/>
</xsl:template>
</xsl:stylesheet>
OHA YOOOO