Skip to content

Commit

Permalink
20180704
Browse files Browse the repository at this point in the history
  • Loading branch information
dbacvetkov committed Jul 4, 2018
1 parent 022fb2c commit 9712c8e
Show file tree
Hide file tree
Showing 32 changed files with 3,162 additions and 1,026 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

Running PASH Viewer
----------------
1) Unpack the archive, eg:
1) Unpack the archive, eg:
unzip PASH-Viewer-0.3.zip

2) A directory called "PASH-Viewer-0.3" will be created.
Expand All @@ -50,4 +50,4 @@

PASH Viewer URL
----------
https://github.com/dbacvetkov/PASH-Viewer
https://github.com/dbacvetkov/PASH-Viewer
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
apply plugin: 'application'
apply plugin: 'java'

version = '0.3'
version = '0.3.2'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Expand Down
80 changes: 23 additions & 57 deletions src/org/ash/conn/gui/ConnectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,25 @@ public class ConnectionDialog extends JDialog {
*/
JPanel connPanel = new JPanel();

/**
* The username label.
*/
JLabel usernameLabel = new JLabel();

/**
* The username text field.
*/
JTextField usernameTF = new JTextField();

/**
* The password label.
*/
JLabel passwdLabel = new JLabel();

JPasswordField passwdTF = new JPasswordField();

JLabel hostLabel = new JLabel();
JTextField hostTF = new JTextField();

JLabel DBLabel = new JLabel();
JTextField DBTF = new JTextField();

/**
* The host field.
*/
JTextField hostTF = new JTextField();
JLabel schemaLabel = new JLabel();
JTextField schemaTF = new JTextField();

/**
* The port label.
*/
JLabel portLabel = new JLabel();

/**
* The port field.
*/
JTextField portTF = new JTextField();

/**
* The name label.
*/
JLabel nameLabel = new JLabel();

/**
* The name field.
*/
JTextField nameTF = new JTextField();

/**
Expand Down Expand Up @@ -262,6 +237,7 @@ private void init() {
urlTF.setText(c.getUrl());
classNameTF.setText(c.getClassName());
DBTF.setText(c.getDB());
schemaTF.setText(c.getSchema());
hostTF.setText(c.getHost());
portTF.setText(c.getPort());
}
Expand Down Expand Up @@ -295,6 +271,9 @@ private void jbInit() throws Exception {
hostLabel.setText(Options.getInstance().getResource("host"));
hostTF.setText("");
hostTF.setColumns(20);
schemaLabel.setText("Schema");
schemaTF.setText("");
schemaTF.setColumns(20);
portLabel.setText(Options.getInstance().getResource("port"));
portTF.setText("5432");
portTF.setColumns(5);
Expand Down Expand Up @@ -331,34 +310,20 @@ public void focusLost(FocusEvent e) {

connPanel.add("DEFAULT", defaultPanel);

defaultPanel.add(usernameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(usernameTF, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(passwdLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(passwdTF, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(hostLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(hostTF, new GridBagConstraints(1, 4, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));


defaultPanel.add(DBLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(DBTF, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));


defaultPanel.add(portLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(portTF, new GridBagConstraints(1, 5, 3, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(nameTF, new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(usernameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(usernameTF, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(passwdLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(passwdTF, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(DBLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(DBTF, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(schemaLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(schemaTF, new GridBagConstraints(1, 4, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(hostLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(hostTF, new GridBagConstraints(1, 5, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(portLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(portTF, new GridBagConstraints(1, 6, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
defaultPanel.add(nameTF, new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

cardLayout.show(connPanel, "DEFAULT");
}
Expand Down Expand Up @@ -395,6 +360,7 @@ void okButton_actionPerformed(ActionEvent e) {
c.setName(nameTF.getText());
c.setUsername(usernameTF.getText());
c.setPassword(passwdTF.getText());
c.setSchema(schemaTF.getText());

String TempPort = portTF.getText();

Expand Down
5 changes: 3 additions & 2 deletions src/org/ash/conn/gui/ConnectionFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void editButton_actionPerformed(ActionEvent e) {
* @param e the ActionEvent
*/
void newButton_actionPerformed(ActionEvent e) {
new ConnectionDialog(parent,this,new DbConnection("","","","",""),ConnectionDialog.INSERT);
new ConnectionDialog(parent,this,new DbConnection("","","","","",""),ConnectionDialog.INSERT);
}


Expand Down Expand Up @@ -396,7 +396,8 @@ void copyButton_actionPerformed(ActionEvent e) {
c.getClassName(),
c.getUrl(),
c.getUsername(),
c.getPassword()
c.getPassword(),
c.getSchema()
),
ConnectionDialog.COPY
);
Expand Down
39 changes: 37 additions & 2 deletions src/org/ash/conn/model/ConnectionPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.sql.*;
import java.util.*;
import org.ash.util.Options;

/**
* The Class ConnectionPool.
Expand Down Expand Up @@ -86,8 +87,7 @@ public ConnectionPool(String driver, String url, String username,
public synchronized Connection getConnection() throws SQLException {
if (!availableConnections.isEmpty()) {

Connection existingConnection = (Connection) availableConnections
.lastElement();
Connection existingConnection = (Connection) availableConnections.lastElement();
int lastIndex = availableConnections.size() - 1;
availableConnections.removeElementAt(lastIndex);
// If connection on available list is closed (e.g.,
Expand Down Expand Up @@ -183,6 +183,41 @@ private Connection makeNewConnection() throws SQLException {
Class.forName(driver);
// Establish network connection to database
Connection connection = DriverManager.getConnection(url, username, password);

// dcvetkov
// set search path for explaining plans
String schema = Options.getInstance().getSchema();
if(schema != null && !schema.equals(""))
{
Statement st = connection.createStatement();
try {
int rs = st.executeUpdate("set search_path TO " + schema + ",\"$user\", public;");
} catch (SQLException e) {
e.printStackTrace();
}

/*
try {
ResultSet rs = null;
rs = st.executeQuery("show search_path;");
while (rs.next()) {
String search_path = rs.getString("search_path");
System.out.println("--- search_path = " + search_path);
}
} catch (SQLException e) {
e.printStackTrace();
}
*/

if (st != null) {
try {
st.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

return (connection);

} catch (ClassNotFoundException cnfe) {
Expand Down
8 changes: 3 additions & 5 deletions src/org/ash/conn/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ public void connectionPoolInit(String driver, String url, String username, Strin
this.driver = driver;
this.url = url;
this.username = username;
this.password = password;
this.password = password;
try {
connectionPool = new ConnectionPool(driver, url, username,
password, 2, 20, true);
connectionPool = new ConnectionPool(driver, url, username, password, 2, 20, true);
setVersion();
} catch (SQLException e) {
System.out.println("SQL Exception occured " +
"while connection pool initialize: "+e.getMessage());
System.out.println("SQL Exception occured while connection pool initialize: " + e.getMessage());
errorMessage = e.toString();
connectionPool = null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/org/ash/conn/settings/ConnectionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void loadProfileV(JFrame parent,File file,ArrayList conns,Vector connNam
String driver = null;
String url = null;
String username = null;
String edition = null;
String schema = null;
BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(file) ));

// create dir for profile /
Expand All @@ -88,6 +88,7 @@ private void loadProfileV(JFrame parent,File file,ArrayList conns,Vector connNam
driver = br.readLine();
url = br.readLine();
username = br.readLine();
schema = br.readLine();
br.close();

File passwdFile = new File(file.getAbsolutePath().substring(0,file.getAbsolutePath().length()-4)+".pwd");
Expand All @@ -97,7 +98,7 @@ private void loadProfileV(JFrame parent,File file,ArrayList conns,Vector connNam
String password = Options.getInstance().decodeFromBytes(bb);
in.close();

conns.add(new DbConnection(name,driver,url,username,password));
conns.add(new DbConnection(name,driver,url,username,password,schema));
connNames.add(name);

} catch (Exception ex) {
Expand Down Expand Up @@ -134,6 +135,7 @@ public void saveProfile(JFrame parent,DbConnection c,boolean isEdit) {
pw.println( c.getClassName() );
pw.println( c.getUrl() );
pw.println( c.getUsername() );
pw.println( c.getSchema() );

// save one empty row...
pw.println( "" );
Expand Down
14 changes: 13 additions & 1 deletion src/org/ash/conn/settings/DbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class DbConnection {

/** The password. */
private String password;

private String schema;

/**
* Instantiates a new db connection.
Expand All @@ -61,12 +63,14 @@ public DbConnection(
String className,
String url,
String username,
String password) {
String password,
String schema) {
this.name = name;
this.className = className;
this.url = url;
this.username = username;
this.password = password;
this.schema = schema;
}

/**
Expand Down Expand Up @@ -136,6 +140,10 @@ public String getName() {
return name;
}

public String getSchema() {
return schema;
}

/**
* Gets the url.
*
Expand Down Expand Up @@ -190,6 +198,10 @@ public void setPassword(String password) {
this.password = password;
}

public void setSchema(String schema) {
this.schema = schema;
}

/**
* Sets the url.
*
Expand Down
16 changes: 7 additions & 9 deletions src/org/ash/database/ASHDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,15 @@ public DefaultTableModel getASHRawData(double begin, double end, String detail)
DefaultTableModel model = new DefaultTableModel(new String[]{
"SampleID",
"SampleTime",
"SessionID",
"PID",
"UserID",
"Username",
"Program",
"Sql type",
"SQL ID",
"Duration",
"Event",
"Wait Class",
"Wait Class id",
"UserID",
"Hostname",
"Backend Type"
}, 0);
Expand All @@ -694,10 +694,8 @@ public DefaultTableModel getASHRawData(double begin, double end, String detail)
String reportDateStr = df.format(td);

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

// Iterate over ActiveSessionHistory (detail)
while (ActiveSessionHistoryIter.hasNext()) {
Expand All @@ -714,14 +712,14 @@ public DefaultTableModel getASHRawData(double begin, double end, String detail)
ASH.getSampleId(),
reportDateStr,
ASH.getSessionId(),
ASH.getUserId(),
ASH.getUserName(),
ASH.getProgram(),
ASH.getCommand_type(),
ASH.getSqlId(),
ASH.getDuration(),
ASH.getEvent(),
ASH.getWaitClass(),
(long) ASH.getWaitClassId(),
ASH.getUserId(),
ASH.getHostname(),
ASH.getBackendType()
});
Expand Down
Loading

0 comments on commit 9712c8e

Please sign in to comment.