JSON, SQLite & Persistence    Daniel Oskarsson   Know IT
Preface24 slides and Netbeans DemoContents are more towards avoiding pitfalls than learning thebasics.
"Simplicity"
JSONjson.org
http://www.json.org
+             -json     size       validationxml    validation     size
JAX-RS                                   JAX-WSpublic class Tv {  @GET  @Path("/tv/")  @Produces({"application/json"})  pu...
JAX-B@XmlRootElementpublic class Channel {  public Channel() {}  @XmlElement  private String id;  @XmlElement  private Str...
{    "channel":[      {          "id":"svt1.svt.se",          "name":"SVT1",          "logo":"svt1.svt.se.png",          "...
SQLitesqlite.org
SQLite"SQLite is a software library that implements a self-contained,server-less, zero-configuration, transactional SQL da...
Storage ClassesValues are one of the following storage classes:  INTEGER (signed)  REAL  TEXT (UTF)  NULL  BLOBBOOL (INTEG...
Type AffinityColumns are one the following type affinities:INTEGERREALNUMERICTEXT (NULL, BLOB)NONEInternally values may be...
http://www.sqlite.org/lang_createtable.html
Foreign keys"Foreign key constraints are disabled by default (for backwardscompatibility), so must be enabled separately f...
As an in-memory-databaseClass.forName("org.sqlite.JDBC");final String url = "jdbc:sqlite::memory:";Connection connection =...
JDBChttp://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC<dependency>  <groupId>org.xerial</groupId>  <artifactId>sqlite-jdbc<...
1+1=3
JSON Persistence Frameworkgithub.com/danieloskarsson/json-persistence
CharacteristicsKey-value-based persistenceZero configuration  No database setup  No mappingsNo modifications of domain obj...
Design decisionsSerialization & Deserialization  JSON Serialization and Deserialization is NOT provided  The user selects ...
A perfect match with Smartphones
SmartPhones often...Comes bundled with support for JSONComes bundled with support for SQLiteReceive JSON data from a REST ...
github.com/danieloskarsson   linkedin.com/in/danieloskarsson
Upcoming SlideShare
Loading in...5
×

Json Persistence Framework

3,217

Published on

Presented at JavaForum 2011-11-24.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,217
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Json Persistence Framework

  1. 1. JSON, SQLite & Persistence Daniel Oskarsson Know IT
  2. 2. Preface24 slides and Netbeans DemoContents are more towards avoiding pitfalls than learning thebasics.
  3. 3. "Simplicity"
  4. 4. JSONjson.org
  5. 5. http://www.json.org
  6. 6. + -json size validationxml validation size
  7. 7. JAX-RS JAX-WSpublic class Tv { @GET @Path("/tv/") @Produces({"application/json"}) public List<Channel> getChannels() { List<Channel> channels = getChannels(); return channels; }}
  8. 8. JAX-B@XmlRootElementpublic class Channel { public Channel() {} @XmlElement private String id; @XmlElement private String name; @XmlElement public String getLogo() { return String.format(path, id); } @XmlElement public List<Program> getPrograms() { return getPrograms(); }}
  9. 9. { "channel":[ { "id":"svt1.svt.se", "name":"SVT1", "logo":"svt1.svt.se.png", "programs":[ { "name":"Kulturnyheterna", "start":"2011-11-23T18:00:00Z", "stop":"2011-11-23T18:15:00Z" }, { "name":"Regionala nyheter", "start":"2011-11-23T18:15:00Z", "stop":"2011-11-23T18:30:00Z" } ]}]}
  10. 10. SQLitesqlite.org
  11. 11. SQLite"SQLite is a software library that implements a self-contained,server-less, zero-configuration, transactional SQL databaseengine""SQLite does not have a separate server process""SQLite reads and writes directly to ordinary disk files""Think of SQLite not as a replacement for Oracle but as areplacement for fopen()" http://www.sqlite.org/about.html
  12. 12. Storage ClassesValues are one of the following storage classes: INTEGER (signed) REAL TEXT (UTF) NULL BLOBBOOL (INTEGER 0 or INTEGER 1)DATE (ISO8601 TEXT or Unix Time INTEGER or Julian days)TIME (ISO8601 TEXT or Unix Time INTEGER or Julian days) http://www.sqlite.org/datatype3.html
  13. 13. Type AffinityColumns are one the following type affinities:INTEGERREALNUMERICTEXT (NULL, BLOB)NONEInternally values may be casted before stored http://www.sqlite.org/datatype3.html
  14. 14. http://www.sqlite.org/lang_createtable.html
  15. 15. Foreign keys"Foreign key constraints are disabled by default (for backwardscompatibility), so must be enabled separately for eachdatabase connection separately." (http://www.sqlite.org/foreignkeys.html)Class.forName("org.sqlite.JDBC");final String url = "jdbc:sqlite:json.db";SQLiteConfig config = new SQLiteConfig();config.enforceForeignKeys(true);Connection connection = DriverManager.getConnection(url,config.toProperties());
  16. 16. As an in-memory-databaseClass.forName("org.sqlite.JDBC");final String url = "jdbc:sqlite::memory:";Connection connection = DriverManager.getConnection(url);
  17. 17. JDBChttp://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC<dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId></dependency>
  18. 18. 1+1=3
  19. 19. JSON Persistence Frameworkgithub.com/danieloskarsson/json-persistence
  20. 20. CharacteristicsKey-value-based persistenceZero configuration No database setup No mappingsNo modifications of domain objects No serializable No annotationsApache 2.0 License
  21. 21. Design decisionsSerialization & Deserialization JSON Serialization and Deserialization is NOT provided The user selects their favorite JSON library for the taskVersioning is NOT supported Some JSON libraries support versioning Some JSON libraries navigates the tree of the desired type As opposed to navigating the tree of the input The data type is used as the key / id E.g. tv.domain.Channel[] or tv.domain.Channel Multiple instance of the same class must be in a list JSON should be parsed before it is persisted
  22. 22. A perfect match with Smartphones
  23. 23. SmartPhones often...Comes bundled with support for JSONComes bundled with support for SQLiteReceive JSON data from a REST callJSON Persistence Framework is forthcoming on Android iOS Windows Phone
  24. 24. github.com/danieloskarsson linkedin.com/in/danieloskarsson
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×