You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Phil Friedman <pf...@terralink.com> on 2004/08/09 22:41:43 UTC

SQL Extension, how to close just one query?

John, 

I'm back at it. What is the XSL to call close( SQLDocument sqldoc ), XConnection line 1084? I need to reales just one query and it's connection, while leaving other queries active.

Here is a simplified version of what I need to do. I connect with:

  <xsl:variable name="DbCon" select="sql:new()"/>
  <xsl:value-of select="sql:setFeature( $DbCon, 'default-pool-enabled', 'true')"/>
  <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
  <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, $DbPwd))" >
    <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
  </xsl:if>

Then I run a parent query

  <xsl:variable name="SQL">
    select Ix from List
  </xsl:variable>
  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
  <xsl:if test="$msg-sql or not( $Qy)">
    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
  </xsl:if>
  <xsl:if test="not( $Qy)" >
    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
  </xsl:if>
  <xsl:for-each select="$Qy/sql/row-set/row">

Then, for each row, I run a child query like this:

  <xsl:variable name="SQL">
    select * from Table where Ix= <xsl:value-of select="col['Ix'=@column-name]"/>
  </xsl:variable>
  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
  <xsl:if test="$msg-sql or not( $Qy)">
    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
  </xsl:if>
  <xsl:if test="not( $Qy)" >
    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
  </xsl:if>
  <!-- return value -->
  <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/>

Then I want to close just the child query, because I'm still in the middle of the parent resultset:

  <xsl:value-of select="sql:close( $DbCon, $Qy)"/>

Gives me:

(Location of error unknown)XSLT Error (javax.xml.transform.TransformerException): java.lang.NoSuchMethodException: For extension function, could not find method static org.apache.xalan.lib.sql.XConnection.close([ExpressionContext, ]#UNKNOWN (org.apache.xalan.lib.sql.XConnection), #NODESET) nor
class org.apache.xalan.lib.sql.XConnection.close([ExpressionContext,] #NODESET).

While: 

  <xsl:value-of select="sql:close( $DbCon)"/>

releases both the parent and child connection and Gives me:

XSLT Error (javax.xml.transform.TransformerException): java.lang.ArrayIndexOutOfBoundsException: -1

because the parent connection has been closed so there is nothing there for the <xsl:for-each select="$Qy/sql/row-set/row"> to evaluate <xsl:value-of select="col['Ix'=@column-name]"/>

If I comment out the <xsl:value-of select="sql:close( $DbCon)"/>

The results are correct. However, this is impractical because if I leave out ALL the closes I get many, many connections opened, which leads to other problems.

Any Ideas? Thanks.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Re: SQL Extension, how to close just one query?

Posted by Phil Friedman <pf...@terralink.com>.
John, here is what I tried:

 public void close( Object sqldoc )throws SQLException
 {
   if (DEBUG)
     System.out.println("Entering XConnection.close(" + sqldoc + ")");

   DTMIterator ni = ((DTMNodeIterator) sqldoc).getDTMIterator();
   int i = ni.getCurrentNode();
   DTM doc = ni.getDTM(i);
   int size = m_OpenSQLDocuments.size();

   for(int x=0; x<size; x++)
   {
     SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
     if (d == doc)
     {
       d.close();
       m_OpenSQLDocuments.removeElementAt(x);
     }
   }
 }

However, ni.getCurrentNode(); returns -1 so ni.getDTM(i); throws an exception. This is being triggered by XSLT like this:

<xsl:variable name="Qy" select="sql:query($DbCon, $SQL)"/>
...
<xsl:value-of select="sql:close( $DbCon, $Qy)"/>

query returns a DTM, why isn't a DTM passed back in? Maybe DTMNodeIterator is a red herring?

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

John Gentilin wrote:
> Phil,
> 
> I would of sworn that I solved this before but now that I look at my notes
> I see big question marks... Although I have an idea if you are willing 
> to give it a try ??
> Get the document with    DTMIterator ni = ((DTMNodeIterator) 
> sqldoc).getDTMIterator();
>    DTM doc = ni.getDTM(ni.getCurrentNode());
> 
> The only thing I am not sure about is if we are always dealing with a
> DTMNodeIterator.
> 
> Regards
> John G
> 
> Phil Friedman wrote:
> 
>> John,
>>
>> In the suggested code, if (d == sqldoc) never evaluates true so 
>> SQLDocuments are never closed and I did not see a way to get from 
>> sqldoc which seems to be a DTMNodeIterator to the SQLDocuments in the 
>> vector m_OpenSQLDocuments. I checked my XSLT and it seemed that I 
>> always used connections like a stack, so I hacked the code to:
>>
>> public void close( Object sqldoc )throws SQLException
>> {
>>   int size = m_OpenSQLDocuments.size();
>>   Object o = m_OpenSQLDocuments.elementAt(size-1);
>>   ((SQLDocument)o).close();
>>   m_OpenSQLDocuments.removeElementAt(size-1);
>> }
>>
>> This works as far as closing connections. HOWEVER, because of Xalan's 
>> "lazy" evaluation, it is not straightforward to determine when a 
>> connection-query can be closed. XSLT like this fails:
>>
>> ...
>> <xsl:variable name="TyXplObjTyMn" 
>> select="$COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name]"/>
>> ...
>> <xsl:value-of select="sql:close( $DbCon, $COWQy)"/>
>> ...
>> <xsl:call-template name="ICowPrevAKOut">
>>  <xsl:with-param name="TyXplObjTyMn" select="$TyXplObjTyMn"/>
>> </xsl:call-template>
>> ...
>>
>> not until inside the ICowPrevAKOut template does 
>> $COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name] get 
>> evaluated, but we get an exception because $COWQy has already been 
>> closed.
>>
>> Once again, I'm not sure what or why this was changed from the 2.0.1 
>> sql extension. But it has been a great deal of effort to make it work. 
>> I hope we're almost there.
>>
>> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101
>>
>> John Gentilin wrote:
>>
>>> Phil,
>>>
>>> This was an issue I posted to the Dev list a while back and finally
>>> found an answer, I think, a while back working on another project.
>>> The proposed fix would be to change the method signature from 
>>> SQLDocument
>>> to just Object. The problem is, the original SQLDocument object can be
>>> casted to one of its many interfaces depending on what operation you
>>> are currently performing, here it was casted to an XNodeSet. The code
>>> should just work since I am just comparing the object to all the open
>>> documents, the closing the SQLDocument in the list that matches the
>>> incoming object.
>>>
>>> If you feel up to it, give it a try. I also have the official changes
>>> for your other fix as well as a skipRec enhancement function to help
>>> out with pagination. The ToDo item to check those changes in are on
>>> my list to do RSN. :-)
>>>
>>> change
>>>  public void close( SQLDocument sqldoc )throws SQLException
>>>  {
>>>    if (DEBUG)
>>>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
>>>
>>>    int size = m_OpenSQLDocuments.size();
>>>
>>>    for(int x=0; x<size; x++)
>>>    {
>>>      SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
>>>      if (d == sqldoc)
>>>      {
>>>        d.close();
>>>        m_OpenSQLDocuments.removeElementAt(x);
>>>      }
>>>    }
>>>  }
>>>
>>> to
>>>
>>>  public void close( Object sqldoc )throws SQLException
>>>  {
>>>    if (DEBUG)
>>>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
>>>
>>>    int size = m_OpenSQLDocuments.size();
>>>
>>>    for(int x=0; x<size; x++)
>>>    {
>>>      Object o =  m_OpenSQLDocuments.elementAt(x);
>>>      if (o == sqldoc)
>>>      {
>>>        ((SQLDocument)d).close();
>>>        m_OpenSQLDocuments.removeElementAt(x);
>>>      }
>>>    }
>>>  }
>>>
>>> Phil Friedman wrote:
>>>
>>>> John,
>>>> I'm back at it. What is the XSL to call close( SQLDocument sqldoc ), 
>>>> XConnection line 1084? I need to reales just one query and it's 
>>>> connection, while leaving other queries active.
>>>>
>>>> Here is a simplified version of what I need to do. I connect with:
>>>>
>>>>  <xsl:variable name="DbCon" select="sql:new()"/>
>>>>  <xsl:value-of select="sql:setFeature( $DbCon, 
>>>> 'default-pool-enabled', 'true')"/>
>>>>  <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
>>>>  <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, 
>>>> $DbPwd))" >
>>>>    <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
>>>>  </xsl:if>
>>>>
>>>> Then I run a parent query
>>>>
>>>>  <xsl:variable name="SQL">
>>>>    select Ix from List
>>>>  </xsl:variable>
>>>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>>>  <xsl:if test="$msg-sql or not( $Qy)">
>>>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>>>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>>>  </xsl:if>
>>>>  <xsl:if test="not( $Qy)" >
>>>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>>>  </xsl:if>
>>>>  <xsl:for-each select="$Qy/sql/row-set/row">
>>>>
>>>> Then, for each row, I run a child query like this:
>>>>
>>>>  <xsl:variable name="SQL">
>>>>    select * from Table where Ix= <xsl:value-of 
>>>> select="col['Ix'=@column-name]"/>
>>>>  </xsl:variable>
>>>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>>>  <xsl:if test="$msg-sql or not( $Qy)">
>>>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>>>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>>>  </xsl:if>
>>>>  <xsl:if test="not( $Qy)" >
>>>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>>>  </xsl:if>
>>>>  <!-- return value -->
>>>>  <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/>
>>>>
>>>> Then I want to close just the child query, because I'm still in the 
>>>> middle of the parent resultset:
>>>>
>>>>  <xsl:value-of select="sql:close( $DbCon, $Qy)"/>
>>>>
>>>> Gives me:
>>>>
>>>> (Location of error unknown)XSLT Error 
>>>> (javax.xml.transform.TransformerException): 
>>>> java.lang.NoSuchMethodException: For extension function, could not 
>>>> find method static 
>>>> org.apache.xalan.lib.sql.XConnection.close([ExpressionContext, 
>>>> ]#UNKNOWN (org.apache.xalan.lib.sql.XConnection), #NODESET) nor
>>>> class 
>>>> org.apache.xalan.lib.sql.XConnection.close([ExpressionContext,] 
>>>> #NODESET).
>>>>
>>>> While:
>>>>  <xsl:value-of select="sql:close( $DbCon)"/>
>>>>
>>>> releases both the parent and child connection and Gives me:
>>>>
>>>> XSLT Error (javax.xml.transform.TransformerException): 
>>>> java.lang.ArrayIndexOutOfBoundsException: -1
>>>>
>>>> because the parent connection has been closed so there is nothing 
>>>> there for the <xsl:for-each select="$Qy/sql/row-set/row"> to 
>>>> evaluate <xsl:value-of select="col['Ix'=@column-name]"/>
>>>>
>>>> If I comment out the <xsl:value-of select="sql:close( $DbCon)"/>
>>>>
>>>> The results are correct. However, this is impractical because if I 
>>>> leave out ALL the closes I get many, many connections opened, which 
>>>> leads to other problems.
>>>>
>>>> Any Ideas? Thanks.
>>>>
>>>> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101
>>>
>>>
>>>
>>>
>>>
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Re: SQL Extension, how to close just one query?

Posted by John Gentilin <ge...@eyecatching.com>.
Phil,

I would of sworn that I solved this before but now that I look at my notes
I see big question marks... Although I have an idea if you are willing to 
give it a try ?? 

Get the document with 
    DTMIterator ni = ((DTMNodeIterator) sqldoc).getDTMIterator();
    DTM doc = ni.getDTM(ni.getCurrentNode());

The only thing I am not sure about is if we are always dealing with a
DTMNodeIterator.

Regards
John G

Phil Friedman wrote:

> John,
> 
> In the suggested code, if (d == sqldoc) never evaluates true so 
> SQLDocuments are never closed and I did not see a way to get from sqldoc 
> which seems to be a DTMNodeIterator to the SQLDocuments in the vector 
> m_OpenSQLDocuments. I checked my XSLT and it seemed that I always used 
> connections like a stack, so I hacked the code to:
> 
> public void close( Object sqldoc )throws SQLException
> {
>   int size = m_OpenSQLDocuments.size();
>   Object o = m_OpenSQLDocuments.elementAt(size-1);
>   ((SQLDocument)o).close();
>   m_OpenSQLDocuments.removeElementAt(size-1);
> }
> 
> This works as far as closing connections. HOWEVER, because of Xalan's 
> "lazy" evaluation, it is not straightforward to determine when a 
> connection-query can be closed. XSLT like this fails:
> 
> ...
> <xsl:variable name="TyXplObjTyMn" 
> select="$COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name]"/>
> ...
> <xsl:value-of select="sql:close( $DbCon, $COWQy)"/>
> ...
> <xsl:call-template name="ICowPrevAKOut">
>  <xsl:with-param name="TyXplObjTyMn" select="$TyXplObjTyMn"/>
> </xsl:call-template>
> ...
> 
> not until inside the ICowPrevAKOut template does 
> $COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name] get 
> evaluated, but we get an exception because $COWQy has already been closed.
> 
> Once again, I'm not sure what or why this was changed from the 2.0.1 sql 
> extension. But it has been a great deal of effort to make it work. I 
> hope we're almost there.
> 
> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101
> 
> John Gentilin wrote:
> 
>> Phil,
>>
>> This was an issue I posted to the Dev list a while back and finally
>> found an answer, I think, a while back working on another project.
>> The proposed fix would be to change the method signature from SQLDocument
>> to just Object. The problem is, the original SQLDocument object can be
>> casted to one of its many interfaces depending on what operation you
>> are currently performing, here it was casted to an XNodeSet. The code
>> should just work since I am just comparing the object to all the open
>> documents, the closing the SQLDocument in the list that matches the
>> incoming object.
>>
>> If you feel up to it, give it a try. I also have the official changes
>> for your other fix as well as a skipRec enhancement function to help
>> out with pagination. The ToDo item to check those changes in are on
>> my list to do RSN. :-)
>>
>> change
>>  public void close( SQLDocument sqldoc )throws SQLException
>>  {
>>    if (DEBUG)
>>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
>>
>>    int size = m_OpenSQLDocuments.size();
>>
>>    for(int x=0; x<size; x++)
>>    {
>>      SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
>>      if (d == sqldoc)
>>      {
>>        d.close();
>>        m_OpenSQLDocuments.removeElementAt(x);
>>      }
>>    }
>>  }
>>
>> to
>>
>>  public void close( Object sqldoc )throws SQLException
>>  {
>>    if (DEBUG)
>>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
>>
>>    int size = m_OpenSQLDocuments.size();
>>
>>    for(int x=0; x<size; x++)
>>    {
>>      Object o =  m_OpenSQLDocuments.elementAt(x);
>>      if (o == sqldoc)
>>      {
>>        ((SQLDocument)d).close();
>>        m_OpenSQLDocuments.removeElementAt(x);
>>      }
>>    }
>>  }
>>
>> Phil Friedman wrote:
>>
>>> John,
>>> I'm back at it. What is the XSL to call close( SQLDocument sqldoc ), 
>>> XConnection line 1084? I need to reales just one query and it's 
>>> connection, while leaving other queries active.
>>>
>>> Here is a simplified version of what I need to do. I connect with:
>>>
>>>  <xsl:variable name="DbCon" select="sql:new()"/>
>>>  <xsl:value-of select="sql:setFeature( $DbCon, 
>>> 'default-pool-enabled', 'true')"/>
>>>  <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
>>>  <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, 
>>> $DbPwd))" >
>>>    <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
>>>  </xsl:if>
>>>
>>> Then I run a parent query
>>>
>>>  <xsl:variable name="SQL">
>>>    select Ix from List
>>>  </xsl:variable>
>>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>>  <xsl:if test="$msg-sql or not( $Qy)">
>>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>>  </xsl:if>
>>>  <xsl:if test="not( $Qy)" >
>>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>>  </xsl:if>
>>>  <xsl:for-each select="$Qy/sql/row-set/row">
>>>
>>> Then, for each row, I run a child query like this:
>>>
>>>  <xsl:variable name="SQL">
>>>    select * from Table where Ix= <xsl:value-of 
>>> select="col['Ix'=@column-name]"/>
>>>  </xsl:variable>
>>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>>  <xsl:if test="$msg-sql or not( $Qy)">
>>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>>  </xsl:if>
>>>  <xsl:if test="not( $Qy)" >
>>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>>  </xsl:if>
>>>  <!-- return value -->
>>>  <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/>
>>>
>>> Then I want to close just the child query, because I'm still in the 
>>> middle of the parent resultset:
>>>
>>>  <xsl:value-of select="sql:close( $DbCon, $Qy)"/>
>>>
>>> Gives me:
>>>
>>> (Location of error unknown)XSLT Error 
>>> (javax.xml.transform.TransformerException): 
>>> java.lang.NoSuchMethodException: For extension function, could not 
>>> find method static 
>>> org.apache.xalan.lib.sql.XConnection.close([ExpressionContext, 
>>> ]#UNKNOWN (org.apache.xalan.lib.sql.XConnection), #NODESET) nor
>>> class org.apache.xalan.lib.sql.XConnection.close([ExpressionContext,] 
>>> #NODESET).
>>>
>>> While:
>>>  <xsl:value-of select="sql:close( $DbCon)"/>
>>>
>>> releases both the parent and child connection and Gives me:
>>>
>>> XSLT Error (javax.xml.transform.TransformerException): 
>>> java.lang.ArrayIndexOutOfBoundsException: -1
>>>
>>> because the parent connection has been closed so there is nothing 
>>> there for the <xsl:for-each select="$Qy/sql/row-set/row"> to evaluate 
>>> <xsl:value-of select="col['Ix'=@column-name]"/>
>>>
>>> If I comment out the <xsl:value-of select="sql:close( $DbCon)"/>
>>>
>>> The results are correct. However, this is impractical because if I 
>>> leave out ALL the closes I get many, many connections opened, which 
>>> leads to other problems.
>>>
>>> Any Ideas? Thanks.
>>>
>>> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101
>>
>>
>>
>>



---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Re: SQL Extension, how to close just one query?

Posted by Phil Friedman <pf...@terralink.com>.
John,

In the suggested code, if (d == sqldoc) never evaluates true so SQLDocuments are never closed and I did not see a way to get from sqldoc which seems to be a DTMNodeIterator to the SQLDocuments in the vector m_OpenSQLDocuments. I checked my XSLT and it seemed that I always used connections like a stack, so I hacked the code to:

 public void close( Object sqldoc )throws SQLException
 {
   int size = m_OpenSQLDocuments.size();
   Object o = m_OpenSQLDocuments.elementAt(size-1);
   ((SQLDocument)o).close();
   m_OpenSQLDocuments.removeElementAt(size-1);
 }

This works as far as closing connections. HOWEVER, because of Xalan's "lazy" evaluation, it is not straightforward to determine when a connection-query can be closed. XSLT like this fails:

...
<xsl:variable name="TyXplObjTyMn" select="$COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name]"/>
...
<xsl:value-of select="sql:close( $DbCon, $COWQy)"/>
...
<xsl:call-template name="ICowPrevAKOut">
  <xsl:with-param name="TyXplObjTyMn" select="$TyXplObjTyMn"/>
</xsl:call-template>
...

not until inside the ICowPrevAKOut template does $COWQy/sql/row-set/row[1]/col['TyXplObjTyMn'=@column-name] get evaluated, but we get an exception because $COWQy has already been closed.

Once again, I'm not sure what or why this was changed from the 2.0.1 sql extension. But it has been a great deal of effort to make it work. I hope we're almost there.

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

John Gentilin wrote:
> Phil,
> 
> This was an issue I posted to the Dev list a while back and finally
> found an answer, I think, a while back working on another project.
> The proposed fix would be to change the method signature from SQLDocument
> to just Object. The problem is, the original SQLDocument object can be
> casted to one of its many interfaces depending on what operation you
> are currently performing, here it was casted to an XNodeSet. The code
> should just work since I am just comparing the object to all the open
> documents, the closing the SQLDocument in the list that matches the
> incoming object.
> 
> If you feel up to it, give it a try. I also have the official changes
> for your other fix as well as a skipRec enhancement function to help
> out with pagination. The ToDo item to check those changes in are on
> my list to do RSN. :-)
> 
> change
>  public void close( SQLDocument sqldoc )throws SQLException
>  {
>    if (DEBUG)
>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
> 
>    int size = m_OpenSQLDocuments.size();
> 
>    for(int x=0; x<size; x++)
>    {
>      SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
>      if (d == sqldoc)
>      {
>        d.close();
>        m_OpenSQLDocuments.removeElementAt(x);
>      }
>    }
>  }
> 
> to
> 
>  public void close( Object sqldoc )throws SQLException
>  {
>    if (DEBUG)
>      System.out.println("Entering XConnection.close(" + sqldoc + ")");
> 
>    int size = m_OpenSQLDocuments.size();
> 
>    for(int x=0; x<size; x++)
>    {
>      Object o =  m_OpenSQLDocuments.elementAt(x);
>      if (o == sqldoc)
>      {
>        ((SQLDocument)d).close();
>        m_OpenSQLDocuments.removeElementAt(x);
>      }
>    }
>  }
> 
> Phil Friedman wrote:
> 
>> John,
>> I'm back at it. What is the XSL to call close( SQLDocument sqldoc ), 
>> XConnection line 1084? I need to reales just one query and it's 
>> connection, while leaving other queries active.
>>
>> Here is a simplified version of what I need to do. I connect with:
>>
>>  <xsl:variable name="DbCon" select="sql:new()"/>
>>  <xsl:value-of select="sql:setFeature( $DbCon, 'default-pool-enabled', 
>> 'true')"/>
>>  <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
>>  <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, 
>> $DbPwd))" >
>>    <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
>>  </xsl:if>
>>
>> Then I run a parent query
>>
>>  <xsl:variable name="SQL">
>>    select Ix from List
>>  </xsl:variable>
>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>  <xsl:if test="$msg-sql or not( $Qy)">
>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>  </xsl:if>
>>  <xsl:if test="not( $Qy)" >
>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>  </xsl:if>
>>  <xsl:for-each select="$Qy/sql/row-set/row">
>>
>> Then, for each row, I run a child query like this:
>>
>>  <xsl:variable name="SQL">
>>    select * from Table where Ix= <xsl:value-of 
>> select="col['Ix'=@column-name]"/>
>>  </xsl:variable>
>>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>>  <xsl:if test="$msg-sql or not( $Qy)">
>>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
>> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>>  </xsl:if>
>>  <xsl:if test="not( $Qy)" >
>>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>>  </xsl:if>
>>  <!-- return value -->
>>  <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/>
>>
>> Then I want to close just the child query, because I'm still in the 
>> middle of the parent resultset:
>>
>>  <xsl:value-of select="sql:close( $DbCon, $Qy)"/>
>>
>> Gives me:
>>
>> (Location of error unknown)XSLT Error 
>> (javax.xml.transform.TransformerException): 
>> java.lang.NoSuchMethodException: For extension function, could not 
>> find method static 
>> org.apache.xalan.lib.sql.XConnection.close([ExpressionContext, 
>> ]#UNKNOWN (org.apache.xalan.lib.sql.XConnection), #NODESET) nor
>> class org.apache.xalan.lib.sql.XConnection.close([ExpressionContext,] 
>> #NODESET).
>>
>> While:
>>  <xsl:value-of select="sql:close( $DbCon)"/>
>>
>> releases both the parent and child connection and Gives me:
>>
>> XSLT Error (javax.xml.transform.TransformerException): 
>> java.lang.ArrayIndexOutOfBoundsException: -1
>>
>> because the parent connection has been closed so there is nothing 
>> there for the <xsl:for-each select="$Qy/sql/row-set/row"> to evaluate 
>> <xsl:value-of select="col['Ix'=@column-name]"/>
>>
>> If I comment out the <xsl:value-of select="sql:close( $DbCon)"/>
>>
>> The results are correct. However, this is impractical because if I 
>> leave out ALL the closes I get many, many connections opened, which 
>> leads to other problems.
>>
>> Any Ideas? Thanks.
>>
>> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Re: SQL Extension, how to close just one query?

Posted by John Gentilin <ge...@eyecatching.com>.
Phil,

This was an issue I posted to the Dev list a while back and finally
found an answer, I think, a while back working on another project.
The proposed fix would be to change the method signature from SQLDocument
to just Object. The problem is, the original SQLDocument object can be
casted to one of its many interfaces depending on what operation you
are currently performing, here it was casted to an XNodeSet. The code
should just work since I am just comparing the object to all the open
documents, the closing the SQLDocument in the list that matches the
incoming object.

If you feel up to it, give it a try. I also have the official changes
for your other fix as well as a skipRec enhancement function to help
out with pagination. The ToDo item to check those changes in are on
my list to do RSN. :-)

change
  public void close( SQLDocument sqldoc )throws SQLException
  {
    if (DEBUG)
      System.out.println("Entering XConnection.close(" + sqldoc + ")");

    int size = m_OpenSQLDocuments.size();

    for(int x=0; x<size; x++)
    {
      SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(x);
      if (d == sqldoc)
      {
        d.close();
        m_OpenSQLDocuments.removeElementAt(x);
      }
    }
  }

to

  public void close( Object sqldoc )throws SQLException
  {
    if (DEBUG)
      System.out.println("Entering XConnection.close(" + sqldoc + ")");

    int size = m_OpenSQLDocuments.size();

    for(int x=0; x<size; x++)
    {
      Object o =  m_OpenSQLDocuments.elementAt(x);
      if (o == sqldoc)
      {
        ((SQLDocument)d).close();
        m_OpenSQLDocuments.removeElementAt(x);
      }
    }
  }

Phil Friedman wrote:
> John,
> I'm back at it. What is the XSL to call close( SQLDocument sqldoc ), 
> XConnection line 1084? I need to reales just one query and it's 
> connection, while leaving other queries active.
> 
> Here is a simplified version of what I need to do. I connect with:
> 
>  <xsl:variable name="DbCon" select="sql:new()"/>
>  <xsl:value-of select="sql:setFeature( $DbCon, 'default-pool-enabled', 
> 'true')"/>
>  <xsl:value-of select="sql:setFeature( $DbCon, 'streaming', 'false')"/>
>  <xsl:if test="not( sql:connect( $DbCon, $DbDrvr, $DbUrl, $DbUsr, 
> $DbPwd))" >
>    <xsl:copy-of select="sql:getError($DbCon)/ext-error" />
>  </xsl:if>
> 
> Then I run a parent query
> 
>  <xsl:variable name="SQL">
>    select Ix from List
>  </xsl:variable>
>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>  <xsl:if test="$msg-sql or not( $Qy)">
>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>  </xsl:if>
>  <xsl:if test="not( $Qy)" >
>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>  </xsl:if>
>  <xsl:for-each select="$Qy/sql/row-set/row">
> 
> Then, for each row, I run a child query like this:
> 
>  <xsl:variable name="SQL">
>    select * from Table where Ix= <xsl:value-of 
> select="col['Ix'=@column-name]"/>
>  </xsl:variable>
>  <xsl:variable name="Qy" select="sql:query( $DbCon, $SQL)"/>
>  <xsl:if test="$msg-sql or not( $Qy)">
>    <xsl:message terminate="no"><xsl:value-of select="$SQL"/>= 
> <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/></xsl:message>
>  </xsl:if>
>  <xsl:if test="not( $Qy)" >
>    <xsl:apply-templates select="sql:getError( $DbCon)/ext-error"/>
>  </xsl:if>
>  <!-- return value -->
>  <xsl:value-of select="$Qy/sql/row-set/row[1]/col[1]"/>
> 
> Then I want to close just the child query, because I'm still in the 
> middle of the parent resultset:
> 
>  <xsl:value-of select="sql:close( $DbCon, $Qy)"/>
> 
> Gives me:
> 
> (Location of error unknown)XSLT Error 
> (javax.xml.transform.TransformerException): 
> java.lang.NoSuchMethodException: For extension function, could not find 
> method static 
> org.apache.xalan.lib.sql.XConnection.close([ExpressionContext, ]#UNKNOWN 
> (org.apache.xalan.lib.sql.XConnection), #NODESET) nor
> class org.apache.xalan.lib.sql.XConnection.close([ExpressionContext,] 
> #NODESET).
> 
> While:
>  <xsl:value-of select="sql:close( $DbCon)"/>
> 
> releases both the parent and child connection and Gives me:
> 
> XSLT Error (javax.xml.transform.TransformerException): 
> java.lang.ArrayIndexOutOfBoundsException: -1
> 
> because the parent connection has been closed so there is nothing there 
> for the <xsl:for-each select="$Qy/sql/row-set/row"> to evaluate 
> <xsl:value-of select="col['Ix'=@column-name]"/>
> 
> If I comment out the <xsl:value-of select="sql:close( $DbCon)"/>
> 
> The results are correct. However, this is impractical because if I leave 
> out ALL the closes I get many, many connections opened, which leads to 
> other problems.
> 
> Any Ideas? Thanks.
> 
> Regards, Phil Friedman - Terralink Software - 1-207-772-6500 x101


-- 
--------------------------------------
John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546

    Contact Info
gentijo@eyecatching.com
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org