Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Creating solutions on the extended sites framework in WebSphere Commerce

Part 1: Using the command layer

Michael DJ Shields (mshields@crossview.com), Solution Architect, CrossView, Inc.
Photo of Michael Shields
Michael Shields works for CrossView®, Inc. He has over a decade consulting and developing strategies to best leverage WebSphere Commerce to match client business requirements. He also has over twelve years of developing interactive web solutions using J2EE, PHP, Zend Framework, Adobe products, HTML, CSS, AJAX, jQuery, DOJO and JavaScript. Michael holds 5 patents, published over 12 tutorials on the WebSphere Commerce Information Center, and 10 tutorials on the developerWorks WebSphere Commerce zone. He holds over 12 technical certifications and a designation as a project manager (PMP).
Quan Nguyen (qnguyen@crossview.com), Solution Architect, CrossView, Inc.
Photo of Quan Nguyen
Quan Nguyen has been working for CrossView, Inc., since 1999, consulting and developing e-business solutions by leveraging WebSphere Commerce. As a Solution Architect, he has over a decade of experience, working with major B2C and B2B companies to implement robust WebSphere Commerce strategies, fulfilling their business requirements.
Raj Sanghvi (rsanghvi@crossview.com), Solution Architect, CrossView, Inc.
Photo of Raj Sanghvi
Raj Sanghvi is a Solution Architect for CrossView, Inc. He has over 6 years of experience consulting in WebSphere Commerce working for different sub systems. He also has over 10 years of experience doing software development using J2EE, Oracle, HTML, XML, and SOAP. He holds over 8 technical certifications and a designation as a project manager (CAMP). He has a Master's degree in Computer Science.
Amar Desai (amar.desai@atech.com), Solution Architect, Ascendant Technology
Photo of Amar Desai
Amar Desai is a Solution Architect at Ascendant® Technology. He has helped many top retail, banking, and dining companies materialize their vision in the e-commerce space using WebSphere Commerce. He has a penchant for applying the latest web application trends such as social commerce, precision marketing, and mobile commerce. He is a certified WebSphere Commerce developer and administrator.

Summary:  The purpose of extended sites in WebSphere® Commerce is to ensure sharable assets among different stores. This tutorial provides insight into different ways to use the store path resource that is an available-to-market framework in WebSphere Commerce. A new concept is introduced in this tutorial that provides provide granular levels of sharing with a sub-set of assets. Also, this tutorial describes how to properly extend an EJB to use the BeanFinderObject for your findBy methods to incorporate sharing queries. You will learn how to better ensure that your store's conglomerate is fully capable to share all of the integral assets to make your business successful, while keeping your software reusable and easy to maintain.

Date:  20 Oct 2010
Level:  Intermediate PDF:  A4 and Letter (143 KB | 53 pages)Get Adobe® Reader®

Activity:  23828 views
Comments:  

Controlling shared assets at the Entity Bean layer

Incorporating new assets into extended sites

Prerequisites

In this section, you will create a new entity bean. Make sure you backup your work and be prepared to revert to your backup. If you make a mistake on any steps while creating a new entity bean, it is always best to restart from scratch.

Note: These steps were originally provided in the WebSphere Commerce Information Center, Creating a new entity bean. Therefore, if you have already referenced this page for creating entity beans, the only difference in this tutorial is the specific step of including a new EJB UserFinderDescriptor finder type FinderHelper method. You can skip this whole section and continue to the next section as it specifically reviews how to add a UserFinderDescriptor finder type FinderHelper method.

When including a new asset into extended site, how will it easily incorporate into the existing shared asset behavior? In theory, your assets fall under one of the existing store relationship types as these components are already modular within WebSphere Commerce. Even conceptually, an asset can find a fitting place within the existing store relationship types in the nature of e-commerce requirements. Once a foreign key is picked up that belongs to data belonging to the existing store relationship types, the new asset is linked up, picked up, and rolled out. However, for the purposes of this tutorial, it is important that you learn how to incorporate extended sites into a newly created assets so that you are aware of code reuse at all layers of your application. You will gain an appreciation for how extended sites have been made available-to-market for all of the existing assets in WebSphere Commerce.

For the steps of this section, you will create a new table and new entity bean. There are some special steps that are not part of a normal scenario of creating an entity bean. Specifically, you will create an extended class to the entity bean called a BeanFinderObject class. From this extended class, BeanFinderObject, the store relationship type will be incorporated by looking at the store path that is passed into the bean. Also, as a new concept is introduced to extended sites, you will be creating what is known as a finer granular level of control of shared assets. This is because the new table you are about to create is a product related table. The product data is already part of the existing store relationship type, which is actually considered part of the existing catalog assets.

There are steps in this entity bean creation that is an alternative to the regular steps to allow the new entity bean to be extendible by a unique SQL join statement. The entity bean requires a UserFinderDescriptor finder type FinderHelper method to enable the join of the store relationships queries. When creating a new entity bean in your environment, it is safest to perform this task in a fresh toolkit environment. This is because the WebSphereCommerceServerExtensionsData project follows every step you take. If you cannot remember precisely how to back out, then it is best to restart from scratch. Therefore, we recommend that you try to create a new entity bean using the steps from the Information Center topic, Creating a new entity bean, a few times to get used to the methodology. If you are brave and have the heart to journey this new path without the need to practice creating entity beans, then that enthusiasm will help you be aware of all the steps you are taking along the way.

Creating the table

To create the entity bean to incorporate the new asset into extended sites:

  1. Ensure the test environment is started.
  2. From your database, prepare to execute an SQL statement. For example, with the toolkit, open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.
  3. From your database, execute the following query:
    • (DB2®)

      Listing 8. DDL: Create a table for DB2
      
      create table XCATENTRY_EXT (
      		CATENTRY_ID BIGINT NOT NULL, 
      		STOREENT_ID BIGINT NOT NULL, 
      		VENDOR_ID BIGINT NOT NULL, 
      		FIELD1 		INTEGER, 
      		FIELD2 		VARCHAR(128), 
        		FIELD3  	DECIMAL(20,5),
        		PRODUCT_TYPE	VARCHAR(128),
      		OPTCOUNTER SMALLINT NOT NULL;
      	
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT PK_XCATENTRYEXT
      	PRIMARY KEY
      	(CATENTRY_ID, STOREENT_ID, VENDOR_ID));
       
      ALTER TABLE XCATENTRY_EXT ADD (
       	CONSTRAINT FK_XCATENTRYEXT_CATENTRYID 
      	FOREIGN KEY (CATENTRY_ID) 
      	REFERENCES CATENTRY (CATENTRY_ID)
      	ON DELETE CASCADE);
      
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT FK_XCATENTRYEXT_STOREENTID 
      	FOREIGN KEY (STOREENT_ID) 
      	REFERENCES STOREENT (STOREENT_ID)
      	ON DELETE CASCADE);
      
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT FK_XCATENTRYEXT_VENDORID 
      	FOREIGN KEY (VENDOR_ID) 
      	REFERENCES VENDOR (VENDOR_ID)
      	ON DELETE CASCADE);

    • (ORACLE®)

      Listing 9. DDL: Create a table for Oracle
      
      create table XCATENTRY_EXT (
      		CATENTRY_ID NUMBER NOT NULL, 
      		STOREENT_ID NUMBER NOT NULL,
      		VENDOR_ID NUMBER NOT NULL, 
              FIELD1 		INTEGER, 
        		FIELD2   	VARCHAR2(128 BYTE),
        		FIELD3  	NUMBER(20,5),
        		PRODUCT_TYPE	VARCHAR2(128 BYTE),
      		OPTCOUNTER SMALLINT NOT NULL;
      		
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT PK_XCATENTRYEXT
      	PRIMARY KEY
      	(CATENTRY_ID, STOREENT_ID, VENDOR_ID));
       
      ALTER TABLE XCATENTRY_EXT ADD (
       	CONSTRAINT FK_XCATENTRYEXT_CATENTRYID 
      	FOREIGN KEY (CATENTRY_ID) 
      	REFERENCES CATENTRY (CATENTRY_ID)
      	ON DELETE CASCADE);
      
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT FK_XCATENTRYEXT_STOREENTID 
      	FOREIGN KEY (STOREENT_ID) 
      	REFERENCES STOREENT (STOREENT_ID)
      	ON DELETE CASCADE);
      
      ALTER TABLE XCATENTRY_EXT ADD (
      	CONSTRAINT FK_XCATENTRYEXT_VENDORID 
      	FOREIGN KEY (VENDOR_ID) 
      	REFERENCES VENDOR (VENDOR_ID)
      	ON DELETE CASCADE);
      	
      COMMENT ON TABLE XCATENTRY_EXT IS 'This table is an extension of the 
      	WCS out of the box CATENTRY table.';
      COMMENT ON COLUMN XCATENTRY_EXT.CATENTRY_ID IS 'Primary key for the table. 
      	Represents a catentry.';
      COMMENT ON COLUMN XCATENTRY_EXT.STOREENT_ID IS 'Primary key for the table. 
      	Represents a store entity.';
      COMMENT ON COLUMN XCATENTRY_EXT.VENDOR_ID IS 'Foreign key for the table. 
      	Represents vendor data representing affiliates.';
      COMMENT ON COLUMN XCATENTRY_EXT.FIELD1 IS 'Extendible field';
      COMMENT ON COLUMN XCATENTRY_EXT.FIELD2 IS 'Extendible field';
      COMMENT ON COLUMN XCATENTRY_EXT.FIELD3 IS 'Extendible field';
      COMMENT ON COLUMN XCATENTRY_EXT.PRODUCT_TYPE IS 'Extendible field for 
      	affiliate related product type recognition';

  4. Click Submit Query if using the cloudscape URL provided. You see a message that the statement resulted in 0 updates.

Creating the Entity Bean

  1. With the table created in the database, you are ready to create the new entity bean. An entity bean encapsulates information about a table. In this tutorial, it is the XCATENTRY_EXT table. In general, creating an entity bean involves the following steps:
    1. Creating the bean.
    2. Setting the bean's isolation level.
    3. Setting the security identity of the bean.
    4. Setting the security role of the methods in the bean.
    5. Removing and adding some methods.
    6. Adding FinderHelper methods.
    7. Map the table to the Entity Bean.
    8. Create an Access Bean.
    9. Generate the deploy code and regenerate the Access Bean.
  2. To create the new entity bean called XCATENTRY_EXT:
    1. In Rational® Application Developer, switch to the Enterprise Explorer view.
    2. Expand EJB Projects > WebSphereCommerceServerExtensionsData.
    3. Right-click Deployment Descriptor: WebSphereCommerceServerExtensionsData and select New > Enterprise Bean.
    4. In the Create an Enterprise Bean window:
      1. Select Entity bean with container-managed persistence (CMP) fields.
      2. In the Bean name field, enter XCatentryExt.
      3. In the Source folder field, leave the default value, ejbModule.
      4. In the Default package field, enter com.dw.commerce.extension.objects.
      5. From the CMP Version list, select 1.x.
      6. Click Next.
    5. In the Enterprise Bean Details window, add the new CMP attributes for the columns in the XCATENTRY_EXT table:
      1. Select the default CMP attribute id: java.lang.Integer and click Remove.
      2. Click Add.
        1. In the Name field, enter catentryId.
        2. In the Type field, enter java.lang.Long.

          You must use the java.lang.Long data type, not the long data type, since the column catentryId that you are trying to map to is BIGINT or NUMBER.

        3. Select the Key Field check box to indicate that this field is the primary key of the database table.
        4. Click Apply.
        5. In the Name field, enter storeentId.
        6. In the Type field, enter java.lang.Long.

          You must use the java.lang.Long data type, not the long data type, since the column storeentId that you are trying to map to is BIGINT or NUMBER.

        7. Select the Key Field check box to indicate that this field is the primary key of the database table.
        8. Click Apply.
        9. In the Name field, enter vendorId.
        10. In the Type field, enter java.lang.Long.

          You must use the java.lang.Long data type, not the long data type, since the column vendorId that you are trying to map to is BIGINT or NUMBER.

        11. Select the Key Field check box to indicate that this field is the primary key of the database table.
        12. Click Apply.
        13. In the Name field, enter field1.
        14. In the Type field, enter java.lang.Integer.

          You must use the java.lang.Integer data type, not the integer data type.

        15. Ensure the Access with getter and setter methods check box is selected. By selecting this option, all getter and setter methods are automatically generated for all fields.
        16. Clear the Promote getter and setter methods to remote interface check box. The Make getter read-only check box will be made unavailable. Clearing the promote getter and setter methods to remote interface causes less overhead and better performance. Since the getter and setter methods are not promoted to the remote interface, clients cannot access the methods. Instead of using the remote interface, the CopyHelper Access Beans contain getters and setters for the CMP fields that do not exist on the remote interface.

          The methods within the CopyHelper Access Beans write data to a hash table that in turn updates the database when commitCopyHelper() is called. The hash table can record multiple database changes, then update the database in one transaction, unlike the remote methods which require one transaction per change. A method called refreshCopyHelper() reverses function of commitCopyHelper(). The method refreshCopyHelper() writes to the hash table from the database. Deselecting the box ensures that the hashtable is used, resulting in the performance increase.
        17. Click Apply.
        18. In the Name field, enter field2.
        19. In the Type field, enter java.lang.String.

          You must use the java.lang.String data type, not the string data type.

        20. Ensure the Access with getter and setter methods check box is selected.
        21. Clear the Promote getter and setter methods to remote interface check box.
        22. Click Apply.
        23. In the Name field, enter field3.
        24. In the Type field, enter java.lang.BigDecimal.
        25. Ensure the Access with getter and setter methods check box is selected.
        26. Clear the Promote getter and setter methods to remote interface check box.
        27. Click Apply.
        28. In the Name field, enter productType.
        29. In the Type field, enter java.lang.String.

          You must use the java.lang.String data type, not the string data type.

        30. Ensure the Access with getter and setter methods check box is selected.
        31. Clear the Promote getter and setter methods to remote interface check box.
        32. Click Apply.
        33. Optional: In the Name field, enter optCounter.
        34. Optional: In the Type field, enter short.
        35. Clear the Access with getter and setter methods check box.
        36. Click Apply, then Close to close this window.
      3. Ensure the Use the single key attribute type for the key class check box is not selected, then click Next. By not selecting this check box, you ensure that a key class is created and ensure consistency with other beans.
    6. In the EJB Java Class Details window:
      1. To select the bean's super class, click Browse.
      2. In the Type Selection window, in the "Select a class using: (any)" field, enter ECEntityBean, and click OK.
      3. Specify the interfaces that the remote interface needs to extend by clicking Add.
      4. In the Type Selection window, in the "Select an interface using: (any)" field, enter Protectable, and click OK to select com.ibm.commerce.security.Protectable. This interface is required to protect the new resource under access control.
      5. Click Next.
      6. Deselect Add bean to Class Diagram.
      7. Click Finish.
  3. Set the isolation level for the new bean:
    1. Expand EJB Projects > WebSphereCommerceServerExtensionsData > Deployment Descriptor : > WebSphereCommerceServerExtensionsData > Entity Beans > XCatentryExt.
    2. Double-click the XCatentryExt bean to open its deployment descriptor.
    3. Click the Access tab.
    4. Next to the Isolation Level text box, click Add.
    5. In the Add Isolation Level window, select Read committed, then click Next.
    6. From the Beans found list, select the XCatentryExt bean, then click Next.
    7. From the Methods found list, select XCatentryExt to select all of its methods, and click Finish.
    8. Save your work and keep the editor open.
  4. Set the security identity of the bean:
    1. Ensure that you still have the Access tab selected.
    2. In the "Security Identity (Method Level)" section, click Add.
    3. Select Use identity of EJB server, then click Next. The "Use identity of EJB server" field ensures that all EJB beans run under the same identity for security.
    4. From the Beans found list, select the XCatentryExt bean, then click Next.
    5. From the Methods found list, select XCatentryExt to select all of its methods, and click Finish.
    6. Save your work and keep the editor open.
  5. Next, set the security role for the methods in the bean:
    1. In the Deployment Descriptor editor, select the Assembly tab.
    2. In the Method Permissions section, click Add.
    3. Select Security Roles, then WCSecurityRole, and click Next. This is the default security role for all EJB beans in WebSphere Commerce.
    4. From the list of beans found, select XCatentryExt and click Next.
    5. In the Method elements page, click Apply to All, then click Finish.
    6. Save your work.
  6. The next step is to remove some of the fields and methods related to the entity context that are generated by Rational Application Developer. You are deleting these fields because the ECEntityBean base class provides its own implementation of these methods. To delete the generated entity context fields and methods:
    1. In the J2EE Navigator view, expand the WebSphereCommerceServerExtensionsData project.
    2. Expand Entity Beans > XCatentryExt, and open the XCatentryExtBean class.
    3. In the Outline view:
      1. Select the myEntityCtx field and from its pop-up menu, select Delete.
      2. Select the getEntityContext() method and from its pop-up menu, select Delete.
      3. Select the setEntityContext(EntityContext) method and from its pop-up menu, select Delete.
      4. Select the unsetEntityContext() method and from its pop-up menu, select Delete.
    4. Save your work. Keep the XCatentryExtBean class open.
  7. Add a new getCatentryId method, getVendorId method, and getStoreentId method to the enterprise bean:
    1. View the source code of the XCatentryExtBean class.
    2. Add the following method to the end of this class:

      Listing 10. XCatentryExtBean Key getters
      
      public java.lang.Long getCatentryId() {
         return catentryId;
      }
      public java.lang.Long getStoreentId() {
         return storeentId;
      }
      public java.lang.Long getVendorId() {
         return vendorId;
      }

    3. Add the new method to the remote interface. In the Outline view, right-click the getCatentryId method, the getVendorId method and the getStoreentId method, and select Enterprise Bean > Promote to Remote Interface. Once this is complete, a small "R" icon displays next to the method, indicating that it has been promoted to the remote interface.
    4. Save your work.
    5. Close the XCatentryExtBean class.
  8. Add the WhereClauseFinderDescriptor finder type FinderHelper methods to the XCatentryExtHome interface. FinderHelpers methods allow you to write your own finders where you might not know the primary key, but need to select on other columns. A FinderHelper method contains the SQL statements used by your bean's finder methods. A findByPrimaryKey() method is created for an EJB bean, but it is often not sufficient because you might not know the primary key.

    Add a findByCatentryId FinderHelper method to the XCatentryExtHome interface:

    1. In the EJB Deployment Descriptor editor, click the Bean tab.
    2. In the Beans pane, select the XCatentryExt bean.
    3. Click Add next to the Finders text box.
    4. In the Name field, enter findByCatentryId.
    5. Click Add next to the Parameters text box:
      1. In the Name field, enter catentryId.
      2. In the Type field, enter java.lang.Long.
      3. Click OK.
    6. From the Return Type list, select Enumeration, then click Next.
    7. From the Finder type list, select WhereClauseFinderDescriptor. In this field, you specify the where clause for a select statement in a finder. You must provide the where clause of a select statement in the EJB FinderHelper method. You do not need to provide the full select statement since the EJB container manages the table.
    8. In the Finder statement field, enter T1.CATENTRY_ID = ?, then click Finish. When the FinderHelper runs, the SQL statement that will run is "select ... FROM XCATENTRY_EXT T1 WHERE T1.CATENTRY_ID = ? ". The "?" is replaced with the dynamic value of "String" provided to the findByCatentryId(String).
    9. Save your work.

    Add a findByStoreentId FinderHelper method to the XCatentryExtHome interface:

    1. In the EJB Deployment Descriptor editor, click the Bean tab.
    2. In the Beans pane, select the XCatentryExt bean.
    3. Click Add next to the Finders text box.
    4. In the Name field, enter findByStoreentId.
    5. Click Add next to the Parameters text box:
      1. In the Name field, enter storeentId.
      2. In the Type field, enter java.lang.Long.
      3. Click OK.
    6. From the Return Type list, select Enumeration, then click Next.
    7. From the Finder type list, select WhereClauseFinderDescriptor. In this field, you specify the where clause for a select statement in a finder. You must provide the where clause of a select statement in the EJB FinderHelper method. You do not need to provide the full select statement since the EJB container manages the table.
    8. In the Finder statement field, enter T1.STOREENT_ID = ?, then click Finish. When the FinderHelper runs, the SQL statement that will run is "select ... FROM XCATENTRY_EXT T1 WHERE T1.STOREENT_ID = ? ". The "?" is replaced with the dynamic value of "String" provided to the findByStoreentId(String).
    9. Save your work.
    There may also be a FinderHelper method for the vendorId field.
  9. Now add a UserFinderDescriptor finder type. With this FinderHelper method in place, you can extend the Entity Bean FinderHelper method. By extending, this means you incorporate a BeanFinderObject. This is the essential step in this tutorial that will link the Entity Bean to the Extended Site behavior. The BeanFinderObject enables a special store path relationship query.

    Add a findByCatentryIdVendorIdStorePathId FinderHelper method to the XCatentryExtHome interface:

    1. In the EJB Deployment Descriptor editor, click the Bean tab.
    2. In the Beans pane, select the XCatentryExt bean.
    3. Click Add next to the Finders text box.
    4. In the Name field, enter findByCatentryIdVendorIdStorePathId.
    5. Click Add next to the Parameters text box:
      1. In the Name field, enter catentryId.
      2. In the Type field, enter java.lang.Long.
      3. Click OK.
      4. In the Name field, enter storeentId.
      5. In the Type field, enter java.lang.Long.
      6. Click OK.
      7. In the Name field, enter vendorId.
      8. In the Type field, enter java.lang.Long.
      9. Click OK.
    6. From the Return Type list, select Enumeration, then click Next.
    7. From the Finder type list, select UserFinderDescriptor. In this field, you specify the where clause for a select statement in a finder.
    8. In the Finder statement field, it should be disabled for any entry.
    9. Save your work.
    Now that you have create a UserFinderDescriptor finder type FinderHelper method, you will later create a BeanFinderObject and call it XCatentryExtBeanFinderObject.java to be picked up by the finder method findByCatentryIdVendorIdStorePathId.
  10. The next section maps the XCATENTRY_EXT table to the XCatentryExtBean entity bean using the meet-in-the-middle mapping.

    To create the mapping:

    1. Open the Data perspective and switch to the Data Definition view.
    2. Navigate to the following directory: WebSphereCommerceServerExtensionsData > ejbModule > META-INF.
    3. Select META-INF and from its pop-up menu, select New > Database Definition.
    4. (DB2) (Oracle) In the Database name field, enter the name of your development database. There is no default database name. (Cloudscape) The default database name is mall.

      Note: The name you enter in the Database name field is not used. When you create a database definition, you create XMI files that are later used to generate deployed code. These XMI files are independent of your database name.

    5. From the Database vendor type list, select one of the following types:
      • (DB2)(Cloudscape)
        • (WebSphere Commerce Professional) (WebSphere Commerce Enterprise) DB2 Universal Database V8.2
        • (WebSphere Commerce - Express) DB2 Universal Database Express V8.2
        • DB2 Universal Database for iSeries V4R5
      • (Oracle) Oracle 9i or Oracle 10g, depending on your target database.
    6. Click Finish. If asked to confirm creation of the /WebSphereCommerceServerExtensionData/ejbModule/META-INF/backends/databaseType folder, click Yes.
    7. Navigate to the following directory: WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > databaseType > databaseName, where databaseType is the database type you chose in the previous step, and databaseName is the name of your development database.
    8. Select databaseName and from its pop-up menu, select New > Schema Definition.
    9. In the Schema name field, enter NULLID and click Finish. You use NULLID as the schema name because this allows flexibility for EJB beans to work against any schema. If the schema name is filled in with a specific value other than NULLID, the EJB bean only works for tables created using a specific schema.
    10. Right-click NULLID and select New > Table Definition.
    11. In the Table name field, type XCATENTRY_EXT and click Next.
    12. Add the following columns to your table definition:

      Column nameColumn typeKey column
      CATENTRY_ID
      • (DB2) BIGINT
      • (Oracle) NUMBER
      • (Cloudscape) Select BIGINT or NUMBER according to your target database.
      Selected
      STOREENT_ID
      • (DB2) BIGINT
      • (Oracle) NUMBER
      • (Cloudscape) Select BIGINT or NUMBER according to your target database.
      Selected
      VENDOR_ID
      • (DB2) BIGINT
      • (Oracle) NUMBER
      • (Cloudscape) Select BIGINT or NUMBER according to your target database.
      Selected
      FIELD1INTEGERClear
      FIELD2
      • (DB2) VARCHAR(128)
      • (Oracle) VARCHAR2(128 BYTE)
      • (Cloudscape) Select VARCHAR(128).
      Clear
      FIELD3
      • (DB2) DECIMAL(20,5)
      • (Oracle) NUMBER(20,5)
      • (Cloudscape) Select DECIMAL(20,5).
      Clear
      PRODUCT_TYPE
      • (DB2) VARCHAR(128)
      • (Oracle) VARCHAR2(128 BYTE)
      • (Cloudscape) Select VARCHAR(128).
      Clear
      OPTCOUNTERSMALLINTClear


    13. Click Finish.
    14. Switch to J2EE perspective and in the Enterprise Explorer view, select EJB Projects > WebSphereCommerceServerExtensionsData.
    15. Select WebSphereCommerceServerExtensionsData and from its pop-up menu, select EJB to RDB Mapping > Generate Map. The Use an existing backend folder radio button is pre-selected. Click Next.
    16. Select Meet In The Middle and click Next.
    17. Select Match By Name and click Finish.
    18. In the Enterprise Beans pane, highlight the XCatentryExt bean. In the Tables pane, highlight the XCATENTRY_EXT table.
    19. Map the fields in the XCatentryExt bean to the columns in the XCATENTRY_EXT table by selecting Match By Name from the bean's pop-up menu.
    20. Save the file and keep the mapping editor open.
  11. To enable optimistic locking:
    1. Enable optimistic locking in the deployment descriptor:
      1. In the Enterprise Explorer view, navigate to EJB Projects > WebSphereCommerceServerExtensionsData > Deployment Descriptor : > WebSphereCommerceServerExtensionsData.
      2. Open the deployment descriptor for editing.
      3. In the Bean tab, select the XCatentryExt bean.
      4. In the lower right pane, scroll down to the Concurrency Control section.
      5. Select Enable optimistic locking.
      6. Save your changes.
    2. Set the optimistic predicate value of the optcounter field:
      1. In the Mapping Editor, the Map.mapxmi file should still be open.
      2. In the Overview section, in the Enterprise Beans pane, select optcounter : short.
      3. Select the Properties view, and select true from the OptimisticPredicate list.
    3. Save your changes.
  12. Create an access bean:
    1. Follow one of these two options:
      • Either select File > New > Access Bean.
      Or follow these steps:
      • Right-click the WebSphereCommerceServerExtensionsData project and select New > Others....
      • From the New wizard, select EJB> Access Bean.
    2. Click Next.
    3. Select Copy helper and click Next.
    4. Select the XCatentryExt bean and click Next.
    5. From the Constructor Method list, select findByPrimaryKey(com.dw.commerce.extension.objects.XCatentryExtKey) and click Finish.
    6. In the EJB Deployment Descriptor Editor, in the Overview tab, scroll down to the JNDI - CMP Connection Factory Binding section, and in the JNDI name field, enter the value that matches your database type:
      • jdbc/WebSphere Commerce Cloudscape DataSource demo
      • (DB2) jdbc/WebSphere Commerce DB2 DataSource demo
      • (i5/OS) jdbc/WebSphere Commerce iSeries DataSource demo
      • (Oracle) jdbc/WebSphere Commerce Oracle DataSource demo

        Ensure there are no spaces appended to the JNDI name. Spaces at the end of the JNDI cause errors when the binding is created.

    7. Save your changes.
  13. Generate the deploy code and regenerate the XCatentryExtAccessBean. The code generation utility analyzes the beans to ensure that Sun® Microsystems EJB specifications are met and it ensures that rules specific to the EJB server are followed. In addition, for each selected enterprise bean, the code-generation tool generates the home and EJBObject (remote) implementations and implementation classes for the home and remote interfaces, as well as the JDBC persister and finder classes for CMP beans. It also generates the Java™ ORB, stubs, and tie classes required for RMI access over IIOP, as well as stubs for the home and remote interfaces.

    To generate the deploy code:

    1. Navigate to EJB projects > WebSphereCommerceServerExtensionsData.
    2. Select the WebSphereCommerceServerExtensionsData project.
    3. From the project's pop-up menu, select Deploy.
    4. After the deploy code is generated, Rational Application Developer rebuilds the workspace. When the workspace building completes, ensure you have no errors in the Problems view.
  14. To regenerate the XCatentryExtAccessBean:
    1. In the Enterprise Explorer view, navigate to EJB Projects > WebSphereCommerceServerExtensionsData > Deployment Descriptor: > WebSphereCommerceServerExtensionsData.
    2. From the deployment descriptors pop-up menu, select Access Beans > Regenerate Access Beans.
    3. On the "Select access beans to regenerate" window, click Deselect All.
    4. Select only XCatentryExtAccessBean.
    5. Click Finish.
    6. Save all files.

Section conclusion

In this section, you have created an entity bean with the special step of appending a UserFinderDescriptor finder type FinderHelper method. This UserFinderDescriptor finder type FinderHelper method allows you to create an additional BeanFinderObject class that extends the entity bean to which you can incorporate the store path relationship type query along with the table data finder.

5 of 11 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=551401
TutorialTitle=Creating solutions on the extended sites framework in WebSphere Commerce
publish-date=10202010
author1-email=mshields@crossview.com
author1-email-cc=dwu@us.ibm.com
author2-email=qnguyen@crossview.com
author2-email-cc=dwu@us.ibm.com
author3-email=rsanghvi@crossview.com
author3-email-cc=dwu@us.ibm.com
author4-email=amar.desai@atech.com
author4-email-cc=dwu@us.ibm.com