Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright  Oracle Corporation, 1998. All rights reserved. 5 More on Creating Database Forms Using AppBuilder.

Similar presentations


Presentation on theme: "Copyright  Oracle Corporation, 1998. All rights reserved. 5 More on Creating Database Forms Using AppBuilder."— Presentation transcript:

1 Copyright  Oracle Corporation, 1998. All rights reserved. 5 More on Creating Database Forms Using AppBuilder

2 Copyright  Oracle Corporation, 1998. All rights reserved. 5-2 Objectives After completing this lesson, you should be able to do the following: Create master-detail forms Use JBCL components programmatically in Java code Filter and sort data records Use data modules, and perform parameterized queries After completing this lesson, you should be able to do the following: Create master-detail forms Use JBCL components programmatically in Java code Filter and sort data records Use data modules, and perform parameterized queries

3 Copyright  Oracle Corporation, 1998. All rights reserved. 5-3 Master-Detail Relationships LOC NEW YORK DALLAS CHICAGO BOSTON DEPTNO 10 20 30 40 DNAME ACCOUNTING RESEARCH SALES OPERATIONS Master table, DEPT EMPNO 7839 7782 7934 7566 7902 ENAME KING CLARK MILLER JONES FORD Details table, EMP DEPTNO 10 20

4 Copyright  Oracle Corporation, 1998. All rights reserved. 5-4 Master-Detail Form at Run Time This is how the Master-Detail form will appear at run time Master section Detail section This is how the Master-Detail form will appear at run time Master section Detail section

5 Copyright  Oracle Corporation, 1998. All rights reserved. 5-5 Two or more QueryDataSets are required in a master-detail form Specifying QueryDataSet Properties Detail query Master query

6 Copyright  Oracle Corporation, 1998. All rights reserved. 5-6 Establishing the Master-Detail Relationship Specify masterLink property in detail QueryDataSet

7 Copyright  Oracle Corporation, 1998. All rights reserved. 5-7 Connecting the Master Query to the Detail Query This column in the master query … … is linked to this column in the detail query

8 Copyright  Oracle Corporation, 1998. All rights reserved. 5-8 Data-aware controls can now be added to display the fields Fields attached to master query Fields attached to detail query Data-aware controls can now be added to display the fields Fields attached to master query Fields attached to detail query Using the Master and Detail QueryDataSets

9 Copyright  Oracle Corporation, 1998. All rights reserved. 5-9 Delayed Fetching Delayed fetching can improve performance Data in the “details” data set is fetched only when needed Select “Delay fetch…” check box in masterLink editor A WHERE clause is required in the SQL string of the detail QueryDataSet Delayed fetching can improve performance Data in the “details” data set is fetched only when needed Select “Delay fetch…” check box in masterLink editor A WHERE clause is required in the SQL string of the detail QueryDataSet

10 Copyright  Oracle Corporation, 1998. All rights reserved. 5-10 Calculated Columns It is also possible to define calculated columns in a QueryDataSet ENAME KING CLARK MILLER ANNUAL_SAL 29400 60000 15600 SAL 2450 5000 1300

11 Copyright  Oracle Corporation, 1998. All rights reserved. 5-11 Adding a Calculated Column to a QueryDataSet 1.Select in the QueryDataSet 2. Open Inspector window 3.Set calcType field to calculated 4. Set columnName and dataType 1.Select in the QueryDataSet 2. Open Inspector window 3.Set calcType field to calculated 4. Set columnName and dataType

12 Copyright  Oracle Corporation, 1998. All rights reserved. 5-12 Supplying a Value for a Calculated Field When a calculated field needs evaluation: QueryDataSet component generates a calcFields event You must handle this event When a calculated field needs evaluation: QueryDataSet component generates a calcFields event You must handle this event

13 Copyright  Oracle Corporation, 1998. All rights reserved. 5-13 Guided Practice: Providing calcFields Handler Method Explain the following handler method: import java.math.BigDecimal; // Standard class … void queryDetail_calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) … { BigDecimal sal, ann; sal = readRow.getBigDecimal("SAL"); ann = sal.multiply(new BigDecimal(12)); dataRow.setBigDecimal("ANNUAL_SAL", ann); }

14 Copyright  Oracle Corporation, 1998. All rights reserved. 5-14 Calculated Columns at Run Time The GridControl displays the calculated column automatically Calculated column The GridControl displays the calculated column automatically Calculated column

15 Copyright  Oracle Corporation, 1998. All rights reserved. 5-15 Filtering Rows If required, a filter can be defined for a QueryDataSet Example: Filter employees earning less than a certain amount If required, a filter can be defined for a QueryDataSet Example: Filter employees earning less than a certain amount

16 Copyright  Oracle Corporation, 1998. All rights reserved. 5-16 QueryDataSets Generate filterRow Events A filterRow event is generated before each row is added to the data set You provide a handler method, to decide whether to keep or reject the row A filterRow event is generated before each row is added to the data set You provide a handler method, to decide whether to keep or reject the row

17 Copyright  Oracle Corporation, 1998. All rights reserved. 5-17 Supplying a Handler Method to Filter Rows void queryDetail_filterRow( ReadRow readRow, RowFilterResponse rowFilterResponse)… { String txt = txtMinSal.getText(); if (txt.equals("")) txt = "0.0"; BigDecimal min = new BigDecimal(txt); BigDecimal sal = readRow.getBigDecimal("SAL"); if (sal.compareTo(min) >= 0) rowFilterResponse.add(); }

18 Copyright  Oracle Corporation, 1998. All rights reserved. 5-18 Forcing a Row Filter to Occur void btn_actionPerformed(ActionEvent e) { try { queryDetail.refilter(); } catch(DataSetException dse) {} } Call refilter() to force rows to be refiltered

19 Copyright  Oracle Corporation, 1998. All rights reserved. 5-19 Sorting Rows A data set can be dynamically re-sorted at any time Example: ChoiceControl can specify the sort column A data set can be dynamically re-sorted at any time Example: ChoiceControl can specify the sort column

20 Copyright  Oracle Corporation, 1998. All rights reserved. 5-20 Performing a Sort Programmatically void choiceControl1_itemStateChanged(ItemEvent e){ String[] s = new String[1]; s[0] = choiceControl1.getSelectedItem(); SortDescriptor sd; sd = new SortDescriptor(s, true, false); try { queryDetail.close(); queryDetail.setSort(sd); queryDetail.open(); } catch (DataSetException dse) {} }

21 Copyright  Oracle Corporation, 1998. All rights reserved. 5-21 Practice 5-1 Overview Define a master-detail form Add a calculated column to a QueryDataSet Add a filter to a QueryDataSet Add sort capabilities to a QueryDataSet Define a master-detail form Add a calculated column to a QueryDataSet Add a filter to a QueryDataSet Add sort capabilities to a QueryDataSet

22 Copyright  Oracle Corporation, 1998. All rights reserved. 5-22 The Bigger Picture The programs we have seen so far comprise a single applet The applet contains the Database and QueryDataSet components The programs we have seen so far comprise a single applet The applet contains the Database and QueryDataSet components database1 queryDataSet1 queryDataSet2 Java applet

23 Copyright  Oracle Corporation, 1998. All rights reserved. 5-23 Working with Larger Programs Complex programs can have many frames Each frame may need its own Database and QueryDataSet components Complex programs can have many frames Each frame may need its own Database and QueryDataSet components database1 queryDataSet1 queryDataSet2 Java applet database1 queryDataSet1 queryDataSet2 Frame 1 database1 queryDataSet1 queryDataSet2 Frame 2

24 Copyright  Oracle Corporation, 1998. All rights reserved. 5-24 The Benefit of Data Modules To avoid duplication, data components can be placed in a shared Data Module database1 queryDataSet1 queryDataSet2 Data module Applet Frame 1 Frame 2 queryDataSet3

25 Copyright  Oracle Corporation, 1998. All rights reserved. 5-25 Creating a Data Module in AppBuilder Select File— >New, and double-click the Data Module icon Fill in details for the new data module

26 Copyright  Oracle Corporation, 1998. All rights reserved. 5-26 Adding Components to a Data Module Add shared Database and QueryDataSet components to the data module

27 Copyright  Oracle Corporation, 1998. All rights reserved. 5-27 Linking an Applet to a Data Module Applets can be linked to a data module, as follows: Data module automatically added to Structure Pane Applets can be linked to a data module, as follows: Data module automatically added to Structure Pane public class MyApplet extends Applet { MyDataModule dm = MyDataModule.getDataModule(); XYLayout xYLayout1 = new XYLayout(); // Etc … };

28 Copyright  Oracle Corporation, 1998. All rights reserved. 5-28 Designing the Applet User Interface Data-aware controls can be added to the applet, as usual The QueryDataSet is now located in the data module Data-aware controls can be added to the applet, as usual The QueryDataSet is now located in the data module

29 Copyright  Oracle Corporation, 1998. All rights reserved. 5-29 Adding a Frame to Display Orders Information Select File—>New, and double-click the Frame icon Fill in details for the new frame

30 Copyright  Oracle Corporation, 1998. All rights reserved. 5-30 Linking a Frame to a Data Module Frames are linked to a data module in exactly the same way as for applets: Data module automatically added to the Structure Pane Frames are linked to a data module in exactly the same way as for applets: Data module automatically added to the Structure Pane public class MyFrame extends DecoratedFrame { MyDataModule dm = MyDataModule.getDataModule(); XYLayout xYLayout1 = new XYLayout(); // Etc … };

31 Copyright  Oracle Corporation, 1998. All rights reserved. 5-31 Specifying a SQL String to Populate the Frame Our frame will display all the orders made by a selected customer Define a separate QueryDataSet to perform this query Place this query in the data module Our frame will display all the orders made by a selected customer Define a separate QueryDataSet to perform this query Place this query in the data module select ORDID, ORDERDATE, SHIPDATE, TOTAL from ORD where CUSTID = :currCust

32 Copyright  Oracle Corporation, 1998. All rights reserved. 5-32 Defining Parameterized Rows The Orders query takes a parameter to specify the current customer This parameter must be represented by a ParameterRow object: The Orders query takes a parameter to specify the current customer This parameter must be represented by a ParameterRow object: void jbInit() … { // Code in MyDataModule ParameterRow pr = new ParameterRow(); pr.addColumn("currCust", Variant.BIGDECIMAL); pr.setBigDecimal("currCust", new BigDecimal(0)); queryOrders.setQuery( new QueryDescriptor(…, pr, true, false)); }

33 Copyright  Oracle Corporation, 1998. All rights reserved. 5-33 Executing the Orders Query void btnControl1_actionPerformed(ActionEvent e) { try { QueryDataSet qc = dm.getQueryCustomers(); BigDecimal custid = qc.getBigDecimal("CUSTID"); QueryDataSet qo = dm.getQueryOrders(); ReadWriteRow pr = qo.getParameterRow(); pr.setBigDecimal("currCust", custid); qo.executeQuery(); new MyFrame().show(); } catch(DataSetException dse) {} }

34 Copyright  Oracle Corporation, 1998. All rights reserved. 5-34 Putting It All Together

35 Copyright  Oracle Corporation, 1998. All rights reserved. 5-35 Summary Master-detail forms can be defined, using the masterLink property Calculated columns can be added to a data set Rows can be filtered and sorted In large programs, a data module can be used for shared components Parameterized queries can be used to specify query values at run time Master-detail forms can be defined, using the masterLink property Calculated columns can be added to a data set Rows can be filtered and sorted In large programs, a data module can be used for shared components Parameterized queries can be used to specify query values at run time

36 Copyright  Oracle Corporation, 1998. All rights reserved. 5-36 Practice 5-2 Overview Define a data module Attach a panel to the data module, and add the panel to an applet Attach a frame window to the data module Launch the frame window from the applet Define a data module Attach a panel to the data module, and add the panel to an applet Attach a frame window to the data module Launch the frame window from the applet

37 Copyright  Oracle Corporation, 1998. All rights reserved. 5-37 Full Notes Page for Practices

38 Copyright  Oracle Corporation, 1998. All rights reserved. 5-38 Full Notes Page for Practices

39 Copyright  Oracle Corporation, 1998. All rights reserved. 5-39 Full Notes Page for Practices

40 Copyright  Oracle Corporation, 1998. All rights reserved. 5-40 Full Notes Page for Practices

41 Copyright  Oracle Corporation, 1998. All rights reserved. 5-41 Full Notes Page for Practices

42 Copyright  Oracle Corporation, 1998. All rights reserved. 5-42 Full Notes Page for Practices

43 Copyright  Oracle Corporation, 1998. All rights reserved. 5-43 Full Notes Page for Practices

44 Copyright  Oracle Corporation, 1998. All rights reserved. 5-44 Full Notes Page for Practices

45 Copyright  Oracle Corporation, 1998. All rights reserved. 5-45 Full Notes Page for Practices

46 Copyright  Oracle Corporation, 1998. All rights reserved. 5-46 Full Notes Page for Practices

47 Copyright  Oracle Corporation, 1998. All rights reserved. 5-47 Full Notes Page for Practices

48 Copyright  Oracle Corporation, 1998. All rights reserved. 5-48 Full Notes Page for Practices

49 Copyright  Oracle Corporation, 1998. All rights reserved. 5-49 Full Notes Page for Practices

50 Copyright  Oracle Corporation, 1998. All rights reserved. 5-50 Full Notes Page for Practices

51 Copyright  Oracle Corporation, 1998. All rights reserved. 5-51 Full Notes Page for Practices

52 Copyright  Oracle Corporation, 1998. All rights reserved. 5-52 Full Notes Page for Practices

53 Copyright  Oracle Corporation, 1998. All rights reserved. 5-53 Full Notes Page for Practices

54 Copyright  Oracle Corporation, 1998. All rights reserved. 5-54 Full Notes Page for Practices

55 Copyright  Oracle Corporation, 1998. All rights reserved. 5-55 Full Notes Page for Practices

56 Copyright  Oracle Corporation, 1998. All rights reserved. 5-56 Full Notes Page for Practices


Download ppt "Copyright  Oracle Corporation, 1998. All rights reserved. 5 More on Creating Database Forms Using AppBuilder."

Similar presentations


Ads by Google