Re: Error when join table spans datamaps

From: Mike Kienenberger (mkienen..mail.com)
Date: Thu May 18 2006 - 18:55:25 EDT

  • Next message: Mike Kienenberger: "Re: Error when join table spans datamaps"

    On 5/18/06, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > But this means that Cayenne will be doing a cartesian
    > product in memory, turning Cayenne in a database engine. I am really
    > not comfortable with "this is a natural limitation" excuse I was
    > about to make. Still not sure how else we can solve this. Short of
    > horrible performance, maybe doing joins within Cayenne SQLAction code
    > is not such bad an idea???

    I completely understand that this is going to give horrible performance.
    But horrible performance is better than no performance.

    This is my first-pass at solving the problem at the application level
    by replacing getWorkList() { return (List)readProperty("workList"); }
    with the following. Seems like there might be a better way to do
    this without an SQLTemplate. If I hit a second relationship like
    this, I would probably pull the string together from the
    ObjEntity/DbEntity fields -- actually I might see if I can fix this in
    the template since all of that info is available there.

    However, I'm not certain that this is sufficient. This might not be
    something I can fix from the application level, short of removing the
    relationships in the datamap.

    I'm hoping I can leave addToWorkList and removeFromWorkList alone.

    I haven't looked at SQLAction so I'm not sure how that fits in yet.
    I'll take a look when I get a chance.

        private List getWorkListTheHardWay()
        {
            String sql = "select distinct(WORK_ID) as ID from
    ENG_WORK_MGMT.AUTHORIZATION_DOC__WORK where AUTHORIZATION_DOCUMENT_ID
    = $PRIMARY_KEY";

            // set parameters and run it...
            Map parameters = new HashMap();
            parameters.put("PRIMARY_KEY", getPrimaryKey());
            SQLTemplate rawSelect = new SQLTemplate(getClass(), sql, true);
            rawSelect.setParameters(parameters);
            rawSelect.setFetchingDataRows(true);
            List distinctFKList = getDataContext().performQuery(rawSelect);

            List toManyList = new ArrayList(distinctFKList.size());
            Iterator foreignKeyIterator = distinctFKList.iterator();
            while (foreignKeyIterator.hasNext())
            {
                DataRow dataRow = (DataRow) foreignKeyIterator.next();
                Object primaryKey = (Object) dataRow.get("ID");
                if (null == primaryKey) continue;

                toManyList.add(DataObjectUtils.objectForPK(getDataContext(),
    com.gvea.core_work_mgmt.entity.cayenne.Work.class, primaryKey));
            }

            return toManyList;
        }



    This archive was generated by hypermail 2.0.0 : Thu May 18 2006 - 18:55:50 EDT