Last modified by Maik Musall on 2007/09/03 13:42

Hide last authors
Pascal Robert 7.1 1 == Overview ==
Quinton Dolan 2.1 2
Maik Musall 10.1 3 First, do no harm - Read and obey [[The EOF Commandments>>doc:documentation.Home.Development Architecture.EOF Architecture.EOF.EOF-Using EOF-The EOF Commandments.WebHome]] before reading this.
Quinton Dolan 2.1 4
Pascal Robert 7.1 5 == Creating EOEnterpriseObjects ==
Quinton Dolan 2.1 6
7 Rather than use
8
Pascal Robert 7.1 9 {{code}}
Quinton Dolan 2.1 10
Pascal Robert 7.1 11 MyEO eo = new MyEO();
12 ec.insertObject(eo);
Quinton Dolan 2.1 13
Pascal Robert 7.1 14 {{/code}}
Quinton Dolan 2.1 15
16 Prefer this form:
17
Pascal Robert 7.1 18 {{code}}
Quinton Dolan 2.1 19
Pascal Robert 7.1 20 MyEO eo = (MyEO) EOUtilities.createAndInsertInstance(ec, "MyEO");
Quinton Dolan 2.1 21
Pascal Robert 7.1 22 {{/code}}
Quinton Dolan 2.1 23
Maik Musall 10.1 24 This has two main advantages. One, it prevents the use of an EO which has not been inserted into an EOEditingContext (see [[The EOF Commandments>>doc:documentation.Home.Development Architecture.EOF Architecture.EOF.EOF-Using EOF-The EOF Commandments.WebHome]]). Two, it supports the case where two or more entities in the EOModel(s) are implemented by the same Java class.
Quinton Dolan 2.1 25
26 A reasonable question to ask here is, If this is good:
27
Pascal Robert 7.1 28 {{code}}
Quinton Dolan 2.1 29
Pascal Robert 7.1 30 MyNewPage nextPage = (MyNewPage)pageWithName(MyNewPage.class.getName());
Quinton Dolan 2.1 31
Pascal Robert 7.1 32 {{/code}}
Quinton Dolan 2.1 33
34 then why not this?
35
Pascal Robert 7.1 36 {{code}}
Quinton Dolan 2.1 37
Pascal Robert 7.1 38 MyEO eo = (MyEO) EOUtilities.createAndInsertInstance(ec, MyEO.class.getName());
Quinton Dolan 2.1 39
Pascal Robert 7.1 40 {{/code}}
Quinton Dolan 2.1 41
42 The key here is that the to second parameter to createAndInsertInstance? is the EOEntity name from the model, not the class name. For component creation it is the class name. The thing is that the entity name and the class name are often not the same. The class names will include package name, but the entity names will not. Also, I've run across cases where multiple entities in the model are implemented by the same class. Gary Teter makes good use of this in the WireHose frameworks.