Skip to content

Commit f2f3075

Browse files
committed
Review fixes
1 parent e49ce5e commit f2f3075

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

database/api/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/api/query/GraphQueryResult.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.neueda.jetbrains.plugin.graphdb.database.api.data.GraphRelationship;
55

66
import java.util.List;
7+
import java.util.Optional;
78

89
public interface GraphQueryResult {
910

@@ -23,7 +24,7 @@ public interface GraphQueryResult {
2324

2425
boolean hasPlan();
2526

26-
boolean hasProfile();
27+
boolean isProfilePlan();
2728

28-
GraphQueryPlan getPlan();
29+
Optional<GraphQueryPlan> getPlan();
2930
}

database/neo4j/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/neo4j/bolt/Neo4jBoltBuffer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,20 @@ public boolean hasPlan() {
114114
.orElse(false);
115115
}
116116

117-
public boolean hasProfile() {
117+
public boolean isProfilePlan() {
118118
return Optional.ofNullable(resultSummary)
119119
.map(ResultSummary::hasProfile)
120120
.orElse(false);
121121
}
122122

123-
public GraphQueryPlan getQueryPlan() {
123+
public Optional<GraphQueryPlan> getQueryPlan() {
124124
if (!hasPlan()) {
125-
return null;
125+
return Optional.empty();
126126
}
127127

128128
Plan plan = resultSummary.plan();
129-
return new Neo4jBoltQueryPlan(plan.operatorType(), getArguments(plan), plan.identifiers(),
130-
getPlanChildren(plan.children()));
129+
return Optional.of(new Neo4jBoltQueryPlan(plan.operatorType(), getArguments(plan), plan.identifiers(),
130+
getPlanChildren(plan.children())));
131131
}
132132

133133
private static List<Neo4jBoltQueryPlan> getPlanChildren(List<? extends Plan> childrenPlans) {

database/neo4j/src/main/java/com/neueda/jetbrains/plugin/graphdb/database/neo4j/bolt/query/Neo4jBoltQueryResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public boolean hasPlan() {
156156
}
157157

158158
@Override
159-
public boolean hasProfile() {
160-
return buffer.hasProfile();
159+
public boolean isProfilePlan() {
160+
return buffer.isProfilePlan();
161161
}
162162

163163
@Override
164-
public GraphQueryPlan getPlan() {
164+
public Optional<GraphQueryPlan> getPlan() {
165165
return buffer.getQueryPlan();
166166
}
167167

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/GraphConsoleView.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
import javax.swing.*;
4242
import java.awt.*;
43+
import java.awt.event.MouseAdapter;
4344
import java.awt.event.MouseEvent;
44-
import java.awt.event.MouseListener;
4545
import java.time.LocalDateTime;
4646
import java.time.format.DateTimeFormatter;
4747
import java.time.format.DateTimeFormatterBuilder;
@@ -51,6 +51,8 @@
5151

5252
public class GraphConsoleView implements Disposable {
5353

54+
public static final String PROFILE_PLAN_TITLE = "Profile";
55+
public static final String EXPLAIN_PLAN_TITLE = "Explain";
5456
private boolean initialized;
5557

5658
private ExecutionStatusBarWidget executionStatusBarWidget;
@@ -147,36 +149,20 @@ private void createUIComponents() {
147149
consoleTabsPane = new JBTabsPaneImpl(null, SwingConstants.TOP, this);
148150
consoleTabs = (JBTabsImpl) consoleTabsPane.getTabs();
149151

150-
consoleTabs.addTabMouseListener(new MouseListener() {
152+
consoleTabs.addTabMouseListener(new MouseAdapter() {
151153
@Override
152154
public void mouseReleased(MouseEvent e) {
153155
if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
154156
final TabInfo info = consoleTabs.findInfo(e);
155157
if (info != null) {
156158
String tabTitle = info.getText();
157-
if (tabTitle.startsWith("Profile") || tabTitle.startsWith("Explain")) {
159+
if (tabTitle.startsWith(PROFILE_PLAN_TITLE) || tabTitle.startsWith(EXPLAIN_PLAN_TITLE)) {
158160
IdeEventQueue.getInstance().blockNextEvents(e);
159161
consoleTabs.removeTab(info);
160162
}
161163
}
162164
}
163165
}
164-
165-
@Override
166-
public void mouseClicked(MouseEvent e) {
167-
}
168-
169-
@Override
170-
public void mousePressed(MouseEvent e) {
171-
}
172-
173-
@Override
174-
public void mouseEntered(MouseEvent e) {
175-
}
176-
177-
@Override
178-
public void mouseExited(MouseEvent e) {
179-
}
180166
});
181167
}
182168

@@ -217,7 +203,7 @@ public void actionPerformed(AnActionEvent e) {
217203
});
218204
tabInfo.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB);
219205

220-
String planType = result.hasProfile() ? "Profile" : "Explain";
206+
String planType = result.isProfilePlan() ? PROFILE_PLAN_TITLE : EXPLAIN_PLAN_TITLE;
221207
consoleTabs.addTab(tabInfo.setText(String.format("%1s %2d - %3s", planType, tabId,
222208
LocalDateTime.now().format(QUERY_PLAN_TIME_FORMAT))));
223209
}

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/plan/QueryPlanPanel.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.awt.*;
2626
import java.util.Collection;
2727
import java.util.Map;
28+
import java.util.Optional;
2829
import java.util.stream.Stream;
2930

3031
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.plan.ColumnDefinitions.getProfileQueryPlanColumns;
@@ -47,7 +48,12 @@ public void initialize(Container container) {
4748
queryLabel.setRows(3);
4849
queryLabel.setEditable(false);
4950

50-
ListTreeTableModelOnColumns model = createModel(result.getPlan(), result.hasProfile());
51+
GraphQueryPlan graphQueryPlan = result.getPlan()
52+
.orElseThrow(() ->
53+
new ShouldNeverHappenException("Sergey Ishchenko",
54+
"GraphQueryPanel is initialized when explain or profile queries are executed"));
55+
56+
ListTreeTableModelOnColumns model = createModel(graphQueryPlan, result.isProfilePlan());
5157

5258
treeTable = new TreeTableView(model);
5359
treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
@@ -131,16 +137,20 @@ private static long calculateTotalDbHits(GraphQueryPlan plan) {
131137

132138
@NotNull
133139
private static String getStatusText(GraphQueryResult result) {
134-
Map<String, Object> args = result.getPlan().getArguments();
135140
StringBuilder sb = new StringBuilder();
136-
sb.append("Cypher version: ").append(args.getOrDefault(VERSION.getKey(), '-')).append(", ")
137-
.append("planner: ").append(args.getOrDefault(PLANNER.getKey(), '-'))
138-
.append("(").append(args.getOrDefault(PLANNER_IMPL.getKey(), '-')).append("), ")
139-
.append("runtime: ").append(args.getOrDefault(RUNTIME.getKey(), '-'));
140-
141-
if (result.hasProfile()) {
142-
sb.append(", ").append(calculateTotalDbHits(result.getPlan())).append(" total db hits in ")
143-
.append(result.getExecutionTimeMs()).append("ms.");
141+
142+
Optional<GraphQueryPlan> plan = result.getPlan();
143+
if (plan.isPresent()) {
144+
Map<String, Object> args = plan.get().getArguments();
145+
sb.append("Cypher version: ").append(args.getOrDefault(VERSION.getKey(), '-')).append(", ")
146+
.append("planner: ").append(args.getOrDefault(PLANNER.getKey(), '-'))
147+
.append("(").append(args.getOrDefault(PLANNER_IMPL.getKey(), '-')).append("), ")
148+
.append("runtime: ").append(args.getOrDefault(RUNTIME.getKey(), '-'));
149+
150+
if (result.isProfilePlan()) {
151+
sb.append(", ").append(calculateTotalDbHits(plan.get())).append(" total db hits in ")
152+
.append(result.getExecutionTimeMs()).append("ms.");
153+
}
144154
}
145155

146156
return sb.toString();

0 commit comments

Comments
 (0)