MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
DevAlternatives
Post subject: Cannot access the model primary key fields on the JPADAO.jet  PostPosted: Apr 12, 2012 - 11:25 PM
Registered Member
Registered Member


Joined: Mar 08, 2012
Posts: 33

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.


Code:

<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>
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
cconway
Post subject:   PostPosted: Apr 13, 2012 - 11:43 AM



Joined: Apr 04, 2011
Posts: 196

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:

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


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

Code:
$primaryDataType/@fields

_________________
Cindy
MyEclipse for Spring Support
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
julio.salazar
Post subject: solution found  PostPosted: Apr 16, 2012 - 05:00 PM
Registered Member
Registered Member


Joined: Mar 07, 2012
Posts: 8

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


Code:

<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>
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits