d
/**
* Custom DML
update/insert/delete logic here.
* @param operation
the operation type
* @param e the
transaction event
*/
protected void
doDML(int operation, TransactionEvent e) {
System.out.println("doDML()");
//
super.doDML(i, transactionEvent);
if(operation
== DML_INSERT){
callInsertProcedure(e);
}
else
if(operation == DML_UPDATE){
callUpdateProcedure(e);
}
else
if(operation == DML_DELETE){
callDeleteProcedure(e);
}
//
super.doDML(operation, e);
}----------------------------------------------------------------------------------
private void
callInsertProcedure(TransactionEvent e) {
callStroredProcedure("employee_api.employee_insert(?,?,?,?,?)",new
Object[] {getSsn(),getName(),getAge(),getSalary(),getCrBy()});
}
private void
callUpdateProcedure(TransactionEvent e) {
callStroredProcedure("employee_api.employee_update(?,?,?,?,?)",new
Object[] {getSsn(),getName(),getAge(),getSalary(),getUpdBy()});
}
private void
callDeleteProcedure(TransactionEvent e) {
callStroredProcedure("employee_api.employee_delete(?)",new
Object[] {getSsn()});
}
protected void
callStroredProcedure(String string, Object[] bindVars) {
PreparedStatement
st = null;
int updatedRow= 0;
try{
st=getDBTransaction().createPreparedStatement("begin
"+string+"; end;",0);
//
st=getDBTransaction().createPreparedStatement(string,0);
if(bindVars !=
null){
for(int z=0; z
< bindVars.length; z++){
st.setObject(z +
1, bindVars[z]);
}
}
updatedRow =
st.executeUpdate();
System.out.println(updatedRow);
}catch(SQLException e){
throw new
JboException(e);
}
finally{
if(st != null){
try{
st.close();
}catch(SQLException e){}
}
}
}
-------------------------------------------------------------------
DB Table:
CREATE TABLE "MENU"."EMPLOYEE"
( "SSN" VARCHAR2(10 BYTE),
"NAME"
VARCHAR2(20 BYTE),
"AGE"
VARCHAR2(5 BYTE),
"SALARY"
VARCHAR2(10 BYTE),
"CR_DT"
DATE,
"CR_BY"
VARCHAR2(10 BYTE),
"UPD_DT"
DATE,
"UPD_BY"
VARCHAR2(10 BYTE),
PRIMARY KEY ("SSN")
USING INDEX PCTFREE
10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL
65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE
"USERS" ENABLE
) PCTFREE 10
PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL
65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;------------------------------------------------------------------
Store Procedure
create or replace
package employee_api as
procedure employee_insert(p_ssn varchar2, p_name varchar2,
p_age varchar2, p_salary varchar2, p_cr_by varchar2);
procedure employee_update(p_ssn varchar2, p_name varchar2,
p_age varchar2, p_salary varchar2, p_upd_by varchar2);
procedure employee_delete(p_ssn varchar2);
end employee_api;create or replace
package body employee_api
is
procedure employee_insert(p_ssn varchar2,
p_name varchar2,
p_age varchar2,
p_salary varchar2,
p_cr_by varchar2)
IS
begin
insert into employee(ssn, name, age, salary, cr_dt, cr_by)
values(p_ssn , p_name , p_age , p_salary ,sysdate, p_cr_by );
commit;
end employee_insert;
procedure employee_update(p_ssn varchar2, p_name varchar2, p_age varchar2, p_salary varchar2, p_upd_by varchar2)
IS
begin
update employee
set name = p_name,
age = p_age,
salary = p_salary,
upd_by = p_upd_by,
upd_dt = sysdate
where ssn=p_ssn;
end employee_update;
procedure employee_delete(p_ssn varchar2)
IS
begin
delete from employee where ssn=p_ssn;
end employee_delete;
end employee_api;
---------------------------------------------------------------------
----------------------------------------------------------------------------------