Tuesday 1 March 2016

createRow and createAndInitRow - Difference

Hi
The major difference between createRow and createAndInitRow methods  is
createAndInitRow  :
Creates and initializes a new Row object, but does not insert it into the Row Set.
This method differs from createRow() mainly in that this method allows the user to pass in a list of name-value pairs with which row attributes are initialized.
E.g:
    public void insertMethodCreateAndInitRow () {
        ViewObjectImpl vo = this.getExampleVo();
        NameValuePairs nvp = new NameValuePairs();
        try {
            nvp.setAttribute("Attr1", "ABC");
            nvp.setAttribute("Attr2", "123");
            nvp.setAttribute("Attr3", "XYZ");
            Row row = vo.createAndInitRow(nvp);
            vo.insertRow(row); // Inserts a row to the Row Set
        } catch (TooManyObjectsException e) {
            e.printStackTrace();
            }catch(DMLConstraintException e){
                e.printStackTrace();
            }
        getDBTransaction().commit();
    }
createRow  :
Creates a new Row object, but does not insert it into the Row Set.
E.g:
    public void insertMethodCreateRow() {
        ViewObjectImpl vo = this.getExampleVo();
        Row row = vo.createRow();
        try {
            row.setAttribute("Attr1", "ABC");
            row.setAttribute("Attr2", "123");
            row.setAttribute("Attr3", "XYZ");
            vo.insertRow(row); // Inserts a row to the Row Set
        } catch (TooManyObjectsException e) {
            e.printStackTrace();
            }catch(DMLConstraintException e){
                e.printStackTrace();
            }
        getDBTransaction().commit();
    }
We can use createAndInitRow instead of createRow because it sets default values of attributes in view object while creation of Row at run time using the named value pair passed to it.


Thanks
Krishna

No comments:

Post a Comment

Hello World in Java and Go

Hello World: Java: public class HelloWorld { public static void main (String[] args) { System.out.println( "Hello, W...

Popular Posts