HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Local Entity Beans and Relationships"
Vol. 6, Issue 10, p. 18

	


Listing 1: ejb-jar.xml

<relationships> 
   <ejb-relation> 
     <ejb-relation-name>Group-User</ejb-relation-name> 
       <ejb-relationship-role> 
         <ejb-relationship-role-name> 
           group-has-users 
          </ejb-relationship-role-name> 
          <multiplicity>many</multiplicity> 
          <relationship-role-source> 
            <ejb-name>Group</ejb-name>
          </relationship-role-source> 
          <cmr-field> 

    <!-- method to retrieve users 
    is java.util.Collection getUsers() --> 

          <cmr-field-name>users</cmr-field-name> 

    <!-- you can specify java.util.Set or java.util.
    Collection if multiplicity is many. 
    You do not have to provide this element if multiplicity is one --> 

          <cmr-field-type>java.util.Collection</cmr-field-type> 
          </cmr-field> 
          </ejb-relationship-role> 

       <ejb-relationship-role>
         <ejb-relationship-role-name> 
           user-belongs-to-group 
         </ejb-relationship-role-name> 
         <multiplicity>many</multiplicity> 
         <relationship-role-source> 
         <ejb-name>User</ejb-name> 
         </relationship-role-source> 
           <cmr-field> 
             <cmr-field-name>groups</cmr-field-name> 
             <cmr-field-type> 
               java.util.Collection 
             </cmr-field-type> 
           </cmr-field> 
       </ejb-relationship-role> 
   </ejb-relation> 
</relationships> 


Listing 2: weblogic-ejb-jar.xml

<weblogic-enterprise-bean> 
   <ejb-name>User</ejb-name>
     <entity-descriptor> 
       <persistence> 
          <persistence-type> 
            <type-identifier> 
                 WebLogic_CMP_RDBMS 
            </type-identifier> 
            <type-version>6.0</type-version> 
            <type-storage> 
                META-INF/weblogic-cmp-rdbms-jar.xml 
            </type-storage> 
          </persistence-type> 
          <persistence-use> 
            <type-identifier> 
                WebLogic_CMP_RDBMS 
             </type-identifier> 
             <type-version>6.0</type-version> 
          </persistence-use> 
       </persistence> 
    </entity-descriptor> 
    <local-jndi-name>User</local-jndi-name> 
</weblogic-enterprise-bean> 


Listing 3: weblogic-cmp-rdbms-jar.xml 

<weblogic-rdbms-relation> 
    <relation-name>Group-User</relation-name> 
     <table-name>USER_GROUP</table-name> 
     <weblogic-relationship-role> 
        <relationship-role-name> 
           group-has-users 
        </relationship-role-name> 
        <column-map> 

          <!-- column from USER_GROUP table> 
          <foreign-key-column> 
             GROUPNAME 
          </foreign-key-column> 

          <!-- column from SYSUSER table>
          <key-column>GROUPNAME</key-column> 
        </column-map> 
     </weblogic-relationship-role> 
     <weblogic-relationship-role> 
        <relationship-role-name> 
            user-belongs-to-group 
        </relationship-role-name> 
        <column-map> 

          <!-- column from USER_GROUP table --> 
          <foreign-key-column> 
              USERNAME 
          </foreign-key-column> 

          <!-- column from SYSGROUP table --> 
          <key-column>USERNAME</key-column> 
        </column-map> 
     </weblogic-relationship-role> 
</weblogic-rdbms-relation> 


Listing 4: Ant build script 

  <!-- Run ejbc to create the deployable jar file --> 
   <target name="ejbc" depends="jar_ejb"> 
     <java classname="weblogic.ejbc" fork="yes"> 
       <sysproperty key="weblogic.home" value="${WL_HOME}"/> 
       <arg line="-compiler javac ${dist}/user_in.jar ./user_out.jar"/> 
       <classpath> 
         <pathelement path="${WL_HOME}/lib/weblogic.jar"/> 
       </classpath> 
     </java> 
   </target> 


Listing 5: Client 

InitialContext ic = new InitialContext();
Object objRef = ic.lookup( "UserManager" ); 
UserManagerHome home = (UserManagerHome) 
PortableRemoteObject.narrow( objRef, UserManagerHome.class ); 
UserManager userManager = home.create(); 

User user = new UserValueObject(); 
user.setUserName("alex"); 
user.setUserType("regular"); 
user.setUserEmail("[email protected]"); 
userManager.createUser(user);

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.