001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.dao.jdbc.pool.c3p0;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.util.PropsUtil;
021    
022    import com.mchange.v2.c3p0.ConnectionCustomizer;
023    
024    import java.sql.Connection;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PortalConnectionCustomizer implements ConnectionCustomizer {
030    
031            @Override
032            public void onAcquire(
033                            Connection connection, String parentDataSourceIdentityToken)
034                    throws Exception {
035    
036                    if (_log.isDebugEnabled()) {
037                            _log.debug("JDBC property prefix " + parentDataSourceIdentityToken);
038                    }
039    
040                    String transactionIsolation = PropsUtil.get(
041                            parentDataSourceIdentityToken + "transactionIsolation");
042    
043                    if (_log.isDebugEnabled()) {
044                            _log.debug("Custom transaction isolation " + transactionIsolation);
045                    }
046    
047                    if (transactionIsolation != null) {
048                            connection.setTransactionIsolation(
049                                    GetterUtil.getInteger(transactionIsolation));
050                    }
051            }
052    
053            @Override
054            public void onCheckIn(
055                    Connection connection, String parentDataSourceIdentityToken) {
056            }
057    
058            @Override
059            public void onCheckOut(
060                    Connection connection, String parentDataSourceIdentityToken) {
061            }
062    
063            @Override
064            public void onDestroy(
065                    Connection connection, String parentDataSourceIdentityToken) {
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    PortalConnectionCustomizer.class);
070    
071    }