001    /**
002     * Copyright (c) 2000-2011 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            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    }