MINI MINI MANI MO
<?xml version="1.0"?>
<!-- Copyright (c) 2005, 2018, Oracle and/or its affiliates.
All rights reserved.-->
<!--
NAME
kustbphd.xsl
DESCRIPTION
Convert PHYSICAL_PROPERTIES in TABLE document (SXML) to creation DDL.
MODIFIED MM/DD/YY
apfwkr 04/13/18 - Backport rmacnico_bug-25882883 from main
rapayne 03/18/18 - add inmemory support for external table objects.
sdavidso 03/24/17 - bug25440009 user name containing apostrophe
tbhukya 02/24/17 - Bug 25571994: Use memoptimize read, write
tbhukya 01/30/17 - Bug 25095866: Generate MEMOPTIMIZE clause
jjanosik 12/07/16 - Bug 24482120: Fix CELLMMEMORY for segment creation
deferred tables
tbhukya 06/09/16 - Bug 22171888: Support CELLMEMORY
tbhukya 01/05/15 - Bug 20319428: Declare referred params
rapayne 11/07/14 - bug 19976325 - deferred segment support for [P]IOTs,
xmltype and object tables.
lbarton 09/24/14 - pretty print BUFFER_POOL
rapayne 02/30/14 - bug 18155007: add INMEMORY support.
bwright 08/16/13 - Bug 17312600: Remove hard tabs from DP src code
lbarton 09/19/11 - project 32935: row level locking
tbhukya 01/24/10 - Bug 11667496:support FLASH_CACHE and CELL_FLASH_CACHE
- for 11.2 and higher versions only
rapayne 05/12/10 - bug 9702802: correct PCTFREE default from 0 to 10.
lbarton 11/11/09 - deferred segment creation for partitions
abodge 09/22/09 - CONSOLIDATE STYLESHEETS: TargetSchemaName, src=1
exclusion
lbarton 07/10/09 - bug 8494344: archive compression
adalee 04/16/09 - add FLASH_CACHE AND CELL_FLASH_CACHE
lbarton 03/16/09 - fix inconsistencies with kustorag.xsl
lbarton 01/29/09 - bug 7831566: SEGMENT CREATION IMMEDIATE
lbarton 01/15/08 - Bug 6724820: table compression
lbarton 03/19/08 - deferred segment creation
htseng 01/11/08 - bug 6702825 : 0 value of PCTFREE/PCTUSED/INITRANS
lbarton 10/09/06 - import kuscommc
slynn 10/30/06 -
htseng 07/31/06 - support LOBRETENTION, MAXSIZE
lbarton 11/15/05 - Bug 4724986: transform params
sdavidso 11/02/05 - fix inconsistent stylesheet format
lbarton 09/16/05 - SXML syntax changes
lbarton 08/10/05 - lbarton_mddiff
htseng 06/07/05 -
lbarton 03/10/05 - Initial version
-->
<xsl:stylesheet version="1.0" xmlns:sxml="http://xmlns.oracle.com/ku" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Top level imports -->
<xsl:import href="kuscommc.xsl"/>
<!-- Top level parms -->
<xsl:param name="STORAGE">1</xsl:param>
<xsl:param name="TABLESPACE">1</xsl:param>
<!-- Templates -->
<xsl:template match="sxml:PHYSICAL_PROPERTIES |
sxml:DEFAULT_PHYSICAL_PROPERTIES">
<xsl:param name="DoCompress">Y</xsl:param>
<!-- *******************************************************************
Template: PHYSICAL_PROPERTIES, DEFAULT_PHYSICAL_PROPERTIES
Parameters:
DoCompress - Y = emit [NO]COMPRESS
******************************************************************** -->
<!-- one of the following will match -->
<xsl:choose>
<xsl:when test="$CM_MODE=1">
<xsl:apply-templates select="sxml:INDEX_ORGANIZED_TABLE[not(@src='1')]"/>
<xsl:apply-templates select="sxml:CLUSTER_TABLE[not(@src='1')]"/>
<xsl:apply-templates select="sxml:EXTERNAL_TABLE[not(@src='1')]"/>
<xsl:apply-templates select="sxml:HEAP_TABLE[not(@src='1')]">
<xsl:with-param name="DoCompress" select="$DoCompress"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="sxml:INDEX_ORGANIZED_TABLE"/>
<xsl:apply-templates select="sxml:CLUSTER_TABLE"/>
<xsl:apply-templates select="sxml:EXTERNAL_TABLE"/>
<xsl:apply-templates select="sxml:HEAP_TABLE">
<xsl:with-param name="DoCompress" select="$DoCompress"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="sxml:INMEMORY"/>
</xsl:template>
<xsl:template match="sxml:INDEX_ORGANIZED_TABLE">
<!-- *******************************************************************
Template: INDEX_ORGANIZED_TABLE
******************************************************************** -->
<!-- Segment creation clause must be generated first -->
<xsl:if test="$VERSION >=1202000000">
<xsl:choose>
<xsl:when test="sxml:SEGMENT_ATTRIBUTES/sxml:SEGMENT_CREATION_DEFERRED">
<xsl:apply-templates select="sxml:SEGMENT_ATTRIBUTES/sxml:SEGMENT_CREATION_DEFERRED"/>
</xsl:when>
<xsl:when test="sxml:SEGMENT_ATTRIBUTES/sxml:SEGMENT_CREATION_IMMEDIATE">
<xsl:apply-templates select="sxml:SEGMENT_ATTRIBUTES/sxml:SEGMENT_CREATION_IMMEDIATE"/>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:text> ORGANIZATION INDEX</xsl:text>
<xsl:choose>
<xsl:when test="sxml:KEYCOMPRESS">
<xsl:apply-templates select="sxml:KEYCOMPRESS"/>
</xsl:when>
<xsl:otherwise> NOCOMPRESS</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="sxml:SEGMENT_ATTRIBUTES">
<xsl:with-param name="IOT">Y</xsl:with-param>
</xsl:apply-templates>
<xsl:if test="sxml:MAPPING_TABLE"> MAPPING TABLE</xsl:if>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:PCTTHRESHOLD"/>
<xsl:apply-templates select="sxml:OVERFLOW"/>
</xsl:template>
<xsl:template match="sxml:HEAP_TABLE">
<xsl:param name="DoCompress">Y</xsl:param>
<!-- *******************************************************************
Template: HEAP_TABLE
Parameters:
DoCompress - Y = emit [NO]COMPRESS
******************************************************************** -->
<!-- HEAP is the default; no need to emit this -->
<!--xsl:text> ORGANIZATION HEAP</xsl:text-->
<xsl:apply-templates select="sxml:SEGMENT_ATTRIBUTES">
<xsl:with-param name="DoCompress" select="$DoCompress"/>
</xsl:apply-templates>
<!--
We use the above kludgy way of doing COMPRESS
in order to produce the same output as GET_DDL.
A more straightforward way is:
<xsl:if test="local-name(.)='PHYSICAL_PROPERTIES'">
<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="RowLevelLocking" select="sxml:ROW_LEVEL_LOCKING"/>
</xsl:call-template>
</xsl:if>
-->
</xsl:template>
<xsl:template match="sxml:SEGMENT_ATTRIBUTES">
<xsl:param name="DoCompress">N</xsl:param>
<xsl:param name="IOT">N</xsl:param>
<!-- *******************************************************************
Template: SEGMENT_ATTRIBUTES
Parameters:
DoCompress - Y = emit [NO]COMPRESS
******************************************************************** -->
<xsl:call-template name="DoSegmentAttributes">
<xsl:with-param name="ParentNode" select="."/>
<xsl:with-param name="DoCompress" select="$DoCompress"/>
<xsl:with-param name="IOT" select="$IOT"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="DoSegmentAttributes">
<xsl:param name="ParentNode" select="''"/>
<xsl:param name="DoCompress">N</xsl:param>
<xsl:param name="IOT">N</xsl:param>
<!-- *******************************************************************
Template: DoSegmentAttributes
Parameters:
ParentNode - parent of PCTFREE, etc.
DoCompress - Y = emit [NO]COMPRESS
******************************************************************** -->
<xsl:if test="$SEGMENT_ATTRIBUTES!=0">
<!-- SEGMENT CREATION (IMMEDIATE/DEFERRED) syntax is new in 11.2;
not valid for partitioned tables
IOTs
clustered tables
temporary tables
typed tables
AQ tables
external tables
tables owned by SYS, SYSTEM, PUBLIC, OUTLN, XDB
To know whether to emit SEGMENT CREATION IMMEDIATE, we check if
the path is
TABLE/RELATIONAL_TABLE/PHYSICAL_PROPERTIES/HEAP_TABLE/SEGMENT_ATTRIBUTES
-->
<xsl:variable name="isXMLType" select="$ParentNode/../../../../sxml:XMLTYPE_TABLE"/>
<xsl:if test="$VERSION>=1102000000 and $IOT = 'N' and not($isXMLType)">
<xsl:choose>
<xsl:when test="$ParentNode/sxml:SEGMENT_CREATION_DEFERRED">
<xsl:apply-templates select="$ParentNode/sxml:SEGMENT_CREATION_DEFERRED"/>
</xsl:when>
<xsl:when test="$ParentNode/sxml:SEGMENT_CREATION_IMMEDIATE">
<xsl:apply-templates select="$ParentNode/sxml:SEGMENT_CREATION_IMMEDIATE"/>
</xsl:when>
<xsl:when test="local-name($ParentNode)='SEGMENT_ATTRIBUTES' and
local-name($ParentNode/..)='HEAP_TABLE' and
local-name($ParentNode/../..)='PHYSICAL_PROPERTIES' and
local-name($ParentNode/../../..)='RELATIONAL_TABLE' and
local-name($ParentNode/../../../..)='TABLE' and
$ParentNode/../../../../sxml:SCHEMA!='SYS' and
$ParentNode/../../../../sxml:SCHEMA!='SYSTEM' and
$ParentNode/../../../../sxml:SCHEMA!='OUBLIC' and
$ParentNode/../../../../sxml:SCHEMA!='OUTLN' and
$ParentNode/../../../../sxml:SCHEMA!='XDB'">
<xsl:text> SEGMENT CREATION IMMEDIATE</xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="$ParentNode/sxml:PCTFREE or $ParentNode/sxml:SEGMENT_CREATION_DEFERRED">
<xsl:apply-templates select="$ParentNode/sxml:PCTFREE"/>
</xsl:if>
<xsl:if test="$ParentNode/sxml:PCTUSED !='0'">
<xsl:apply-templates select="$ParentNode/sxml:PCTUSED"/>
</xsl:if>
<xsl:if test="$ParentNode/sxml:INITRANS !='0'">
<xsl:apply-templates select="$ParentNode/sxml:INITRANS"/>
</xsl:if>
<xsl:if test="$PRETTY=1 and ($ParentNode/sxml:MEMOPTIMIZE_READ or
$ParentNode/sxml:MEMOPTIMIZE_WRITE)">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:if test="$ParentNode/sxml:MEMOPTIMIZE_READ">
<xsl:text> MEMOPTIMIZE FOR READ</xsl:text>
</xsl:if>
<xsl:if test="$ParentNode/sxml:MEMOPTIMIZE_WRITE">
<xsl:text> MEMOPTIMIZE FOR WRITE</xsl:text>
</xsl:if>
<!-- Generate CellMemory clause if needed -->
<xsl:if test="$ParentNode/sxml:NO_CELLMEMORY or
$ParentNode/../sxml:NO_CELLMEMORY">
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text> NO CELLMEMORY</xsl:text>
</xsl:if>
<xsl:if test="$ParentNode/sxml:CELLMEMORY or
$ParentNode/../sxml:CELLMEMORY">
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text> CELLMEMORY</xsl:text>
<xsl:choose>
<xsl:when test="$ParentNode/sxml:CELLMEMORY='MEMCOMPRESS FOR QUERY' or
$ParentNode/../sxml:CELLMEMORY='MEMCOMPRESS FOR QUERY'">
<xsl:text> MEMCOMPRESS FOR QUERY</xsl:text>
</xsl:when>
<xsl:when test="$ParentNode/sxml:CELLMEMORY='MEMCOMPRESS FOR CAPACITY' or
$ParentNode/../sxml:CELLMEMORY='MEMCOMPRESS FOR CAPACITY'">
<xsl:text> MEMCOMPRESS FOR CAPACITY</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="$DoCompress='Y'">
<xsl:call-template name="DoCompressDDL">
<xsl:with-param name="Compress" select="$ParentNode/parent::node()/sxml:COMPRESS"/>
<xsl:with-param name="CompressLevel" select="$ParentNode/parent::node()/sxml:COMPRESS_LEVEL"/>
<xsl:with-param name="RowLevelLocking" select="$ParentNode/parent::node()/sxml:ROW_LEVEL_LOCKING"/>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates select="$ParentNode/sxml:LOGGING"/>
<xsl:apply-templates select="$ParentNode/sxml:STORAGE"/>
<xsl:if test="$TABLESPACE!=0 and $ParentNode/sxml:TABLESPACE">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="$ParentNode/sxml:TABLESPACE"/>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:SEGMENT_CREATION_DEFERRED">
<!-- *******************************************************************
Template: SEGMENT_CREATION_DEFERRED
******************************************************************** -->
<xsl:text> SEGMENT CREATION DEFERRED</xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:SEGMENT_CREATION_IMMEDIATE">
<!-- *******************************************************************
Template: SEGMENT_CREATION_IMMEDIATE
******************************************************************** -->
<xsl:text> SEGMENT CREATION IMMEDIATE</xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:PCTFREE | sxml:PCTUSED | sxml:INITRANS |
sxml:INITIAL | sxml:NEXT | sxml:MINEXTENTS |
sxml:MAXEXTENTS | sxml:PCTINCREASE | sxml:FREELISTS |
sxml:FREELIST_GROUPS|
sxml:MAXSIZE | sxml:BUFFER_POOL | sxml:FLASH_CACHE | sxml:CELL_FLASH_CACHE |
sxml:TABLESPACE | sxml:PCTTHRESHOLD | sxml:COMPRESS |
sxml:INCLUDING | sxml:DEFAULT_DIRECTORY |
sxml:REJECT_LIMIT | sxml:RETURN_AS | sxml:STORE_AS |
sxml:CHUNK | sxml:PCTVERSION">
<!-- *******************************************************************
Template: PCTFREE, PCTUSED, INITRANS,
INITIAL, NEXT, MINEXTENTS, MAXEXTENTS, PCTINCREASE, FREELISTS,
FREELIST_GROUPS, MAXSIZE, BUFFER_POOL, FLASH_CACHE, CELL_FLASH_CACHE
TABLESPACE, PCTTHRESHOLD,
COMPRESS, INCLUDING, DEFAULT_DIRECTORY, REJECT_LIMIT,
RETURN_AS, STORE_AS, CHUNK, PCTVERSION
******************************************************************** -->
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="local-name(.)='FREELIST_GROUPS'">FREELIST GROUPS </xsl:when>
<xsl:when test="local-name(.)='DEFAULT_DIRECTORY'">DEFAULT DIRECTORY "</xsl:when>
<xsl:when test="local-name(.)='REJECT_LIMIT'">REJECT LIMIT </xsl:when>
<xsl:when test="local-name(.)='RETURN_AS'">RETURN AS </xsl:when>
<xsl:when test="local-name(.)='STORE_AS'">STORE AS </xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name(.)"/>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="local-name(.)='TABLESPACE'">"</xsl:if>
<xsl:if test="local-name(.)='INCLUDING'">"</xsl:if>
<xsl:value-of select="."/>
<xsl:if test="local-name(.)='TABLESPACE'">"</xsl:if>
<xsl:if test="local-name(.)='INCLUDING'">"</xsl:if>
<xsl:if test="local-name(.)='DEFAULT_DIRECTORY'">"</xsl:if>
</xsl:template>
<xsl:template match="sxml:LOGGING">
<!-- *******************************************************************
Template: LOGGING
******************************************************************** -->
<xsl:choose>
<xsl:when test=".='Y'"> LOGGING</xsl:when>
<xsl:when test=".='N'"> NOLOGGING</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="sxml:STORAGE">
<!-- *******************************************************************
Template: STORAGE
******************************************************************** -->
<xsl:if test="$STORAGE!=0">
<xsl:if test="sxml:INITIAL or sxml:NEXT or sxml:MINEXTENTS or
sxml:MAXEXTENTS or sxml:PCTINCREASE or sxml:FREELISTS or
sxml:FREELIST_GROUPS or sxml:MAXSIZE or sxml:BUFFER_POOL or
sxml:FLASH_CACHE or sxml:CELL_FLASH_CACHE">
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> STORAGE(</xsl:text>
<xsl:apply-templates select="sxml:INITIAL"/>
<xsl:apply-templates select="sxml:NEXT"/>
<xsl:apply-templates select="sxml:MINEXTENTS"/>
<xsl:apply-templates select="sxml:MAXEXTENTS"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:PCTINCREASE"/>
<xsl:apply-templates select="sxml:FREELISTS"/>
<xsl:apply-templates select="sxml:FREELIST_GROUPS"/>
<xsl:apply-templates select="sxml:MAXSIZE"/>
<xsl:if test="$PRETTY=1 and (sxml:PCTINCREASE or sxml:FREELISTS or sxmlFREELIST_GROUPS or sxml:MAXSIZE)">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:BUFFER_POOL"/>
<xsl:if test="$VERSION>=1102000000">
<xsl:apply-templates select="sxml:FLASH_CACHE"/>
<xsl:apply-templates select="sxml:CELL_FLASH_CACHE"/>
</xsl:if>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:OVERFLOW">
<!-- *******************************************************************
Template: OVERFLOW
******************************************************************** -->
<xsl:apply-templates select="sxml:INCLUDING"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> OVERFLOW</xsl:text>
<xsl:apply-templates select="sxml:SEGMENT_ATTRIBUTES"/>
</xsl:template>
<xsl:template match="sxml:EXTERNAL_TABLE">
<!-- *******************************************************************
Template: EXTERNAL_TABLE
******************************************************************** -->
<xsl:text> ORGANIZATION EXTERNAL</xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ( TYPE </xsl:text>
<xsl:value-of select="sxml:ACCESS_DRIVER_TYPE"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:DEFAULT_DIRECTORY"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ACCESS PARAMETERS </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ( </xsl:text>
<xsl:value-of select="sxml:ACCESS_PARAMETERS"/>
<xsl:text>) </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> LOCATION </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ( </xsl:text>
<xsl:for-each select="sxml:LOCATION/sxml:LOCATION_ITEM">
<xsl:if test="sxml:DIRECTORY">
<xsl:text>"</xsl:text>
<xsl:value-of select="sxml:DIRECTORY"/>
<xsl:text>":</xsl:text>
</xsl:if>
<xsl:text>'</xsl:text>
<xsl:call-template name="EscapeStringSxD">
<xsl:with-param name="TheString" select="sxml:NAME"/>
</xsl:call-template>
<xsl:text>'</xsl:text>
<xsl:if test="position()!=last()">,</xsl:if>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> ) </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:text> ) </xsl:text>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
<xsl:apply-templates select="sxml:REJECT_LIMIT"/>
<xsl:if test="sxml:INMEMORY and $VERSION>=1800000000">
<xsl:apply-templates select="sxml:INMEMORY"/>
</xsl:if>
</xsl:template>
<xsl:template match="sxml:CLUSTER_TABLE">
<!-- *******************************************************************
Template: CLUSTER_TABLE
******************************************************************** -->
<xsl:text> CLUSTER </xsl:text>
<xsl:choose>
<xsl:when test="$CM_MODE=1">
<xsl:call-template name="TargetSchemaName">
<xsl:with-param name="ParentNode" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="SchemaName">
<xsl:with-param name="ParentNode" select="."/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:text> (</xsl:text>
<xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM">
<xsl:choose>
<xsl:when test="substring(sxml:NAME,1,1)='"'">
<xsl:value-of select="sxml:NAME"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
<xsl:value-of select="sxml:NAME"/>
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
</xsl:stylesheet>
OHA YOOOO