openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin <kns...@gmail.com>
Subject Re: Restrict collection items
Date Thu, 25 Dec 2008 07:08:09 GMT

Perhaps I should put here getWhere() method too, because its modification is
needed for lazily fetched collections. It is quite obscure, but may be it
will help to someone in similar situation.

    protected SQLBuffer getWhere(Select sel, boolean forUpdate) {
        Joins joins = sel.getJoins();
        if (sel.getJoinSyntax() == SYNTAX_SQL92
            || joins == null || joins.isEmpty())
        {
            SQLBuffer buf = sel.getWhere();

            Map<Table, String> tables = new HashMap<Table, String>();
            Collection columns;
            if (buf != null) {
                columns = buf.getColumns();
            }
            else {
                columns = sel.getSelects();
            }
            for (Object item : columns) {
                if (item instanceof Column) {
                    Column col = (Column) item;
                    for (String s : (Collection<String>)
sel.getTableAliases()) {
                        int i = s.indexOf(' ');
                        String tableName = s.substring(0, i);
                        if (col.getTable().getName().equals(tableName)) {
                            if
(col.getTable().containsColumn(DELETE_TS_COL))
                                tables.put(col.getTable(), s.substring(i +
1));
                            break;
                        }
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            for (String alias : tables.values()) {
                sb.append(alias).append(".").append(DELETE_TS_COL).append("
IS NULL");
            }
            sel.where(sb.toString());
            return sel.getWhere();
        }
    ...
    }   

Regards,
Konstantin

-- 
View this message in context: http://n2.nabble.com/Restrict-collection-items-tp1690569p1802209.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message