[ 
https://issues.apache.org/jira/browse/METAMODEL-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15280296#comment-15280296
 ] 

Kasper Sørensen commented on METAMODEL-251:
-------------------------------------------

Interesting idea. I guess we should really carefully consider if we want the 
behaviour to change this way. I always thought that the interface of a Row was 
resembling that of a Map, and I would usually not expect my maps to throw 
exceptions when keys are not resolved. But I can see your point too, failing 
fast is good - as long as we then all agree that this is a real failure... It 
depends a lot on how we want/expect the usage of the object to be.

I forget if the Row interface has "containsColumn(...)" and/or 
"containsSelectItem(...)" like methods already. Having those would be quite an 
important addition as well.

The change would certainly be one that has quite some implifications for end 
users, so I would suggest that it would go into the 5.0 branch, if we decide to 
do this.

Small remarks on your proposal patch, should we decide to go with the idea:

 * I would use IllegalArgumentException instead of MetaModelException and the 
use of this should be explicit on the interface declaration and javadoc.
 * In the exception message I would make sure we're consistent about using the 
word "DataSet" and not "result set" or other aliases.

> MetaModel should fail when accessing a column that is not a select item
> -----------------------------------------------------------------------
>
>                 Key: METAMODEL-251
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-251
>             Project: Apache MetaModel
>          Issue Type: Bug
>    Affects Versions: 4.5.2
>         Environment: Postgres
>            Reporter: Hans Drexler
>         Attachments: MetaModel251Sample.java
>
>
> In our software, we create a query with SelectItems for 6 out of the 7 
> columns of a postgres data base table. We actually forgot to add the seventh 
> column as a SelectItem.
> {code}
>         query.select(selectItems)
>              .from(someTable)
> {code}
> When consuming the rows returned by this query, the code actually fetches the 
> column that was not a select item, using a construct like:
> {code}
> row.getValue(table.getColumnByName('foo'));
> {code}
> This returns null values most of the time. But under stress, the code starts 
> to throw exceptions. 
> It would be much better if MetaModel throws an exception when the code 
> attempts to access a column that is not part of the query (fail fast).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to