Connects to a Database.
()
| 42 | * Connects to a Database. |
| 43 | */ |
| 44 | protected synchronized Connection openConnection() throws NoConnectionException { |
| 45 | try { |
| 46 | try { |
| 47 | if (connection != null) { |
| 48 | closeConnection(); |
| 49 | } |
| 50 | } catch (Exception ignored) { |
| 51 | } |
| 52 | getLogger().debug("Connecting to " + databaseConfiguration); |
| 53 | Class.forName(databaseConfiguration.getDriver()); |
| 54 | Connection conn = databaseConfiguration.getConnection(); |
| 55 | getLogger().debug("Connected to Database!"); |
| 56 | connected = true; |
| 57 | return this.connection = conn; |
| 58 | } catch (Exception e) { |
| 59 | throw new NoConnectionException("Could not connect to " + databaseConfiguration, e); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | public <T> SQLQuery<T> get(Class<T> entity) { |
| 64 | return new SQLQuery<T>(this, entity); |
no test coverage detected