Canvas provides the default support for iBATIS, which is a persistence layer that works on the concept of query-based abstraction and an XML-based modeling of the DML.

...

       3.  The given mapping file expects the PymtTxnAction action class to read the client request. Create the action class extending the Canvas's PortletAction class that validates the user entitlement and              and formats the request data as JSON request to the server:

...

        4.  In the handler properties file (which is defined for the HANDLER_PROPERTIES_FILE key in System Preference Configurator), Map the handler class to the Host Code to handle all the requests               from requests from the host (defined in the forward mapping file).

The typical mapping should be::

Code Block
languagejs
HOST_CODE_Handler = Handler file path


For the Payment Transaction form, create the mapping in the (handler.properties) file as follows:

Code Block
languagejs
PYTTXNHOST_Handler = com.intellectdesign.modelhouse.PymtTxnRequestHandler


       5. Create the handler class (added in the system handler properties file) extending the Canvas SimpleRequestHandler class that provides the Ajax request data as HashMap to the handler class.

          You can use this handler class to massage the data, implement your business logic and pass to instruction class.

Code Block
languagejava
package com.intellectdesign.modelhouse;

...

 
import java.util.HashMap;

...


import java.util.Vector;

...

 
import com.intellectdesign.canvas.common.ExtReplyObject;

...


import com.intellectdesign.canvas.common.ReplyObject;

...


import com.intellectdesign.canvas.constants.util.TIConstants;

...


import com.intellectdesign.canvas.database.DatabaseException;

...


import com.intellectdesign.canvas.event.handler.IData;

...


import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException;

...


import com.intellectdesign.canvas.handler.SimpleRequestHandler;

...


import com.intellectdesign.modelhouse.txn.PaymentInstruction;

...


import com.intellectdesign.modelhouse.txn.TxnData;

...

 
public class PymtTxnRequestHandler extends SimpleRequestHandler

...


	{
		public ReplyObject processRequest(Vector obj) throws ProcessingErrorException

...


			{
				ReplyObject reply = new ExtReplyObject();

...

 
				if (obj instanceof Vector)

...


					{
						Vector inputVector = (Vector) obj;

...


						String userNo = (String) inputVector.get(TIConstants.USER_NO_INDEX_IN_VECTOR);

...

 
						HashMap map = (HashMap) inputVector.get(inputVector.size() - 1);

...


						map.put("USER_NO", userNo);

...


						TxnData txnData = (TxnData) formatTxnData(map);

...

 
						try
						{
							//Pass the transaction data to the instruction

...

 class
							PaymentInstruction paymentInstruction = new PaymentInstruction(); 
							paymentInstruction.insertTxnData(txnData);

...

 
							HashMap successMap = new HashMap();

...

 
							reply = constructSuccessReply(successMap);

...

 
						} 
						catch (DatabaseException dbException)
						{
							throw new ProcessingErrorException("TXN0001", userNo)

...

;
						}
				return reply;
		}
	return reply;
} 
private ExtReplyObject constructSuccessReply(HashMap respMap)
	{
		ExtReplyObject reply = new ExtReplyObject();
		reply.headerMap = new HashMap(); 
		reply.headerMap.put("REPLY_TYPE", "SUCCESS");

...

 
		if (respMap != null)

...


			{
				reply.headerMap.put("JSON_MAP", respMap);

...


			}
	return reply;

...


}

...

 
protected IData formatTxnData(HashMap mapData)

...


	{
		TxnData txnData = new TxnData();

...


		txnData.setAccNo((String) mapData.get("ACC_NO"));

...


		txnData.setAccName((String) mapData.get("ACC_NAME"));

...


		txnData.setAccCcy((String) mapData.get("BENE_ACC_NO"));

...


		txnData.setAccName((String) mapData.get("BENE_NAME"));

...


		txnData.setAccBranch((String) mapData.get("TRANS_DATE"));

...


		txnData.setAccBranch((String) mapData.get("TRANS_AMNT"));

...

 
	return txnData;

...


	}

...


}


        6. Create the Instruction class that handles the DBRequest.

Refer the Canvas Technology – Database Framework Reference Guide to learn about Canvas database framework.

Code Block
languagejava
package com.intellectdesign.modelhouse;

...

 
import java.util.HashMap;

...

 
import com.intellectdesign.canvas.database.DatabaseConstants;

...


import com.intellectdesign.canvas.database.DatabaseException;

...


import com.intellectdesign.canvas.database.DatabaseRequest;

...


import com.intellectdesign.modelhouse.txn.TxnData;

...

 
public class PaymentInstruction

...


	{
		public void insertTxnData(TxnData txnData) throws DatabaseException

...


			{
				// First prepare the hashmap for passing to the db layer.

...


				DatabaseRequest dbRequest = null;

...


				HashMap dataMap = new HashMap();

...

 
				dataMap.put("ACC_NO", txnData.getAccNo());

...


				dataMap.put("ACC_NAME", txnData.getAccName());

...

 
				dataMap.put("TRANSACTION_AMT", txnData.getTransactionAmt());

...


				dataMap.put("TRAN_TYPE", txnData.getTranType());

...


				dataMap.put("TRAN_DATE", txnData.getTranDate());

...

 
				dataMap.put("BENE_ACC_NO", txnData.getBeneAccNo());

...


				dataMap.put("BENE_NAME", txnData.getBeneName());

...


				// Create a db request to execute the query.

...


			try
			{
				dbRequest = new DatabaseRequest();

...


				dbRequest.setDataSource(DatabaseConstants.DEFAULT_DATASOURCE);

...


				dbRequest.setDataAccessMapKey("INSERT_PAYMNT");

...


				dbRequest.setOperation(DatabaseConstants.INSERT);

...


				dbRequest.setData(dataMap); //Pass the data to

...

 insert 
				dbRequest.execute();

...

 
			} 
		catch (DatabaseException dbException)

...


		{
		throw dbException;
		} 
	}
}


        7.  The given instruction class expects a result map with the Access Key INSERT_PAYMNT in the SQL map file.

So, create PaymentSQLMap.xml SQLMap file that contains the SQLs to insert the data into the database as follows:

Code Block
languagexml
<?

...

xmlversion="1.0"encoding="UTF-8" ?>

...

 
	<!DOCTYPE sqlMap

...

 
	PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">

...


		<sqlMap>
			<!-- Parameter map for inserting details in PAYMENT_TXN_DATA table -->

...


			<parameterMapid="TRASACTION_PARAM_MAP"class="java.util.HashMap">

...


			<parameterproperty="ACC_NO"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			<parameterproperty="ACC_TYPE"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			<parameterproperty="ACC_CCY"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			<parameterproperty="ACC_NAME"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			<parameterproperty="TRANS_AMT"jdbcType="NUMBER"javaType="java.lang.String" />

...


			<parameterproperty="TRAN_DATE"jdbcType="TIMESTAMP"javaType="java.lang.String" />

...


			<parameterproperty="BENE_ACC_NO"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			<parameterproperty="BENE_NAME"jdbcType="VARCHAR"javaType="java.lang.String" />

...


			</

...

parameterMap> 
			<!-- PAYMENT_TXN_DATA insertion -->

...


			<insertid="INSERT_PAYMNT_INSERT_TRASACTION"parameterMap="TRASACTION_PARAM_MAP">

...


			INSERT INTO PAYMENT_TXN_DATA

...


				(
					ACC_NO,

...


					ACC_NAME,

...

 
					TRANSACTION_AMT,

...


					TRAN_DATE,

...


					BENE_ACC_NO,

...


					BENE_NAME

...


				)
			VALUES
				(
					?,
					?, 
					?,
					?,
					to_date(?,'DD/MM/YY'),

...


					?,

...


					?
				) 
		</insert> 
	</sqlMap>