John,

I've refactored the _nsFanTest.bat.xsl to use the for-each w/ xalan-doc-cache-off, as 
well as your other suggestions, but still looks like every SQLDocument stays around 
indefinitely.

_nsFanTest.bat.xsl creates the Fan table, inserts rows, does the nested selects and 
drops the Fan table. Please try to run it.

Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101

John Gentilin wrote:
Phil,
see below..

Regards
John G

John, I was expecting that you would use what ever db platform you have available. I think the SQL is standard, though you might need to tweak it, but it is self contained to create and drop the "Fan" table.

Did you sent the Create Table code for the Fan Table before, does the Fan table need to be populated with data.
I just did a fairly high level review of the code.



And finally, I got JMechanic to give me a heap dump in eclipse, Now that I see the results, It's no surprise nor much help either. There are 6190 SQLDocument (1634160bytes) allocated and all of them are active. Just because we close the SQLDocument, doesn't mean xalan has no references to it. It seems to me that we need to "unregister" the SQLDocument to be symmetrical with the mgrDefault.addDTM(doc, dtmIdent) in getNewDocument.


There is an unregister function but it was designed to be used as a call back mechanism to inform a document that it is being unloaded to
allow for clean up. i.e. dropping SQL connections. I think, even if I could can unregister from close(), it would not do any good because
at the Java level (opposed to the Xalan level), if some other code held onto a reference to the SQLDocument, it would still be lost to the JVM.


but.... There was just a thread on the group about the document() function caching documents that were no longer in use. I wonder
if this is the same issue. I searched the list and found this message, there is a proposed a solution about the third message in the thread. If
this does the trick, let me know what it was. Post the solution to the thread for historical purposes.
http://marc.theaimsgroup.com/?l=xalan-dev&m=109596329809849&w=2


What do you think?
Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101

John Gentilin wrote:





<?xml version="1.0"?>
<!-- <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#160;"> ]> -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
                xmlns:sql="org.apache.xalan.lib.sql.XConnection" extension-element-prefixes="sql"
                xmlns:xalan="http://xml.apache.org/xalan"; exclude-result-prefixes="xalan"
                >

<xsl:variable name="DbCon" select="sql:new()"/>

<xsl:param name="msg-sql" select="true()"/>
<xsl:param name="DbConPool"/> <!-- no value, used as connection method switch -->
<xsl:param name="DbDrvr" select="'com.sybase.jdbc2.jdbc.SybDriver'"/>
<xsl:param name="DbUrl" select="'jdbc:sybase:Tds:localhost:2638?servicename=TerralinkDemo'"/>
<xsl:param name="DbUsr"/>
<xsl:param name="DbPwd"/>

<xsl:template match="/">
  <xsl:call-template name="DbConnect"/>
  <xsl:call-template name="DropFan"/>
  <xsl:call-template name="CreateFan"/>
  <xsl:call-template name="InsertFan"/>
  <xsl:call-template name="SelectFanCnt"/>
  <xsl:call-template name="DropFan"/>
</xsl:template> <!-- / -->

<xsl:template name="DbConnect">
  <xsl:param name="DbCon" select="$DbCon"/> <!-- use global if not passed  -->
  <xsl:param name="DbUsr" select="$DbUsr"/> <!-- use global if not passed  -->
  <xsl:param name="DbPwd" select="$DbPwd"/> <!-- use global if not passed  -->
  <!--  -->
  <xsl:choose>
    <xsl:when test="$DbConPool">
      <xsl:if test="not( sql:connect( $DbCon, $DbConPool))" >
        <xsl:copy-of select="sql:getError($DbCon)/ext-error"/>
      </xsl:if>
      <!-- <xsl:if test="function-available( 'sql:setFeature')"> -->
        <xsl:message terminate="no">sql:setFeature( 'streaming', 'false')</xsl:message>
        <xsl:value-of select="sql:setFeature( 'streaming', 'false')"/>
      <!-- </xsl:if> -->
      <xsl:message terminate="no">DbConnect sql:connect( <xsl:value-of select="$DbCon"/>
                                            <xsl:text/>, <xsl:value-of select="$DbConPool"/>
                                            <xsl:text/>)</xsl:message>
      <xsl:if test="function-available( 'sql:setFeature')">
        <xsl:message terminate="no">sql:setFeature( 'default-pool-enabled', 'false')</xsl:message>
        <xsl:value-of select="sql:setFeature( 'default-pool-enabled', 'false')"/>
        <xsl:message terminate="no">sql:setFeature( 'streaming', 'false')</xsl:message>
        <xsl:value-of select="sql:setFeature( 'streaming', 'false')"/>
      </xsl:if>
      <xsl:if test="function-available( 'sql:disableStreamingMode')">
        <xsl:message terminate="no">sql:disableStreamingMode( $DbCon)</xsl:message>
        <xsl:value-of select="sql:disableStreamingMode( $DbCon)"/>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <xsl:if test="function-available( 'sql:setFeature')">
        <xsl:message terminate="no">sql:setFeature( 'default-pool-enabled', 'true')</xsl:message>
        <xsl:value-of select="sql:setFeature( $DbCon, 'default-pool-enabled', 'true')"/>
        <xsl:message terminate="no">sql:setFeature( 'streaming', 'false')</xsl:message>
        <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
      </xsl:if>
      <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, $DbPwd))" >
        <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
      </xsl:if>
      <xsl:message terminate="no">DbConnect sql:connect( <xsl:value-of select="$DbCon"/>
                                            <xsl:text/>, <xsl:value-of select="$DbDrvr"/>
                                            <xsl:text/>, <xsl:value-of select="$DbUrl"/>
                                            <xsl:text/>, <xsl:value-of select="$DbUsr"/>
                                            <xsl:text/>, <xsl:value-of select="'{password}'"/>
                                            <xsl:text/>)</xsl:message>
    </xsl:otherwise>
  </xsl:choose>
  <!-- <xsl:copy-of select="$DbCon"/> -->
</xsl:template>

<!-- ext-error -->
<!-- looks like this:
<ext-error>
<message>ASA Error -143: Column 'DprtDtTmsdfb' not found</message>
<sql-error>
<code>207</code>
<message>ASA Error -143: Column 'DprtDtTmsdfb' not found</message>
</sql-error>
</ext-error>
-->
<xsl:template name="ext-error">
  <xsl:param name="terminate" select="yes"/>
    <xsl:copy-of select="."/>
    <xsl:message terminate="yes"><xsl:value-of select="Date:new()" xmlns:Date="xalan://java.util.Date"/>
                                 <xsl:value-of select="concat( ' '
                                                             , ' msg: '
                                                             , sql-error/message
                                                             , ' cd: '
                                                             , sql-error/code)"/></xsl:message>
                                                             <!-- , message -->
</xsl:template>

<xsl:template name="CreateFan">
  <xsl:variable name="SQLCreate">
    create table Fan ( Ix integer, Cnt integer )
    select 0
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLCreate)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLCreate"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>
    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
  </xsl:for-each>
</xsl:template>

<xsl:template name="InsertFan">
  <xsl:variable name="SQLInsert">
    insert into Fan select 1, 1
    insert into Fan select 1, 2
    insert into Fan select 2, 2
    insert into Fan select 1, 3
    insert into Fan select 2, 3
    insert into Fan select 3, 3
    insert into Fan select 1, 4
    insert into Fan select 2, 4
    insert into Fan select 3, 4
    insert into Fan select 4, 4
    insert into Fan select 1, 5
    insert into Fan select 2, 5
    insert into Fan select 3, 5
    insert into Fan select 4, 5
    insert into Fan select 5, 5
    insert into Fan select 1, 6
    insert into Fan select 2, 6
    insert into Fan select 3, 6
    insert into Fan select 4, 6
    insert into Fan select 5, 6
    insert into Fan select 6, 6
    insert into Fan select 1, 7
    insert into Fan select 2, 7
    insert into Fan select 3, 7
    insert into Fan select 4, 7
    insert into Fan select 5, 7
    insert into Fan select 6, 7
    insert into Fan select 7, 7
    insert into Fan select 1, 8
    insert into Fan select 2, 8
    insert into Fan select 3, 8
    insert into Fan select 4, 8
    insert into Fan select 5, 8
    insert into Fan select 6, 8
    insert into Fan select 7, 8
    insert into Fan select 8, 8

    insert into Fan select 1, 9
    insert into Fan select 2, 9
    insert into Fan select 3, 9
    insert into Fan select 4, 9
    insert into Fan select 5, 9
    insert into Fan select 6, 9
    insert into Fan select 7, 9
    insert into Fan select 8, 9
    insert into Fan select 9, 9
    insert into Fan select 1, 10
    insert into Fan select 2, 10
    insert into Fan select 3, 10
    insert into Fan select 4, 10
    insert into Fan select 5, 10
    insert into Fan select 6, 10
    insert into Fan select 7, 10
    insert into Fan select 8, 10
    insert into Fan select 9, 10
    insert into Fan select 10,10
    insert into Fan select 1, 11
    insert into Fan select 2, 11
    insert into Fan select 3, 11
    insert into Fan select 4, 11
    insert into Fan select 5, 11
    insert into Fan select 6, 11
    insert into Fan select 7, 11
    insert into Fan select 8, 11
    insert into Fan select 9, 11
    insert into Fan select 10,11
    insert into Fan select 11,11
    insert into Fan select 1, 12
    insert into Fan select 2, 12
    insert into Fan select 3, 12
    insert into Fan select 4, 12
    insert into Fan select 5, 12
    insert into Fan select 6, 12
    insert into Fan select 7, 12
    insert into Fan select 8, 12
    insert into Fan select 9, 12
    insert into Fan select 10,12
    insert into Fan select 11,12
    insert into Fan select 12,12
    insert into Fan select 1, 13
    insert into Fan select 2, 13
    insert into Fan select 3, 13
    insert into Fan select 4, 13
    insert into Fan select 5, 13
    insert into Fan select 6, 13
    insert into Fan select 7, 13
    insert into Fan select 8, 13
    insert into Fan select 9, 13
    insert into Fan select 10,13
    insert into Fan select 11,13
    insert into Fan select 12,13
    insert into Fan select 13,13
    insert into Fan select 1, 14
    insert into Fan select 2, 14
    insert into Fan select 3, 14
    insert into Fan select 4, 14
    insert into Fan select 5, 14
    insert into Fan select 6, 14
    insert into Fan select 7, 14
    insert into Fan select 8, 14
    insert into Fan select 9, 14
    insert into Fan select 10,14
    insert into Fan select 11,14
    insert into Fan select 12,14
    insert into Fan select 13,14
    insert into Fan select 14,14
    insert into Fan select 1, 15
    insert into Fan select 2, 15
    insert into Fan select 3, 15
    insert into Fan select 4, 15
    insert into Fan select 5, 15
    insert into Fan select 6, 15
    insert into Fan select 7, 15
    insert into Fan select 8, 15
    insert into Fan select 9, 15
    insert into Fan select 10,15
    insert into Fan select 11,15
    insert into Fan select 12,15
    insert into Fan select 13,15
    insert into Fan select 14,15
    insert into Fan select 15,15
    insert into Fan select 1, 16
    insert into Fan select 2, 16
    insert into Fan select 3, 16
    insert into Fan select 4, 16
    insert into Fan select 5, 16
    insert into Fan select 6, 16
    insert into Fan select 7, 16
    insert into Fan select 8, 16
    insert into Fan select 9, 16
    insert into Fan select 10,16
    insert into Fan select 11,16
    insert into Fan select 12,16
    insert into Fan select 13,16
    insert into Fan select 14,16
    insert into Fan select 15,16
    insert into Fan select 16,16
    select 1
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLInsert)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLInsert"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>
    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
  </xsl:for-each> <!-- sql:query -->
</xsl:template>

<xsl:template name="SelectFanCnt">
  <xsl:variable name="SQLSelectCnt">
    select Cnt from Fan where Cnt= Ix
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLSelectCnt)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLSelectCnt"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>

    <xsl:for-each select="sql/row-set/row">
      <xsl:element name='Cnt'>
        <xsl:attribute name="Cnt">
          <xsl:value-of select="[EMAIL PROTECTED]'Cnt']"/>
        </xsl:attribute>

        <xsl:call-template name="SelectFanIx">
          <xsl:with-param name="Cnt" select="[EMAIL PROTECTED]'Cnt']"/>
        </xsl:call-template>

      </xsl:element> <!-- Cnt -->
    </xsl:for-each> <!-- Cnt row -->

    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
    <xsl:message terminate="no">sql:close( $DbCon, '<xsl:value-of select="normalize-space( substring-before( substring-after( $SQLSelectCnt, '&#xA;'), '&#xA;'))"/>')</xsl:message>
  </xsl:for-each> <!-- sql:query -->
</xsl:template> <!-- SelectFanCnt -->

<xsl:template name="SelectFanIx">
  <xsl:param name="Cnt"/>
  <!--  -->
  <xsl:variable name="SQLSelectIx">
    select Ix from Fan where <xsl:value-of select="$Cnt"/>=Cnt
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLSelectIx)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLSelectIx"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>

    <xsl:for-each select="sql/row-set/row">
      <xsl:element name="Ix">
        <xsl:attribute name="Val">
          <xsl:value-of select="[EMAIL PROTECTED]'Ix']"/>
        </xsl:attribute>

        <xsl:call-template name="SelFanCntIx"/>

      </xsl:element> <!-- Ix -->
    </xsl:for-each> <!-- Cnt row -->

    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
    <xsl:message terminate="no">sql:close( $DbCon, '<xsl:value-of select="normalize-space( substring-before( substring-after( $SQLSelectIx, '&#xA;'), '&#xA;'))"/>')</xsl:message>
  </xsl:for-each> <!-- sql:query -->
</xsl:template> <!-- SelectFanIx -->

<xsl:template name="SelFanCntIx">
  <!--  -->
  <xsl:variable name="SQLSelectCntIx">
    select Cnt, Ix from Fan
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLSelectCntIx)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLSelectCntIx"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>

    <xsl:for-each select="sql/row-set/row">
      <xsl:element name='CntIx'>
        <xsl:attribute name="Cnt">
          <xsl:value-of select="[EMAIL PROTECTED]'Cnt']"/>
        </xsl:attribute>
        <xsl:attribute name="Ix">
          <xsl:value-of select="[EMAIL PROTECTED]'Ix']"/>
        </xsl:attribute>
      </xsl:element> <!-- CntIx -->
    </xsl:for-each> <!-- Cnt, Ix row -->

    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
    <xsl:message terminate="no">sql:close( $DbCon, '<xsl:value-of select="normalize-space( substring-before( substring-after( $SQLSelectCntIx, '&#xA;'), '&#xA;'))"/>')</xsl:message>
  </xsl:for-each>
</xsl:template> <!-- SelFanCntIx -->

<xsl:template name="DropFan">
  <xsl:variable name="SQLDrop">
    drop table Fan
    select 0
  </xsl:variable>
  <xsl:for-each select="sql:query($DbCon, $SQLDrop)">
    <?xalan-doc-cache-off?>
    <xsl:if test="$msg-sql or not( current())">
      <xsl:message terminate="no"><xsl:value-of select="$SQLDrop"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="not( current())" >
      <xsl:apply-templates select="sql:getError($DbCon)/ext-error"/>
    </xsl:if>

    <!-- close this connection -->
    <xsl:value-of select="sql:close( $DbCon, current())"/>
    <xsl:message terminate="no">sql:close( $DbCon, '<xsl:value-of select="normalize-space( substring-before( substring-after( $SQLDrop, '&#xA;'), '&#xA;'))"/>')</xsl:message>
  </xsl:for-each> <!-- sql:query -->
</xsl:template> <!-- DropFan -->

</xsl:stylesheet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to