· 8 years ago · Feb 20, 2018, 05:22 AM
1You can execute PLSQL Code in your ADF application,you have to implement java class for the view object you wish to perform PLSQL code on
2then you'll create a method like the following:
3
4
5 public Integer updatemps (Double sal,Integer dept) {
6
7 int result=0;
8
9 String PLSQLCODE= "begin\n" +
10
11 " update employees set salary=salary+?\n" +
12
13 " where department_id=?; commit;\n" +
14
15 " end;";
16
17
18
19
20 CallableStatement stat=null;
21
22 try {
23
24 stat = getDBTransaction().createCallableStatement(PLSQLCODE, getDBTransaction().DEFAULT);
25
26 stat.setDouble(1, sal);
27
28 stat.setInt(2, dept);
29
30 result=stat.executeUpdate();
31
32 } catch (Exception sqle) {
33
34 // TODO: Add catch code
35
36 sqle.printStackTrace();
37
38 } finally {
39
40
41 try {
42
43 stat.close();
44
45 } catch (SQLException sqle) {
46
47 // TODO: Add catch code
48
49 sqle.printStackTrace();
50
51 }
52
53
54
55
56
57 }
58
59
60
61 return result;
62
63 }
64
65}Once you're done,you can create an interface in your view object and drop it into your JSF page.
66but when you create an ADF form,and execute the PLSQL code,you will not be able to view the changes which have been made
67into your database (of course if there's a read-only table exists in your application).
68to refresh the data you will have to double click on the button of your JSF page which has been created when you dropped the
69ADF parameter form and create a new java bean with a class containing a method like the following:
70
71
72
73package view;
74
75
76import oracle.adf.model.BindingContext;
77
78
79import oracle.adf.model.binding.DCBindingContainer;
80
81
82import oracle.adf.model.binding.DCIteratorBinding;
83
84
85import oracle.adfdt.model.objects.IteratorBinding;
86
87
88import oracle.binding.BindingContainer;
89
90import oracle.binding.OperationBinding;
91
92
93public class refresh {
94
95 public refresh() {
96
97 }
98
99
100 public BindingContainer getBindings() {
101
102 return BindingContext.getCurrent().getCurrentBindingsEntry();
103
104 }
105
106
107 public String cb1_action() {
108
109 BindingContainer bindings = getBindings();
110
111 OperationBinding operationBinding = bindings.getOperationBinding("updatemps");
112
113 Object result = operationBinding.execute();
114
115 if (!operationBinding.getErrors().isEmpty()) {
116
117 return null;
118
119 }
120
121 DCBindingContainer DCB = (DCBindingContainer)getBindings();
122
123 DCIteratorBinding DCBI=DCB.findIteratorBinding("EmployeesView1Iterator");
124
125 DCBI.executeQuery();
126
127 return null;
128
129 }
130
131}
132
133Take care of Iterator's name ;).
134-Ahmed Alhadedy