I’m trying to insert a new row into a database. The new data comes from a form, and is bind to a new temporary RowItem that is filled by the user. Not all the rows have to be inserted in the database as some are
null
and some other are autogenerated, although some can be manually overriden/inserted in concrete situations. For this reason I’m getting all the database row when I query them from the database, and they all “are” in my RowItem object.
So when I’m passing it to my StatementDelegate in order to be used to construct the final query (via utilities like
generateInsertQuery()
), I found there was a
removeItemProperty()
which seemed useful to me for removing “columns” (item properties) that I didn’t want in the final constructed query. I was getting some exceptions, so I did a debugging session and amazingly discovered that the RowItem
removeItemProperty(Object id)
method, an implementation of the Item interface, was simply throwing an UnsupportedOperationException()! More surprisingly, in the Javadoc for that method it says that "
Removing properties is not supported. Properties are generated by SQLContainer
.".
Well, it may be that I’m not approaching it from the proper view, but I already explained a situation where I’m using a bunch of properties in my SQLContainer, coming from a RowItem, where I want to remove some of them at a certain moment. Anyway, if Vaadin designers think that properties don’t have to be ever removed from a RowItem, then what’s the point of implementing a method that all what it does is throwing an exception?? It’s misleading and surely is not good practice, but, morevoer, one goes to the Item interface to read the specification and discovers that
addItemProperty()
and
removeItemProperty()
are “optional”. "
This functionality is optional
.", says there. Then, why you define them in an interface? If the whole purpose of an interface is to define method functionality that has to be implemented in an implementing class, why do you say there that “is optional”? And why in the hell you “implement” it as a “just exception-throwing” method? Better remove it from the interface (it’s your own interface! You can do it!), or don’t say that class is implementing it because it’s not true.
Again, I’d be happy to get some advise if my approach is terribly wrong, but finding those things that, to me, break the fundamental principles of object-oriented programming, is very discouraging.