JXPath - Iterating over all elements that 'lie on the way'

2005-07-14 Thread Gebhardt, Jörn
Hi,

I have the following scenario:
1.) I'm using Hibernate as O/R mapping tool.
2.) I dynamically need parts of the object tree in the frontend. To achieve 
this, I have a DTO structure that is similar to the Hibernate objects and that 
has also some kind of lazy loading capabilities.

Now I want to use JXPath expressions to define the parts of the backend object 
graph that should be shipped to the frontend.

E.g. if I have the association:
 Company (1)-(n) Department (1)-(n) Employee
(i.e. a company has several departments and each department has a number of 
employees)
and I have a specific company that I use as root context and I want to retrieve 
all employoees of the company I'd write some code like this:

JXPathContext.newContext(company).iterate(departments/employees)

However, I also want to iterate over all objects that 'lie on the way', i.e. in 
the above example I additionally want to iterate over all departments.

Is there a way to access all objects that have been visited while resolving the 
XPath expression? Or can I write my own extension to the reference 
implementation that helps me, collecting all these objects?

Thanks in advance,
Jörn


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



Re: JXPath - Iterating over all elements that 'lie on the way'

2005-07-14 Thread Torsten Curdt
However, I also want to iterate over all objects that 'lie on the  
way', i.e. in the above example I additionally want to iterate over  
all departments.


Is there a way to access all objects that have been visited while  
resolving the XPath expression? Or can I write my own extension to  
the reference implementation that helps me, collecting all these  
objects?




I think you are after the ancestor axis

HTH

cheers
--
Torsten


PGP.sig
Description: This is a digitally signed message part


Unable to create and use a Connection Pool

2005-07-14 Thread Ramon Garcia

Hi,
I have a problem tring to create and use a connection pool, I'm using Tomcat
5.0.28 and MySQL.
I followed the examples of the  JNDI Datasource HOW-TO But when I use it
the server shows a javax.naming.NameNotFoundException
My conifuration files are like:

CATALINA_HOME/conf/server.xml

?xml version='1.0' encoding='utf-8'?
Server
 Listener className=org.apache.catalina.mbeans.ServerLifecycleListener/
 Listener
className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener/
 GlobalNamingResources
   Environment name=simpleValue type=java.lang.Integer value=30/
   Resource auth=Container description=User database that can be
updated and saved name=UserDatabase
type=org.apache.catalina.UserDatabase/
   Resource name=jdbc/ramon type=javax.sql.DataSource/
   ResourceParams name=UserDatabase
 parameter
   namefactory/name
   valueorg.apache.catalina.users.MemoryUserDatabaseFactory/value
 /parameter
 parameter
   namepathname/name
   valueconf/tomcat-users.xml/value
 /parameter
   /ResourceParams
   ResourceParams name=jdbc/ramon
 parameter
   namevalidationQuery/name
   valueselect * from pista;/value
 /parameter
 parameter
   namemaxWait/name
   value5000/value
 /parameter
 parameter
   namemaxActive/name
   value4/value
 /parameter
 parameter
   namepassword/name
   valueclient/value
 /parameter
 parameter
   nameurl/name
   valuejdbc:mysql://localhost:3306/proves/value
 /parameter
 parameter
   namedriverClassName/name
   valueorg.gjt.mm.mysql.Driver/value
 /parameter
 parameter
   namemaxIdle/name
   value2/value
 /parameter
 parameter
   nameusername/name
   valueclient/value
 /parameter
   /ResourceParams
 /GlobalNamingResources
 Service name=Catalina
   Connector acceptCount=100 connectionTimeout=2
disableUploadTimeout=true port=8080 redirectPort=8443
maxSpareThreads=75 maxThreads=150 minSpareThreads=25
   /Connector
   Connector port=8009 protocol=AJP/1.3
protocolHandlerClassName=org.apache.jk.server.JkCoyoteHandler
redirectPort=8443
   /Connector
   Engine defaultHost=localhost name=Catalina
 Host appBase=webapps name=localhost
   Logger className=org.apache.catalina.logger.FileLogger
prefix=localhost_log. suffix=.txt timestamp=true/
 /Host
 Logger className=org.apache.catalina.logger.FileLogger
prefix=catalina_log. suffix=.txt timestamp=true/
 Realm className=org.apache.catalina.realm.UserDatabaseRealm/
   /Engine
 /Service
/Server


conf/Catalina/localhost/myapp.xml

?xml version='1.0' encoding='utf-8'?
Context docBase=prova path=/prova
workDir=work\Catalina\localhost\prova
ResourceLink name=jdbc/ramon type=javax.sql.DataSource
global=jdbc/ramon/
 Logger className=org.apache.catalina.logger.FileLogger prefix=prova.
timestamp=true/

/Context


and finally the web.xml file:
...
 resource-ref
   descriptionProva BD/description
   res-ref-namejdbc/ramon/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
 /resource-ref
..

What is my problem? I forgot to do something?

Thanks and Best Regards.

Ramon Garcia


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



Re: [betwixt] Making deserialise work like serialise (long)

2005-07-14 Thread Ricardo Gladwell

robert burrell donkin wrote:

On Tue, 2005-07-12 at 15:47 +0100, Ricardo Gladwell wrote:

Hi All,


hi Ricardo


How can I simulate this behaviour for serialisation? That is, how do I
force betwixt to interpret the bank account and generate an appropriate
country specific bank account, placing it into the bank account property
of the shopper, without having to create an additional bean for generic
bank account to hold the country-specific bank account.


i suggest that you being by getting hold of the betwixt source (either
from subversion see http://jakarta.apache.org/site/cvsindex.html or from
the latest release candidate
http://people.apache.org/~rdonkin/commons-betwixt/). you need to create
a custom ChainedBeanCreator which creates the right bean based on the
element type (take a look at ChainedBeanCreatorFactory for example of
creating a bean on the basis of an attribute value) and then add it to
the chain used to create new beans (see
http://jakarta.apache.org/commons/betwixt/guide/reading.html#Reading%
20Beans%20-%20In%20Depth). though you'll have to add an entry for each
subclass, it should work.


Thanks for the above. Unfortunately, the dependencies for the project 
I'm working on are quite strict and it wouldn't be possible to use 
snapshot code as you suggest above (it is worth noting the Maven 
repository on Ibiblio for this project is out of date, snapshots and 
all). Otherwise, implementing your own ChainedBeanCreator and modifying 
the bean creator chain is a very good idea.


In the end, I cheated and hard-coded XPath to read specific bank 
accounts using the BeanReader.registerBeanClass method:


reader.registerBeanClass(//bankAccount[bankAccount-AT], 
AustrianBankAccount.class);


And reading the file twice: once for the XML file, and again to extract 
bank details and manually insert them into the appropriate bean. That 
said, the bank accounts do not seem to be being read properly and the 
parse() method returns null. Not sure what might be causing this.



BTW any ideas about the best way to solve (or at least, chip away at)
the general problem would be gratefully received


Not sure this problems is resolvable: it means creating a reverse of the 
betwixt file and applying it intelligently to XML reading. For example, 
the following betwixt file:


!-- AustrianBankAccount.betwixt --
?xml version=1.0 encoding=UTF-8 ?
info primitiveTypes=element
  element name=bankAccount
element name=bankAccount-AT...

Would have to be interpreted as being /bankAccount[bankAccount-AT] - 
AustrianBankAccount. How would BeanReader be able to grasp this is what 
is wanted from the above than, for example, the bankAccount-AT refers to 
a property of the AustrianBankAccount bean, for example? Some sort of 
intelligent comparison between the betwixt file and the bean object 
model would be required to interpolate expected behaviour. Perhaps some 
sort of additional scripting would be required?


Kind regards...

-- Ricardo Gladwell

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



Re: [betwixt] Making deserialise work like serialise (long)

2005-07-14 Thread robert burrell donkin
On Thu, 2005-07-14 at 17:46 +0100, Ricardo Gladwell wrote:
 robert burrell donkin wrote:
  On Tue, 2005-07-12 at 15:47 +0100, Ricardo Gladwell wrote:
  Hi All,
  
  hi Ricardo
  
  How can I simulate this behaviour for serialisation? That is, how do I
  force betwixt to interpret the bank account and generate an appropriate
  country specific bank account, placing it into the bank account property
  of the shopper, without having to create an additional bean for generic
  bank account to hold the country-specific bank account.
  
  i suggest that you being by getting hold of the betwixt source (either
  from subversion see http://jakarta.apache.org/site/cvsindex.html or from
  the latest release candidate
  http://people.apache.org/~rdonkin/commons-betwixt/). you need to create
  a custom ChainedBeanCreator which creates the right bean based on the
  element type (take a look at ChainedBeanCreatorFactory for example of
  creating a bean on the basis of an attribute value) and then add it to
  the chain used to create new beans (see
  http://jakarta.apache.org/commons/betwixt/guide/reading.html#Reading%
  20Beans%20-%20In%20Depth). though you'll have to add an entry for each
  subclass, it should work.
 
 Thanks for the above. Unfortunately, the dependencies for the project 
 I'm working on are quite strict and it wouldn't be possible to use 
 snapshot code as you suggest above (it is worth noting the Maven 
 repository on Ibiblio for this project is out of date, snapshots and 
 all). 

it's a bit complicated by the fact that it's a release candidate (not a
SNAPSHOT). release candidates should not be uploaded to ibiblio (or any
other mirror). but thank's for the warning: i will remember to try to
check that the maven repository is right when the full release is cut. 

 Otherwise, implementing your own ChainedBeanCreator and modifying 
 the bean creator chain is a very good idea.

i think i managed to confuse matters a little (in the rush).

the chain is pluggable: just implement the interface and plug it in. 

the reason why i suggested obtaining the source is that the code
contains better examples than the documentation. (no changes are needed
to the source to create a custom creation chain.)

FYI the release candidate is very close now to being accepted as betwixt
0.7. it is strongly recommended that all users upgrade to this new
version. 

 In the end, I cheated and hard-coded XPath to read specific bank 
 accounts using the BeanReader.registerBeanClass method:
 
 reader.registerBeanClass(//bankAccount[bankAccount-AT], 
 AustrianBankAccount.class);
 
 And reading the file twice: once for the XML file, and again to extract 
 bank details and manually insert them into the appropriate bean. That 
 said, the bank accounts do not seem to be being read properly and the 
 parse() method returns null. Not sure what might be causing this.

it is possible to make betwixt work that way (you can integrate it with
digester rules) but it's pretty black belt...  

  BTW any ideas about the best way to solve (or at least, chip away at)
  the general problem would be gratefully received
 
 Not sure this problems is resolvable: it means creating a reverse of the 
 betwixt file and applying it intelligently to XML reading. For example, 
 the following betwixt file:
 
 !-- AustrianBankAccount.betwixt --
 ?xml version=1.0 encoding=UTF-8 ?
 info primitiveTypes=element
element name=bankAccount
  element name=bankAccount-AT...
 
 Would have to be interpreted as being /bankAccount[bankAccount-AT] - 
 AustrianBankAccount. How would BeanReader be able to grasp this is what 
 is wanted from the above than, for example, the bankAccount-AT refers to 
 a property of the AustrianBankAccount bean, for example? 

exactly :)

i've seen some mappers do things using reflection to determine
inheritance but in the end they still need to know the names of the
classes involved so i'm not sure how much is gained...

 Some sort of 
 intelligent comparison between the betwixt file and the bean object 
 model would be required to interpolate expected behaviour. Perhaps some 
 sort of additional scripting would be required?

scripting sounds very interesting (hadn't really thought about it
before). betwixt is generally declarative but maven's mix of declarative
data and scripting works very well. how do you see this working?

one way to solve your narrow problem would be to create a custom chain
bean creator using an option to pass element name - class name mappings
through and add that to the default chain. if you need to use full
releases, then it'd probably be a little too late, though...

- robert


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



Re: [betwixt] Making deserialise work like serialise (long)

2005-07-14 Thread robert burrell donkin
On Tue, 2005-07-12 at 15:47 +0100, Ricardo Gladwell wrote:
 Hi All,
 
 I'm using an external XML syntax to read and write data for payment 
 transactions. The format for specifying bank accounts is as follows:
 
 shopper
bankAccount
  bankAcount-GB.../bankAccount-GB
/bankAccount
 /shopper

i was wonder whether this structure is by design or just because Betwixt
forces it...

would (for example) the following be better?

shopper
bank-account-gb.../bank-account-gb.
/shopper

(if betwixt could map it appropriately)

- robert


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



Configuration: XML - Configuration Check?

2005-07-14 Thread Wolfgang 'Dreamguard' Nagele

Hello list,

Is there any possibility to do a check for requried elements, etc. in a 
XMLConfiguration?


I was thinking about validation against a xml schema or so.

Thanks.

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



[DBCP] Anther lame pool exhausted exception question

2005-07-14 Thread Brian Cook


I have several apps written that use org.apache.commons.dbcp.  And I am 
getting the  org.apache.commons.dbcp.SQLNestedException: Cannot get a 
connection, pool exhausted exception.


When I run netstat sure enough it shows about 60 - 100 ESTABLISHED 
connections open at any given time.  Looking deeper it looks like new 
connections are created most but not each time the Java Bean the uses 
the data base is called.  So it seems pretty clear that I am failing to 
close all of the connections in my app.  My problem is that I can not 
find where that is.


My understanding is that as long as I close every ResultSet, and each 
Connection object I should have my bases covered.  I have gone back 
though the app repeatedly and verified that all the ResultSets, 
Connections, and BasicDataSource objects are all being closed.


Due to an internal political problem I am not using JNDI for the 
connections.  Instead I have a class file that is called when a 
connection is need. After the object is used a close() method is called 
and closes the Statement, Connection, ResultSet, BasicDataSource objects.


So my questions are ..

   1.  Is there something else I should be doing to return the 
connections to the pool?
   2.  Does not using JNDI with org.apache.commons.dbcp cause problems 
with closing the connection pool some how?



I have been though about 6 months of the archives for this list and did 
not find any hints,  I went to look at the examples lnik at on the 
Commons.DBCP page but the link to 
http://cvs.apache.org/downviewcvs.html/jakarta-commons/dbcp/doc/ seems 
to be broken.  Googling has only just returned the usall advice of make 
sure you are closing every connection.


I am open to any ideas or thoughts to what I am failing to due here.  
Details and the code are included below.



OS: Linux Red Hat 9.0
Container:   Tomcat 4.127
DBCP:commons-dbcp-1.2.1.jar, commons-pool-1.2.jar
JDK:   1.5
Database:MySQL 4.1
JDBC Driver:  mysql-connector-java-3.1.7-bin.jar



public class DBConector {


Omited Code/


   public DBConector(String dataBaseName) {

 try{
   String DataBaseURL = jdbc:mysql://+DataBaseHost+/+dataBaseName+
   ?user=+DataBaseUser+password=+DataBasePassword;

   mysqlCon = getPooledConection(DataBaseURL);
   sqlStatement = mysqlCon.createStatement();

 }
 catch(Exception s) {
   System.err.println(new java.util.Date()+ Error throw by +
DBConector()\n+s);
 }
   }


Omited Code/


   public ResultSet read(String SQL) {

 try{
rs = sqlStatement.executeQuery( SQL );
  }   // Close try
  catch(Exception s) {
   System.err.println(new java.util.Date()+ Error throw by an 
SQL  +

   call in DBConector.read() class : \n+s+\n+s.getMessage()+
   \nSQL Queary : +SQL+\n);
  }  // Close catch

   return(DataFromDB);
   }   // Close the read method



Omited Code/


  protected static Connection getPooledConection(String connectURI) {
   ds = new BasicDataSource();
   ds.setDriverClassName(DBDriver);
   ds.setUsername(DataBaseUser);
   ds.setPassword(DataBasePassword);
   ds.setUrl(connectURI);
   ds.setInitialSize(3);
   ds.setMaxActive(32);
   ds.setMaxIdle(8);
   ds.setMinIdle(3);
   Connection con = null;

 try {
   con = ds.getConnection();
 }
 catch(Exception a){System.out.println(new java.util.Date() +
   PrintTimeDataBase6.getPooledConection() has thrown an 
exception.\n+a+

   \n+ a.getMessage()   );
 }
   return con;
   }   // Close method


Omited Code/


  public void close() {
  try {  sqlStatement.close(); } catch(Exception a) {  }
  try {  mysqlCon.close();  } catch(Exception a) {  }
  try {  rs.close();   } catch(Exception a) {  }
  try {  ds.close();   } catch(Exception a) {  }
  }// Close method
}   // Close the PrintTimeWebServices Class

--
Brian Cook
Digital Services Analyst
Print Time Inc.
[EMAIL PROTECTED]




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

RE: [betwixt] AddDefaultsRule bug in 0.7RC2

2005-07-14 Thread Glenn Goldenberg
hi robert:

 you help's appreciated. if (in future) you want to help to speed the
 process of application, please read
 http://jakarta.apache.org/site/getinvolved.html and consider creating
 some patches (once you get the hang of them, you'll find them easier
 than describing things in words). if you find your emails are getting a
 little long, then you could open a report in
 http://issues.apache.org/bugzilla/ (if you like) and then follow up on
 list .

Thanks, I will take a look at this for contributing in the future...

 BTW are you happy to contribute your test cases (which i've deleted from
 the bottom of this mail) to apache? (saves me having to create fresh
 ones.) just FYI if you attach the apache software license 2.0 to the top
 of any new classes you post then i won't have to ask ;)

Sure, no problem.  Glad you can use the tests.

thanks,
glenn


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



Re: [DBCP] Anther lame pool exhausted exception question

2005-07-14 Thread Craig McClanahan
The key to returning connections to the connection pool is to call
close() on the *connection* itself.  The most common way people get
themselves in trouble is to skip this somehow (perhaps because an
exception is thrown).

To avoid that sort of problem, I tend to use an idiom like this for
JDBC access code:

DataSource ds = ...; // Acquire a reference from JNDI or wherever
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection(); // Or whatever
stmt = conn.prepareStatement(...);
rs = stmt.executeQuery();
... process the results ...
} catch (SQLException e) {
... process the exception ...
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
... record or ignore ...
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
... record or ignore ...
}
rs = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
... record or ignore ...
}
conn = null;
}
}

Courtesy of the finally logic, I'm guaranteed to always execute my
cleanup code, no matter where an exception might get thrown.

You'll note that it can be pretty tedious to do all this stuff with
raw JDBC.  You might also want to look at using one of the SQL
frameworks that encapsulate this sort of stuff, but still give you the
guarantee that the connection will ultimately be returned to the pool.

Craig



On 7/14/05, Brian Cook [EMAIL PROTECTED] wrote:
 
 I have several apps written that use org.apache.commons.dbcp.  And I am
 getting the  org.apache.commons.dbcp.SQLNestedException: Cannot get a
 connection, pool exhausted exception.
 
 When I run netstat sure enough it shows about 60 - 100 ESTABLISHED
 connections open at any given time.  Looking deeper it looks like new
 connections are created most but not each time the Java Bean the uses
 the data base is called.  So it seems pretty clear that I am failing to
 close all of the connections in my app.  My problem is that I can not
 find where that is.
 
 My understanding is that as long as I close every ResultSet, and each
 Connection object I should have my bases covered.  I have gone back
 though the app repeatedly and verified that all the ResultSets,
 Connections, and BasicDataSource objects are all being closed.
 
 Due to an internal political problem I am not using JNDI for the
 connections.  Instead I have a class file that is called when a
 connection is need. After the object is used a close() method is called
 and closes the Statement, Connection, ResultSet, BasicDataSource objects.
 
 So my questions are ..
 
 1.  Is there something else I should be doing to return the
 connections to the pool?
 2.  Does not using JNDI with org.apache.commons.dbcp cause problems
 with closing the connection pool some how?
 
 
 I have been though about 6 months of the archives for this list and did
 not find any hints,  I went to look at the examples lnik at on the
 Commons.DBCP page but the link to
 http://cvs.apache.org/downviewcvs.html/jakarta-commons/dbcp/doc/ seems
 to be broken.  Googling has only just returned the usall advice of make
 sure you are closing every connection.
 
 I am open to any ideas or thoughts to what I am failing to due here.
 Details and the code are included below.
 
 
 OS: Linux Red Hat 9.0
 Container:   Tomcat 4.127
 DBCP:commons-dbcp-1.2.1.jar, commons-pool-1.2.jar
 JDK:   1.5
 Database:MySQL 4.1
 JDBC Driver:  mysql-connector-java-3.1.7-bin.jar
 
 
 
 public class DBConector {
 
 
 Omited Code/
 
 
 public DBConector(String dataBaseName) {
 
   try{
 String DataBaseURL = jdbc:mysql://+DataBaseHost+/+dataBaseName+
 ?user=+DataBaseUser+password=+DataBasePassword;
 
 mysqlCon = getPooledConection(DataBaseURL);
 sqlStatement = mysqlCon.createStatement();
 
   }
   catch(Exception s) {
 System.err.println(new java.util.Date()+ Error throw by +
  DBConector()\n+s);
   }
 }
 
 
 Omited Code/
 
 
 public ResultSet read(String SQL) {
 
   try{
  rs = sqlStatement.executeQuery( SQL );
}   // Close try
catch(Exception s) {
 System.err.println(new java.util.Date()+ Error throw by an
 SQL  +
 call in DBConector.read() class : \n+s+\n+s.getMessage()+
 \nSQL Queary : +SQL+\n);
}  // Close catch
 
 return(DataFromDB);
 }   // Close the read method
 
 
 
 Omited Code/
 
 
protected static Connection 

RE: [DBCP] Anther lame pool exhausted exception question

2005-07-14 Thread Alfredo Ledezma Melendez


Hello.

Maybe you can use DbUtils class from dbutils project to code less in the finally
clause; methods closeQuietly and close makes this tedious stuff easier.

DataSource ds = ...; // Acquire a reference from JNDI or wherever
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection(); // Or whatever
stmt = conn.prepareStatement(...);
rs = stmt.executeQuery();
... process the results ...
} catch (SQLException e) {
... process the exception ...
} finally {
DbUtils.closeQuietly(rs);
DbUtils.closeQuietly(stmt);
DbUtils.closeQuietly(conn);
}

Even further, you can avoid ResultSet and Statement closing, using methods from
QueryRunner to execute or update a database. Look into documentation, it's
pretty useful.

I hope this help. Regards,

Alfredo Ledezma Meléndez.
Gerencia de Sistemas CRM
Consultor Externo de Sistemas de Atención a Clientes
RadioMovil DIPSA, S. A. de C. V.
Ejército Nacional No. 488, Col. Anahuac, C.P. 11570
México D.F.

-Original Message-
From: Craig McClanahan [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 14, 2005 5:10 PM
To: Jakarta Commons Users List; [EMAIL PROTECTED]
Subject: Re: [DBCP] Anther lame pool exhausted exception question

The key to returning connections to the connection pool is to call
close() on the *connection* itself.  The most common way people get
themselves in trouble is to skip this somehow (perhaps because an
exception is thrown).

To avoid that sort of problem, I tend to use an idiom like this for
JDBC access code:

DataSource ds = ...; // Acquire a reference from JNDI or wherever
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection(); // Or whatever
stmt = conn.prepareStatement(...);
rs = stmt.executeQuery();
... process the results ...
} catch (SQLException e) {
... process the exception ...
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
... record or ignore ...
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
... record or ignore ...
}
rs = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
... record or ignore ...
}
conn = null;
}
}

Courtesy of the finally logic, I'm guaranteed to always execute my
cleanup code, no matter where an exception might get thrown.

You'll note that it can be pretty tedious to do all this stuff with
raw JDBC.  You might also want to look at using one of the SQL
frameworks that encapsulate this sort of stuff, but still give you the
guarantee that the connection will ultimately be returned to the pool.

Craig



On 7/14/05, Brian Cook [EMAIL PROTECTED] wrote:

 I have several apps written that use org.apache.commons.dbcp.  And I am
 getting the  org.apache.commons.dbcp.SQLNestedException: Cannot get a
 connection, pool exhausted exception.

 When I run netstat sure enough it shows about 60 - 100 ESTABLISHED
 connections open at any given time.  Looking deeper it looks like new
 connections are created most but not each time the Java Bean the uses
 the data base is called.  So it seems pretty clear that I am failing to
 close all of the connections in my app.  My problem is that I can not
 find where that is.

 My understanding is that as long as I close every ResultSet, and each
 Connection object I should have my bases covered.  I have gone back
 though the app repeatedly and verified that all the ResultSets,
 Connections, and BasicDataSource objects are all being closed.

 Due to an internal political problem I am not using JNDI for the
 connections.  Instead I have a class file that is called when a
 connection is need. After the object is used a close() method is called
 and closes the Statement, Connection, ResultSet, BasicDataSource objects.

 So my questions are ..

 1.  Is there something else I should be doing to return the
 connections to the pool?
 2.  Does not using JNDI with org.apache.commons.dbcp cause problems
 with closing the connection pool some how?


 I have been though about 6 months of the archives for this list and did
 not find any hints,  I went to look at the examples lnik at on the
 Commons.DBCP page but the link to
 http://cvs.apache.org/downviewcvs.html/jakarta-commons/dbcp/doc/ seems
 to be broken.  Googling has only just returned the usall advice of make
 sure you are closing every connection.

 I am open to any ideas or thoughts to what I am failing to due here.
 Details and the code are included below.


 OS:   

Re: [collections] Name that data structure

2005-07-14 Thread Stephen Colebourne

Wendy Smoak wrote:

I put together a simple example that demonstrates the problem:
http://wiki.wendysmoak.com/cgi-bin/wiki.pl?CircularFifoBuffer

Bug?  Surely I'm not doing anything wrong by calling remove(...) on a
Collection?  (Inefficient though it may be, first I just want to see it
work.)


Your wiki indicates that this is solved in SVN. Is this the case?



Meanwhile, is there another way I can get the buffer to be in the correct
LRU order?  The LRUMap did work, but it's ugly having to put  the empty
String into the Map, when I don't need key/value pairs.


Our only LRU implementation is LRUMap at present.

Stephen

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



Re: [collections] Name that data structure

2005-07-14 Thread Wendy Smoak

From: Stephen Colebourne [EMAIL PROTECTED]


Your wiki indicates that this is solved in SVN. Is this the case?


It looks like it.  I only got as far as creating the test case and seeing it
NOT fail.  (After I posted the original message.)  I need the LRU behavior,
though, so I don't think CircularFifoBuffer is really going to do it.

I'll probably go back to LRUMap; it beats having to write and maintain it
myself. :)

Thanks,
Wendy Smoak



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