1 package com.atlassian.activeobjects.internal;
2
3 import net.java.ao.ActiveObjectsException;
4
5 import javax.sql.DataSource;
6 import java.sql.Connection;
7 import java.sql.SQLException;
8
9 public final class DriverNameExtractorImpl implements DriverNameExtractor {
10 public String getDriverName(final DataSource dataSource) {
11 Connection connection = null;
12 try {
13 connection = dataSource.getConnection();
14 return connection.getMetaData().getDriverName();
15 } catch (SQLException e) {
16 throw new ActiveObjectsException(e);
17 } finally {
18 closeQuietly(connection);
19 }
20 }
21
22 private static void closeQuietly(Connection connection) {
23 try {
24 if (connection != null) {
25 connection.close();
26 }
27 } catch (SQLException e) {
28 throw new RuntimeException(e);
29 }
30 }
31 }