package com.acme.intg.controls; 

import com.bea.control.*; 
import com.bea.control.JdbcControl;
import java.sql.SQLException; 
import org.apache.beehive.controls.api.bean.ControlExtension;


/** 
 * @author Selvan V. Rajan
 * @version 1.0 
 * Defines a new database control. 
 * 
 * The '@jc:connection' tag indicates which WebLogic data source will be used by 
 * this database control. Please change this to suit your needs. You can see a 
 * list of available data sources by going to the WebLogic console in a browser 
 * (typically http://localhost:7001/console) and clicking Services, JDBC, 
 * Data Sources. 
 * 
 * @jc:connection data-source-jndi-name="samplesDataSource" 
 * @jc:log category-name="DB"
 */ 
@ControlExtension()
@JdbcControl.ConnectionDataSource(jndiName = "cgDataSource")
public interface CCTxnDBControl extends JdbcControl
{ 
    // Sample database function.  Uncomment to use 

    // static public class Customer 
    // { 
    //   public int id; 
    //   public String name; 
    // } 
    // 
    // /** 
    //  * @jc:sql statement="SELECT ID, NAME FROM CUSTOMERS WHERE ID = {id}" 
    //  */ 
    // Customer findCustomer(int id);

    // Add "throws SQLException" to request that SQLExeptions be thrown on errors.

    static final long serialVersionUID = 1L;

    /**
     * @jc:sql command-type="insert" statement::
     * insert into CC_TRKG
     * values (
     * {CC_NUM},
     * {MERCHANT_ID},
     * {AMOUNT},
     * {AUTH_CODE},
     * {REF_ID},
     * {TXN_DATE}
     * )::
     */
    @JdbcControl.SQL(statement = "insert into CC_TRKG values ( {CC_NUM}, {MERCHANT_ID}, {AMOUNT}, {AUTH_CODE}, {REF_ID}, {TXN_DATE} )")
    int insertTxn(long CC_NUM, long MERCHANT_ID, String AMOUNT, String AUTH_CODE, String REF_ID, java.sql.Date TXN_DATE) throws Exception;

    /**
     * @jc:sql statement::
     * select AVLBL_AMOUNT from CC_MASTER
     * where CC_NUM = {CC_NUM}
     * ::
     */
    @JdbcControl.SQL(statement = "select AVLBL_AMOUNT from CC_MASTER where CC_NUM = {CC_NUM}")
    float checkBal(long CC_NUM) throws Exception;

    /**
     * @jc:sql command-type="update" statement::
     * update CC_MASTER
     * set AVLBL_AMOUNT = AVLBL_AMOUNT - {REQ_AMOUNT}
     * where CC_NUM = {CC_NUM}
     * ::
     */
    @JdbcControl.SQL(statement = "update CC_MASTER set AVLBL_AMOUNT = AVLBL_AMOUNT - {REQ_AMOUNT} where CC_NUM = {CC_NUM}")
    int updateCCMaster(long CC_NUM, float REQ_AMOUNT) throws Exception;
}