Re: Error when join table spans datamaps

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu May 18 2006 - 19:35:34 EDT

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

    Yeah, things can be simplified in case of relationships (i.e.
    qualifiers matching a single object). A generic solution that works
    with an arbitrary qualifier will be substantially more involved.

    Andrus

    On May 18, 2006, at 7:05 PM, Mike Kienenberger wrote:

    > On 5/18/06, Mike Kienenberger <mkienen..mail.com> wrote:
    >> This is my first-pass at solving the problem at the application level
    >
    > Cleaned up version that can go in the Base DataObject class.
    >
    > protected List getToManyRelationshipTheHardWay(String
    > targetPrimaryKey, String joinTable, String sourcePrimaryKey, Class
    > targetClass)
    > {
    > String sql = "select distinct(" + targetPrimaryKey + ") as ID
    > from " + joinTable + " where " + sourcePrimaryKey + " = $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
    > (),
    > targetClass, primaryKey));
    > }
    >
    > return toManyList;
    > }
    >



    This archive was generated by hypermail 2.0.0 : Thu May 18 2006 - 19:36:00 EDT