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 org.kuali.common.jdbc.JdbcUtils;
019 import org.kuali.common.util.FormatUtils;
020 import org.kuali.common.util.LoggerLevel;
021 import org.kuali.common.util.LoggerUtils;
022 import org.slf4j.Logger;
023 import org.slf4j.LoggerFactory;
024
025 /**
026 * @deprecated
027 */
028 @Deprecated
029 public class SummaryListener extends NoOpSqlListener {
030
031 private static final Logger logger = LoggerFactory.getLogger(SummaryListener.class);
032
033 long count;
034 long size;
035 LoggerLevel loggerLevel = LoggerLevel.INFO;
036 boolean showRate = true;
037
038 public SummaryListener() {
039 this(true);
040 }
041
042 public SummaryListener(boolean showRate) {
043 this(showRate, LoggerLevel.INFO);
044 }
045
046 public SummaryListener(boolean showRate, LoggerLevel loggerLevel) {
047 super();
048 this.showRate = showRate;
049 this.loggerLevel = loggerLevel;
050 }
051
052 @Override
053 public void afterMetaData(SqlMetaDataEvent event) {
054 this.count = JdbcUtils.getSqlCount(event.getContext().getSuppliers());
055 this.size = JdbcUtils.getSqlSize(event.getContext().getSuppliers());
056 String count = FormatUtils.getCount(this.count);
057 String sources = FormatUtils.getCount(event.getContext().getSuppliers().size());
058 String size = FormatUtils.getSize(this.size);
059 Object[] args = { count, sources, size };
060 LoggerUtils.logMsg("Executing - [SQL Count: {} Sources: {} Size: {}]", args, logger, loggerLevel);
061 }
062
063 @Override
064 public void afterExecution(SqlExecutionEvent event) {
065 long elapsed = event.getStopTimeMillis() - event.getStartTimeMillis();
066 String count = FormatUtils.getCount(this.count);
067 String sources = FormatUtils.getCount(event.getContext().getSuppliers().size());
068 String size = FormatUtils.getSize(this.size);
069 String time = FormatUtils.getTime(elapsed);
070 String rate = FormatUtils.getRate(elapsed, this.size);
071 String throughput = FormatUtils.getThroughputInSeconds(elapsed, this.count, "SQL/s");
072 Object[] args = { count, sources, size, time, throughput, rate };
073 if (showRate) {
074 LoggerUtils.logMsg("Completed - [SQL Count: {} Sources: {} Size: {} Time: {} Throughput: {} Rate: {}]", args, logger, loggerLevel);
075 } else {
076 LoggerUtils.logMsg("Completed - [SQL Count: {} Sources: {} Size: {} Time: {} Throughput: {}]", args, logger, loggerLevel);
077 }
078 }
079
080 public boolean isShowRate() {
081 return showRate;
082 }
083
084 public void setShowRate(boolean showRate) {
085 this.showRate = showRate;
086 }
087
088 }