diff --git a/ashv/src/main/java/config/profile/ConfigProfile.java b/ashv/src/main/java/config/profile/ConfigProfile.java index 4393c19..72333c9 100644 --- a/ashv/src/main/java/config/profile/ConfigProfile.java +++ b/ashv/src/main/java/config/profile/ConfigProfile.java @@ -10,6 +10,8 @@ public class ConfigProfile { private String configName; private boolean isRunning; + private int initialLoading = ConstantManager.INITIAL_LOADING; + private int rawRetainDays = ConstantManager.RETAIN_DAYS_MAX; private int olapRetainDays = ConstantManager.RETAIN_DAYS_MAX; diff --git a/ashv/src/main/java/core/manager/ConfigurationManager.java b/ashv/src/main/java/core/manager/ConfigurationManager.java index 76fb5f5..3d7daf0 100644 --- a/ashv/src/main/java/core/manager/ConfigurationManager.java +++ b/ashv/src/main/java/core/manager/ConfigurationManager.java @@ -98,6 +98,7 @@ public ConnectionBuilder getConnectionParameters(String connName) { .url(connOut.getUrl()) .jar(connOut.getJar()) .profile(connOut.getProfileName()) + .initialLoading(String.valueOf(cfg.getValue().getInitialLoading())) .rawRetainDays(String.valueOf(cfg.getValue().getRawRetainDays())) .olapRetainDays(String.valueOf(cfg.getValue().getOlapRetainDays())) .build(); @@ -121,6 +122,7 @@ public void saveConnection(ConnectionBuilder connIn) { connOut.setProfileName(connIn.getProfile()); connOut.setDriver(connIn.getDriverName()); + cfg.getValue().setInitialLoading(Integer.parseInt(connIn.getInitialLoading())); cfg.getValue().setRawRetainDays(getRawRetainDays()); cfg.getValue().setOlapRetainDays(getOlapRetainDays()); diff --git a/ashv/src/main/java/core/manager/ConstantManager.java b/ashv/src/main/java/core/manager/ConstantManager.java index d6c4c93..d62980a 100644 --- a/ashv/src/main/java/core/manager/ConstantManager.java +++ b/ashv/src/main/java/core/manager/ConstantManager.java @@ -29,6 +29,9 @@ public enum RetainData {Never, Always}; public static int RETAIN_DAYS_MIN = 0; public static int RETAIN_DAYS_MAX = 101; + public static int INITIAL_LOADING = -1; + public static int INITIAL_LOADING_DEFAULT = 5; + private static Map coreOpt = new LinkedHashMap(); private ConstantManager() {} diff --git a/ashv/src/main/java/core/parameter/ConnectionBuilder.java b/ashv/src/main/java/core/parameter/ConnectionBuilder.java index 2fc32b2..2b4ad66 100644 --- a/ashv/src/main/java/core/parameter/ConnectionBuilder.java +++ b/ashv/src/main/java/core/parameter/ConnectionBuilder.java @@ -8,6 +8,7 @@ public class ConnectionBuilder { private final String jar; private final String profile; private final String driverName; + private final String initialLoading; private final String rawRetainDays; private final String olapRetainDays; @@ -18,6 +19,7 @@ public class ConnectionBuilder { public String getJar() { return jar; } public String getProfile() { return profile; } public String getDriverName() { return driverName; } + public String getInitialLoading() { return initialLoading; } public String getRawRetainDays() { return rawRetainDays; } public String getOlapRetainDays() { return olapRetainDays; } @@ -29,6 +31,7 @@ public static class Builder { private String jar; private String profile; private String driverName; + private String initialLoading; private String rawRetainDays; private String olapRetainDays; @@ -42,6 +45,7 @@ public Builder(String connectionName) { public Builder jar(String jr) { jar = jr; return this; } public Builder profile(String pr) { profile = pr; return this; } public Builder driverName(String dr) { driverName = dr; return this; } + public Builder initialLoading(String il) { initialLoading = il; return this; } public Builder rawRetainDays(String raw) { rawRetainDays = raw; return this; } public Builder olapRetainDays(String raw) { olapRetainDays = raw; return this; } @@ -58,6 +62,7 @@ private ConnectionBuilder(Builder builder){ jar = builder.jar; profile = builder.profile; driverName = builder.driverName; + initialLoading = builder.initialLoading; rawRetainDays = builder.rawRetainDays; olapRetainDays = builder.olapRetainDays; } diff --git a/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java b/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java index f3b54d4..48b5991 100644 --- a/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java +++ b/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java @@ -2,6 +2,8 @@ import com.sleepycat.persist.EntityCursor; import config.Labels; +import config.profile.ConnProfile; +import config.profile.SqlColProfile; import core.manager.ColorManager; import core.manager.ConfigurationManager; import core.manager.ConstantManager; @@ -10,6 +12,33 @@ import gui.chart.ChartDatasetManager; import gui.chart.panel.NameChartDataset; import gui.detail.explainplan.ExplainPlanModel10g2; +import java.math.BigDecimal; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; +import java.util.Vector; +import java.util.concurrent.atomic.AtomicInteger; +import javax.inject.Inject; +import javax.inject.Singleton; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -19,8 +48,6 @@ import org.jdesktop.swingx.treetable.TreeTableModel; import org.jetbrains.annotations.NotNull; import org.rtv.Options; -import config.profile.ConnProfile; -import config.profile.SqlColProfile; import pojo.SqlPlanPojo; import pojo.SqlPojo; import profile.IProfile; @@ -28,7 +55,10 @@ import profile.OracleEEObject; import profile.Postgres; import remote.RemoteDBManager; -import store.*; +import store.ConvertManager; +import store.OlapCacheManager; +import store.RawStoreManager; +import store.StoreManager; import store.entity.database.SqlPlan; import store.entity.olap.AshAggrMinData; import store.entity.olap.AshUser; @@ -36,16 +66,6 @@ import utility.StackTraceUtil; import utility.Utils; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.math.BigDecimal; -import java.sql.*; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - @Slf4j @Singleton public class GetFromRemoteAndStore { @@ -142,7 +162,8 @@ public void loadDataFromRemoteToLocalStore() { this.loadUsername(); // For main chart - iProfile.getUniqueTreeEventListByWaitClass().forEach(e-> chartDatasetManager.getMainNameChartDataset() + iProfile.getUniqueTreeEventListByWaitClass().forEach(e -> + chartDatasetManager.getMainNameChartDataset() .getStackChartPanel().getStackedChart().setSeriesPaintDynamicDetail(e)); } @@ -152,7 +173,7 @@ public void loadDataFromRemoteToLocalStore() { this.loadToMainStackedChart(); log.info("Stop loading olap"); - if (!this.isFirstRun) { // resolve the issue with the gap for big data in ASH + if (!this.isFirstRun) { // resolve the issue with the gap for large amount of data in ASH this.isFirstRun = true; this.loadDataToOlap(); this.loadToMainStackedChart(); @@ -517,8 +538,7 @@ private PreparedStatement getPreparedStatement(String sqlText) throws SQLExcepti PreparedStatement s; if (!this.isFirstRun) { s = connection.prepareStatement(sqlText); - ParameterBuilder param = new ParameterBuilder.Builder(currServerTime - ConstantManager.CURRENT_WINDOW, currServerTime).build(); - s.setTimestamp(1, new Timestamp(this.storeManager.getDatabaseDAO().getMax(param))); + s.setTimestamp(1, new Timestamp(getSampleTimeValue(currServerTime))); } else { s = connection.prepareStatement(sqlText); s.setTimestamp(1, new Timestamp(sampleTimeG)); @@ -526,6 +546,26 @@ private PreparedStatement getPreparedStatement(String sqlText) throws SQLExcepti return s; } + private long getSampleTimeValue(long currServerTime) { + ParameterBuilder param = + new ParameterBuilder.Builder(currServerTime - ConstantManager.CURRENT_WINDOW, currServerTime) + .build(); + + long sampleTime = this.storeManager.getDatabaseDAO().getMax(param); + + String initialLoadingStr = configurationManager + .getConnectionParameters(connProfile.getConnName()).getInitialLoading(); + + if (!initialLoadingStr.equals("-1")) { + long initialLoadingLong = Integer.parseInt(initialLoadingStr); + long sampleTimeFromConfig = currServerTime - (initialLoadingLong*60*1000); + + sampleTime = Math.max(sampleTimeFromConfig, sampleTime); + } + + return sampleTime; + } + private int getColumnIdForCol(String filterCol){ return metadataMap .get(modNameAshSql) diff --git a/ashv/src/main/java/gui/connect/ConnectToDbArea.java b/ashv/src/main/java/gui/connect/ConnectToDbArea.java index e58903e..089df0c 100644 --- a/ashv/src/main/java/gui/connect/ConnectToDbArea.java +++ b/ashv/src/main/java/gui/connect/ConnectToDbArea.java @@ -26,6 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import javax.swing.AbstractButton; +import javax.swing.ButtonModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -35,14 +37,18 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; +import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JSeparator; +import javax.swing.JSpinner; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.JViewport; import javax.swing.ListSelectionModel; import javax.swing.ScrollPaneConstants; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -109,6 +115,19 @@ public class ConnectToDbArea extends JDialog { private JLabel profileMessageLbl = new JLabel(Labels.getLabel("gui.connection.profile.message")); private JLabel offlineLbl = new JLabel(Labels.getLabel("gui.connection.offline")); + + private JPanel initialLoadPanel; + private JLabel separatorInitialLoadingLbl = new JLabel(Labels.getLabel("gui.connection.initial.loading")); + private JLabel initialLoadingOracleEELbl = new JLabel(Labels.getLabel("gui.connection.initial.loading.oracle")); + private String initialLoadingAllStr = Labels.getLabel("gui.connection.initial.loading.all"); + private String initialLoadingLastStr = Labels.getLabel("gui.connection.initial.loading.last"); + private JLabel initialLoadingMinLbl = new JLabel(Labels.getLabel("gui.connection.initial.loading.min")); + + private JSpinner initialLoadSpinner; + private SpinnerModel initialSpinnerModel; + private JRadioButton initialLoadAllRButton; + private JRadioButton initialLoadLastRButton; + private JLabel separatorRetainLbl = new JLabel(Labels.getLabel("gui.connection.retain")); private JLabel retainRawDataLbl = new JLabel(Labels.getLabel("gui.connection.retain.raw")); private JLabel retainOlapDataLbl = new JLabel(Labels.getLabel("gui.connection.retain.olap")); @@ -157,7 +176,7 @@ public ConnectToDbArea(BasicFrame jFrame, private void init(){ MigLayout lmMain = new MigLayout("", "[grow][][grow]", "[][][]"); MigLayout lmConnMain = new MigLayout("ins 10", "[para]0[grow][150lp, fill][60lp][95lp, fill]", ""); - MigLayout lmConnOther = new MigLayout("ins 10", "[para]0[grow][200lp, fill][60lp][95lp, fill]", ""); + MigLayout lmConnOther = new MigLayout("ins 10", "[para]0[grow][250lp, fill][60lp][95lp, fill]", ""); MigLayout lmButtonPanel = new MigLayout("fillx", "[50lp][50lp][50lp][50lp]"); mainJPanel = new JPanel(lmMain); @@ -273,16 +292,56 @@ private void init_gui(){ configMainJPanel.add(isOffline, "span, growx"); isOffline.setSelected(false); + separatorInitialLoadingLbl.setForeground(LABEL_COLOR); + configOtherJPanel.add(separatorInitialLoadingLbl, "gapbottom 1, span, split 2, aligny center"); + configOtherJPanel.add(new JSeparator(), "gapleft rel, growx"); + + MigLayout lmInitialLoad = new MigLayout("", "[30lp][30lp][30lp][30lp]"); + initialLoadPanel = new JPanel(lmInitialLoad); + + initialSpinnerModel = new SpinnerNumberModel(5, 0, 120, 1); + initialLoadSpinner = new JSpinner(initialSpinnerModel); + initialLoadSpinner.setToolTipText(Labels.getLabel("gui.connection.initial.loading.tooltip")); + + initialLoadAllRButton = new JRadioButton(initialLoadingAllStr); + initialLoadAllRButton.addChangeListener(e -> { + AbstractButton aButton = (AbstractButton)e.getSource(); + ButtonModel aModel = aButton.getModel(); + if (aModel.isSelected()) { + initialLoadLastRButton.setSelected(false); + initialLoadSpinner.setEnabled(false); + } + }); + + initialLoadLastRButton = new JRadioButton(initialLoadingLastStr); + initialLoadLastRButton.addChangeListener(e -> { + AbstractButton aButton = (AbstractButton)e.getSource(); + ButtonModel aModel = aButton.getModel(); + if (aModel.isSelected()) { + initialLoadAllRButton.setSelected(false); + initialLoadSpinner.setEnabled(true); + } + }); + + initialLoadPanel.add(initialLoadAllRButton, "gap 1"); + initialLoadPanel.add(new JSeparator(SwingConstants.VERTICAL), "growy, hmin 10, alignx center"); + initialLoadPanel.add(initialLoadLastRButton, "gap 1"); + initialLoadPanel.add(initialLoadSpinner); + initialLoadPanel.add(initialLoadingMinLbl); + + configOtherJPanel.add(initialLoadingOracleEELbl, "skip"); + configOtherJPanel.add(initialLoadPanel, "span, growx, wmin 100"); + separatorRetainLbl.setForeground(LABEL_COLOR); configOtherJPanel.add(separatorRetainLbl, "gapbottom 1, span, split 2, aligny center"); configOtherJPanel.add(new JSeparator(), "gapleft rel, growx"); configOtherJPanel.add(retainRawDataLbl, "skip"); - configOtherJPanel.add(rawDataDaysRetainTF, "span, growx"); + configOtherJPanel.add(rawDataDaysRetainTF, "span, growx, wmin 150"); rawDataDaysRetainTF.setToolTipText(Labels.getLabel("gui.connection.retain.raw.tooltip")); configOtherJPanel.add(retainOlapDataLbl, "skip"); - configOtherJPanel.add(olapDataDaysRetainTF, "span, growx"); + configOtherJPanel.add(olapDataDaysRetainTF, "span, growx, wmin 150"); olapDataDaysRetainTF.setToolTipText(Labels.getLabel("gui.connection.retain.olap.tooltip")); jButtonConnect.addActionListener(e -> { @@ -427,6 +486,10 @@ private void setDetailEditable(boolean bParameter){ jButtonDeleteConfig.setEnabled(!bParameter); jButtonSaveConfig.setEnabled(bParameter); jButtonCancel.setEnabled(bParameter); + + initialLoadAllRButton.setEnabled(bParameter); + initialLoadLastRButton.setEnabled(bParameter); + initialLoadSpinner.setEnabled(bParameter); } private void clearProfileFields(){ @@ -437,6 +500,9 @@ private void clearProfileFields(){ jarTF.setText(""); rawDataDaysRetainTF.setText(""); olapDataDaysRetainTF.setText(""); + + initialLoadAllRButton.setSelected(true); + initialLoadLastRButton.setSelected(false); } private void copyConnection(){ @@ -473,6 +539,8 @@ private void selectFromDbAndSetInGui(String connName){ jButtonConnect.setText(Labels.getLabel("gui.connection.button.connect")); } + setInitialLoading(connParameters.getInitialLoading()); + if (!rawDataDaysRetainTF.isEnabled()) { setTextDataDaysRetainTF(rawDataDaysRetainTF, Integer.parseInt(connParameters.getRawRetainDays())); } @@ -491,6 +559,7 @@ private void saveData(){ .profile(String.valueOf((profileBox.getSelectedItem()))) .driverName(configurationManager.getProfileImpl( String.valueOf((profileBox.getSelectedItem()))).getDriverName()) + .initialLoading(initialLoadAllRButton.isSelected() ? "-1" : initialLoadSpinner.getValue().toString()) .rawRetainDays(rawDataDaysRetainTF.getText()) .olapRetainDays(olapDataDaysRetainTF.getText()) .build(); @@ -659,4 +728,18 @@ private void setProfileMessageLblVisible(String selectedItem) { } } + private void setInitialLoading(String initialLoading) { + if (initialLoading.equals("-1")) { + initialLoadAllRButton.setSelected(true); + initialLoadLastRButton.setSelected(false); + initialLoadSpinner.setEnabled(false); + initialLoadSpinner.setValue(ConstantManager.INITIAL_LOADING_DEFAULT); + } else { + initialLoadAllRButton.setSelected(false); + initialLoadLastRButton.setSelected(true); + initialLoadSpinner.setEnabled(connNameTF.isEnabled()); + initialLoadSpinner.setValue(Integer.valueOf(initialLoading)); + } + } + } diff --git a/ashv/src/main/resources/messages.properties b/ashv/src/main/resources/messages.properties index 77c4e8e..e6cf272 100644 --- a/ashv/src/main/resources/messages.properties +++ b/ashv/src/main/resources/messages.properties @@ -33,11 +33,18 @@ gui.connection.profile.detail=Detail gui.connection.profile.message=Enterprise edition must have Diagnostic pack license purchased gui.connection.offline=Offline +gui.connection.initial.loading=Initial loading +gui.connection.initial.loading.oracle=Oracle EE +gui.connection.initial.loading.all=All data +gui.connection.initial.loading.last=Custom: last +gui.connection.initial.loading.min=minutes +gui.connection.initial.loading.tooltip=Allowed values: 0..120 minutes + gui.connection.retain=Retain data (days) gui.connection.retain.raw=Raw gui.connection.retain.olap=Olap -gui.connection.retain.raw.tooltip=Feature under development -gui.connection.retain.olap.tooltip=Feature under development +gui.connection.retain.raw.tooltip=The feature is under development +gui.connection.retain.olap.tooltip=The feature is under development gui.connection.button.connect=Connect gui.connection.button.connect.running=Running..