All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.akquinet.jbosscc.guttenbase.connector.impl.AbstractURLConnector Maven / Gradle / Ivy

The newest version!
package de.akquinet.jbosscc.guttenbase.connector.impl;

import de.akquinet.jbosscc.guttenbase.repository.ConnectorRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Connection info via explicit URL and driver.
 *
 * 

* © 2012-2034 akquinet tech@spree *

* * @author M. Dahm */ public abstract class AbstractURLConnector extends AbstractConnector { protected static final Logger LOG = LoggerFactory.getLogger(AbstractURLConnector.class); private final URLConnectorInfo _urlConnectionInfo; public AbstractURLConnector(final ConnectorRepository connectorRepository, final String connectorId, final URLConnectorInfo urlConnectionInfo) { super(connectorRepository, connectorId, urlConnectionInfo); assert urlConnectionInfo != null : "urlConnectionInfo != null"; _urlConnectionInfo = urlConnectionInfo; } /** * {@inheritDoc} */ @Override public Connection openConnection() throws SQLException { if (_connection == null || _connection.isClosed()) { try { Class.forName(_urlConnectionInfo.getDriver()).getDeclaredConstructor().newInstance(); } catch (final Exception e) { LOG.error("JDBC driver not found", e); throw new SQLException("Creating JDBC driver", e); } _connection = DriverManager .getConnection(_urlConnectionInfo.getUrl(), _urlConnectionInfo.getUser(), _urlConnectionInfo.getPassword()); } return _connection; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy