<commit_before>/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.tomcat.jdbc.pool.jmx;
/**
 * @author <NAME>
 */
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;

import javax.management.DynamicMBean;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;

import org.apache.tomcat.jdbc.pool.JdbcInterceptor;

public class ConnectionPool extends NotificationBroadcasterSupport implements ConnectionPoolMBean  {
    protected org.apache.tomcat.jdbc.pool.ConnectionPool pool = null;
    protected AtomicInteger sequence = new AtomicInteger(0);

    public ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool pool) {
        super(getDefaultNotificationInfo());
        this.pool = pool;
    }

    public org.apache.tomcat.jdbc.pool.ConnectionPool getPool() {
        return pool;
    }
    
    //=================================================================
    //       NOTIFICATION INFO
    //=================================================================
    public static final String NOTIFY_INIT = "INIT FAILED";
    public static final String NOTIFY_CONNECT = "CONNECTION FAILED";
    public static final String NOTIFY_ABANDON = "CONNECTION ABANDONED";
    
    
    
    @Override 
    public MBeanNotificationInfo[] getNotificationInfo() { 
        return getDefaultNotificationInfo(); 
    }
    
    public static MBeanNotificationInfo[] getDefaultNotificationInfo() {
        String[] types = new String[] {NOTIFY_INIT, NOTIFY_CONNECT, NOTIFY_ABANDON}; 
        String name = Notification.class.getName(); 
        String description = "A connection pool error condition was met."; 
        MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description); 
        return new MBeanNotificationInfo[] {info};
    }
    
    public void notify(final String type, String message) {
        Notification n = new Notification(
            type,
            this,
            sequence.incrementAndGet(),
            System.currentTimeMillis(),
            message!=null?message:"");
        sendNotification(n);
    }
    
    //=================================================================
    //       POOL STATS
    //=================================================================

    public int getSize() {
        return pool.getSize();
    }

    public int getIdle() {
        return pool.getIdle();
    }

    public int getActive() {
        return pool.getActive();
    }
    
    public boolean isPoolSweeperEnabled() {
        return pool.getPoolProperties().isPoolSweeperEnabled();
    }

    //=================================================================
    //       POOL OPERATIONS
    //=================================================================
    public void checkIdle() {
        pool.checkIdle();
    }

    public void checkAbandoned() {
        pool.checkAbandoned();
    }

    public void testIdle() {
        pool.testAllIdle();
    }
    //=================================================================
    //       POOL PROPERTIES
    //=================================================================
    public Properties getDbProperties() {
        return pool.getPoolProperties().getDbProperties();
    }
    public String getUrl() {
        return pool.getPoolProperties().getUrl();
    }
    public String getDriverClassName() {
        return pool.getPoolProperties().getDriverClassName();
    }
    public boolean isDefaultAutoCommit() {
        return pool.getPoolProperties().isDefaultAutoCommit();
    }
    public boolean isDefaultReadOnly() {
        return pool.getPoolProperties().isDefaultReadOnly();
    }
    public int getDefaultTransactionIsolation() {
        return pool.getPoolProperties().getDefaultTransactionIsolation();
    }
    public String getConnectionProperties() {
        return pool.getPoolProperties().getConnectionProperties();
    }
    public String getDefaultCatalog() {
        return pool.getPoolProperties().getDefaultCatalog();
    }
    public int getInitialSize() {
        return pool.getPoolProperties().getInitialSize();
    }
    public int getMaxActive() {
        return pool.getPoolProperties().getMaxActive();
    }
    public int getMaxIdle() {
        return pool.getPoolProperties().getMaxIdle();
    }
    public int getMinIdle() {
        return pool.getPoolProperties().getMinIdle();
    }
    public int getMaxWait() {
        return pool.getPoolProperties().getMaxWait();
    }
    public String getValidationQuery() {
        return pool.getPoolProperties().getValidationQuery();
    }
    public boolean isTestOnBorrow() {
        return pool.getPoolProperties().isTestOnBorrow();
    }
    public boolean isTestOnReturn() {
        return pool.getPoolProperties().isTestOnReturn();
    }
    public boolean isTestWhileIdle() {
        return pool.getPoolProperties().isTestWhileIdle();
    }
    public int getTimeBetweenEvictionRunsMillis() {
        return pool.getPoolProperties().getTimeBetweenEvictionRunsMillis();
    }
    public int getNumTestsPerEvictionRun() {
        return pool.getPoolProperties().getNumTestsPerEvictionRun();
    }
    public int getMinEvictableIdleTimeMillis() {
        return pool.getPoolProperties().getMinEvictableIdleTimeMillis();
    }
    public boolean isAccessToUnderlyingConnectionAllowed() {
        return pool.getPoolProperties().isAccessToUnderlyingConnectionAllowed();
    }
    public boolean isRemoveAbandoned() {
        return pool.getPoolProperties().isRemoveAbandoned();
    }
    public int getRemoveAbandonedTimeout() {
        return pool.getPoolProperties().getRemoveAbandonedTimeout();
    }
    public boolean isLogAbandoned() {
        return pool.getPoolProperties().isLogAbandoned();
    }
    public int getLoginTimeout() {
        return pool.getPoolProperties().getLoginTimeout();
    }
    public String getName() {
        return pool.getPoolProperties().getName();
    }
    public String getPassword() {
        return pool.getPoolProperties().getPassword();
    }
    public String getUsername() {
        return pool.getPoolProperties().getUsername();
    }
    public long getValidationInterval() {
        return pool.getPoolProperties().getValidationInterval();
    }
    public String getInitSQL() {
        return pool.getPoolProperties().getInitSQL();
    }
    public boolean isTestOnConnect() {
        return pool.getPoolProperties().isTestOnConnect();
    }
    public String getJdbcInterceptors() {
        return pool.getPoolProperties().getJdbcInterceptors();
    }

}
<commit_msg>Catch any exceptions since we don't handle them later in the chain<commit_after>/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.tomcat.jdbc.pool.jmx;
/**
 * @author <NAME>
 */
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;

import javax.management.DynamicMBean;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.JdbcInterceptor;

public class ConnectionPool extends NotificationBroadcasterSupport implements ConnectionPoolMBean  {
    //logger
    protected static Log log = LogFactory.getLog(ConnectionPool.class);

    protected org.apache.tomcat.jdbc.pool.ConnectionPool pool = null;
    protected AtomicInteger sequence = new AtomicInteger(0);

    public ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool pool) {
        super(getDefaultNotificationInfo());
        this.pool = pool;
    }

    public org.apache.tomcat.jdbc.pool.ConnectionPool getPool() {
        return pool;
    }
    
    //=================================================================
    //       NOTIFICATION INFO
    //=================================================================
    public static final String NOTIFY_INIT = "INIT FAILED";
    public static final String NOTIFY_CONNECT = "CONNECTION FAILED";
    public static final String NOTIFY_ABANDON = "CONNECTION ABANDONED";
    
    
    
    @Override 
    public MBeanNotificationInfo[] getNotificationInfo() { 
        return getDefaultNotificationInfo(); 
    }
    
    public static MBeanNotificationInfo[] getDefaultNotificationInfo() {
        String[] types = new String[] {NOTIFY_INIT, NOTIFY_CONNECT, NOTIFY_ABANDON}; 
        String name = Notification.class.getName(); 
        String description = "A connection pool error condition was met."; 
        MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description); 
        return new MBeanNotificationInfo[] {info};
    }
    
    /**
     * Return true if the notification was sent successfully, false otherwise.
     * @param type
     * @param message
     * @return
     */
    public boolean notify(final String type, String message) {
        try {
            Notification n = new Notification(
                    type,
                    this,
                    sequence.incrementAndGet(),
                    System.currentTimeMillis(),
                    message!=null?message:"");
            sendNotification(n);
            return true;
        }catch (Exception x) {
            if (log.isDebugEnabled()) {
                log.debug("Notify failed. Type="+type+"; Message="+message,x);
            }
            return false;
        }
        
    }
    
    //=================================================================
    //       POOL STATS
    //=================================================================

    public int getSize() {
        return pool.getSize();
    }

    public int getIdle() {
        return pool.getIdle();
    }

    public int getActive() {
        return pool.getActive();
    }
    
    public boolean isPoolSweeperEnabled() {
        return pool.getPoolProperties().isPoolSweeperEnabled();
    }

    //=================================================================
    //       POOL OPERATIONS
    //=================================================================
    public void checkIdle() {
        pool.checkIdle();
    }

    public void checkAbandoned() {
        pool.checkAbandoned();
    }

    public void testIdle() {
        pool.testAllIdle();
    }
    //=================================================================
    //       POOL PROPERTIES
    //=================================================================
    public Properties getDbProperties() {
        return pool.getPoolProperties().getDbProperties();
    }
    public String getUrl() {
        return pool.getPoolProperties().getUrl();
    }
    public String getDriverClassName() {
        return pool.getPoolProperties().getDriverClassName();
    }
    public boolean isDefaultAutoCommit() {
        return pool.getPoolProperties().isDefaultAutoCommit();
    }
    public boolean isDefaultReadOnly() {
        return pool.getPoolProperties().isDefaultReadOnly();
    }
    public int getDefaultTransactionIsolation() {
        return pool.getPoolProperties().getDefaultTransactionIsolation();
    }
    public String getConnectionProperties() {
        return pool.getPoolProperties().getConnectionProperties();
    }
    public String getDefaultCatalog() {
        return pool.getPoolProperties().getDefaultCatalog();
    }
    public int getInitialSize() {
        return pool.getPoolProperties().getInitialSize();
    }
    public int getMaxActive() {
        return pool.getPoolProperties().getMaxActive();
    }
    public int getMaxIdle() {
        return pool.getPoolProperties().getMaxIdle();
    }
    public int getMinIdle() {
        return pool.getPoolProperties().getMinIdle();
    }
    public int getMaxWait() {
        return pool.getPoolProperties().getMaxWait();
    }
    public String getValidationQuery() {
        return pool.getPoolProperties().getValidationQuery();
    }
    public boolean isTestOnBorrow() {
        return pool.getPoolProperties().isTestOnBorrow();
    }
    public boolean isTestOnReturn() {
        return pool.getPoolProperties().isTestOnReturn();
    }
    public boolean isTestWhileIdle() {
        return pool.getPoolProperties().isTestWhileIdle();
    }
    public int getTimeBetweenEvictionRunsMillis() {
        return pool.getPoolProperties().getTimeBetweenEvictionRunsMillis();
    }
    public int getNumTestsPerEvictionRun() {
        return pool.getPoolProperties().getNumTestsPerEvictionRun();
    }
    public int getMinEvictableIdleTimeMillis() {
        return pool.getPoolProperties().getMinEvictableIdleTimeMillis();
    }
    public boolean isAccessToUnderlyingConnectionAllowed() {
        return pool.getPoolProperties().isAccessToUnderlyingConnectionAllowed();
    }
    public boolean isRemoveAbandoned() {
        return pool.getPoolProperties().isRemoveAbandoned();
    }
    public int getRemoveAbandonedTimeout() {
        return pool.getPoolProperties().getRemoveAbandonedTimeout();
    }
    public boolean isLogAbandoned() {
        return pool.getPoolProperties().isLogAbandoned();
    }
    public int getLoginTimeout() {
        return pool.getPoolProperties().getLoginTimeout();
    }
    public String getName() {
        return pool.getPoolProperties().getName();
    }
    public String getPassword() {
        return pool.getPoolProperties().getPassword();
    }
    public String getUsername() {
        return pool.getPoolProperties().getUsername();
    }
    public long getValidationInterval() {
        return pool.getPoolProperties().getValidationInterval();
    }
    public String getInitSQL() {
        return pool.getPoolProperties().getInitSQL();
    }
    public boolean isTestOnConnect() {
        return pool.getPoolProperties().isTestOnConnect();
    }
    public String getJdbcInterceptors() {
        return pool.getPoolProperties().getJdbcInterceptors();
    }

}

{'fraction_non_alphanumeric': 0.15559576117859913, 'fraction_numerical': 0.0006461617989144482, 'mean_word_length': 3.1897671900378994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '377816', 'n_tokens_mistral': 3843, 'n_tokens_neox': 3758, 'n_words': 920}