The Frequently Asked Questions

Q: The UJO Framework offers several Ujo implementations. What is the best implementation?
A: I think that implementation QuickUjo satisfies both requirements for good performance and user friendliness.

Q: How to use the QuickUjo for my business object ?
A: Follow the next code. The static block with init(..) method assigns correct indexes and names into Property objects.

public class Person extends QuickUjo {
  public static final Property<Person,String > NAME = newProperty(String.class);
  public static final Property<Person,Boolean> MALE = newProperty(Boolean.class);
  public static final Property<Person,Double > CASH = newProperty(0);
  static { init(Person.class); }
}

Q: Is the static block calling the QuickUjo.init(..) method necessary?
A: The static block with init(..) method assigns correct indexes and names into Property objects. Alternatively you can call the method Ujo.readProperties() before the first using of the object instead of.

Q: Why a subclass OrmTable implementations don't use the static block init(..)?
A: The Ujorm initializes all properties automatically in the ORM meta-model building time.

Q: May the UjoProperty contain a reference to a List?
A: Yes, of course, however a better solution is to use a special subtype ListProperty.

public class Person extends QuickUjo {
  public static final ListProperty<Person,String > EMAILS = newListProperty("email", String.class);
  static { init(Person.class); }
}

Q: How do I quickly copy all the attributes of an UJO object to another instance?
A: Use the next code:

Person oldUser = createPerson();
Person newUser = new Person ();
for (UjoProperty p : newUser.readProperties()) {
    newUser.writeValue(p, oldUser.readValue(p));
}

Q: How do I copy all the attributes of an UJO object to another instance excluding a property?
A: See the next code for excluding a CASH property for example. Note that each property have got a unique instance of the object so it is allowed to use the == operator to a quick comparison:

for (UjoProperty p : oldUser.readProperties()) {
    if (Person.CASH != p) {
        newUser.writeValue(p, oldUser.readValue(p));
    }
}

Q: How to test that a type of property is the Date for example?
A: Use a property method isTypeOf(Class)

if (property.isTypeOf(Date.class)) {
    // your code ...
}

Q: How to save the UJO from to a XML file?
A: Use the next code:

String defaultXmlHeader = null;
UjoManagerXML.getInstance().saveXML(dataFile, person, defaultXmlHeader, "Save");

Q: How to restore the UJO from a XML file?
A: Use the next code:

Person user = UjoManagerXML.getInstance().parseXML(dataFile, Person.class, "Restore");

Q: How works the QuickUjo implementation?
A: The one QuickUjo instance have got the exactly one field: private array of objects. Because each instance of UjoProperty has an index to the one cell of the array, so it is easy to read or write values.

Discussion

Enter your comment
OJEFA
 
 
core_faq.txt · Last modified: 2009/09/20 12:55 by pponec
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki