/activeobjects-plugin/src/main/java/com/atlassian/activeobjects/internal/DriverNameExtractorImpl.java

https://bitbucket.org/activeobjects/ao-plugin · Java · 31 lines · 27 code · 4 blank · 0 comment · 2 complexity · 4aac721fe6d78b8276d552ad8877f2bb MD5 · raw file

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