Re: Cayenne and Java 1.5?

From: Marcin Skladaniec (marci..sh.com.au)
Date: Tue Feb 14 2006 - 00:37:56 EST

  • Next message: Dave Merrin: "Double inner joins (again)"

    Hi
    I'm not sure if it is what you mean, but thats what we added to the
    template to access fields in generic way :

            /**
             *..eturn a list of all property keys.
             */
            public List getAllPropertyKeys() {
                    Vector v=new Vector() ;
    #foreach( $attr in ${objEntity.DeclaredAttributes} )
                    v.add(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY);
    #end
    #foreach( $rel in ${objEntity.DeclaredRelationships} )
                         v.add(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY);
    #end
                    return v;
            }
            
            
            /**
            *..eturn number of property keys.
            */
            public int getPropertyCount() {
                    return getAllPropertyKeys().size();
            }
            
            
            
             /**
          * Convenience function that returns the human readable
    representation of the
          * key - useful when building options in search menus.
          * Needs to be overriden in childClass, otherwise returns
    getValueForKey(key).toString()
          *..aram key entity parameter
          *..eturn the human readable name
          */
         public String getCaptionForKey(String key) {
                         if (getValueForKey(key) != null)
                         return getValueForKey(key).toString();
                 else
                         return null;
         }
            
            /**
            * Gets data type for given key.
            *..eturn Class - data type for given key
            *..aram key - Property String
            */
            public Class getDataTypeForKey(String key) {
    #foreach( $attr in ${objEntity.DeclaredAttributes} )
                         if(key.equals("${attr.Name}")) return
    $importUtils.formatJavaType(${attr.Type}) .class;
    #end
                    return null;
            }
            
            
            public void setValueForKey(String key, Object value) {
    #foreach( $attr in ${objEntity.DeclaredAttributes} )
                         if(key.equals("${attr.Name}")) { set${stringUtils.capitalized
    ($attr.Name)}( ($importUtils.formatJavaType(${attr.Type})) value);
    return; }
    #end
    }

    /**
             * Gets value converted to String for given key.
             *..aram key - the property/attribute key
             *..eturn the human readable version
             */
            public Object getValueForKey(String key) {
            #foreach( $attr in ${objEntity.DeclaredAttributes} )
                         if(key.equals("${attr.Name}")) return get$
    {stringUtils.capitalized($attr.Name)}();
    #end
                    return null;
            }

    and it is generating something like that :

            /**
             *..eturn a list of all property keys.
             */
            public List getAllPropertyKeys() {
                    Vector v=new Vector() ;
                    v.add(CREATED_PROPERTY);
    ...........
            }
            
            
            /**
            *..eturn number of property keys.
            */
            public int getPropertyCount() {
                    return getAllPropertyKeys().size();
            }
            
            
            
             /**
          * Convenience function that returns the human readable
    representation of the
          * key - useful when building options in search menus.
          * Needs to be overriden in childClass, otherwise returns
    getValueForKey(key).toString()
          *..aram key entity parameter
          *..eturn the human readable name
          */
         public String getCaptionForKey(String key) {
                 if (getValueForKey(key) != null)
                         return getValueForKey(key).toString();
                 else
                         return null;
         }
            
            /**
            * Gets data type for given key.
            *..eturn Class - data type for given key
            *..aram key - Property String
            */
            public Class getDataTypeForKey(String key) {
            
                 if(key.equals("created")) return Date .class;
    ........
            
            
            public void setValueForKey(String key, Object value) {
                 if(key.equals("created")) { setCreated( (Date) value);
    return; }
      ...........
    }

    /**
             * Gets value converted to String for given key.
             *..aram key - the property/attribute key
             *..eturn the human readable version
             */
            public Object getValueForKey(String key) {
                        if(key.equals("created")) return getCreated();
      ...........

    On 14/02/2006, at 3:50 PM, Jeff de Vries wrote:

    >
    > Can the auto-generated classes create "genericized" methods (e.g.
    > List<Foo> getFooArray())?
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Feb 14 2006 - 00:38:00 EST