Thursday, 3 October 2013

Update attribute value in View Object Programmatically

In this post i willl explain you how to update the attribute value of a Row.

The following code will find the EmployeeId 100 in Employee View object and update the FirstName.

        Number empid=100;
       // create the key object
        Key key = new Key(new Object[] { empid });
        Employees1ViewImpl vo = (Employees1ViewImpl)this.getEmployees1View1();
        //find the row using key reference in View Object.
        Row k=vo.getRow(key);
        //using this method we can set the new value to FirstName  
        k.setAttribute("FirstName", "stev");
       System.out.println("the name is");

Programmatically Insert New Row in DB using View Object reference

We have seen declarative approach to insert new row in database.

In this post i will explain you how to insert new row Programmatically.

1. Create the AppModuleImpl class and also create the java class for respective ViewObject. In this example i am working on EmployeeView. So i have generated EmploueeViewImpl java class.

2. Create the user defined method in AppModuleImple calss as shown below.

    public void createNewRow(){

//get he EmployeeViewImpl class instance
        EmployeesViewImpl vo=this.getEmployeesView1();

       // Create new row to insert data
        Row r=vo.createRow();
//Set the values to respective attributes.
            r.setAttribute("EmployeeId", 509);
            r.setAttribute("FirstName", "test");
            r.setAttribute("LastName", "test");
            r.setAttribute("Email", "");
            r.setAttribute("PhoneNumber", "800000444");
            r.setAttribute("HireDate", new Timestamp(System.currentTimeMillis()));
            r.setAttribute("JobId", "IT_PROG");
            r.setAttribute("Salary", 5000);
            r.setAttribute("CommissionPct", "");
            r.setAttribute("ManagerId", "");
            r.setAttribute("DepartmentId", 340);
//insert row in the view object
//commit the transaction