You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
none-void setter-methods are not valid to the javabean specification. An alternative is to add methods named without "set" prefix at all or use the prefix "with", using the regular setter inside and return "self()".
adds a type parameter declaring the type of "this", which is needed to return the real object-type, not it's possibly abstract parent. Therefore users will get a compiler warning on using those interfaces an abstract classes without type-declaration.
Select select = Select.builder().selectBody(
PlainSelect.builder().fromItem(1).selectItems(Arrays.asList(new AllColumns())
.joins(Arrays.asList(Join.builder().rightItem(t2).onExpression( new EqualsTo(new Column(t1, "ref"), new Column(t2, "id"))))
.where(....etc)
.build())
.build();
Where we make the builder accessible through a static method, it can have not the 'set' methods , maybe we get rid of build() with the caveat that it's not returning an immutable object. But that builder lets us not deal with the restriction of void methods.
The effect would be using a static construction method "builder" instead of "new". Static constructors are ok for me, but i would prefer a common util class (i.e. JSQL.select() { return new Select() ;} ) providing static construction methods for this.
The fluent api should operate directly on a mutable object. If you think of the usecase of manipulate a query after parsing, a real builder does not fit the needs.
This sort of feels like jooq to me, particularly the JSQL.select() portions.
I see nothing wrong with that.
But if you like the method within the object and change the name of "builder()" into "create()" it would be more clear that you will create a mutable object without the need to warn about.
adds a type parameter declaring the type of "this", which is needed to return the real object-type, not it's possibly abstract parent. Therefore users will get a compiler warning on using those interfaces an abstract classes without type-declaration.
I reverted this change, because it makes the api incompatible with users of older versions. As an alternative we are able to overwrite fluent setter methods within the concrete type returning the specific concrete type casting the super-result.
i.e.
public class Table implements FromItem {
...
@Override
public Table alias(Alias alias) {
return (Table) FromItem.super.alias(alias);
}
...
}
the advantage is, that you save a lot of brackets, if you want to chain the getter-methods.
ie.
Agreed. The fluent usage is much more concise. You are creating a second way of addressing parse tree objects. Since the visitor stuff is sometimes daunting. But this would be a massive change / addition, right?
void setExpr(Expression expr);
Expression getExpr();
T get(Class<T>);
MyClass withExpr(Expression expr);
So the last both have to be implemented for all methods, to be complete.
The casting getter is implemented for all methods returning interfaces or abstract types, the last method (chaining setter) is implemented for all setters (but i'ts named without prefix "with" at the moment)
If I didn't overlooked something the changes should be backward compatible. The performance shouldn't be touched. So we don't even make a new major version.
So this will be a huge improvement due to the useability of this tool. Nice.
Activity
https://github.com/JSQLParser/JSqlParser/issues/1004
gitmotte commentedon Jun 27, 2020
Downside:
AnEmortalKid commentedon Jun 27, 2020
@gitmotte how do you feel about:
Where we make the builder accessible through a static method, it can have not the 'set' methods , maybe we get rid of
build()with the caveat that it's not returning an immutable object. But that builder lets us not deal with the restriction of void methods.gitmotte commentedon Jun 27, 2020
The effect would be using a static construction method "builder" instead of "new". Static constructors are ok for me, but i would prefer a common util class (i.e. JSQL.select() { return new Select() ;} ) providing static construction methods for this.
i.e:
But i'm ok with the new operator too! The utility class may contain more complex shortcut-methods for building sql.
gitmotte commentedon Jun 27, 2020
I'm ok with methods without prefix "set" and "with"-methods are good option too, not breaking javabean spec. What is your preference?
gitmotte commentedon Jun 27, 2020
The fluent api should operate directly on a mutable object. If you think of the usecase of manipulate a query after parsing, a real builder does not fit the needs.
AnEmortalKid commentedon Jun 27, 2020
This sort of feels like
jooqto me, particularly theJSQL.select()portions.Isn't anything outside
setfor mutators,get/isfor accesors not part of the bean spec?gitmotte commentedon Jun 27, 2020
I see nothing wrong with that.
But if you like the method within the object and change the name of "builder()" into "create()" it would be more clear that you will create a mutable object without the need to warn about.
But leave the empty constructor public because of the javabean-spec !
Yes,
get/isare part of the javabean-spec too, but we won't change them.For all Collection - fields i'd like to add elements without the need to create an empty list.
i.e.
gitmotte commentedon Jun 29, 2020
I reverted this change, because it makes the api incompatible with users of older versions. As an alternative we are able to overwrite fluent setter methods within the concrete type returning the specific concrete type casting the super-result.
i.e.
and
https://github.com/JSQLParser/JSqlParser/issues/1004
gitmotte commentedon Jun 29, 2020
Check out new branch master.fluent to get a picture of all api addons i'd like to add:
returning concrete type
interface-type
@AnEmortalKid @wumpz how do you feel about the proposed changes? Whould you merge them into your lib?
JSQLParser#1004 add chaining - methods returning "this"
* add<Name> methods on collection-fields with varargs-parameter
AnEmortalKid commentedon Jul 3, 2020
Comparison link: master...gitmotte:master.fluent
AnEmortalKid commentedon Jul 3, 2020
Those seem fine to me, it's @wumpz 's call.
Is the expectation here that future enhancements also include chained methods like these?
I think if you were to PR this, you'd probably have to do it in chunks just cause 100+ files is harder to parse through mentally
16 remaining items
wumpz commentedon Jul 4, 2020
So I assume you somehow limit the scope of where the changes should happen.
gitmotte commentedon Jul 4, 2020
The casting getter is implemented for all methods returning interfaces or abstract types, the last method (chaining setter) is implemented for all setters (but i'ts named without prefix "with" at the moment)
The "with" prefix i would add if you prefer it, but next week ...
wumpz commentedon Jul 4, 2020
The get instead of getExpr was simply a typo. :)
If I didn't overlooked something the changes should be backward compatible. The performance shouldn't be touched. So we don't even make a new major version.
So this will be a huge improvement due to the useability of this tool. Nice.
I would indeed prefer the with prefix.
* add with prefix for fluent setters.
* add with prefix for fluent setters. (revert to chaining setters, do
* add with prefix for fluent setters. (revert to chaining setters, do
gitmotte commentedon Jul 14, 2020
@wumpz @AnEmortalKid i put a merge request for this issue some days ago, have you seen it?
AnEmortalKid commentedon Jul 14, 2020
negative @gitmotte , lost track of it since your other PR was merged :) thx for the reminder, i'll take a look tonight!
wumpz commentedon Jul 15, 2020
@gitmotte thx for reminding me. I got into another issue.
Fluent builder api #1004 (#1014)
wumpz commentedon Aug 25, 2020
Since the corresponding pull request was merged, I close this issue.
Fluent builder api JSQLParser#1004 (JSQLParser#1014)
Validation visitor framework (#1045)
Closes JSQLParser#1004, removed superfluous constructor.