From: <bu...@me...> - 2007-05-30 22:09:37
|
Hi Jody, My soultion is to enclose only the canProcess() in a try-catch block, and save the result of it in a boolean variable. Then decide wether a factory can handle a specific db based on the value of this boolean. But a few lines of code tells more than tousand words: while (ps.hasNext()) { fac = (DataStoreFactorySpi) ps.next(); boolean canProcess = false; try { canProcess = fac.canProcess(params); } catch (Throwable t) { /** The logger for the filter module. */ LOGGER.log( Level.WARNING, "Could not acquire "+fac.getDescription()+":"+t, t ); // Protect against DataStores that don't carefully // code canProcess continue; } if (canProcess) { return fac.createDataStore(params); } } This way an exception from canProcess() is silently ignored, but a real connection error is thrown back to the caller. Best, Peter PS: attached is the same as a patch against SVN head. Jody Garnett írta: > Thanks Peter - or rather good "catch" > > Can you cut and paste the modified code for me? I would be happy to > review and think about this change. > We do have a common problem where data store implementors say they > canProcess, but then they really cannot. This has resulted in a very > unhappy GeoServer community on occasion. > > If I understand the need: > - you would like a decent failure reported when you cannot connect > - we cannot afford to let a single bad apple ruin the batch > Jody >> Hi! >> >> In the SVN HEAD version DataStoreFinder.getDataStore(...) the whole >> canProcess(...), createDataStore(...) cycle is in a try {} >> catch(Throwable t) block. This way if a DataStore can handle a type of >> database, but fails to open it (e.g. corrupt db file) no exception is >> thrown, only a debug message is logged. This contradicts with the >> javadoc, which says that an IOException is thrown "If a suitable >> loader can be found, but it can not be attached to the specified >> resource without errors." And even the comment in the catch block >> states that it "Protect against DataStores that don't carefully code >> canProcess". >> >> I modifyed my copy in a way that only the canProcess(..) is in a >> try-catch block, but I think the SVN version should be modified also. >> The same allpies to FileDataStoreFinder also. >> >> Greetings, >> Peter >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geo...@li... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > > |