1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.dao.jdbc.pool.c3p0;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.util.PropsUtil;
21  
22  import com.mchange.v2.c3p0.ConnectionCustomizer;
23  
24  import java.sql.Connection;
25  
26  /**
27   * <a href="PortalConnectionCustomizer.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PortalConnectionCustomizer implements ConnectionCustomizer {
32  
33      public void onAcquire(
34              Connection connection, String parentDataSourceIdentityToken)
35          throws Exception {
36  
37          if (_log.isDebugEnabled()) {
38              _log.debug("JDBC property prefix " + parentDataSourceIdentityToken);
39          }
40  
41          String transactionIsolation = PropsUtil.get(
42              parentDataSourceIdentityToken + "transactionIsolation");
43  
44          if (_log.isDebugEnabled()) {
45              _log.debug("Custom transaction isolation " + transactionIsolation);
46          }
47  
48          if (transactionIsolation != null) {
49              connection.setTransactionIsolation(
50                  GetterUtil.getInteger(transactionIsolation));
51          }
52      }
53  
54      public void onCheckIn(
55          Connection connection, String parentDataSourceIdentityToken) {
56      }
57  
58      public void onCheckOut(
59          Connection connection, String parentDataSourceIdentityToken) {
60      }
61  
62      public void onDestroy(
63          Connection connection, String parentDataSourceIdentityToken) {
64      }
65  
66      private static Log _log = LogFactoryUtil.getLog(
67          PortalConnectionCustomizer.class);
68  
69  }