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

Issue #90 Convert to RunCommand: CountCollectionByNameStatement + int… #104

Conversation

jsonking
Copy link

@jsonking jsonking commented Feb 20, 2021

introduce ListCollectionNamesStatement (as a runCommand statement) to be used by

  • CountCollectionByNameStatement
  • DropAllCollectionsStatement

Edited DropCollectionStatement to support options ( as per https://docs.mongodb.com/manual/reference/command/drop/ )

┆Issue is synchronized with this Jira Bug by Unito

@jsonking
Copy link
Author

Please squash the commits when merging if you are happy to include this change request.

…uce ListCollectionNamesStatement for this and DropAllCollectionsStatement
…tatement and DropAllCollectionsStatement to AbstractRunCommandStatement
@Getter
@EqualsAndHashCode(callSuper = true)
public class CountCollectionByNameStatement extends AbstractCollectionStatement
public class CountCollectionByNameStatement extends ListCollectionNamesStatement
Copy link
Author

Choose a reason for hiding this comment

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

I'm curious - why not prefer composition over inheritance?

Choose a reason for hiding this comment

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

Just unified logic under AbstractRunCommandStatement as in the end they are runCommand underneath. It eliminates duplication of code and logic like toJs, run, checkErrors, etc. Yes we could think about adopting composition if you give an example of real value. For now I don't see that as an urgency. We could go via SqlGenerators used by over liquibase SqlStatements however think it brings more complexity rather than value.

Comment on lines +46 to +51
public static final String FILTER = "filter";
public static final String CURSOR = "cursor";
public static final String FIRST_BATCH = "firstBatch";
public static final String NAME = "name";
public static final String AUTHORIZED_COLLECTIONS = "authorizedCollections";
public static final String NAME_ONLY = "nameOnly";
Copy link
Author

@jsonking jsonking Feb 23, 2021

Choose a reason for hiding this comment

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

My personal style would not extract constants for these unless there's reuse as it detracts from readability in-situ (increasing the 'code distance' which increases probability of errors). There's no performance penalty since the compiler will optimise the String literals anyway.
Could these be private static final String... too?

Noted that this is the style you would like in the project though, so will follow it moving forward.

Choose a reason for hiding this comment

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

Yes, that's style and some of our Sonar rules related to magic values. I prefer the fields used by mongo driver to be as constants, even for the current set NAME is reused. For example Cosmos java driver is exposing constants for their fields which I'm using in the liquibase-cosmosdb extension. Related to whether the constants have to be private, I usually don't like hiding the things that do not worth hiding, if they are potentially to be used in other Statements.
Hopefully this style aspects won't irritate you and you will continue contributing :)

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.

Convert all statements to runCommand so it is compatible with majority JavaDriver versions
2 participants