001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            public void onAcquire(
032                            Connection connection, String parentDataSourceIdentityToken)
033                    throws Exception {
034    
035                    if (_log.isDebugEnabled()) {
036                            _log.debug("JDBC property prefix " + parentDataSourceIdentityToken);
037                    }
038    
039                    String transactionIsolation = PropsUtil.get(
040                            parentDataSourceIdentityToken + "transactionIsolation");
041    
042                    if (_log.isDebugEnabled()) {
043                            _log.debug("Custom transaction isolation " + transactionIsolation);
044                    }
045    
046                    if (transactionIsolation != null) {
047                            connection.setTransactionIsolation(
048                                    GetterUtil.getInteger(transactionIsolation));
049                    }
050            }
051    
052            public void onCheckIn(
053                    Connection connection, String parentDataSourceIdentityToken) {
054            }
055    
056            public void onCheckOut(
057                    Connection connection, String parentDataSourceIdentityToken) {
058            }
059    
060            public void onDestroy(
061                    Connection connection, String parentDataSourceIdentityToken) {
062            }
063    
064            private static Log _log = LogFactoryUtil.getLog(
065                    PortalConnectionCustomizer.class);
066    
067    }