You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by "Hans Drexler (JIRA)" <ji...@apache.org> on 2016/05/11 12:10:12 UTC

[jira] [Commented] (METAMODEL-251) MetaModel should fail when accessing a column that is not a select item

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

Hans Drexler commented on METAMODEL-251:
----------------------------------------

From AbstractRow class

{code}
    @Override
    public final Object getValue(Column column) {
        int index = indexOf(column);
        if (index == -1) {
            return null;
        }
        return getValue(index);
    }
{code}

Should be?

{code}
    @Override
    public final Object getValue(Column column) {
        int index = indexOf(column);
        if (index == -1) {
            throw new MetaModelException("The result set does not contain column: " + column.getName());
        }
        return getValue(index);
    }
{code}

But then also 

{code}
public final Object getValue(SelectItem item)
{code}

should do something similar.

> 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)