You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "sdedic (via GitHub)" <gi...@apache.org> on 2023/02/24 15:49:42 UTC
[GitHub] [netbeans] sdedic opened a new pull request, #5560: Vscode ext should update default extension
sdedic opened a new pull request, #5560:
URL: https://github.com/apache/netbeans/pull/5560
The vscode "Database" view queried NBLS for the default DB just on startup, then it retained the connection node's ID, and only allowed vscode > NBLS change propagation. We need - for example when defining a new DB - that the NBLS's default connection is reflected back in the vscode. That will help if no connection is present and a new (first) one is defined that becomes the default. May also help in cases when other command(s) redefine the default connection internally.
I've changed DB module since there was a bug in that it offered the 1st connection as a default if none was specifically set - but was willing to change the default 'on the fly' if a new connection appeared, so the default could shift unexpectedly. Case when there's a preferred connection name stored, but the definition is somehow missing was also mishandled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lbownik commented on a diff in pull request #5560: Vscode ext should update default extension
Posted by "lbownik (via GitHub)" <gi...@apache.org>.
lbownik commented on code in PR #5560:
URL: https://github.com/apache/netbeans/pull/5560#discussion_r1118136263
##########
ide/db/src/org/netbeans/modules/db/explorer/ConnectionList.java:
##########
@@ -273,32 +278,57 @@ public void setPreferredConnection(DatabaseConnection c) {
}
ref.clear();
preferred = new PreferredRef(c);
+ lastPrefName = null;
}
dbPreferences.put(PREF_PREFERRED_CONNECTION_NAME, c.getName());
fireListeners();
}
public DatabaseConnection getPreferredConnection(boolean selectFirst) {
- DatabaseConnection p = preferred.get();
- if (p != null) {
- return p;
+ String fallback;
+ DatabaseConnection p;
+ synchronized (this) {
+ p = preferred.get();
+ if (p != null) {
+ return p;
+ }
+ fallback = this.lastPrefName;
}
String prefName = dbPreferences.get(PREF_PREFERRED_CONNECTION_NAME, null);
DatabaseConnection[] conns = getConnections();
- if (prefName == null) {
- return conns.length == 0 || !selectFirst ? null : conns[0];
+ DatabaseConnection selected = findConnection(prefName, conns);
+ boolean prefChanged = false;
+ if (selected == null) {
+ if (conns.length > 0) {
+ // find the last one, or just anything.
+ selected = findConnection(fallback, conns);
+ }
+ if (selected != null) {
+ prefChanged = !Objects.equals(lastPrefName, selected.getName());
+ lastPrefName = selected.getName();
+ } else {
+ return null;
+ }
}
+ synchronized (this) {
+ p = preferred.get();
+ if (p == null) {
+ preferred = new PreferredRef(selected);
+ p = selected;
+ }
+ }
+ if (prefChanged) {
+ fireListeners();
+ }
+ return p;
+ }
+
+ private static DatabaseConnection findConnection(String name, DatabaseConnection[] conns) {
for (int i = 0; i < conns.length; i++) {
Review Comment:
for-each loop maybe?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a diff in pull request #5560: Vscode ext should update default connection
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #5560:
URL: https://github.com/apache/netbeans/pull/5560#discussion_r1126016374
##########
ide/db/src/org/netbeans/modules/db/explorer/ConnectionList.java:
##########
@@ -273,32 +278,57 @@ public void setPreferredConnection(DatabaseConnection c) {
}
ref.clear();
preferred = new PreferredRef(c);
+ lastPrefName = null;
}
dbPreferences.put(PREF_PREFERRED_CONNECTION_NAME, c.getName());
fireListeners();
}
public DatabaseConnection getPreferredConnection(boolean selectFirst) {
- DatabaseConnection p = preferred.get();
- if (p != null) {
- return p;
+ String fallback;
+ DatabaseConnection p;
+ synchronized (this) {
+ p = preferred.get();
+ if (p != null) {
+ return p;
+ }
+ fallback = this.lastPrefName;
}
String prefName = dbPreferences.get(PREF_PREFERRED_CONNECTION_NAME, null);
DatabaseConnection[] conns = getConnections();
- if (prefName == null) {
- return conns.length == 0 || !selectFirst ? null : conns[0];
+ DatabaseConnection selected = findConnection(prefName, conns);
+ boolean prefChanged = false;
+ if (selected == null) {
+ if (conns.length > 0) {
+ // find the last one, or just anything.
+ selected = findConnection(fallback, conns);
+ }
+ if (selected != null) {
+ prefChanged = !Objects.equals(lastPrefName, selected.getName());
+ lastPrefName = selected.getName();
+ } else {
+ return null;
+ }
}
+ synchronized (this) {
+ p = preferred.get();
+ if (p == null) {
+ preferred = new PreferredRef(selected);
+ p = selected;
+ }
+ }
+ if (prefChanged) {
+ fireListeners();
+ }
+ return p;
+ }
+
+ private static DatabaseConnection findConnection(String name, DatabaseConnection[] conns) {
for (int i = 0; i < conns.length; i++) {
Review Comment:
I usually use for-loops in these situations ... this part was actually extracted from the older code - but that is obviously not an explanation for not updating the style. I usually incorporate 'style issues' whenever some func/perf ("real") issue is found and a new commit has to be made.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic merged pull request #5560: Vscode ext should update default connection
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic merged PR #5560:
URL: https://github.com/apache/netbeans/pull/5560
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] jhorvath commented on a diff in pull request #5560: Vscode ext should update default connection
Posted by "jhorvath (via GitHub)" <gi...@apache.org>.
jhorvath commented on code in PR #5560:
URL: https://github.com/apache/netbeans/pull/5560#discussion_r1124805115
##########
ide/db/src/org/netbeans/modules/db/explorer/ConnectionList.java:
##########
@@ -273,32 +278,57 @@ public void setPreferredConnection(DatabaseConnection c) {
}
ref.clear();
preferred = new PreferredRef(c);
+ lastPrefName = null;
}
dbPreferences.put(PREF_PREFERRED_CONNECTION_NAME, c.getName());
fireListeners();
}
public DatabaseConnection getPreferredConnection(boolean selectFirst) {
- DatabaseConnection p = preferred.get();
- if (p != null) {
- return p;
+ String fallback;
+ DatabaseConnection p;
+ synchronized (this) {
+ p = preferred.get();
+ if (p != null) {
+ return p;
+ }
+ fallback = this.lastPrefName;
}
String prefName = dbPreferences.get(PREF_PREFERRED_CONNECTION_NAME, null);
DatabaseConnection[] conns = getConnections();
- if (prefName == null) {
- return conns.length == 0 || !selectFirst ? null : conns[0];
+ DatabaseConnection selected = findConnection(prefName, conns);
+ boolean prefChanged = false;
+ if (selected == null) {
+ if (conns.length > 0) {
+ // find the last one, or just anything.
+ selected = findConnection(fallback, conns);
+ }
+ if (selected != null) {
+ prefChanged = !Objects.equals(lastPrefName, selected.getName());
+ lastPrefName = selected.getName();
+ } else {
+ return null;
+ }
}
+ synchronized (this) {
+ p = preferred.get();
+ if (p == null) {
+ preferred = new PreferredRef(selected);
+ p = selected;
+ }
+ }
+ if (prefChanged) {
+ fireListeners();
+ }
+ return p;
+ }
+
+ private static DatabaseConnection findConnection(String name, DatabaseConnection[] conns) {
for (int i = 0; i < conns.length; i++) {
Review Comment:
I don't see the problem, it's a matter of personal preference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a diff in pull request #5560: Vscode ext should update default connection
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #5560:
URL: https://github.com/apache/netbeans/pull/5560#discussion_r1126016374
##########
ide/db/src/org/netbeans/modules/db/explorer/ConnectionList.java:
##########
@@ -273,32 +278,57 @@ public void setPreferredConnection(DatabaseConnection c) {
}
ref.clear();
preferred = new PreferredRef(c);
+ lastPrefName = null;
}
dbPreferences.put(PREF_PREFERRED_CONNECTION_NAME, c.getName());
fireListeners();
}
public DatabaseConnection getPreferredConnection(boolean selectFirst) {
- DatabaseConnection p = preferred.get();
- if (p != null) {
- return p;
+ String fallback;
+ DatabaseConnection p;
+ synchronized (this) {
+ p = preferred.get();
+ if (p != null) {
+ return p;
+ }
+ fallback = this.lastPrefName;
}
String prefName = dbPreferences.get(PREF_PREFERRED_CONNECTION_NAME, null);
DatabaseConnection[] conns = getConnections();
- if (prefName == null) {
- return conns.length == 0 || !selectFirst ? null : conns[0];
+ DatabaseConnection selected = findConnection(prefName, conns);
+ boolean prefChanged = false;
+ if (selected == null) {
+ if (conns.length > 0) {
+ // find the last one, or just anything.
+ selected = findConnection(fallback, conns);
+ }
+ if (selected != null) {
+ prefChanged = !Objects.equals(lastPrefName, selected.getName());
+ lastPrefName = selected.getName();
+ } else {
+ return null;
+ }
}
+ synchronized (this) {
+ p = preferred.get();
+ if (p == null) {
+ preferred = new PreferredRef(selected);
+ p = selected;
+ }
+ }
+ if (prefChanged) {
+ fireListeners();
+ }
+ return p;
+ }
+
+ private static DatabaseConnection findConnection(String name, DatabaseConnection[] conns) {
for (int i = 0; i < conns.length; i++) {
Review Comment:
I usually use for-loops in these situations ... this part was actually extracted from the older code that is obviously no excuse for not updating the style. I usually incorporate 'style issues' whenever some func/perf ("real") issue is found and a new commit has to be made.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists