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 DataSummaryListener extends NoOpSqlListener {
030    
031            private static final Logger logger = LoggerFactory.getLogger(DataSummaryListener.class);
032    
033            long count;
034            long size;
035            LoggerLevel loggerLevel = LoggerLevel.INFO;
036            boolean showRate = true;
037            String label = "Rows";
038            String throughputLabel = "rows/s";
039    
040            public DataSummaryListener() {
041                    this(true);
042            }
043    
044            public DataSummaryListener(boolean showRate) {
045                    super();
046                    this.showRate = showRate;
047            }
048    
049            @Override
050            public void afterMetaData(SqlMetaDataEvent event) {
051                    this.count = JdbcUtils.getSqlCount(event.getContext().getSuppliers());
052                    this.size = JdbcUtils.getSqlSize(event.getContext().getSuppliers());
053                    String count = FormatUtils.getCount(this.count);
054                    String sources = FormatUtils.getCount(event.getContext().getSuppliers().size());
055                    String size = FormatUtils.getSize(this.size);
056                    Object[] args = { label, count, sources, size };
057                    LoggerUtils.logMsg("Executing - [{}: {}  Sources: {}  Size: {}]", args, logger, loggerLevel);
058            }
059    
060            @Override
061            public void afterExecution(SqlExecutionEvent event) {
062                    long elapsed = event.getStopTimeMillis() - event.getStartTimeMillis();
063                    String count = FormatUtils.getCount(this.count);
064                    String sources = FormatUtils.getCount(event.getContext().getSuppliers().size());
065                    String size = FormatUtils.getSize(this.size);
066                    String time = FormatUtils.getTime(elapsed);
067                    String rate = FormatUtils.getRate(elapsed, this.size);
068                    String throughput = FormatUtils.getThroughputInSeconds(elapsed, this.count, throughputLabel);
069                    Object[] args = { label, count, sources, size, time, throughput, rate };
070                    if (showRate) {
071                            LoggerUtils.logMsg("Completed - [{}: {}  Sources: {}  Size: {}  Time: {}  Throughput: {}  Rate: {}]", args, logger, loggerLevel);
072                    } else {
073                            LoggerUtils.logMsg("Completed - [{}: {}  Sources: {}  Size: {}  Time: {}  Throughput: {}]", args, logger, loggerLevel);
074                    }
075            }
076    
077            public boolean isShowRate() {
078                    return showRate;
079            }
080    
081            public void setShowRate(boolean showRate) {
082                    this.showRate = showRate;
083            }
084    
085            public LoggerLevel getLoggerLevel() {
086                    return loggerLevel;
087            }
088    
089            public void setLoggerLevel(LoggerLevel loggerLevel) {
090                    this.loggerLevel = loggerLevel;
091            }
092    
093            public String getLabel() {
094                    return label;
095            }
096    
097            public void setLabel(String label) {
098                    this.label = label;
099            }
100    
101            public String getThroughputLabel() {
102                    return throughputLabel;
103            }
104    
105            public void setThroughputLabel(String throughputLabel) {
106                    this.throughputLabel = throughputLabel;
107            }
108    
109    }