Skip to content

Commit

Permalink
Add the raw data viewer in History tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
akardapolov committed Apr 4, 2016
1 parent f8498c7 commit eac64b5
Show file tree
Hide file tree
Showing 4 changed files with 340 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/org/ash/database/Database10g11gSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ private void loadAshDataToLocal() {
Long eventHash = resultSetAsh.getLong("EVENT#");
Long seqHash = resultSetAsh.getLong("SEQ#");
double p1 = resultSetAsh.getDouble("P1");
double p2 = resultSetAsh.getDouble("P1");
double p3 = resultSetAsh.getDouble("P1");
double p2 = resultSetAsh.getDouble("P2");
double p3 = resultSetAsh.getDouble("P3");
String waitClass = resultSetAsh.getString("WAIT_CLASS");
Double waitClassId = resultSetAsh
.getDouble("WAIT_CLASS_ID");
Expand Down
248 changes: 248 additions & 0 deletions src/org/ash/gui/ASHrawdata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
*-------------------
* The ASHReport.java is part of ASH Viewer
*-------------------
*
* ASH Viewer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ASH Viewer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ASH Viewer. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2009, Alex Kardapolov, All rights reserved.
*
*/
package org.ash.gui;

import com.sleepycat.je.DatabaseException;
import org.ash.database.ASHDatabase;
import org.ash.history.ASHDatabaseH;
import org.ash.util.ProgressBarUtil;
import org.jfree.ui.NumberCellRenderer;
import org.joda.time.DateTime;
import org.joda.time.Period;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class ASHrawdata extends JPanel {

/** The main. */
private JPanel main;

/** The root. */
private JFrame root;

/** The database. */
private ASHDatabaseH database;

/** The date format. */
private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

/**
* Constructor.
*
* @param rootFrame0
* @param database0
*/
public ASHrawdata(JFrame rootFrame0, ASHDatabaseH database0, double begin, double end) {

super();
setLayout(new GridLayout(1, 1, 3, 3));

this.database = database0;
this.root = rootFrame0;

this.main = new JPanel();
this.main.setLayout(new BorderLayout());

this.add(this.main);

// Create empty panel
JPanel ashReport = new JPanel();
ashReport.setLayout(new GridLayout(1, 1, 3, 3));

// The button panel
JToolBar buttonPanel;
buttonPanel = new JToolBar("PanelButton");
buttonPanel.setFloatable(false);
buttonPanel.setBorder(new EtchedBorder());

// get ASH Report button
JButton getASHReportButton = new JButton();
getASHReportButton.setText("Get ASH raw data in table");
getASHReportButton.setPreferredSize(new Dimension(100, 30));
getASHReportButton.setActionCommand("ASHrawdata");

ButtonPlanActionListener buttonListener = new ButtonPlanActionListener(
ashReport, getASHReportButton, database, begin, end);

getASHReportButton.addActionListener(buttonListener);

// Layout of buttons
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(getASHReportButton);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(new JLabel(dateFormat.format(begin)+
" <<" + getPeriod(begin,end) + ">> "+
dateFormat.format(end)
)
);

// Add buttonPanel, main
this.main.add(buttonPanel, BorderLayout.NORTH);
this.main.add(ashReport, BorderLayout.CENTER);
}

private class ButtonPlanActionListener implements ActionListener {
JPanel panelASHReport;
JButton getASHReportButton;
ASHDatabaseH database;
double begin;
double end;

public ButtonPlanActionListener(final JPanel tabsSQLPlan, final JButton getASHReportButton,
final ASHDatabaseH database, final double begin, final double end) {
super();
this.panelASHReport = tabsSQLPlan;
this.getASHReportButton = getASHReportButton;
this.database = database;
this.begin = begin;
this.end = end;
}

public void actionPerformed(final ActionEvent e) {
/** Get action command */
final String str = e.getActionCommand();

if (str.equalsIgnoreCase("ASHrawdata")) {
getASHReport();
}
}

private void getASHReport() {

//Disable getASHReportButton
//getASHReportButton.setEnabled(false);

// Clear tabbedpane
JPanel panelLoading = createProgressBar("Loading, please wait...");
panelASHReport.removeAll();
panelASHReport.add(panelLoading);

Thread t = new Thread() {
@Override
public void run() {
// delay
try {
Thread.sleep(5L);
} catch (InterruptedException e) {
e.printStackTrace();
}
root.repaint();

/*----------------------*/
JTable table;
DefaultTableModel model;
try {
model = database.getASHRawData(begin, end);

table = new JTable(model);

TableColumnModel tcm = table.getColumnModel();
//tcm.getColumn(3).setCellRenderer(new NumberCellRenderer());
JPanel p = new JPanel(new BorderLayout());
//JScrollPane scroller = new JScrollPane(table);

JScrollPane tableRawDataPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableRawDataPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);

tableRawDataPane.setViewportView(table);
tableRawDataPane.setVerticalScrollBar(tableRawDataPane.getVerticalScrollBar());

//(JTable)componentList.get(0)

p.add(tableRawDataPane);
p.setBorder(BorderFactory.createCompoundBorder(new TitledBorder(
"Selected Items: "), new EmptyBorder(4, 4, 4, 4)));

/*----------------------*/

panelASHReport.removeAll();
panelASHReport.add(p);

root.repaint();

} catch (DatabaseException e) {
e.printStackTrace();
}


}
};
t.start();
}
}

/**
* Creates the progress bar.
*
* @param msg the msg
*
* @return the j panel
*/
private JPanel createProgressBar(String msg) {
JProgressBar progress = ProgressBarUtil.createJProgressBar(msg);
progress.setPreferredSize(new Dimension(250, 30));
JPanel panel = new JPanel();
panel.add(progress);
return panel;
}

/**
* Get period in mm, dd, hh, ss
* @param begind
* @param endd
* @return
*/
private String getPeriod(double begind, double endd){
String out = "";
Double beginD = begind;
Double endD = endd;
DateTime start = new DateTime(beginD.longValue());
DateTime end = new DateTime(endD.longValue());

Period period = new Period(start, end);

if (period.getMonths() > 0)
out = period.getMonths()+" m. ";
if (period.getDays() > 0)
out = out + period.getDays()+" d. ";
if (period.getHours() > 0)
out = out + period.getHours()+" h. ";
if (period.getMinutes() > 0)
out = out + period.getMinutes()+" min. ";
if (period.getSeconds() > 0)
out = out + period.getSeconds()+" sec. ";

return out;
}

}
79 changes: 75 additions & 4 deletions src/org/ash/history/ASHDatabaseH.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import com.sleepycat.persist.EntityStore;
import com.sleepycat.persist.StoreConfig;

import javax.swing.table.DefaultTableModel;

/**
* The Class ASHDatabaseH (history).
*/
Expand Down Expand Up @@ -442,10 +444,79 @@ public void loadDataToChartPanelDataSetTA(CategoryTableXYDataset _dataset, doubl
// TODO Auto-generated catch block
e.printStackTrace();
}
}



}



public DefaultTableModel getASHRawData(double begin, double end) throws DatabaseException {

DefaultTableModel model = new DefaultTableModel(new String[] {
"SessionId:",
"SessionSerial:",
"Program:",
"ClientId:",
"Action",
"Event",
"P1",
"P1Text",
"P2",
"P2Text",
"P3",
"P3Text"
}, 0);

try {

/* Do a filter on AshIdTime by SampleTime. (detail) */
EntityCursor<AshIdTime> ashIdTimeCursor =
dao.doRangeQuery(dao.getAshBySampleTime(),
begin, true, end, false);

Iterator<AshIdTime> ashIdTimeIter = ashIdTimeCursor.iterator();

// Iterate over AshIdTime (detail)
while (ashIdTimeIter.hasNext()) {
AshIdTime ashIdTimeMain = ashIdTimeIter.next();

/* Do a filter on ActiveSessionHistory by SampleID (detail). */
EntityCursor<ActiveSessionHistory> ActiveSessionHistoryCursor =
dao.getActiveSessionHistoryByAshId().subIndex(ashIdTimeMain.getsampleId()).entities();
Iterator<ActiveSessionHistory> ActiveSessionHistoryIter =
ActiveSessionHistoryCursor.iterator();

// Iterate over ActiveSessionHistory (detail)
while (ActiveSessionHistoryIter.hasNext()) {
ActiveSessionHistory ASH = ActiveSessionHistoryIter.next();

//System.out.println(ASH.getAction()+ASH.getEvent()+ASH.getP1());

model.addRow(new Object[] {
ASH.getSessionId(),
(long)ASH.getSessionSerial(),
ASH.getProgram(),
ASH.getClientId(),
ASH.getAction(),
ASH.getEvent(),
(long)ASH.getP1(),
ASH.getP1Text(),
(long)ASH.getP2(),
ASH.getP2Text(),
(long)ASH.getP3(),
ASH.getP3Text()
});
}
ActiveSessionHistoryCursor.close();
}
ashIdTimeCursor.close();

} catch (Exception e){
e.printStackTrace();
}

return model;
}


/**
* Gets the parameter value from local BDB.
*
Expand Down
20 changes: 15 additions & 5 deletions src/org/ash/history/GanttH.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.ash.database.Database11g1;
import org.ash.database.Database11g2;
import org.ash.gui.ASHReport;
import org.ash.gui.ASHrawdata;
import org.ash.gui.GanttSplitPane;
import org.ash.gui.SqlPlan;
import org.ash.util.Options;
Expand Down Expand Up @@ -307,9 +308,9 @@ private void loadDataToJPanelsPrivate(double beginTime, double endTime){
splitPane.setRightComponent(rightPane);
splitPane.setDividerLocation(this.getWidth()/2);
splitPane.setOneTouchExpandable(true);
this.main.removeAll();

this.main.removeAll();

if (Options.getInstance().isCurrentProfile() &&
Options.getInstance().getEditionDb().equalsIgnoreCase("EE") &&
!Options.getInstance().getVersionDb().equalsIgnoreCase("9i") &&
Expand All @@ -321,11 +322,20 @@ private void loadDataToJPanelsPrivate(double beginTime, double endTime){
JTabbedPane tabPane = new JTabbedPane();
tabPane.add("Top sql & sessions",splitPane);
tabPane.add("ASH Report",new ASHReport(mainFrame, databaseCurrent, beginTime, endTime));

tabPane.add("ASH raw data",new ASHrawdata(mainFrame, this.database, beginTime, endTime));

this.main.add(tabPane);
this.validate();
} else {
this.main.add(splitPane);
//this.main.add(splitPane);
//ASHDatabase databaseCurrent = Options.getInstance().getASHDatabase();

JTabbedPane tabPane = new JTabbedPane();
tabPane.add("Top sql & sessions",splitPane);
//tabPane.add("ASH Report",new ASHReport(mainFrame, databaseCurrent, beginTime, endTime));
tabPane.add("ASH raw data",new ASHrawdata(mainFrame, this.database, beginTime, endTime));

this.main.add(tabPane);
this.validate();
}

Expand Down

0 comments on commit eac64b5

Please sign in to comment.