001 /**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.jdbc.listener;
017
018 import java.util.ArrayList;
019 import java.util.Arrays;
020 import java.util.List;
021
022 import org.kuali.common.jdbc.JdbcUtils;
023 import org.kuali.common.jdbc.supplier.SqlSupplier;
024 import org.kuali.common.jdbc.threads.SqlBucket;
025 import org.kuali.common.util.FormatUtils;
026 import org.kuali.common.util.LoggerLevel;
027 import org.kuali.common.util.LoggerUtils;
028 import org.slf4j.Logger;
029 import org.slf4j.LoggerFactory;
030
031 /**
032 * This listener will print statistics related to how the SQL is being divided up into different buckets for execution. Only useful when concurrent SQL execution is being
033 * performed.
034 *
035 * @deprecated
036 */
037 @Deprecated
038 public class BucketListener extends NoOpSqlListener implements SqlListener {
039
040 private static final Logger logger = LoggerFactory.getLogger(BucketListener.class);
041 LoggerLevel level = LoggerLevel.DEBUG;
042
043 @Override
044 public void bucketsCreated(BucketEvent event) {
045 List<SqlBucket> buckets = event.getBuckets();
046 List<Object[]> argsList = new ArrayList<Object[]>();
047 for (int i = 0; i < buckets.size(); i++) {
048 SqlBucket bucket = buckets.get(i);
049 List<SqlSupplier> suppliers = bucket.getSuppliers();
050 String count = FormatUtils.getCount(JdbcUtils.getSqlCount(suppliers));
051 String srcs = FormatUtils.getCount(suppliers.size());
052 String size = FormatUtils.getSize(JdbcUtils.getSqlSize(suppliers));
053 Object[] args = { i + 1, count, srcs, size };
054 argsList.add(args);
055 }
056 List<String> columns = Arrays.asList("Bucket", "SQL Count", "Sources", "Size");
057 LoggerUtils.logTable(columns, argsList, level, logger);
058 }
059
060 public LoggerLevel getLevel() {
061 return level;
062 }
063
064 public void setLevel(LoggerLevel level) {
065 this.level = level;
066 }
067
068 }