I ended up resolving the issue.

https://github.com/dewthefifth/java-examples/tree/master/postgis-deadlock has a 
sample project demonstrating the features.

The short answer is that if you include the "required" parameters with 
basically any value it will make it past the "required" checks and the move 
forward to using the provided DataSource. The only parameter I wasn't able to 
set to an empty String "" was the port parameter, which had to be numeric.

Also a little unexpected, the method I used to write my SimpleFeatures 
complained about my primary key until I added "Expose primary keys" as true. 
I'm not actually sure how I'd be expected to write objects without the property 
set to true, and even reading might get complicated.

As a future enhancement to how this works, which I'd be willing to take a stab 
at, you might want to consider a PostgisNGBYODataSourceDataStoreFactory 
implementation which functions similar to the PostgisNGJNDIDataStoreFactory 
(JDBCJNDIDataStoreFactory), which has a different set of required parameters.

-Duane

From: Duane Zamrok [mailto:zam...@cubrc.org]
Sent: Monday, April 23, 2018 6:39 PM
To: 'GeoTools-GT2-Users@lists.sourceforge.net' 
<GeoTools-GT2-Users@lists.sourceforge.net>
Subject: [Geotools-gt2-users] JDBC BYO DataSource

I'm trying to connect to a PostGIS database using a DataSource that I've 
already configured using my preferred connection pooling method, connection 
driver, etc.

http://docs.geotools.org/stable/userguide/library/jdbc/datastore.html seems 
imply that it's possible and
http://docs.geotools.org/latest/userguide/welcome/javaEE.html comes right out 
and says it can be done

DataStoreFinder#getAvailableDataStores returns the following results
- 
org.geotools.data.postgis.PostgisNGDataStoreFactory@10ee04df=java.lang.Object@3e7545e8<mailto:org.geotools.data.postgis.PostgisNGDataStoreFactory@10ee04df=java.lang.Object@3e7545e8>
- 
org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory@6b667cb3=java.lang.Object@3e7545e8<mailto:org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory@6b667cb3=java.lang.Object@3e7545e8>

The problem comes down that, when iterating through the 
PostgisNGDataStoreFactory "hostname", "port", etc are considered to be 
"required" parameters. Instead of returning a DataStore backed by my 
DataSource, the DataStoreFinder effectively reports that none of my DataStores 
are appropriate for my connection.

// Attempted connection code
private DataStore createDataStore(DataSource dataSource)
{
               try
               {
                              Map<String, Object> parameters = new HashMap<>();
                              parameters.put("Data Source", dataSource);
                              parameters.put("dbtype", "postgis");

                              // This returns null :(
                              return DataStoreFinder.getDataStore(parameters);
               } catch (IOException e)
               {
                              LOG.error("Exception thrown initializing 
DataStore", e);
                              throw new IllegalStateException(e);
               }
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to