1 / 25

Java ME persistence made easy! by Thiago Rossato Thiago Moreira

Java ME persistence made easy! by Thiago Rossato Thiago Moreira. About Us. Thiago Moreira Works with … Java since 2001 Java ME since 2002 SCJP, SCMAD, SCDJWS and SCDBC Thiago Rossato Works with … Java since 1999 Java ME since 2002 SCJP and SCMAD Priscila Lugon Works with …

edana
Download Presentation

Java ME persistence made easy! by Thiago Rossato Thiago Moreira

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java ME persistence made easy! by Thiago Rossato Thiago Moreira

  2. About Us • Thiago Moreira • Works with … • Java since 2001 • Java ME since 2002 • SCJP, SCMAD, SCDJWS and SCDBC • Thiago Rossato • Works with … • Java since 1999 • Java ME since 2002 • SCJP and SCMAD • Priscila Lugon • Works with … • Java ME since 2004 Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  3. About Floggy • What is Floggy? • Floggy is a 100% object-oriented open source persistence framework for Java ME / MIDP applications. • Floggy allows developers to work with high-level persistence commands. • What Floggy is not? • A database for Java ME applications. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  4. RMS and JSR-75 • How to store data when developing MIDP applications? • RMS (Record Management System) • Implementation is mandatory: in most cases is the only option. • JSR 75 adds file system support • Implementation is optional: not all devices support this JSR. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  5. RMS • Supported by all MIDP devices • Simple and functional API • Modeled after a simple record-oriented database • Data is manipulated as byte arrays Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  6. Sample using RMS publicclassPerson { private String name; private Date birthday; privatechargender; (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  7. Sample using RMS public Person load(int id) { Person p; try { RecordStorers = RecordStore.openRecordStore(“Person”, true); byte[] data = rs.getRecord(id); ByteArrayInputStreambais = new ByteArrayInputStream(data); DataInputStreamdis = new DataInputStream(bais); try { p = new Person(); p.setName(dis.readUTF()); p.setBirthday(new Date(dis.readLong())); p.setGender(dis.readChar()); dis.close(); } catch (IOException e) {} rs.closeRecordStore(); } catch (RecordStoreException e) {} return p; } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  8. Sample using RMS public void save(Person p) { byte[] data = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeUTF(p.getName()); dos.writeLong(p.getBirthday().getTime()); dos.writeChar(p.getGender()); data = baos.toByteArray(); dos.close(); } catch (IOException e) {} RecordStore rs = null; try { rs = RecordStore.openRecordStore(“Person”, true); int id = rs.addRecord(data, 0, data.length); rs.closeRecordStore(); } catch (RecordStoreException e) {} } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  9. How Floggy works? Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  10. Structure • Package net.sourceforge.floggy.persistence • Persistence • Persistable • PersistableManager • Search • ObjsetSet • Filter • Comparator • Exception • FloggyException Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  11. IDEs • Eclipse • Floggy Eclipse Plugin • Netbeans • Ant • Maven • Command Line Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  12. Entity Person import net.sourceforge.floggy.persistence.Persistable; public class Person implements Persistable { private String name; private Date birthday; private char gender; private Phone[] phones; private transient int age; public static int SOME_STATIC_FIELD = 1; (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  13. Entity Person import net.sourceforge.floggy.persistence.Persistable; public class Person implements Persistable { private String name; private Date birthday; private char gender; private Phone[] phones; private transient int age; public static int SOME_STATIC_FIELD = 1; (...) } The markup interface identifiesthepersistable classes. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  14. Entity Person import net.sourceforge.floggy.persistence.Persistable; public class Person implements Persistable { private String name; private Date birthday; private char gender; private Phone[] phones; private transient int age; public static int SOME_STATIC_FIELD = 1; (...) } Transientandstaticfieldaren’tpersisted. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  15. Entity Phone import net.sourceforge.floggy.persistence.Persistable; public class Phone implements Persistable { private String number; private String extension; private int type; // Mobile, Home, Work, etc (...) } 15 Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  16. Saving Person p = new Person(); p.setName(...); p.setBirthday(...); p.setGender(...); p.setPhones(...); try { int id = PersistableManager.getInstance().save(p); } catch (FloggyException e) { (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  17. Saving Person p = new Person(); p.setName(...); p.setBirthday(...); p.setGender(...); p.setPhones(...); try { int id = PersistableManager.getInstance().save(p); } catch (FloggyException e) { (...) } Anunique ID is returnedaftersavinganobject. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  18. Editing and saving Person person = new Person(); try { PersistableManager.getInstance().load(person, id); person.setName(...); id = PersistableManager.getInstance().save(person); } catch (FloggyException e) { (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  19. Editing and saving Person person = new Person(); try { PersistableManager.getInstance().load(person, id); person.setName(...); id = PersistableManager.getInstance().save(person); } catch (FloggyException e) { (...) } Use theunique ID to loadanobject. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  20. Listing PersistableManager pm = PersistableManager.getInstance(); ObjectSet persons = pm.find(Person.class, null, null); for (int i = 0; i < persons.size(); i++) { Person p = (Person) persons.get(i); (...) } An optimized way ... Person person = new Person(); PersistableManager pm = PersistableManager.getInstance(); ObjectSet persons = pm.find(Person.class, null, null); for (int i = 0; i < persons.size(); i++) { persons.get(i, person); (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  21. Filtering publicclassMaleFilterimplements net.sourceforge.floggy.persistence.Filter { publicboolean matches(Persistable persistable) { Person p = (Person) persistable; returnp.getGender() == 'M'; } } (...) ObjectSetpersons = pm.find(Person.class, newMaleFilter(), null); for (int i = 0; i < persons.size(); i++) { Person p = (Person) persons.get(i); (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  22. Ordering publicclassAgeComparatorimplements net.sourceforge.floggy.persistence.Comparator { publicint compare(Persistable o1, Persistable o2) { Person p1 = (Person) o1; Person p2 = (Person) o2; if (p1.getBirthday().getTime() < p2.getBirthday().getTime()) { return PRECEDES; } if (p1.getBirthday().getTime() > p2.getBirthday().getTime()) { return FOLLOWS; } return EQUIVALENT; } } ObjectSetpersons = pm.find(Person.class, null, newAgeCompator()); Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  23. Removing operations • Removing a single object try { PersistableManager.getInstance().delete(person); } catch (FloggyException e) {} • Removing all objects of a specified class try { PersistableManager.getInstance().deleteAll(Person.class); } catch (FloggyException e) {} • Removing all objects try { PersistableManager.getInstance().deleteAll(); } catch (FloggyException e) {} Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  24. Information • Site • Documentation • Roadmap • FAQ • Mailing lists at SF.net • floggy-users@lists.sourceforge.net • Tracker at SF.net • Bugs • Feature requests Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

  25. Thanks! http://floggy.org Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!

More Related