> > Then you can call to that methods from all the locations you want and
> > don't need to worry about serialization.
> >
> 
> For GenericDataSource itself, I was not planning on changing anything -- the
> remainder of the class cannot be serialized because of the
> Connections themselves cannot be serialized.

But the when it get's serialized (with externalizeable) the connections that are open
don't get's serialized also, but the are being closed.
After deserializing the connections are made again (just as they would when the 
datasource
was fist made). Alle the properties are just strings so perfectly serializeable.

I have attached an implementation.

Here are the 2 new methods:

The read in:

public void readExternal(java.io.ObjectInput in) throws java.io.IOException, 
java.lang.ClassNotFoundException {
 driverClass = (String)in.readObject();
 url = (String)in.readObject();
 user = (String)in.readObject();
 password = (String)in.readObject();
 properties = (Properties)in.readObject();
 description = (String)in.readObject();
 maxCount = in.readInt();
 minCount = in.readInt();
 loginTimeout = in.readInt();
 readOnly = in.readBoolean();
 autoCommit = in.readBoolean();
 closed = in.readBoolean();
 if(!closed) {
  try  {
   open();
  } catch(SQLException ex)  {
   // what to do with it when an exeption does occur?
  }
 }
 // WHAT TO DO WITH IT???
 //protected PrintWriter logWriter = null;
}

The writer out:
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
 if(useCount > 0) {
  //What to do now exactly? (Because there are connections being used!)
  //for now just throwing NotSerializableException 
  throw new java.io.NotSerializableException("GenericDataSource");
 }
 out.writeObject(driverClass);
 out.writeObject(url);
 out.writeObject(user);
 out.writeObject(password);
 out.writeObject(properties);
 out.writeObject(description);
 out.writeInt(maxCount);
 out.writeInt(minCount);
 out.writeInt(loginTimeout);
 out.writeBoolean(readOnly);
 out.writeBoolean(autoCommit);
 out.writeBoolean(closed);
 if(!closed) {
  try  {
   close();
  } catch(SQLException ex)  {
   // what to do with it when an exeption does occur?
  }
 }
 // WHAT TO DO WITH IT???
 //protected PrintWriter logWriter = null;
}

Please comment on it if this absolutly doesn't work.
There are only 2 real exceptions/problems:
The PrintWriter and what 2 do when the useCount > 0 when it want to serialize.

I really thing this should be implemented because i can't say to my customers you must
use that or you must use this. So i must use a GenericDataSource (or something like 
that)
But maybe they have a Container that wants all objects to be serializeable so 
DataSource is at this
time, only then there are maybe some cases that must be thought through when deploying 
them on such
a container.

Johan C.





GenericDataSource.java

Reply via email to