Skip to content

JAVA-1174: Add ifNotExists option to mapper - #826

Merged
olim7t merged 2 commits into
3.xfrom
java1174
Mar 13, 2017
Merged

olim7t merged 2 commits into
3.xfrom
java1174

Conversation

@olim7t

@olim7t olim7t commented Mar 9, 2017

Copy link
Copy Markdown
Contributor

No description provided.

@olim7t olim7t added this to the 3.2.0 milestone Mar 9, 2017

@adutra adutra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

void appendTo(Insert.Options usings) {
throw new UnsupportedOperationException("shouldn't be called");
void validate(QueryType qt, MappingManager manager) {
checkArgument(qt == QueryType.SAVE || qt == QueryType.DEL || qt == QueryType.GET,

@adutra adutra Mar 10, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just noticed: this check is useless, these is no other QueryType at this moment.

void appendTo(Insert.Options usings) {
throw new UnsupportedOperationException("shouldn't be called");
void validate(QueryType qt, MappingManager manager) {
checkArgument(qt == QueryType.SAVE || qt == QueryType.DEL || qt == QueryType.GET,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here.

@newkek newkek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sgtm, had some minor comments

* Options may also affect the statement itself, not a bound variable; in that case, the
* method must return the index unchanged.
*/
abstract int bind(BoundStatement bs, int currentIndex);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bind sounds a bit ambiguous to me since the implementations are going to either bind a parameter, or set an option on the statement. Couldn't we call it something like applyOption?


final Type type;

protected Option(Type type) {

@newkek newkek Mar 10, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just noticed that I don't think protected is actually helpful here, I think it can go package-private. Since the other abstract methods on Option are package-private, I don't think we can expect anybody outside the driver to extends Option because of the package private abstract methods, and so the only implementations possible are in this package

* Otherwise, comparing the class is good enough. See subclasses for examples.
*/
@Override
public abstract boolean equals(Object other);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Isn't it misleading that we end up with different options with different values being equal? Meaning Option.ttl(1).equals(Option.ttl(2)) // => true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, the option values are exposed to the end user after all. I've added an asCacheKey method to improve this.

@tolbertam

tolbertam commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

I think we need to add a rule in Clirr:

[ERROR] 7002: com.datastax.driver.mapping.Mapper$Option: Method 'public com.datastax.driver.mapping.Mapper$Option$Type getType()' has been removed

I don't think users would address Options separately (just always pass in Option / never look at it), so it is probably ok to add an exception, wdyt?

@tolbertam

Copy link
Copy Markdown
Contributor

On second thought, it seems like it wouldn't be a problem to add getType() back and that seems like the most low risk thing to do, thoughts?


@Override
void validate(QueryType qt, MappingManager manager) {
checkArgument(qt == QueryType.SAVE, "IfNotExists option is only allowed in save queries");

@tolbertam tolbertam Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could technically protocol version check here like we do for TTLs, although LWTs aren't tied to protocol version but CQL/C* version instead ( so maybe it's best the way it is since we can't reliably check if the C* server will support it)

@tolbertam

Copy link
Copy Markdown
Contributor

Ah, type itself was protected to begin with, so even though the API method was present, you couldn't use it for comparison purposes...sounds like clirr rule is more appropriate after all.

@tolbertam

Copy link
Copy Markdown
Contributor

Went ahead and added the clirr exception, feel free to back out if disagree. Also added a couple negative tests.

@olim7t

olim7t commented Mar 13, 2017

Copy link
Copy Markdown
Contributor Author

Good catch. The public getType was an oversight, but just to be safe I think it's better to keep it and deprecate it.

@tolbertam tolbertam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm 👍

@tolbertam

Copy link
Copy Markdown
Contributor

Just remembered, it would be good to add the new option to the manual where we document the rest of the mapper options.

- improve method names
- prepare for options that require different prepared statements
  depending on their value
@olim7t

olim7t commented Mar 13, 2017

Copy link
Copy Markdown
Contributor Author

Done

@olim7t olim7t changed the title JAVA-1174: Add IF_NOT_EXISTS option to mapper JAVA-1174: Add ifNotExists option to mapper Mar 13, 2017
@olim7t
olim7t merged commit 30d30b1 into 3.x Mar 13, 2017
@olim7t
olim7t deleted the java1174 branch March 13, 2017 22:12
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.

5 participants