-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add restoration functionality for shared database #2014
Conversation
0bccbc6
to
412a412
Compare
try { | ||
new SharedDatabaseUIManager(mainFrame, keywordSeparator).openLastSharedDatabaseTab(isFocused); | ||
} catch (ClassNotFoundException | SQLException | DatabaseNotSupportedException e) { | ||
LOGGER.error("Failed to restore shared database. Use connection dialog to connect."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the exception e
as second parameter to the logger.error (there is already an overload for that=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't add it, cause those exceptions basically inform the user about the failure. It's not a real problem. But I think it's better to use LOGGER.info(...)
. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay. It's just about that in case of a real exception, e.g. soemthing is wrong it helps the developers to debug the root cause ;)
412a412
to
2be310d
Compare
- Restoration of the last shared database tab which was sucessfully connected - Popup of the connection dialog for the case that the new connection wasn't sucessfull - Reorganisation of DBMSConnectionProperties & OpenSharedDatabaseDialog (simplification)
2be310d
to
d8257e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some minor comments
} | ||
} | ||
|
||
if (prefs.getHost().isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use prefs.getHost().ifPresent(prefsHost -> this.host = prefsHost)
.
This avoids the if statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
try { | ||
this.password = new Password(prefs.getPassword().get().toCharArray(), prefs.getUser().get()).decrypt(); | ||
} catch (UnsupportedEncodingException | GeneralSecurityException e) { | ||
LOGGER.error("Could not decrypt pasword" + e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace +
with ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
if (prefs.getPort().isPresent()) { | ||
this.port = Integer.parseInt(prefs.getPort().get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should catch here the NumberFormatException and log, if the port contains some values that cannot converted to an int. Or is this somewhere else done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A NumberFormatException
can never occur, except hard changes in prefs
(on the file system or registry) were made.
} | ||
|
||
if (prefs.getUser().isPresent()) { | ||
this.user = prefs.getUser().get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't add here if(prefs.getPassword.isPresent())
? Then you don't have to check twice if user is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean ifPresent...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well the user as the password is required for the class Password
. It takes the Username as secret key. Therefore I have to check both. Or am I understanding sth. wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, here I meant isPresent
. You check here for user.isPresent and below you check whether password.isPresent and user.isPresent. So why don't combine both:
if(prefs.getUser().isPresent() {
this.user = ...
if(prefs.getPassword().isPresent() {
this.password = ....
}
}
So then you have only one check if prefs.getUser.isPresent and not twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both is required you could just combine the two with and &&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok nevermind. That's ok how it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you mean sth. like:
if (A) {
x = ...
}
if (A && B) {
y = ...
}
=>
if (A) {
x = ...
if (B) {
y = ...
}
}
Here you can save one check (A). 👍
Done.
@tschechlovdev Thanks for suggestions 👍. Appropriate changes have been applied. |
94fe423
to
d8257e7
Compare
} | ||
} | ||
|
||
if (!prefs.getPassword().isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could combine this if and the if statement above with an if / else if like the following:
if(!prefs.getPassword().isPresent()) {
...
} else if(prefs.getPassword().isPresent() && prefs.getUser().isPresent()){
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I choosed the option from above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's ok 👍
But then please delete
prefs.getUser().ifPresent(theUser -> this.user = theUser);
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah. Done.
5c0f46a
to
eea0629
Compare
eea0629
to
5d30b42
Compare
- Fix Conflicts in: CHANGELOG.md src/main/java/net/sf/jabref/gui/JabRefFrame.java src/main/java/net/sf/jabref/gui/shared/OpenSharedDatabaseDialog.java src/main/java/net/sf/jabref/gui/shared/SharedDatabaseUIManager.java
b917634
to
5d3e8c1
Compare
Went through with Admir. LGTM. |
- Restoration of the last shared database tab which was sucessfully connected - Popup of the connection dialog for the case that the new connection wasn't sucessfull - Reorganisation of DBMSConnectionProperties & OpenSharedDatabaseDialog (simplification)
Related to #1703:
-> Decision: Open from last connection.