2 * Copyright 2000-2018 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.data.util.sqlcontainer.connection;
18 import java.sql.Connection;
19 import java.sql.SQLException;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
23 import javax.naming.InitialContext;
24 import javax.naming.NamingException;
25 import javax.sql.DataSource;
28 * @deprecated As of 8.0, no replacement available.
31 public class J2EEConnectionPool implements JDBCConnectionPool {
33 private String dataSourceJndiName;
35 private DataSource dataSource = null;
37 public J2EEConnectionPool(DataSource dataSource) {
38 this.dataSource = dataSource;
41 public J2EEConnectionPool(String dataSourceJndiName) {
42 this.dataSourceJndiName = dataSourceJndiName;
46 public Connection reserveConnection() throws SQLException {
47 Connection conn = getDataSource().getConnection();
48 conn.setAutoCommit(false);
53 private DataSource getDataSource() throws SQLException {
54 if (dataSource == null) {
55 dataSource = lookupDataSource();
60 private DataSource lookupDataSource() throws SQLException {
62 InitialContext ic = new InitialContext();
63 return (DataSource) ic.lookup(dataSourceJndiName);
64 } catch (NamingException e) {
65 throw new SQLException(
66 "NamingException - Cannot connect to the database. Cause: "
72 public void releaseConnection(Connection conn) {
76 } catch (SQLException e) {
77 Logger.getLogger(J2EEConnectionPool.class.getName())
78 .log(Level.FINE, "Could not release SQL connection", e);
84 public void destroy() {