* @param sDataSource The data source name.
* @return false if a SQL connection could not be obtained
*/
public static void testConnection(Metadata metadata, String sDataSource) throws SQLException
{
InvocationContext context = null;
Context contextSaved = ThreadContextHolder.getContext();
try
{
DataSource db = metadata.getDataSource(sDataSource);
Component comp = metadata.findComponent("System.InvocationContext");
context = (comp != null) ? (InvocationContext)comp.getInstance(null) : new InvocationContext(metadata);
context.initialize(null);
context.setLocale(Locale.getDefault());
context.setProtected(false);
context.setSecure(false);
context.setPartitioned(false);
for (Iterator itr = db.getFragmentIterator(); itr.hasNext();)
{
Object o = itr.next();
if (o instanceof RelationalDatabaseFragment)
{
((SQLConnectionFactory)((RelationalDatabaseFragment)o).getConnectionFactory().getInstance(context))
.getConnection(null).close();
}
}
}
finally
{
if (context != null)
{
context.complete(false);
}
ThreadContextHolder.setContext(contextSaved);
}
}