Java ME persistence made easy! by Thiago Rossato Thiago Moreira
About Us <ul><li>Thiago Moreira </li></ul><ul><ul><li>Works with … </li></ul></ul><ul><ul><ul><li>Java since 2001 </li></u...
About Floggy <ul><li>What is Floggy? </li></ul><ul><ul><li>Floggy is a  100% object-oriented open source persistence frame...
RMS and JSR-75 <ul><li>How to store data when developing MIDP applications? </li></ul><ul><ul><li>RMS (Record Management S...
RMS <ul><li>Supported by all MIDP devices </li></ul><ul><li>Simple and functional API </li></ul><ul><li>Modeled after a si...
Sample using RMS <ul><li>public class Person { </li></ul><ul><li>  </li></ul><ul><li>private String name; </li></ul><ul><l...
Sample using RMS <ul><li>public Person load(int id) { </li></ul><ul><li>Person p; </li></ul><ul><li>try { </li></ul><ul><l...
Sample using RMS <ul><li>public void save(Person p) { </li></ul><ul><li>byte[] data = null; </li></ul><ul><li>ByteArrayOut...
How Floggy works? Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work ...
Structure <ul><li>Package  net.sourceforge.floggy.persistence </li></ul><ul><li>Persistence </li></ul><ul><ul><li>Persista...
IDEs <ul><li>Eclipse </li></ul><ul><ul><li>Floggy Eclipse Plugin </li></ul></ul><ul><li>Netbeans </li></ul><ul><li>Ant </l...
<ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Person implements Persistabl...
<ul><li>import  net.sourceforge.floggy.persistence.Persistable ; </li></ul><ul><li>public class Person  implements Persist...
<ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Person implements Persistabl...
<ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Phone implements Persistable...
Saving <ul><li>Person p = new Person(); </li></ul><ul><li>p.setName(...); </li></ul><ul><li>p.setBirthday(...); </li></ul>...
Saving <ul><li>Person p = new Person(); </li></ul><ul><li>p.setName(...); </li></ul><ul><li>p.setBirthday(...); </li></ul>...
Editing and saving <ul><li>Person person = new Person(); </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getI...
Editing and saving <ul><li>Person person = new Person(); </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getI...
Listing <ul><li>PersistableManager pm =  PersistableManager.getInstance(); </li></ul><ul><li>ObjectSet persons = pm.find(P...
Filtering <ul><li>public class MaleFilter implements  </li></ul><ul><li>net.sourceforge.floggy.persistence.Filter { </li><...
Ordering <ul><li>public class AgeComparator implements </li></ul><ul><li>net.sourceforge.floggy.persistence.Comparator { <...
Removing operations <ul><li>Removing a single object </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInsta...
Information <ul><li>Site </li></ul><ul><ul><li>Documentation </li></ul></ul><ul><ul><li>Roadmap </li></ul></ul><ul><ul><li...
Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!  Thanks! ...
Upcoming SlideShare
Loading in …5
×

Floggy-M3DD-2009-01-21

864 views
824 views

Published on

Presentation used on the M3DD conference in Santa Clara, CA

Published in: Technology
2 Comments
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
864
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
33
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

Floggy-M3DD-2009-01-21

  1. 1. Java ME persistence made easy! by Thiago Rossato Thiago Moreira
  2. 2. About Us <ul><li>Thiago Moreira </li></ul><ul><ul><li>Works with … </li></ul></ul><ul><ul><ul><li>Java since 2001 </li></ul></ul></ul><ul><ul><ul><li>Java ME since 2002 </li></ul></ul></ul><ul><ul><li>SCJP, SCMAD, SCDJWS and SCDBC </li></ul></ul><ul><li>Thiago Rossato </li></ul><ul><ul><li>Works with … </li></ul></ul><ul><ul><ul><li>Java since 1999 </li></ul></ul></ul><ul><ul><ul><li>Java ME since 2002 </li></ul></ul></ul><ul><ul><li>SCJP and SCMAD </li></ul></ul><ul><li>Priscila Lugon </li></ul><ul><ul><li>Works with … </li></ul></ul><ul><ul><ul><li>Java ME since 2004 </li></ul></ul></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  3. 3. About Floggy <ul><li>What is Floggy? </li></ul><ul><ul><li>Floggy is a 100% object-oriented open source persistence framework for Java ME / MIDP applications. </li></ul></ul><ul><ul><li>Floggy allows developers to work with high-level persistence commands. </li></ul></ul><ul><li>What Floggy is not? </li></ul><ul><ul><li>A database for Java ME applications. </li></ul></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  4. 4. RMS and JSR-75 <ul><li>How to store data when developing MIDP applications? </li></ul><ul><ul><li>RMS (Record Management System) </li></ul></ul><ul><ul><ul><li>Implementation is mandatory: in most cases is the only option. </li></ul></ul></ul><ul><ul><li>JSR 75 adds file system support </li></ul></ul><ul><ul><ul><li>Implementation is optional: not all devices support this JSR. </li></ul></ul></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  5. 5. RMS <ul><li>Supported by all MIDP devices </li></ul><ul><li>Simple and functional API </li></ul><ul><li>Modeled after a simple record-oriented database </li></ul><ul><li>Data is manipulated as byte arrays </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  6. 6. Sample using RMS <ul><li>public class Person { </li></ul><ul><li>  </li></ul><ul><li>private String name; </li></ul><ul><li>private Date birthday; </li></ul><ul><li>private char gender; </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  7. 7. Sample using RMS <ul><li>public Person load(int id) { </li></ul><ul><li>Person p; </li></ul><ul><li>try { </li></ul><ul><li>RecordStore rs = RecordStore.openRecordStore(“Person”, true); </li></ul><ul><li>byte[] data = rs.getRecord(id); </li></ul><ul><li>ByteArrayInputStream bais = new ByteArrayInputStream(data); </li></ul><ul><li>DataInputStream dis = new DataInputStream(bais); </li></ul><ul><li>try { </li></ul><ul><li>p = new Person(); </li></ul><ul><li>p.setName(dis.readUTF()); </li></ul><ul><li>p.setBirthday(new Date(dis.readLong())); </li></ul><ul><li>p.setGender(dis.readChar()); </li></ul><ul><li>dis.close(); </li></ul><ul><li>} catch (IOException e) {} </li></ul><ul><li>rs.closeRecordStore(); </li></ul><ul><li>} catch (RecordStoreException e) {} </li></ul><ul><li>return p; </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  8. 8. Sample using RMS <ul><li>public void save(Person p) { </li></ul><ul><li>byte[] data = null; </li></ul><ul><li>ByteArrayOutputStream baos = new ByteArrayOutputStream(); </li></ul><ul><li>DataOutputStream dos = new DataOutputStream(baos); </li></ul><ul><li>try { </li></ul><ul><li>dos.writeUTF(p.getName()); </li></ul><ul><li>dos.writeLong(p.getBirthday().getTime()); </li></ul><ul><li>dos.writeChar(p.getGender()); </li></ul><ul><li>data = baos.toByteArray(); </li></ul><ul><li>dos.close(); </li></ul><ul><li>} catch (IOException e) {} </li></ul><ul><li>RecordStore rs = null; </li></ul><ul><li>try { </li></ul><ul><li>rs = RecordStore.openRecordStore(“Person”, true); </li></ul><ul><li>int id = rs.addRecord(data, 0, data.length); </li></ul><ul><li>rs.closeRecordStore(); </li></ul><ul><li>} catch (RecordStoreException e) {} </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  9. 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. 10. Structure <ul><li>Package net.sourceforge.floggy.persistence </li></ul><ul><li>Persistence </li></ul><ul><ul><li>Persistable </li></ul></ul><ul><ul><li>PersistableManager </li></ul></ul><ul><li>Search </li></ul><ul><ul><li>ObjsetSet </li></ul></ul><ul><ul><li>Filter </li></ul></ul><ul><ul><li>Comparator </li></ul></ul><ul><li>Exception </li></ul><ul><ul><li>FloggyException </li></ul></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  11. 11. IDEs <ul><li>Eclipse </li></ul><ul><ul><li>Floggy Eclipse Plugin </li></ul></ul><ul><li>Netbeans </li></ul><ul><li>Ant </li></ul><ul><li>Maven </li></ul><ul><li>Command Line </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  12. 12. <ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Person implements Persistable { </li></ul><ul><li>private String name; </li></ul><ul><li>private Date birthday; </li></ul><ul><li>private char gender; </li></ul><ul><li>private Phone[] phones; </li></ul><ul><li>private transient int age; </li></ul><ul><li>public static int SOME_STATIC_FIELD = 1; </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Entity Person Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  13. 13. <ul><li>import net.sourceforge.floggy.persistence.Persistable ; </li></ul><ul><li>public class Person implements Persistable { </li></ul><ul><li>private String name; </li></ul><ul><li>private Date birthday; </li></ul><ul><li>private char gender; </li></ul><ul><li>private Phone[] phones; </li></ul><ul><li>private transient int age; </li></ul><ul><li>public static int SOME_STATIC_FIELD = 1; </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Entity Person Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you! The markup interface identifies the persistable classes.
  14. 14. <ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Person implements Persistable { </li></ul><ul><li>private String name; </li></ul><ul><li>private Date birthday; </li></ul><ul><li>private char gender; </li></ul><ul><li>private Phone[] phones; </li></ul><ul><li>private transient int age; </li></ul><ul><li>public static int SOME_STATIC_FIELD = 1; </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Entity Person Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you! Transient and static field aren’t persisted.
  15. 15. <ul><li>import net.sourceforge.floggy.persistence.Persistable; </li></ul><ul><li>public class Phone implements Persistable { </li></ul><ul><li>private String number; </li></ul><ul><li>private String extension; </li></ul><ul><li>private int type; // Mobile, Home, Work, etc </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Entity Phone Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  16. 16. Saving <ul><li>Person p = new Person(); </li></ul><ul><li>p.setName(...); </li></ul><ul><li>p.setBirthday(...); </li></ul><ul><li>p.setGender(...); </li></ul><ul><li>p.setPhones(...); </li></ul><ul><li>try { </li></ul><ul><li>int id = PersistableManager.getInstance().save(p); </li></ul><ul><li>} catch (FloggyException e) { </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  17. 17. Saving <ul><li>Person p = new Person(); </li></ul><ul><li>p.setName(...); </li></ul><ul><li>p.setBirthday(...); </li></ul><ul><li>p.setGender(...); </li></ul><ul><li>p.setPhones(...); </li></ul><ul><li>try { </li></ul><ul><li>int id = PersistableManager.getInstance().save(p); </li></ul><ul><li>} catch (FloggyException e) { </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>An unique ID is returned after saving an object. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  18. 18. Editing and saving <ul><li>Person person = new Person(); </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInstance().load(person, id); </li></ul><ul><li>person.setName(...); </li></ul><ul><li>id = PersistableManager.getInstance().save(person); </li></ul><ul><li>} catch (FloggyException e) { </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  19. 19. Editing and saving <ul><li>Person person = new Person(); </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInstance().load(person, id ); </li></ul><ul><li>person.setName(...); </li></ul><ul><li>id = PersistableManager.getInstance().save(person); </li></ul><ul><li>} catch (FloggyException e) { </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Use the unique ID to load an object. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  20. 20. Listing <ul><li>PersistableManager pm = PersistableManager.getInstance(); </li></ul><ul><li>ObjectSet persons = pm.find(Person.class, null, null); </li></ul><ul><li>for (int i = 0; i < persons.size(); i++) { </li></ul><ul><li>Person p = (Person) persons.get(i); </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul><ul><li>An optimized way ... </li></ul><ul><li>Person person = new Person(); </li></ul><ul><li>PersistableManager pm = PersistableManager.getInstance(); </li></ul><ul><li>ObjectSet persons = pm.find(Person.class, null, null); </li></ul><ul><li>for (int i = 0; i < persons.size(); i++) { </li></ul><ul><li>persons.get(i, person ); </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  21. 21. Filtering <ul><li>public class MaleFilter implements </li></ul><ul><li>net.sourceforge.floggy.persistence.Filter { </li></ul><ul><li>public boolean matches(Persistable persistable) { </li></ul><ul><li>Person p = (Person) persistable; </li></ul><ul><li>return p.getGender() == 'M'; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>(...) </li></ul><ul><li>ObjectSet persons = </li></ul><ul><li>pm.find(Person.class, new MaleFilter(), null); </li></ul><ul><li>for (int i = 0; i < persons.size(); i++) { </li></ul><ul><li>Person p = (Person) persons.get(i); </li></ul><ul><li>(...) </li></ul><ul><li>} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  22. 22. Ordering <ul><li>public class AgeComparator implements </li></ul><ul><li>net.sourceforge.floggy.persistence.Comparator { </li></ul><ul><li>public int compare(Persistable o1, Persistable o2) { </li></ul><ul><li>Person p1 = (Person) o1; </li></ul><ul><li>Person p2 = (Person) o2; </li></ul><ul><li>if (p1.getBirthday().getTime() < p2.getBirthday().getTime()) { </li></ul><ul><li>return PRECEDES; </li></ul><ul><li>} </li></ul><ul><li>if (p1.getBirthday().getTime() > p2.getBirthday().getTime()) { </li></ul><ul><li>return FOLLOWS; </li></ul><ul><li>} </li></ul><ul><li>return EQUIVALENT; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>ObjectSet persons = </li></ul><ul><li>pm.find(Person.class, null, new AgeCompator()); </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  23. 23. Removing operations <ul><li>Removing a single object </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInstance().delete(person); </li></ul><ul><li>} catch (FloggyException e) {} </li></ul><ul><li>Removing all objects of a specified class </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInstance().deleteAll(Person.class); </li></ul><ul><li>} catch (FloggyException e) {} </li></ul><ul><li>Removing all objects </li></ul><ul><li>try { </li></ul><ul><li>PersistableManager.getInstance().deleteAll(); </li></ul><ul><li>} catch (FloggyException e) {} </li></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  24. 24. Information <ul><li>Site </li></ul><ul><ul><li>Documentation </li></ul></ul><ul><ul><li>Roadmap </li></ul></ul><ul><ul><li>FAQ </li></ul></ul><ul><li>Mailing lists at SF.net </li></ul><ul><ul><li>[email_address] </li></ul></ul><ul><li>Tracker at SF.net </li></ul><ul><ul><li>Bugs </li></ul></ul><ul><ul><li>Feature requests </li></ul></ul>Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
  25. 25. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you! Thanks! http://floggy.org

×