Monday, June 29, 2015

Creating new EJB in IBM WCS


NOTE: If you want your table to be used in stagprop, Make sure table name doesnot exceed 18 CHAR length.

Creating new EJB :
Create Table:

1.       Do physical mapping in RAD : Go to WebSphereCommerceServerExtensionsData > Data Models > WCDEV.dbm à Select DB2ADMIN schema. Rename it to NULLID
2.       Right-click NULLID > Add Data Object > Table.
3.       Create ur table. Right click on table and generate DDL. This ddl you can use to create table in DB.



4.       Create the XOrderItemsBundles entity bean
4.1 In the Enterprise Explorer view, expand WebSphereCommerceServerExtensionsData.
4.2 Right-click Deployment Descriptor: WebSphereCommerceServerExtensionsData; select New > Enterprise Bean
4.3 In the Create and Enterprise Bean window:
4.4 Select Entity bean with container-managed persistence (CMP) fields
In the Source folder field, leave the default value, ejbModule.
In the Default package field, enter com.ibm.commerce.extension.objects.
From the CMP Version list, select 1.x.
Click Next.


5.       In the Enterprise Bean Details window, add new CMP attributes for the OrederId,OrderItemsID etc.
5.1 Select the default CMP attribute id:java.lang.Integer and click Remove.
Click Add.
5.2 In the Name field, enter OrederId.
5.3 In the Type field, enter java.lang.Long.
Note : You must use the java.lang.Long data type, not the long data type, since the column OrederId that you are trying to map to is BIGINT or NUMBER.

Select the Key Field check box to indicate that this field is the primary key of the database table.
Click Apply.
Same way for other field.
You must use the java.lang.Integer data type, not the integer data type.


Ensure the Access with getter and setter methods check box is selected. By selecting this option all getter and setter methods will be automatically generated for all fields.



Clear the Access with getter and setter methods check box.
Click Apply then Close to close this window.
Ensure the Use the single key attribute type for the key class check box is not selected, then click Next. Ensuring this check box is not selected ensures that a key class is created, ensuring consistency with other beans.
In the EJB Java Class Details window, create the entity bean called Bonus:
To select the bean's superclass, click Browse.
In the Type Selection window, in the Select a class using: (any) field, enter ECEntityBean and click OK.
Specify the interfaces that the remote interface should extend by clicking Add.
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 in order to protect the new resource under access control.
Click Next.






Deselect Add bean to Class Diagram.
Click Finish.



Setting EJB properties : Set the EJB isolation level
WebSphereCommerceServerExtensionsData > Deployment Descriptor > Entity Beans
  1. Right-click On your bean and open the bean in its deployment descriptor.
  2. Click the Access tab.
  3. Next to the Isolation Level text box, click Add.
  4. In the Add Isolation Level window, select Read committed, then click Next.
  5. From the Beans found list, select the Bonus bean, then click Next.
  6. From the Methods found list, select Bonus to select all of its methods, and click Finish.
  7. Save your changes and keep the editor open





Set the security identity of the bean:
Ø  Select the Access tab selected.
Ø  In the Security Identity (Method Level) section, click Add.
Ø  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.
Ø  From the Beans found list, select the your bean, then click Next.
Ø  From the Methods found list, select your bean to select all of its methods, and click Finish.
Ø  Save your changes and keep the editor open.





Remove the unused generated fields and methods. The ECEntityBean base class provides its own implementation of these methods:
In the Java EE view, expand WebSphereCommerceServerExtensionsData > Entity Beans > XOrderItemsBundlesBean
Open the XOrderItemsBundlesBeanclass for editing
Ø  In the Outline view removed the unused fields:
Ø  Select the myEntityCtx field and from its pop-up menu, select Delete.
Ø  Select the getEntityContext() method and from its pop-up menu, select Delete.
Ø  Select the setEntityContext(EntityContext) method and from its pop-up menu, select Delete.
Ø  Select the unsetEntityContext() method and from its pop-up menu, select Delete.


Add getter method for all primary key fields.
You can generate this method without having to type the source. Right-click the catalogId property in the Outline view, and select Source > Generate Getter and Setters. Select only the getOrderItemId()
method
In the Outline view, right-click the getOrderItemId method and select Enterprise Bean (1.x-2.x) > Promote to Remote Interface

Add Ejb finder :
  1. In the EJB Deployment Descriptor editor, click the Bean tab.
  2. In the Beans pane, select the XOrderItemsBundles bean.
  3. Click Add next to the Finders text box, as in the following screen capture:



Add ejbCreate and ejbPostCreate methods :
/**
                 * ejbCreate method for a CMP entity bean.
                 */
                public com.XYZ.commerce.bundleorder.XOrderItemsBundlesKey ejbCreate(
                                java.lang.Long orderItemsId,
                                java.lang.Long bundleCatentryId,
                                java.lang.Long ordersId,
                                java.lang.Long catentryId,
                                java.lang.String slot,
                                java.lang.String field1,
                                java.lang.String field2,
                                java.lang.Integer field3) throws javax.ejb.CreateException {
                                this.initializeFields();
                                _initLinks();
                                this.orderItemsId = orderItemsId;
                                this.bundleCatentryId = bundleCatentryId;
                                this.ordersId = ordersId;
                                this.catentryId= catentryId;
                                this.slot = slot;
                                this.field1 = field1;
                                this.field2 = field2;
                                this.field3 = field3;
                                XOrderItemsBundlesKey bunKey = new XOrderItemsBundlesKey(orderItemsId,bundleCatentryId);
                                this.initializeOptCounter(bunKey);
                                return null;
                }

                /**
                 * ejbPostCreate
                 */
                public void ejbPostCreate(
                                java.lang.Long orderItemsId,
                                java.lang.Long bundleCatentryId,
                                java.lang.Long ordersId,
                                java.lang.Long catentryId,
                                java.lang.String slot,
                                java.lang.String field1,
                                java.lang.String field2,
                                java.lang.Integer field3) throws javax.ejb.CreateException {
                }
In the Outline view, right-click the ejbCreate(Long, Integer, Short, Integer, String) method you just created and select Enterprise Bean (1.x-2.x) >Promote to Home Interface

getOwner And fulfills method is not necessary till you have foreign key to any table.

Create getter method for all primary key and in outline right click on getter method  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.

Map the database table to the EJB :
In the Java EE perspective Enterprise Explorer view, right-click WebSphereCommerceServerExtensionsData and select Java EE > EJB to RDB Mapping (1.x-2.x) > Generate Map






Click finish. If you have preexisting folder :
In overview section by clicking all column you should get field mapped.

Make the bean portable and enable optimistic locking

Enable optimistic locking. Open the deployment descriptor under WebSphereCommerceServerExtensionsData
In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData > Deployment Descriptor.
Ø  Open the deployment descriptor for editing.
Ø  In the Bean tab, select the your bean.
Ø  In the lower right pane, scroll down to the Concurrency Control section.
Ø  Select Enable optimistic locking.
Ø  Save your changes.
Edit methods to call optimistic locking classes. In the XOrderItemsBundle class make the following changes:
Ø  In the Outline view, select ejbLoad() and add the following code as the first line in the method: super.ejbLoad();
Ø  In the Outline view, select ejbStore() and add the following code as the first line in the method: super.ejbStore();
Ø  In the Outline view, select ejbCreate(Long, Integer) and add the following code:
Ø  Add this.initializeFields(); as the first line in the method.
Ø  Add the following two lines to the method before the return statement
XOrderItemsBundlesKey bunKey = new XOrderItemsBundlesKey(orderItemsId,bundleCatentryId);
            this.initializeOptCounter(bunKey);
Ø  Save your changes.
Generate the Access Bean for the EJB
In the Java EE perspective Enterprise Explorer view, right-click WebSphereCommerceServerExtensionsData . Select New > Other. In the list of options, expand EJB
and select Access Bean. Select Next.
On the Select an Access Bean Type page, select Copy helper . Select Next
On the Select EJB Project page, select XOrderItemsBundles bean.
Select Next.
 On the Copy Helper Access Bean page, for the Constructor method, select
findByPrimaryKey(com.ibm.commerce.extension.helpers.XPaperCatalog).
Select Finish.
Right-click WebSphereCommerceServerExtensionsData. Select Java EE >Prepare for Deployment


Save all file.

Tuesday, June 23, 2015

SQLCODE=-7, SQLSTATE=42601

Issue : com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-7, SQLSTATE=42601

While testing EJB from test client in IBM wcs - If u are getting above issue.

1. Recreate table in NULLID.
2. Save your .dbm file
3. Do mapping again.
4.Do prepare for deployment
5. Regenerate accessbean
6. Test again - It will work

Adding/Deleting fields for Existing EJB


Adding/Deleting fields for Existing EJB

As requirements evolve during the course of a project, the developer may find it necessary to adjust the existing data model.  In most cases, this involves adding or deleting a table column.  Once the table definition is changed, the developer must also update the corresponding EJB.  This is a common development task, yet there is no tutorial or documentation in the WebSphere Commerce Infocenter.
A number of files are generated automatically when the EJB is first created, so it’s not always clear which code should be updated. Follow these steps when adding or deleting fields for existing EJB:
1. Take snapshot!
2. Modify deployment descriptor/bean class
3. Open bean class and add/delete CMP attribute
4. Demote ejbCreate from Home interface
5. Add/delete CMP attribute in ejbCreate and ejbPostCreate argument list
6. Promote ejbCreate to Home interface
7. Modify _copyToEJB and _copyfromEJB methods to account for added/removed field
8. Modify data definition:  WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > {databaseType} > MALL_NULLID_{tableName}.tblxmi. Add/delete column from table definition.
9. Modify EJB to RDB mapping:   WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > {databaseType} > Map.mapxmi

If adding an EJB field, map the field to the table column.
If deleting a field, remove it from the mapping.

 Note: The field may already have been removed from the mapping when the deployment descriptor and data definition were saved in the previous steps.
10. Deploy.  If the following error occurs, There are no enterprise beans in WebSphereCommerceServerExtensionsData, delete all auto-generated files (prefixed with the underscore), and deploy again.
Build.
11. Regenerate access bean.


We modify the _copy methods to ensure that all bean references are updated.  Without this step, we found that the deployment descriptor sometimes reverted to the original bean definition.

Wednesday, June 17, 2015

Display all subcatogry in facets IBM WCS

Displaying only child category facets of a browsed category
Displaying only child category facets of a browsed category helps limit the number of SQL queries for catalogs with a large number of categories.

Problem
Displaying only child category facets of a browsed category helps limit the number of SQL queries for catalogs with a large number of categories. Otherwise, there is a performance hit for browsing child categories within a category.

If the MAX_DISPLAY column in the FACET value is set too low, some categories might not work correctly.

Solution
To resolve this issue:
Set the MAX_DISPLAY column in the FACET table to -1.
Set the displayChildCategoriesOnly property to true in your custom wc-component.xml file. For more information, see Changing properties in the component configuration file (wc-component.xml) (Search EAR).

These settings ensure that only child category facets of the browsed category are displayed, and that the subcategories of the child categories are not faceted.

e.g To display all subcatogry in catogry landing page 

update facet set  MAX_DISPLAY  = -1
where SRCHATTR_ID in (select SRCHATTR_ID from SRCHATTR where IDENTIFIER= '_cat.ParentCatalogGroup'  and INDEXTYPE = 'CatalogEntry' ) ;

Tables involved with WebSphere Commerce Scheduler framework

Tables involved with WebSphere Commerce Scheduler framework


SCHCMD - All the store and site level scheduler commands are configured in this table. For site level scheduler commands, we can also use the controller commands configured in the struts config file and it's not necessary that all site level schedulers commands needs to be configured in this table but all store level scheduler commands need to configured in this table.

CHKCMD - Check command details are stored in this table. Lets consider a simple scenario, as per requirement you would like to run a specific scheduler command only on weekdays. So before running a scheduler command, you would like to check whether it's weekday or not and decide based on it. This kind of validation is done through this check command and each scheduler command may or may not have a check command.

SCHCONFIG - When you configure a scheduler in WebSphere Commerce admin console, all configuration details are stored in this table. It has details about all the scheduler jobs configured at WebSphere Commerce

SCHACTIVE - This table holds details about what schedule job needs to be executed and when it needs to be executed. WebSphere Commerce scheduler framework looks up for this table to identify which scheduler job needs to be executed at a given time.

SCHSTATUS - The status of all the scheduled jobs gets stored in this table. Like what's the current status of this schedule job, when it's started, when it's ended, whether it's failed or succeed etc.

SCHERRORLOG - When particular schedule job failed to execute, this table logs the exception information against each failed job. This helps to understand why specific scheduled job failed to run.

In short, scheduler command and task command details are stored in SCHCMD and CHKCMD table and scheduler configuration related details are stored in SCHCONFIG and SCHACTIVE. Scheduler framework monitors the SCHACTIVE table to identify which scheduled job needs to be running at a specified time, pulls the corresponding scheduled job configuration details from SCHCONFIG table, executes the identified scheduled job and updates the status in SCHSTATUS table and logs the error message in SCHERRORLOG table if specific scheduled job failed.

The above mentioned tables are not the complete list of tables used by WebSphere Commerce Scheduler Framework, you can refer the Knowledge Center article here to know more about it. This is more like a basic foundation blog for the succeeding blogs which I am going to write about scheduler framework.


Tuesday, June 16, 2015

ERROR - import javax.servlet can't be resolved

ERROR - import javax.servlet can't be resolved
Solution:
Add servlet-api.jsr to the build path or specify the target runtime for the project.
Steps to add servlet-api.jar

1.       Right-click the project, click Properties.
2.       Choose Java Build Path.
3.       Click Add External JARs...
4.       Browse to find servlet-api.jar and select it.
5.       Click OK to update the build path.
Steps to specify the target runtime
1.       Right-click the project, click Properties.
2.       Click Target Runtime.

3.       Set the target runtime and click Ok.

Tuesday, June 9, 2015

Exception detected - PromotionSystemException

Error : Exception detected "com.ibm.commerce.promotion.facade.server.exception.PromotionSystemException: Exception detected "org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. ".". --


Solution :

Mostly we get this issue when we creat promotion or custom promotion in debug mode.

1. Do a clean build
2. Build LobTools
3. Restart server in normal mode.