Recent Changes - Search:

Main.SideBar (edit)



BatchUpdateOfBC

Batch Update of Business Components

I recently needed to add audit columns to a load of ADF business components. the biggest pain about this was having to set the HistoryColumn attribute on each column, so I decided to do it with an XSLT (Extensible Stylesheet Language Transformation) - it may have been easier to do with sed but ...

Firstly I added the column attributes to the components by synchronising with the database, so the XML for each component had the column definition in it, AND I knew that the columns had exactly the same names in each component (because I added them to the database with a script). What I needed to so was copy the XML for each business component and transform the audit columns to add the HistoryColumn attributes. The style sheet I cam up with to do this looked like:

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output  doctype-system="jbo_03_01.dtd" version='1.0' encoding='windows-1252' />

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="Attribute[@Name='CreatedBy']">
<xsl:copy>
<xsl:attribute name="IsUpdateable">while_insert</xsl:attribute>
<xsl:attribute name="HistoryColumn">UserHistory</xsl:attribute>

<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Attribute[@Name='CreatedAt']">
<xsl:copy>
<xsl:attribute name="IsUpdateable">while_insert</xsl:attribute>
<xsl:attribute name="HistoryColumn">DateHistory</xsl:attribute>

<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Attribute[@Name='LastModifiedBy']">
<xsl:copy>
<xsl:attribute name="HistoryColumn">UserHistory</xsl:attribute>

<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Attribute[@Name='LastModifiedAt']">
<xsl:copy>
<xsl:attribute name="HistoryColumn">DateHistory</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

The first template matches and copies all entities and the second matches and copies other things (attributes, processing instructions and comments), then there are templates to match the columns (confusingly Oracle have named these "Attribute" in the XML) that need the HistoryColumn attribute setting, notice to distinguish the "created" from the updated the IsUpdateable attribute is set to while_insert

Edit - History - Print - Recent Changes - Search
Page last modified on June 18, 2007, at 04:59 PM