Sean's static connection pool actually gave me an idea of
doing the same sort of thing for schemas, so that DataSources
created during the same jvm session could just look to see if
someone else already went through the trouble to make the
schema. The other alternative is one that used to be in
postgis, namely a constructor that takes a schema as an
argument. I did away with it because it ended up being a
hacky way to do getProperties, as you could pass in an
abbreviated schema (geoserver worked this way before I got
the Query object in geotools). But yes, if we were to do
that, and with the connection pooling, it seems like it would
be nice to just have one getDataSource() function in
TypeInfo, as geotools would be handling things well enough
that GeoServer doesn't have to micro-manage what's going on.
Oh wait, actually the second option wouldn't work by itself,
as GeoServer requests things through the DataSourceFinder,
which can't use the schema constructor. But perhaps the
DataSourceFactory could have a Singleton holding on to
schemas or datasources?
I think the singleton FeatureType cache in the DataSourceFactory is probably a good idea and it should improve performance for most applications. We should probably make sure the constructor in the datasource that takes the schema is package private though. That way we know that the schema comes from a "trusted" source and we can forego verifying it, which would eliminate any performance improvement.
Actually, the OracleDataSource constructor also constructs a few oracle specific objects aswell, which could prove to be a pain. Im not sure if this method would work with it. An alternative would be to move a lot of the database query work to another class, possibly and InnerClass and the OracleDataSource would be more like an adapter between this other class and the DataSource interface. The OracleDataSource could store multiple instances of this class and pass request of to it. Hrmm that might not work either, since there is to way of knowing whether a transaction is coming from a different source.
Perhap my best solution would be to move the "state" of the DataSource into a separate object and then cache that new OracleDataSourceState object in the OracleDataSourceFactory.
Sean