Chapter 14 - Code Snippets ========================== p.475, step 2: import oracle.jbo.*; import oracle.jbo.domain.*; step 3: import oracle.jbo.client.Configuration; step 4: import hrbc4j.common.*; step 5: ApplicationModule acctPromModule = Configuration.createRootApplicationModule( "hrbc4j.AccountantPromotionModule", "AccountantPromotionModuleLocal" ); step 6: ViewObject allDepts = acctPromModule.findViewObject("AllDepartments"); ---------------------------------------------------------------------------------- p.476, step 1: while (allDepts.hasNext()) { DepartmentsViewRow currDept = (DepartmentsViewRow) allDepts.next(); System.out.println("Now accessing department " + currDept.getDepartmentId() + ": " + currDept.getDepartmentName() + "." ); } ---------------------------------------------------------------------------------- p.477, step 2 at the bottom of the page: import oracle.jbo.*; import oracle.jbo.domain.*; import oracle.jbo.client.Configuration; import hrbc4j.common.*; ---------------------------------------------------------------------------------- p.478, step 3 at the top of the page: ApplicationModule careerModule = Configuration.createRootApplicationModule( "hrbc4j.CareerPathListerModule", "CareerPathListerModuleLocal" ); ViewObject allJobs = careerModule.findViewObject("AllJobs"); step 1: if (args.length==0) { System.out.println("This program requires a Job ID as a parameter."); System.exit(0); } String requestedJobId = args[0]; step 2: Object[] jobKeyValues = new Object[] { requestedJobId }; Key jobKey = new Key(jobKeyValues); step 3: Row[] foundJobs = allJobs.findByKey(jobKey, 1); JobsViewRow requestedJob = (JobsViewRow) foundJobs[0]; allJobs.setCurrentRow(requestedJob); ---------------------------------------------------------------------------------- p.479, top of the page: String jobTitle = requestedJob.getJobTitle(); System.out.println("Found job " + requestedJobId + ": " + jobTitle + "." ); ---------------------------------------------------------------------------------- p.486, step 3, first bullet: ViewObject locs = AbstractVoModule.findViewObject("Locations"); ViewObject depts = AbstractVoModule.findViewObject("DeptsInLocation"); Row loc = locs.createRow(); locs.insertRow(loc); locs.setCurrentRow(loc); loc.setAttribute("LocationId", "US"); loc.setAttribute("LocationId", "JP"); loc.setAttribute("LocationId", "UK"); Row ukDept = depts.createRow(); depts.insertRow(ukDept); second bullet: ViewObject locs = abstractVOModule.findViewObject("Locations"); Row usRow = locs.createRow(); usRow.setAttribute("LocationId", "US"); locs.insertRow(usRow); Row deRow = locs.createRow(); deRow.setAttribute("LocationId", "DE"); locs.insertRow(deRow); Row jpRow = locs.createRow(); deRow.setAttribute("LocationId", "JP"); locs.insertRow(jpRow); Row ukRow = locs.createRow(); ukRow.setAttribute("LocationId", "UK"); locs.insertRow(ukRow); ---------------------------------------------------------------------------------- p.488, step 2: public boolean manyJobs() { oracle.jbo.RowIterator pastJobs = getPastJobs(); if (pastJobs.getRowCount() >= 2) { return true; } return false; } ---------------------------------------------------------------------------------- p.489, step 2: public void promoteAll() { while (hasNext()) { EmpJobsViewRowImpl currRow = (EmpJobsViewRowImpl) next(); String currJob = currRow.getJobId(); String newJob = nextJob(currJob); currRow.setJobId(newJob); } } step 3: private String nextJob(String thisJob) { if (thisJob.equals("AD_VP")) return "AD_PRES"; if (thisJob.equals("AC_MGR")) return "AD_VP"; if (thisJob.equals("AC_ACCOUNT")) return "AC_MGR"; if (thisJob.equals("FI_MGR")) return "AD_VP"; if (thisJob.equals("FI_ACCOUNT")) return "FI_MGR"; /* You could go on, but this is more than sufficient for this practice */ return thisJob; } ---------------------------------------------------------------------------------- p.491, step 3 under "Retrieve the Other View Usage:" EmpJobsView departmentEmps = (EmpJobsView) acctPromModule.findViewObject("DepartmentEmployees"); ViewObject pastJobs = acctPromModule.findViewObject("PastJobs"); step 2 at the bottom of the page: while (departmentEmps.hasNext()) { EmpJobsViewRow currEmp = (EmpJobsViewRow) departmentEmps.next(); System.out.println(" Employee " + currEmp.getEmployeeId() + ": " + currEmp.getLastName() + " makes about $" + currEmp.getYearlyPay() + " as a(n) " + currEmp.getJobTitle() + "." ); } ---------------------------------------------------------------------------------- p.492, step 1 at the top of the page: if (currEmp.manyJobs()) { System.out.println(" This employee has had more than two jobs."); } step 1 under "Write Code to Promote the Accountants in the Department:" departmentEmps.setWhereClause("Employees.JOB_ID = 'FI_ACCOUNT'"); departmentEmps.executeQuery(); step 2: System.out.println(" Promoting all accountants in the department."); departmentEmps.promoteAll(); departmentEmps.setWhereClause(null); ---------------------------------------------------------------------------------- p.493, step 3: ViewObject currHolders = careerModule.findViewObject("CurrentHolders"); ViewObject pastHolders = careerModule.findViewObject("PastHolders"); ---------------------------------------------------------------------------------- p.494, step 2: System.out.println( "The following employees currently have the job title " + jobTitle + ":" ); while (currHolders.hasNext()) { EmployeesViewRow currEmp = (EmployeesViewRow) currHolders.next(); System.out.println( currEmp.getLastName() + ", who makes about $" + currEmp.getYearlyPay() +" and has " + currEmp.getNumReports() + " direct reports." ); } step 3: System.out.println( "The following employees previously had the job title " + jobTitle + ":" ); while (pastHolders.hasNext()) { EmpJobsViewRow currPastHolder = (EmpJobsViewRow) pastHolders.next(); System.out.println( currPastHolder.getLastName() + ", who now makes about $" + currPastHolder.getYearlyPay() + " as a(n) " + currPastHolder.getJobTitle() + "." ); } ---------------------------------------------------------------------------------- p.496, step 2 at the top of the page: public void promoteAccountants() { DepartmentsViewImpl allDepts = getAllDepartments(); EmpJobsViewImpl departmentEmps = getDepartmentEmployees(); } step 3: departmentEmps.setWhereClause("Employees.JOB_ID = 'AC_ACCOUNT'"); while (allDepts.hasNext()) { allDepts.next(); departmentEmps.promoteAll(); } ---------------------------------------------------------------------------------- p.497, step 10: import oracle.jbo.client.Configuration; import hrbc4j.common.AccountantPromotionModule; step 11: (This is a corrected version of the printed text.) AccountantPromotionModule accPromModule = (AccountantPromotionModule) Configuration.createRootApplicationModule( "hrbc4j.AccountantPromotionModule", "AccountantPromotionModuleLocal"); accPromModule.promoteAccountants(); System.out.println("Success!"); ---------------------------------------------------------------------------------- p.498: String viewUsageName = "EmployeesView1"; String viewObjectName = "hrbc4j.EmployeesView"; ViewObject emps = dynamicModule.createViewObject(viewUsageName, viewObjectName); p.499, middle of the page: String viewUsageName="RunTimeQueryResults"; String query="SELECT EMPLOYEES.EMPLOYEE_ID, EMPLOYEES.LAST_NAME, " + "DEPARTMENTS.DEPARTMENT_ID, DEPARTMENTS.DEPARTMENT_NAME " + "FROM DEPARTMENTS, EMPLOYEES " + "WHERE EMPLOYEES.DEPARTMENT_ID = DEPARTMENTS.DEPARTMENT_ID"; ViewObject empsDepts = dynamicModule.createViewObjectFromQueryStmt( viewUsageName, query); ---------------------------------------------------------------------------------- p.500: String viewUsageName = "DynamicEntityBasedUsage"; String entityObjectName = "bc4j.Countries"; String selectClause = "COUNTRY_ID, COUNTRY_NAME"; String fromClause = "COUNTRIES"; String whereClause = null; String orderByClause = "COUNTRY_ID"; ViewObject newVO = dynamicModule.createViewObjectFromQueryClauses( viewUsageName, entityObjectName, selectClause, fromClause, whereClause, orderByClause); ---------------------------------------------------------------------------------- p.501, top of the page: ViewObject master = dynamicModule.findViewObject("SomeEmployees"); ViewObject detail = dynamicModule.findViewObject("SomeJobs"); String viewLinkName = "hrbc4j.EmpPastJobsLink"; String viewLinkUsage = "EmpPastJobsLink2"; dynamicModule.createViewLink( viewLinkUsage, viewLinkName, master, detail); towards the bottom of the page: ViewObject source = dynamicModule.findViewObject("AllDepartments"); ViewObject dest = dynamicModule.findViewObject("SomeEmployees"); /* Create an array containing DepartmentsView.DepartmentId, the source attribute */ AttributeDef[] sourceAttrs = new AttributeDef[1]; sourceAttrs[0] = source.findAttributeDef("DepartmentId"); /* Create an array containing EmployeesView.DepartmentId, the destination attribute */ AttributeDef[] destAttrs = new AttributeDef[1]; destAttrs[0] = dest.findAttributeDef("DepartmentId"); ---------------------------------------------------------------------------------- p.502, top of the page: ViewLink empJobLink = dynamicModule.createViewLinkBetweenViewObjects( "DynamicViewLinkUsage", source, sourceAttrs, dest, destinationAttrs, null); bottom of the page: ViewObject empJobsView = appMod.findViewObject("EmpJobsView"); /* Pass a unique name into createRowSetIterator() to get a secondary row set iterator */ RowSetIterator secondIterator = createRowSetIterator("EmpJobsSecondaryIterator"); while (secondIterator.hasNext()) { Row currRow = secondIterator.next(); /* code that uses currRow */ } Row firstRow = empJobsView.next(); ----------------------------------------------------------------------------------