Skip to content

Commit 8359c4a

Browse files
committed
Review fixes
1 parent 9fc9e23 commit 8359c4a

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
@@ -41,8 +41,8 @@
4141

4242
import javax.swing.*;
4343
import java.awt.*;
44+
import java.awt.event.MouseAdapter;
4445
import java.awt.event.MouseEvent;
45-
import java.awt.event.MouseListener;
4646
import java.time.LocalDateTime;
4747
import java.time.format.DateTimeFormatter;
4848
import java.time.format.DateTimeFormatterBuilder;
@@ -52,6 +52,8 @@
5252

5353
public class GraphConsoleView implements Disposable {
5454

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

5759
private ExecutionStatusBarWidget executionStatusBarWidget;
@@ -153,36 +155,20 @@ private void createUIComponents() {
153155
consoleTabsPane = new JBTabsPaneImpl(null, SwingConstants.TOP, this);
154156
consoleTabs = (JBTabsImpl) consoleTabsPane.getTabs();
155157

156-
consoleTabs.addTabMouseListener(new MouseListener() {
158+
consoleTabs.addTabMouseListener(new MouseAdapter() {
157159
@Override
158160
public void mouseReleased(MouseEvent e) {
159161
if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
160162
final TabInfo info = consoleTabs.findInfo(e);
161163
if (info != null) {
162164
String tabTitle = info.getText();
163-
if (tabTitle.startsWith("Profile") || tabTitle.startsWith("Explain")) {
165+
if (tabTitle.startsWith(PROFILE_PLAN_TITLE) || tabTitle.startsWith(EXPLAIN_PLAN_TITLE)) {
164166
IdeEventQueue.getInstance().blockNextEvents(e);
165167
consoleTabs.removeTab(info);
166168
}
167169
}
168170
}
169171
}
170-
171-
@Override
172-
public void mouseClicked(MouseEvent e) {
173-
}
174-
175-
@Override
176-
public void mousePressed(MouseEvent e) {
177-
}
178-
179-
@Override
180-
public void mouseEntered(MouseEvent e) {
181-
}
182-
183-
@Override
184-
public void mouseExited(MouseEvent e) {
185-
}
186172
});
187173
}
188174

@@ -225,7 +211,7 @@ public void actionPerformed(AnActionEvent e) {
225211
});
226212
tabInfo.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB);
227213

228-
String planType = result.hasProfile() ? "Profile" : "Explain";
214+
String planType = result.isProfilePlan() ? PROFILE_PLAN_TITLE : EXPLAIN_PLAN_TITLE;
229215
consoleTabs.addTab(tabInfo.setText(String.format("%1s %2d - %3s", planType, tabId,
230216
LocalDateTime.now().format(QUERY_PLAN_TIME_FORMAT))));
231217
}

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)