DataStores use an internal connection pool; they are heavy weight objects and 
must be reused (and don't create duplicates talking to the same service).

We offer some help for managing DataStores in your application in the form of 
the "Repository" shown here:
- http://docs.geotools.org/latest/userguide/library/main/repository.html

We have found however that most apps create their own (example uDig and 
GeoServer both use a "catalog" to track their datastores and ensure they are 
correctly disposed).

Tips:
- For small apps you could also just use a singleton (as shown on the above 
page).
- In an application server you can configure a datastore to use a connection 
pool configured by the server admin (often available through a JNDI lookup).

-- 
Jody Garnett


On Friday, 10 June 2011 at 10:22 PM, Matthias Lendholt wrote:

> Hi all,
> 
> I'm running into postgis/postgres connectivity problems when directly 
> one after another two postgis datastores to the same table (same db, 
> same schema) are opened. This error does not happen if I wait some 
> seconds in between.
> 
> The error message is in German
> "Caused by: org.postgresql.util.PSQLException: Verbindung verweigert. 
> Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass 
> der Datenbankserver TCP/IP-Verbindungen annimmt."
> 
> it means that the connection is blocked and I should check hostname and 
> port. And I should check whether the DB server accepts the tcp/ip 
> connection. However the first connection works and if I wait some time 
> it works again.
> 
> 
> Caused by: java.net.ConnectException: Connection refused: connect
> 
> Do you think it's a fault on the db/server side or on my Windows 7 
> client? Are there any static objects in postgis datastore which force me 
> to re-use datastores?
> 
> Thanks,
> Matthias
> 
> 
> 
> 10.06.2011 13:56:03 
> org.geotools.referencing.factory.epsg.ThreadedPostgreSQLEpsgFactory 
> isAvailable
> WARNUNG: Unavailable authority factory: European Petroleum Survey Group
> org.opengis.referencing.FactoryException: Failed to connect to the EPSG 
> database.
>  at 
> org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:420)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:130)
>  at 
> org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:233)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:117)
>  at 
> org.geotools.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:668)
>  at 
> org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:500)
>  at 
> org.geotools.factory.FactoryRegistry$1.filter(FactoryRegistry.java:191)
>  at javax.imageio.spi.FilterIterator.advance(Unknown Source)
>  at javax.imageio.spi.FilterIterator.<init>(Unknown Source)
>  at javax.imageio.spi.ServiceRegistry.getServiceProviders(Unknown 
> Source)
>  at 
> org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:196)
>  at 
> org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:176)
>  at 
> org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:451)
>  at 
> org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:88)
>  at 
> org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:69)
>  at org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:199)
>  at org.geotools.referencing.CRS.decode(CRS.java:437)
>  at org.geotools.referencing.CRS.decode(CRS.java:365)
>  at org.geotools.jdbc.SQLDialect.createCRS(SQLDialect.java:530)
>  at 
> org.geotools.jdbc.JDBCFeatureSource.buildFeatureType(JDBCFeatureSource.java:299)
>  at 
> org.geotools.jdbc.JDBCDataStore.createFeatureSource(JDBCDataStore.java:712)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:383)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:348)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:101)
>  at 
> org.fosslab.wps.gcap.util.FeatureCollectionFactory.getFeatureCollectionFromPostgis(FeatureCollectionFactory.java:166)
>  at 
> org.fosslab.wps.gcap.internal.ConfigurationManager.getFeature(ConfigurationManager.java:165)
>  at 
> org.fosslab.wps.gcap.processes.ReturnGeometry.process(ReturnGeometry.java:106)
>  at 
> org.fosslab.wps.gcap.processes.ReturnGeometry.process(ReturnGeometry.java:88)
>  at 
> org.fosslab.wps.gcap.test.ReturnGeometryTest.testLevel1HASC1PLAKANOPostgis(ReturnGeometryTest.java:71)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>  at java.lang.reflect.Method.invoke(Unknown Source)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>  at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
>  at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.postgresql.util.PSQLException: Verbindung verweigert. 
> Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass 
> der Datenbankserver TCP/IP-Verbindungen annimmt.
>  at 
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
>  at 
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>  at 
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
>  at 
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>  at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>  at org.postgresql.Driver.makeConnection(Driver.java:393)
>  at org.postgresql.Driver.connect(Driver.java:267)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at 
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:87)
>  at 
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:70)
>  at 
> org.geotools.referencing.factory.epsg.DirectEpsgFactory.getConnection(DirectEpsgFactory.java:3077)
>  at 
> org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:415)
>  ... 50 more
> Caused by: java.net.ConnectException: Connection refused: connect
>  at java.net.PlainSocketImpl.socketConnect(Native Method)
>  at java.net.PlainSocketImpl.doConnect(Unknown Source)
>  at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
>  at java.net.PlainSocketImpl.connect(Unknown Source)
>  at java.net.SocksSocketImpl.connect(Unknown Source)
>  at java.net.Socket.connect(Unknown Source)
>  at java.net.Socket.connect(Unknown Source)
>  at java.net.Socket.<init>(Unknown Source)
>  at java.net.Socket.<init>(Unknown Source)
>  at org.postgresql.core.PGStream.<init>(PGStream.java:62)
>  at 
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
>  ... 62 more
> 10.06.2011 13:56:06 
> org.geotools.referencing.factory.epsg.ThreadedPostgreSQLEpsgFactory 
> isAvailable
> WARNUNG: Unavailable authority factory: European Petroleum Survey Group
> org.opengis.referencing.FactoryException: Failed to connect to the EPSG 
> database.
>  at 
> org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:420)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:130)
>  at 
> org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:233)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:117)
>  at 
> org.geotools.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:668)
>  at 
> org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:500)
>  at 
> org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:436)
>  at 
> org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:364)
>  at 
> org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:143)
>  at 
> org.geotools.referencing.ReferencingFactoryFinder.getAuthorityFactory(ReferencingFactoryFinder.java:216)
>  at 
> org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactory(ReferencingFactoryFinder.java:436)
>  at 
> org.geotools.referencing.factory.epsg.LongitudeFirstFactory.createBackingStore(LongitudeFirstFactory.java:189)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:130)
>  at 
> org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:233)
>  at 
> org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:117)
>  at 
> org.geotools.factory.FactoryRegistry.isAvailable(FactoryRegistry.java:668)
>  at 
> org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:500)
>  at 
> org.geotools.factory.FactoryRegistry$1.filter(FactoryRegistry.java:191)
>  at javax.imageio.spi.FilterIterator.advance(Unknown Source)
>  at javax.imageio.spi.FilterIterator.next(Unknown Source)
>  at org.geotools.resources.LazySet.addNext(LazySet.java:70)
>  at org.geotools.resources.LazySet.get(LazySet.java:120)
>  at org.geotools.resources.LazySet$Iter.next(LazySet.java:139)
>  at 
> org.geotools.referencing.factory.ManyAuthoritiesFactory.<init>(ManyAuthoritiesFactory.java:118)
>  at 
> org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:116)
>  at 
> org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:69)
>  at org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:199)
>  at org.geotools.referencing.CRS.decode(CRS.java:437)
>  at org.geotools.referencing.CRS.decode(CRS.java:365)
>  at org.geotools.jdbc.SQLDialect.createCRS(SQLDialect.java:530)
>  at 
> org.geotools.jdbc.JDBCFeatureSource.buildFeatureType(JDBCFeatureSource.java:299)
>  at 
> org.geotools.jdbc.JDBCDataStore.createFeatureSource(JDBCDataStore.java:712)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:383)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:348)
>  at 
> org.geotools.data.store.ContentDataStore.getFeatureSource(ContentDataStore.java:101)
>  at 
> org.fosslab.wps.gcap.util.FeatureCollectionFactory.getFeatureCollectionFromPostgis(FeatureCollectionFactory.java:166)
>  at 
> org.fosslab.wps.gcap.internal.ConfigurationManager.getFeature(ConfigurationManager.java:165)
>  at 
> org.fosslab.wps.gcap.processes.ReturnGeometry.process(ReturnGeometry.java:106)
>  at 
> org.fosslab.wps.gcap.processes.ReturnGeometry.process(ReturnGeometry.java:88)
>  at 
> org.fosslab.wps.gcap.test.ReturnGeometryTest.testLevel1HASC1PLAKANOPostgis(ReturnGeometryTest.java:71)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>  at java.lang.reflect.Method.invoke(Unknown Source)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>  at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
>  at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>  at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.postgresql.util.PSQLException: Verbindung verweigert. 
> Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass 
> der Datenbankserver TCP/IP-Verbindungen annimmt.
>  at 
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
>  at 
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>  at 
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
>  at 
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>  at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>  at org.postgresql.Driver.makeConnection(Driver.java:393)
>  at org.postgresql.Driver.connect(Driver.java:267)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at 
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:87)
>  at 
> org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:70)
>  at 
> org.geotools.referencing.factory.epsg.DirectEpsgFactory.getConnection(DirectEpsgFactory.java:3077)
>  at 
> org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:415)
>  ... 61 more
> Caused by: java.net.ConnectException: Connection refused: connect
>  at java.net.PlainSocketImpl.socketConnect(Native Method)
>  at java.net.PlainSocketImpl.doConnect(Unknown Source)
>  at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
>  at java.net.PlainSocketImpl.connect(Unknown Source)
>  at java.net.SocksSocketImpl.connect(Unknown Source)
>  at java.net.Socket.connect(Unknown Source)
>  at java.net.Socket.connect(Unknown Source)
>  at java.net.Socket.<init>(Unknown Source)
>  at java.net.Socket.<init>(Unknown Source)
>  at org.postgresql.core.PGStream.<init>(PGStream.java:62)
>  at 
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
>  ... 73 more
> 
> -- 
> [[email protected] (mailto:[email protected])]
> GFZ German Research Centre for Geosciences
> CeGIT Centre for GeoInformation Technology
> Tel +49 331 288-1687; FAX +49 331 288-1703
> Telegrafenberg A20, 14473 Potsdam, Germany
> Blog http://zeigertelegraph.gfz-potsdam.de
> Contact MECARD QR Code: http://goo.gl/488J
> 
> ------------------------------------------------------------------------------
> EditLive Enterprise is the world's most technically advanced content
> authoring tool. Experience the power of Track Changes, Inline Image
> Editing and ensure content is compliant with Accessibility Checking.
> http://p.sf.net/sfu/ephox-dev2dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected] 
> (mailto:[email protected])
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to