Download presentation
Presentation is loading. Please wait.
Published byHumberto Ferrer Modified over 10 years ago
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! 2
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! 3
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! 4
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! 5
6
Sample using RMS public class Person { private String name; private Date birthday; private char gender; (...) } Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you! 6
7
Sample using RMS public Person load(int id) { Person p; try { RecordStore rs = RecordStore.openRecordStore(“Person”, true); byte[] data = rs.getRecord(id); ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dis = 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! 7
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! 8
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! 9
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! 10
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! 11
12
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! 12 Entity Person
13
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 The markup interface identifies the persistable classes.
14
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! 14 Entity Person Transient and static field aren’t persisted.
15
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 Entity Phone 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) { (...) } 16 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) { (...) } An unique ID is returned after saving an object. 17 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) { (...) } 18 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 the unique ID to load an object. 19 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); (...) } 20 Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
21
Filtering public class MaleFilter implements net.sourceforge.floggy.persistence.Filter { public boolean matches(Persistable persistable) { Person p = (Person) persistable; return p.getGender() == 'M'; } (...) ObjectSet persons = pm.find(Person.class, new MaleFilter(), null); for (int i = 0; i < persons.size(); i++) { Person p = (Person) persons.get(i); (...) } 21 Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
22
Ordering public class AgeComparator implements net.sourceforge.floggy.persistence.Comparator { public int 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; } ObjectSet persons = pm.find(Person.class, null, new AgeCompator()); 22 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! 23
24
Information Site – Documentation – Roadmap – FAQ Mailing lists at SF.net – floggy-users@lists.sourceforge.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! 24
25
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.