You are on page 1of 11

IBM Software Group

Rational Software Architect
Named Query and Secondary Table support for IDX - FDS
Version 0.1

.............................................................................................................1........................................................ 4 2........................ 4 1......... PROFILE............................. 6 2.......................... 4 1.....1 STEREOTYPES ...................................................................................................................................................................................... INSTALLING THE EXTENSION Confidential ©IBM Software Group Rational Software 2010 Page 2 ...........................................................1 Description Named Query and Secondary Table support Author Mohamed Badr....1 TRANSFORMATION EXTENSION .............2 MODELING ....1............2 MODELING ...............1 NamedQuery.3................. 5 2........2 SecondaryTable ..........................doc Version: 0...................................................................................................................................... 7 3................................ Danny Lei 1...................................................................................3. 8 4.......................................................................................................... 6 2................................................................ 5 2..............3 GENERATED OUTPUT .........................................................................................Rational Software Architect Named Query and Secondary Table support Nq&st support............1 Issue Date: 10/3/2010 Revision History Date 10/3/2010 Version 0...................................................................................................... 7 3................................ SECONDARY TABLE.................................................... NAMED QUERY ...............................3 GENERATED OUTPUT ................................................... 4 1....................................................................... 6 3........................................ 7 3............................................................2 The session bean .............1 The entity bean ...........................1 TRANSFORMATION EXTENSION ............................................................... 5 2.................

Rational Software Architect Named Query and Secondary Table support Nq&st support.doc Version: 0.1 Issue Date: 10/3/2010 Confidential ©IBM Software Group Rational Software 2010 Page 3 .

Profile A new profile IDXProfile will be added 1.1 NamedQuery NamedQuery is applicable to uml property. type is enum LockModeType.1 Stereotypes 1. Named query has 5 attributes 1.1 Issue Date: 10/3/2010 1.Rational Software Architect Named Query and Secondary Table support Nq&st support. lockMode. name : the name of the named query. hints_name: list of strings representing hintNames 5. User should apply it to a uml property under a session bean. User should apply it to a uml property under an entity bean.1. SecondaryTable has 5 attributes Confidential Page 4 ©IBM Software Group Rational Software 2010 .doc Version: 0.1. and this property has association to an Entity bean. it also will be parsed to add implementation to the operation as mush as possible 3. query: the sql query.2 SecondaryTable SecondadyTable is applicable to uml property. and this property has association to an Entity bean. hints_value: list of strings representing hintValues 1. 4. it also will be used as the name of the generated Operation 2.

pkJoinColumns_referencedColumnName:list of strings representing the names to be used as the pkJoinColumn referenced column names 3.extention.xtools.idx. pkJoinColumns_columnDefinition:list of strings representing the names to be used as the pkJoinColumn definitions 4.doc Version: 0.2 Modeling User will create a directed association between a session bean and an Entity bean.ejb3 is added to extent the ejb 3. Then used will apply <<NamedQuery>> stereotype of the property under the session bean (in this case the entityClass) then in the stereotype tab user can set the different values needed to generate the named query Confidential ©IBM Software Group Rational Software 2010 Page 5 .1 Issue Date: 10/3/2010 1.transform.1 Transformation Extension A new extension com.ibm. uniqueConstraint_columnNames:list of strings representing the names to be used as the uniqueConstraint column names 2. pkJoinColumns_name:list of strings representing the names to be used as the pkJoinColumn names 2.0 transformation to support the generation 2.jpa.uml2. uniqueConstraints_name:string that will be used as uniqueConstraint name 5. Named Query 2.Rational Software Architect Named Query and Secondary Table support Nq&st support.

doc Version: 0. hints = { @QueryHint(name = "a". 2. the transformation gets all the parameters from the query (the strings after the “:”) Confidential ©IBM Software Group Rational Software 2010 Page 6 . y=:yy".setParameter(0.class). } As noticed. query = "SELECT * FROM EntityClass WHERE x = :xx . entity manager instance with the required annotation and imports @PersistenceContext private EntityManager entityManager. query.3.3 Generated output 2. Object yy) { Query query = entityManager.setParameter(1. catalog = "XX".createNamedQuery("findByXX". lockMode = LockModeType. return (Collection<EntityClass>) query.1 The entity bean The generated entity bean will have an extra named query .2 The session bean The generated session bean will have 1. value = "x").1 Issue Date: 10/3/2010 2. all the variables are coming from the stereotype @Table(name = "YY". @QueryHint(name = "b". xx).3.EntityClass. schema = "ZZ") @Entity @NamedQuery(name = "findByXX".PESSIMISTIC_FORCE_INCREMENT.Rational Software Architect Named Query and Secondary Table support Nq&st support.getResultList(). An extra operation will be added to the session bean to call the named query from the entity bean public Collection<EntityClass> findByXX(Object xx. value = "y") }) public class EntityClass implements Serializable { all the imports should be added automatically and the generated code should compile without a problem 2. yy). query.

query. Object yy) { Query query = entityManager. Then used will apply <<SecondaryTable>> stereotype of the property under the session bean (in this case the department) then in the stereotype tab user can set the different values needed to generate the named query Confidential ©IBM Software Group Rational Software 2010 Page 7 .setParameter(1. the transformation will use a generic Collection public Collection findByXX(Object xx. If different table(s) is used or if not all the columns are selected. is using table YY just like the named query. } 3.extention.1 Issue Date: 10/3/2010 And if the query is selecting everything (*) from the target Entity table (Entity class.ibm. xx).xtools.doc Version: 0.setParameter(0.jpa.2 Modeling User will create a directed association between two Entity beans.Rational Software Architect Named Query and Secondary Table support Nq&st support.jpa is added to extent the jpa transformation to support the generation 3. query.idx.uml2. yy). return (Collection) query.1 Transformation Extension A new extension com. Secondary Table 3.createNamedQuery("findByXX").transform. the operation will return Collection<EntityClass>.getResultList().

pkJoinColumns = { @PrimaryKeyJoinColumn(name = "deptID".Rational Software Architect Named Query and Secondary Table support Nq&st support. // end-user-code } public void setDeptName(String deptName) { // begin-user-code this.1 Issue Date: 10/3/2010 3. schema and catalog) also the source entity will have all the properties from the secondary entity (except the transient and the ones that has a name collision) @Column(table = "Department") private String deptName. referencedColumnName = "id") }) public class Employee implements Serializable { the entity will have a secondary table annotation with the required data retrieved from the <<SecondaryTable>> stereotype and from the <<Entity>> stereotype applied to the entity in the other end in the association (to get the table name.3 Generated Output In the source Entity (the Employee) @Entity @SecondaryTable(name = "Department".deptName = deptName. columnNames = { "col1" }) }. } Confidential ©IBM Software Group Rational Software 2010 Page 8 . public String getDeptName() { // begin-user-code return deptName. columnDefinition = "columnDefinition". uniqueConstraints = { @UniqueConstraint(name = "uqName".doc Version: 0.

This will deploy both the transformation extension and the new UML2 profile (IDXProfile) that is required by the extension. Then follow the following screen shots to install (deploy) the extension into Eclipse workbench environment.Rational Software Architect Named Query and Secondary Table support Nq&st support.1 Issue Date: 10/3/2010 First import the plugin project into RSA and build it. Confidential ©IBM Software Group Rational Software 2010 Page 9 . Installing the Transformation Extension Version: 0.doc 4.

doc Version: 0.1 Issue Date: 10/3/2010 Confidential ©IBM Software Group Rational Software 2010 Page 10 .Rational Software Architect Named Query and Secondary Table support Nq&st support.

Click Finish to complete the deployment.doc Version: 0.1 Issue Date: 10/3/2010 Specify the RSA installation location on your machine.xtools. Now you need to restart RSA in order to have the newly installed plugin loaded into workbench.Rational Software Architect Named Query and Secondary Table support Nq&st support. Make sure to check the check box for “com. A executable JAR file will be placed in the plugins subfolder. Confidential ©IBM Software Group Rational Software 2010 Page 11 .idx”.ibm.extention.jpa.uml2.transform. You will notice when configuring transformation that a new tab named Extension is added.