facebook

Cannot access the model primary key fields on the JPADAO.jet

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #325197 Reply

    DevAlternatives
    Participant

    Hi,

    I’m trying to get the primary key fields on the DAO Impl for the spring mvc scaffolding, I did the below changes on the JPADAO.jet but with no success, it seems that the model/fields or persistence:idClass is not available on the DAOImpl generation.

    Can you help us to know how we can get from the $model the primary key fields ? I took these ideas from the DataType.jet and it works perfect there.

    
    <c:set select="$model" name="gaudi-composedEntity">
        <persistence:idClass select="$model" package="true"  />
    </c:set>
    
    <c:choose>
              <c:when test="$model/@gaudi-composedEntity != ''">
                  <c:get select="$model/@gaudi-composedEntity" />
              </c:when>
              <c:otherwise>
                     <c:iterate select="$model/@fields" var="field">
                           <c:if test="$field/@primaryKey = 'true'">
                               <c:get select="$field" />
                             
                        </c:if>
                    </c:iterate>
                </c:otherwise>
    </c:choose> 
    #325208 Reply

    cconway
    Member

    The $model in the DAO template will correspond to the DAO, you need the key fields from the Data Type associated with the DAO. You should see near the top of the DAO template is this line:

    <sw:getDataTypeForDao select="$model" var="primaryDataType"/>

    That is getting you the data type. So you should be able to do something like this:

    $primaryDataType/@fields
    #325285 Reply

    Thanks Cindy, after a couple of iteratios I was able to extract the name, here is my code for reference.

    
    <sw:getDataTypeForDao select="$model" var="primaryDataType"/>
    
    <c:setVariable select="-" var="GaudiPkType" /> 
    <c:setVariable select="0" var="i" />
    <c:iterate select="$primaryDataType/fields" var="field">
        <c:setVariable select="string($field/@primaryKey)" var="isPrimaryString" />
        <c:choose>
            <c:when test="$isPrimaryString = 'true'">
                <c:setVariable select="$i+1" var="i" />
            </c:when>
         </c:choose>
    </c:iterate>
        <c:choose>
            <c:when test="$i > 1">
                    <c:set select="$model" name="gaudiIdTypeName"><sw:javaType select="$primaryDataType"/></c:set>
                    <c:setVariable select="concat($model/@gaudiIdTypeName,'PK')" var="gaudiPkType"/>
    import <sw:package select="$primaryDataType" />.<c:get select="$gaudiPkType"/>;
                      
                     
            </c:when>
            <c:otherwise>
                <c:iterate select="$primaryDataType/fields" var="fieldSingle">
                    <c:setVariable select="string($fieldSingle/@primaryKey)" var="isPrimaryStringSingle" />
                    <c:choose>
                        <c:when test="$isPrimaryStringSingle = 'true'">
                        <c:set select="$model" name="gaudiIdTypeName"><sw:javaType select="$fieldSingle"/></c:set>
                        <c:setVariable select="$model/@gaudiIdTypeName" var="gaudiPkType"/>
                        </c:when>
                     </c:choose>
                </c:iterate>
            </c:otherwise>    
        </c:choose>
    
Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Cannot access the model primary key fields on the JPADAO.jet

You must be logged in to post in the forum log in