Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor shared package into the architecture #3523

Merged
merged 3 commits into from
Jan 2, 2018
Merged

Conversation

lenhard
Copy link
Member

@lenhard lenhard commented Dec 12, 2017

The new Java 9 module system brings us the possibility to actually modularize inside Java, i.e. to distribute our source code into multiple modules and specify dependencies and constraints among them, much in the way that we do it now with tests. But to extract modules, there can be no cyclic dependencies among them.

The model package is our best candidate for extracting a new module. Here the last dependency that coupled it to transitively to everything else was the shared package. This PR refactors the shared package and puts most of it into logic. I broke the dependency from model by introducing a number of interface that the logic layer implements. These interfaces will have just one implementation now, but at least they break the dependency cycle.

This is just a refactoring, so I think it should be merged after the release of 4.1


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@lenhard lenhard added this to the v4.2 milestone Dec 12, 2017
.putAllDBMSConnectionProperties(properties);
DatabaseSynchronizer synchronizer = context.getDBMSSynchronizer();
if (synchronizer instanceof DBMSSynchronizer) {
DatabaseConnectionProperties properties = ((DBMSSynchronizer) synchronizer).getDBProcessor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add getDBMSConnectionProperties to the Synchronizer interface, then you probably don't need the if statement and the explicit cast here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nicely spotted! So far, I was focused on the refactoring only, but the code certainly has a lot of potential for improvements. Implementing your suggestion was fairly easy and I fixed this at a second position as well.

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring is a nice step in the right direction. In the long term, I think we should refactor everything related to saving and opening databases to use a common interfaces regardless if the file is stored on the PC, in the cloud or somewhere else.

@koppor
Copy link
Member

koppor commented Dec 14, 2017

This refs #110. I am still planning to work on that as I want to provide our logic package as standalone library.

@lenhard
Copy link
Member Author

lenhard commented Dec 15, 2017

@koppor Ah, I was looking for that issue :) Maybe we should re-open it, since we now have a tangible use case (the new Java module system). Once the model package is modularized, the logic package will not be far off.

@lenhard
Copy link
Member Author

lenhard commented Jan 2, 2018

@JabRef/developers With another review, this could be merged.


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Keeps all essential data for establishing a new connection to a DBMS using {@link DBMSConnection}.
*/
public class DBMSConnectionProperties {
public class DBMSConnectionProperties implements DatabaseConnectionProperties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only don't get this, isn't this supposed to be same or are DataBaseConnectionProperties more general?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBMSConnectionProperties are the only implementation of DatabaseConnectionProperties, they're essentially the same. The sole reason for the existence of the interface is that it breaks the dependency from model to elsewhere.


void registerListener(Object listener);

void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would let this rather be more general, by not having the concrete SQLException here. I could implement this interface for my Sharelatex Connection.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've inlined the SQLException in favor of an IllegalStateException.

@tobiasdiez tobiasdiez merged commit c751715 into master Jan 2, 2018
@tobiasdiez tobiasdiez deleted the refactor-shared branch January 2, 2018 18:38
Siedlerchr added a commit that referenced this pull request Jan 2, 2018
* upstream/master:
  Refactor shared package into the architecture (#3523)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants