EOFetchSpecification bindings using Velocity EOGenerator

From: Jim Roepcke (jimroepck..mail.com)
Date: Fri Dec 21 2007 - 00:55:24 EST

  • Next message: Mike Schrag: "Re: EOFetchSpecification bindings using Velocity EOGenerator"

    Hello all,

    I'm updating an application from WO 5.2.x to WO 5.4. Using WOLips,
    Wonder, all the good stuff that couldn't be used in the olden days.
    Currently I'm rewriting/merging the old MiscMerge EOGenerator template
    into Mike's Velocity _Entity.java template.

    VEOGenerator is working, but an addition I've made to isn't working yet.

    Specifically, the old template had this section:

    <$comment
    Add methods to call named fetch specifications, with any qualifier
    bindings having typed
    parameters.

    $><$foreach FetchSpec
    javaBeautifiedFetchSpecificationDictionaries..ortedNameArray do$>
        public static NSArray
    objectsFor<$FetchSpec.niceName$>(EOEditingContext context<$foreach
    Binding FetchSpec.bindings do2$>,
    <$Binding.codeType$><$Binding.name$>Binding<$endforeach do2$>) {
            EOFetchSpecification spec =
    EOFetchSpecification.fetchSpecificationNamed("<$FetchSpec.fetchName$>",
    "<$name$>");
    <$if FetchSpec.bindings.count > 0$>
            NSMutableDictionary bindings = new NSMutableDictionary();
    <$foreach Binding FetchSpec.bindings do2$>
            if (<$Binding.name$>Binding != null)
                bindings.setObjectForKey(<$Binding.name$>Binding,
    "<$Binding.name$>");<$endforeach do2$>
            spec = spec.fetchSpecificationWithQualifierBindings(bindings);
    <$endif$>
            return context.objectsWithFetchSpecification(spec);
        }<$endforeach do$>

    I've translated that to velocity with the help of
    <http://wiki.objectstyle.org/confluence/display/WOL/mail/2654345>:

    #foreach ($FetchSpec in $entity.sortedFetchSpecs)
      public static NSArray
    objectsFor${FetchSpec.capitalizedName}(EOEditingContext
    context#foreach ($Binding in $FetchSpec.bindings), ${Binding.codeType}
    ${Binding.name}Binding#end) {
        EOFetchSpecification spec =
    EOFetchSpecification.fetchSpecificationNamed("${FetchSpec.name}",
    "${entity.name}");
    #if ($FetchSpec.bindings.count > 0)
        NSMutableDictionary bindings = new NSMutableDictionary();
    #foreach ($Binding in $FetchSpec.bindings)
        if (${Binding.name}Binding != null)
            bindings.setObjectForKey(${Binding.name}Binding, "${Binding.name}");
    #end
        spec = spec.fetchSpecificationWithQualifierBindings(bindings);
    #end
        return context.objectsWithFetchSpecification(spec);
      }

    #end

    Unfortunately, it seems that $FetchSpec.bindings doesn't work, as
    neither 'foreach' that iterates over the bindings produces output when
    I expect it to.

    Here's what VEOGenerator is generating:

      public static NSArray
    objectsForPrivateCategoriesForUser(EOEditingContext context) {
        EOFetchSpecification spec =
    EOFetchSpecification.fetchSpecificationNamed("PrivateCategoriesForUser",
    "WordCategory");
        return context.objectsWithFetchSpecification(spec);
      }

    Here's the code EOGenerator generated:

        public static NSArray
    objectsForPrivateCategoriesForUser(EOEditingContext context, Account
    accountBinding) {
            EOFetchSpecification spec =
    EOFetchSpecification.fetchSpecificationNamed("PrivateCategoriesForUser",
    "WordCategory");

            NSMutableDictionary bindings = new NSMutableDictionary();

            if (accountBinding != null)
                bindings.setObjectForKey(accountBinding, "account");
            spec = spec.fetchSpecificationWithQualifierBindings(bindings);

            return context.objectsWithFetchSpecification(spec);
        }

    Here's the PrivateCategoriesForUser specification from the .fspec file:

        PrivateCategoriesForUser = {
            class = EOFetchSpecification;
            entityName = WordCategory;
            fetchLimit = 0;
            isDeep = YES;
            qualifier = {
                class = EOAndQualifier;
                qualifiers = (
                    {
                        class = EOKeyValueQualifier;
                        key = isPrivate;
                        selectorName = "isEqualTo:";
                        value = {class = NSNumber; value = 1; };
                    },
                    {
                        class = EOKeyValueQualifier;
                        key = allowedPrivateCategories.account;
                        selectorName = "isEqualTo:";
                        value = {_key = account; class = EOQualifierVariable; };
                    }
                );
            };
            sortOrderings = (
                {
                    class = EOSortOrdering;
                    key = orderNumber;
                    selectorName = "compareAscending:";
                }
            );
        };

    Can anybody confirm whether or not I should be able to get at the
    bindings (as in MiscMerge) using the API above (specifically,
    $FetchSpec.bindings, $Binding.name and $Binding.codeType)?

    Also, it is true that VEOGenerator is using the EOModel model defined here:

    <https://svn.objectstyle.org/repos/woproject/trunk/woproject/wolips/core/plugins/org.objectstyle.wolips.eomodeler.core/java/org/objectstyle/wolips/eomodeler/core/model/>
    ?

    If that's the case, perhaps this doesn't work because I don't see a
    getBindings method in EOFetchSpecification.java...

    Thanks for all the great work that's gone into WO, Wonder and WOLips,
    I've been excited about WO again since WWDC '07 so it's great to
    finally move a project up to the cutting edge.

    Jim



    This archive was generated by hypermail 2.0.0 : Fri Dec 21 2007 - 01:22:05 EST