Problems with retrieving Model results
Hi all,
we are experienced some issues with SQLModelbase/ResultsetModelBase
models closing connection before the results can be quereed. We are using
JATO 1.1 and jakarta-tomcat-3.2.1. Following is some sample code that gets a
model and executes it. It is not very different to what is specified in the
NDtoJATO-J2EE-API-Map document.
doGetNameModelImpl doGet = (doGetNameModelImpl )
context.getModelManager().getModel(doGetNameModelImpl.class);
doGet .clearUserWhereCriteria();
doGet .addUserWhereCriterion(keyName, "=",custId);
ResultSet results = doLogin.executeSelect(new
DataSetModelExecutionContextImpl());
if (results == null )
{
Log.log("LOGIN_LOGIN_PASSWORD = " +
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
throw new Exception("blah blah blah.. ");
}
//the following line will throw and exception
_db_password =
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
A java.sql.Exception was thrown because getValue() attempts to access the
ResultSet of the Model after it has been closed.
Directly manipulating the ResultSet returned buy the executeSelect() methods
also fails with the similar error.
According to the Java Docs,a ResultSet gets closed when the Statement that
generated it is closed. A Statement get closed either explictly(which JATO
does not do) or when it is garbage collected. In JATO, a Connection and
Statement are defined locally in executeSelect() method in QueryModelBase.
The Connection gets closed at the end of the method if the default
connection had to be created. So it looks like the Resultset is getting
closed either because its statement is getting garbage collected or its
Connection is getting closed.
One way to get the above code to work is straightfoward - passing a
Statement and or a Connection to the executeSelect()using a
SQLModelExecutionContext. eg:
doGetNameModelImpl doGet = (doGetNameModelImpl )
context.getModelManager().getModel(doGetNameModelImpl.class);
doGet.clearUserWhereCriteria();
doGet.addUserWhereCriterion(keyName, "=",custId);
Statement statement = ((SQLConnectionManagerImpl)
context.getSQLConnectionManager()).getConnection().createStatement();
DatasetSQLModelExecutionContext execContext = new
DatasetSQLModelExecutionContext(statement);
ResultSet results = doGet .executeSelect(execContext);
if (results == null )
{
Log.log("LOGIN_LOGIN_PASSWORD = " +
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
throw new Exception("blah blah blah.. ");
}
//the following line successfully retrieves the results.
_db_password =
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
While this works, is it desirable to allways have to manage the creation and
closing of Connections and Statements for regular Model execution? This is
something you would want to do if the Models were participating in
transactions and you want to control the
openning/closing/committing/rollback of Connections outside the Models. But
I thought you would want to hide JDBC specific execution details for regular
Model data retrival. Is there another approach to prevent the Resultset from
closing? ie. do we need to introduce a setStatement() to prevent it from gc
?.
> -
> Kostas Morfis
> Senior Consultant
> i R i s e
> 2101 Rosecrans Ave., Suite 1250
> El Segundo, CA 90245
>
> (310) 640-8656 phone
> (310) 614-8417 cell
> (651) 319-0862 fax
> <a href="/group/SunONE-JATO/post?protectID=200233066165158233015056109026229239071 179066034">kostas@i...</a>
>
>
[Non-text portions of this message have been removed]
[4049 byte] By [
Guest] at [2007-11-25 9:26:31]

a typo.
I did not want to distribute a clients source code over the internet so I
put together the
example based on real code. The basic issue still applies though. That line
should read.
ResultSet results = doLogin.executeSelect(new
DataSetModelExecutionContextImpl());
Kostas
I assure you I am not making this up :)
--Original Message--
From: Matthew Stevens [mailto:<a href="/group/SunONE-JATO/post?protectID=029166114165042198028082000056130080177 026031196184123241150093211220076052127084">matthew.stevens@E...</a>]
Sent: Wednesday, February 28, 2001 2:04 PM
Subject: RE: [iPlanet-JATO] Problems with retrieving Model results
Kostas,
I see two references [doGet and doLogin]
What is doLogin?
matt
> --Original Message--
> From: Craig V Conover [mailto:<a href="/group/SunONE-JATO/post?protectID=219212113009229091025149066024064239039 098031198039130252055210">craig.conover@s...</a>]
> Sent: Wednesday, February 28, 2001 5:01 PM
> Subject: Re: [iPlanet-JATO] Problems with retrieving Model results
>
>
> Kostas,
> That example may be a bit dated.
>
> This line of code:
> doLogin.executeSelect(new DataSetModelExecutionContextImpl());
>
> should be this instead:
> doLogin.executeSelect(null);
>
> Unless you need to control the ExecutionContext, null should be
> passed in. This was my example and may have been a victim of my
> lack of JATO knowledge at the time.
>
> craig
>
>
> -- Original Message --
> From: Kostas Morfis
> Sent: Wednesday, February 28, 2001 1:52 PM
> Subject: [iPlanet-JATO] Problems with retrieving Model results
>
>
> Hi all,
> we are experienced some issues with
> SQLModelbase/ResultsetModelBase
> models closing connection before the results can be quereed. We
> are using
> JATO 1.1 and jakarta-tomcat-3.2.1. Following is some sample
> code that gets a
> model and executes it. It is not very different to what is
> specified in the
> NDtoJATO-J2EE-API-Map document.
>
>
> doGetNameModelImpl doGet = (doGetNameModelImpl )
> context.getModelManager().getModel(doGetNameModelImpl.class);
> doGet .clearUserWhereCriteria();
> doGet .addUserWhereCriterion(keyName, "=",custId);
> ResultSet results = doLogin.executeSelect(new
> DataSetModelExecutionContextImpl());
> if (results == null )
> {
> Log.log("LOGIN_LOGIN_PASSWORD = " +
> (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
> throw new Exception("blah blah blah.. ");
> }
>
> //the following line will throw and exception
> _db_password =
> (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
>
> A java.sql.Exception was thrown because getValue() attempts to
> access the
> ResultSet of the Model after it has been closed.
> Directly manipulating the ResultSet returned buy the
> executeSelect() methods
> also fails with the similar error.
>
> According to the Java Docs,a ResultSet gets closed when the
> Statement that
> generated it is closed. A Statement get closed either
> explictly(which JATO
> does not do) or when it is garbage collected. In JATO, a Connection and
> Statement are defined locally in executeSelect() method in
> QueryModelBase.
> The Connection gets closed at the end of the method if the default
> connection had to be created. So it looks like the Resultset is getting
> closed either because its statement is getting garbage collected or its
> Connection is getting closed.
>
> One way to get the above code to work is straightfoward - passing a
> Statement and or a Connection to the executeSelect()using a
> SQLModelExecutionContext. eg:
>
>
> doGetNameModelImpl doGet = (doGetNameModelImpl )
> context.getModelManager().getModel(doGetNameModelImpl.class);
> doGet.clearUserWhereCriteria();
> doGet.addUserWhereCriterion(keyName, "=",custId);
> Statement statement = ((SQLConnectionManagerImpl)
> context.getSQLConnectionManager()).getConnection().createStatement();
> DatasetSQLModelExecutionContext execContext = new
> DatasetSQLModelExecutionContext(statement);
> ResultSet results = doGet .executeSelect(execContext);
> if (results == null )
> {
> Log.log("LOGIN_LOGIN_PASSWORD = " +
> (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
> throw new Exception("blah blah blah.. ");
> }
>
> //the following line successfully retrieves the results.
> _db_password =
> (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
>
>
>
> While this works, is it desirable to allways have to manage the
> creation and
> closing of Connections and Statements for regular Model
> execution? This is
> something you would want to do if the Models were participating in
> transactions and you want to control the
> openning/closing/committing/rollback of Connections outside the
> Models. But
> I thought you would want to hide JDBC specific execution
> details for regular
> Model data retrival. Is there another approach to prevent the
> Resultset from
> closing? ie. do we need to introduce a setStatement() to
> prevent it from gc
> ?.
>
>
>
> > -
> > Kostas Morfis
> > Senior Consultant
> > i R i s e
> > 2101 Rosecrans Ave., Suite 1250
> > El Segundo, CA 90245
> >
> > (310) 640-8656 phone
> > (310) 614-8417 cell
> > (651) 319-0862 fax
> > <a href="/group/SunONE-JATO/post?protectID=200233066165158233015056109026229239071 179066034">kostas@i...</a>
> >
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
> <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
>
>
>
>
>
>
<a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
[Non-text portions of this message have been removed]
Guest at 2007-7-1 16:30:58 >

Kostas--
Craig is exactly right. Unless you are going to customize the retrieval of
data from the model, you should just pass in null as the execution context.
Todd
-- Original Message --
From: "Kostas Morfis" <<a href="/group/SunONE-JATO/post?protectID=200232253180021132090218186148231088177 048234051197">kmorfis@i...</a>>
Sent: Wednesday, February 28, 2001 15:54
Subject: RE: [iPlanet-JATO] Problems with retrieving Model results
> a typo.
>
> I did not want to distribute a clients source code over the internet so I
> put together the
> example based on real code. The basic issue still applies though. That
line
> should read.
>
> ResultSet results = doLogin.executeSelect(new
> DataSetModelExecutionContextImpl());
>
>
>
> Kostas
>
> I assure you I am not making this up :)
>
>
> --Original Message--
> From: Matthew Stevens [mailto:<a href="/group/SunONE-JATO/post?protectID=029166114165042198028082000056130080177 026031196184123241150093211220076052127084">matthew.stevens@E...</a>]
> Sent: Wednesday, February 28, 2001 2:04 PM
> Subject: RE: [iPlanet-JATO] Problems with retrieving Model results
>
>
> Kostas,
>
> I see two references [doGet and doLogin]
>
> What is doLogin?
>
> matt
>
> > --Original Message--
> > From: Craig V Conover [mailto:<a href="/group/SunONE-JATO/post?protectID=219212113009229091025149066024064239039 098031198039130252055210">craig.conover@s...</a>]
> > Sent: Wednesday, February 28, 2001 5:01 PM
> > Subject: Re: [iPlanet-JATO] Problems with retrieving Model results
> >
> >
> > Kostas,
> > That example may be a bit dated.
> >
> > This line of code:
> > doLogin.executeSelect(new DataSetModelExecutionContextImpl());
> >
> > should be this instead:
> > doLogin.executeSelect(null);
> >
> > Unless you need to control the ExecutionContext, null should be
> > passed in. This was my example and may have been a victim of my
> > lack of JATO knowledge at the time.
> >
> > craig
> >
> >
> > -- Original Message --
> > From: Kostas Morfis
> > Sent: Wednesday, February 28, 2001 1:52 PM
> > Subject: [iPlanet-JATO] Problems with retrieving Model results
> >
> >
> > Hi all,
> > we are experienced some issues with
> > SQLModelbase/ResultsetModelBase
> > models closing connection before the results can be quereed. We
> > are using
> > JATO 1.1 and jakarta-tomcat-3.2.1. Following is some sample
> > code that gets a
> > model and executes it. It is not very different to what is
> > specified in the
> > NDtoJATO-J2EE-API-Map document.
> >
> >
> > doGetNameModelImpl doGet = (doGetNameModelImpl )
> > context.getModelManager().getModel(doGetNameModelImpl.class);
> > doGet .clearUserWhereCriteria();
> > doGet .addUserWhereCriterion(keyName, "=",custId);
> > ResultSet results = doLogin.executeSelect(new
> > DataSetModelExecutionContextImpl());
> > if (results == null )
> > {
> > Log.log("LOGIN_LOGIN_PASSWORD = " +
> > (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
> > throw new Exception("blah blah blah.. ");
> > }
> >
> > //the following line will throw and exception
> > _db_password =
> > (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
> >
> > A java.sql.Exception was thrown because getValue() attempts to
> > access the
> > ResultSet of the Model after it has been closed.
> > Directly manipulating the ResultSet returned buy the
> > executeSelect() methods
> > also fails with the similar error.
> >
> > According to the Java Docs,a ResultSet gets closed when the
> > Statement that
> > generated it is closed. A Statement get closed either
> > explictly(which JATO
> > does not do) or when it is garbage collected. In JATO, a Connection
and
> > Statement are defined locally in executeSelect() method in
> > QueryModelBase.
> > The Connection gets closed at the end of the method if the default
> > connection had to be created. So it looks like the Resultset is
getting
> > closed either because its statement is getting garbage collected or
its
> > Connection is getting closed.
> >
> > One way to get the above code to work is straightfoward - passing a
> > Statement and or a Connection to the executeSelect()using a
> > SQLModelExecutionContext. eg:
> >
> >
> > doGetNameModelImpl doGet = (doGetNameModelImpl )
> > context.getModelManager().getModel(doGetNameModelImpl.class);
> > doGet.clearUserWhereCriteria();
> > doGet.addUserWhereCriterion(keyName, "=",custId);
> > Statement statement = ((SQLConnectionManagerImpl)
> > context.getSQLConnectionManager()).getConnection().createStatement();
> > DatasetSQLModelExecutionContext execContext = new
> > DatasetSQLModelExecutionContext(statement);
> > ResultSet results = doGet .executeSelect(execContext);
> > if (results == null )
> > {
> > Log.log("LOGIN_LOGIN_PASSWORD = " +
> > (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
> > throw new Exception("blah blah blah.. ");
> > }
> >
> > //the following line successfully retrieves the results.
> > _db_password =
> > (String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
> >
> >
> >
> > While this works, is it desirable to allways have to manage the
> > creation and
> > closing of Connections and Statements for regular Model
> > execution? This is
> > something you would want to do if the Models were participating in
> > transactions and you want to control the
> > openning/closing/committing/rollback of Connections outside the
> > Models. But
> > I thought you would want to hide JDBC specific execution
> > details for regular
> > Model data retrival. Is there another approach to prevent the
> > Resultset from
> > closing? ie. do we need to introduce a setStatement() to
> > prevent it from gc
> > ?.
> >
> >
> >
> > > -
> > > Kostas Morfis
> > > Senior Consultant
> > > i R i s e
> > > 2101 Rosecrans Ave., Suite 1250
> > > El Segundo, CA 90245
> > >
> > > (310) 640-8656 phone
> > > (310) 614-8417 cell
> > > (651) 319-0862 fax
> > > <a href="/group/SunONE-JATO/post?protectID=200233066165158233015056109026229239071 179066034">kostas@i...</a>
> > >
> > >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> > <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
> >
> >
> >
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> > <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
> >
> >
> >
> >
> >
> >
>
>
> <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
> <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
>
>
>
>
>
Guest at 2007-7-1 16:30:58 >

Looks like you did your homework - bravo for that ;)
It looks as if Todd has replied with the answer. Mine was going to be bit
simpler and less informative.
thanks todd
c
-- Original Message --
From: Kostas Morfis
Sent: Wednesday, February 28, 2001 3:45 PM
Subject: RE: [iPlanet-JATO] Problems with retrieving Model results
Hi Craig,
Unfortunatly I can't quickly test this now as I don't have to the
environment.
Wouldn't passing null achieve the same effect ?
ie. following is the code from QueryModelBase.executeSelect():
if (context!=null && context instanceof SQLModelExecutionContext)
{
// We try to use the statement from the context if one is
available.
// In general, we'll have either a statement, a connection,
or neither.
statement=((SQLModelExecutionContext)context).getStatement();
connection=((SQLModelExecutionContext)context).getConnection();
}
// If we didn't get a statement, then we need to get a
connection
// (if one wasn't already provided) and use it to get a
statement.
if (statement==null)
{
Log.log(" | QueryModelBase.executeSelect() | " +
getClass().getName() +
" statement is null, creating new one " );
// Get the connection from the context. If one is not
// available, obtain the default connection.
if (connection==null)
{
connection=getDefaultConnection();
usedDefaultConnection=true;
}
if (OPTIMAL_DRIVER_USAGE)
{
try
{
// TODO: Make these constants members that
can be changed
// by developers
statement=connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
}
catch (UnsupportedOperationException e)
{
// If this fails for some reason, we take he
default statement type
statement=connection.createStatement();
}
}
else
statement=connection.createStatement();
The above shows a statement will get created if
1. context is null
2. context is not SQLModelExecutionContext
3. context is a SQLModelExecutionContext but has a null statement
your example - doLogin.executeSelect(null) matches criteria 1,
my exmaple - doLogin.executeSelect(new DataSetModelExecutionContextImpl())
matches criteria 2.
The net affect is the same though. I don't see how passing in null would
make a difference, except for
bypassing some additional processing occurs with the positionResultSet()
method;
Kostas
--Original Message--
From: Craig V Conover [mailto:<a href="/group/SunONE-JATO/post?protectID=219212113009229091025149066024064239039 098031198039130252055210">craig.conover@s...</a>]
Sent: Wednesday, February 28, 2001 2:01 PM
Subject: Re: [iPlanet-JATO] Problems with retrieving Model results
Kostas,
That example may be a bit dated.
This line of code:
doLogin.executeSelect(new DataSetModelExecutionContextImpl());
should be this instead:
doLogin.executeSelect(null);
Unless you need to control the ExecutionContext, null should be passed in.
This was my example and may have been a victim of my lack of JATO knowledge
at the time.
craig
-- Original Message --
From: Kostas Morfis
Sent: Wednesday, February 28, 2001 1:52 PM
Subject: [iPlanet-JATO] Problems with retrieving Model results
Hi all,
we are experienced some issues with
SQLModelbase/ResultsetModelBase
models closing connection before the results can be quereed. We are using
JATO 1.1 and jakarta-tomcat-3.2.1. Following is some sample code that gets
a
model and executes it. It is not very different to what is specified in
the
NDtoJATO-J2EE-API-Map document.
doGetNameModelImpl doGet = (doGetNameModelImpl )
context.getModelManager().getModel(doGetNameModelImpl.class);
doGet .clearUserWhereCriteria();
doGet .addUserWhereCriterion(keyName, "=",custId);
ResultSet results = doLogin.executeSelect(new
DataSetModelExecutionContextImpl());
if (results == null )
{
Log.log("LOGIN_LOGIN_PASSWORD = " +
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
throw new Exception("blah blah blah.. ");
}
//the following line will throw and exception
_db_password =
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
A java.sql.Exception was thrown because getValue() attempts to access the
ResultSet of the Model after it has been closed.
Directly manipulating the ResultSet returned buy the executeSelect()
methods
also fails with the similar error.
According to the Java Docs,a ResultSet gets closed when the Statement that
generated it is closed. A Statement get closed either explictly(which JATO
does not do) or when it is garbage collected. In JATO, a Connection and
Statement are defined locally in executeSelect() method in QueryModelBase.
The Connection gets closed at the end of the method if the default
connection had to be created. So it looks like the Resultset is getting
closed either because its statement is getting garbage collected or its
Connection is getting closed.
One way to get the above code to work is straightfoward - passing a
Statement and or a Connection to the executeSelect()using a
SQLModelExecutionContext. eg:
doGetNameModelImpl doGet = (doGetNameModelImpl )
context.getModelManager().getModel(doGetNameModelImpl.class);
doGet.clearUserWhereCriteria();
doGet.addUserWhereCriterion(keyName, "=",custId);
Statement statement = ((SQLConnectionManagerImpl)
context.getSQLConnectionManager()).getConnection().createStatement();
DatasetSQLModelExecutionContext execContext = new
DatasetSQLModelExecutionContext(statement);
ResultSet results = doGet .executeSelect(execContext);
if (results == null )
{
Log.log("LOGIN_LOGIN_PASSWORD = " +
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD"));
throw new Exception("blah blah blah.. ");
}
//the following line successfully retrieves the results.
_db_password =
(String)doLogin.getValue("LOGIN_LOGIN_PASSWORD");
While this works, is it desirable to allways have to manage the creation
and
closing of Connections and Statements for regular Model execution? This is
something you would want to do if the Models were participating in
transactions and you want to control the
openning/closing/committing/rollback of Connections outside the Models.
But
I thought you would want to hide JDBC specific execution details for
regular
Model data retrival. Is there another approach to prevent the Resultset
from
closing? ie. do we need to introduce a setStatement() to prevent it from
gc
?.
> -
> Kostas Morfis
> Senior Consultant
> i R i s e
> 2101 Rosecrans Ave., Suite 1250
> El Segundo, CA 90245
>
> (310) 640-8656 phone
> (310) 614-8417 cell
> (651) 319-0862 fax
> <a href="/group/SunONE-JATO/post?protectID=200233066165158233015056109026229239071 179066034">kostas@i...</a>
>
>
[Non-text portions of this message have been removed]
<a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
[Non-text portions of this message have been removed]
<a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
[Non-text portions of this message have been removed]
<a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
[Non-text portions of this message have been removed]
Guest at 2007-7-1 16:30:58 >

