Floggy-M3DD-2009-01-21

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Floggy-M3DD-2009-01-21 - 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
      • 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!
    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!
    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!
      • 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;
      • (...)
      • }
      Entity Person Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
      • 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;
      • (...)
      • }
      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.
      • 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;
      • (...)
      • }
      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.
      • import net.sourceforge.floggy.persistence.Persistable;
      • public class Phone implements Persistable {
      • private String number;
      • private String extension;
      • private int type; // Mobile, Home, Work, etc
      • (...)
      • }
      Entity Phone Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
    12. 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!
    13. 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. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
    14. 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!
    15. 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. Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
    16. 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!
    17. 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);
      • (...)
      • }
      Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
    18. 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());
      Now you don't need to write hundred of lines of persistence code anymore. Floggy will do the dirty work for you!
    19. 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!
    20. Information
      • Site
        • Documentation
        • Roadmap
        • FAQ
      • Mailing lists at SF.net
        • [email_address]
      • 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!
    21. 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

    + Thiago MoreiraThiago Moreira, 10 months ago

    custom

    718 views, 0 favs, 0 embeds more stats

    Presentation used on the M3DD conference in Santa C more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 718
      • 718 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 20
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories