SlideShare a Scribd company logo
1 of 24
Download to read offline
JSON, SQLite & Persistence

    Daniel Oskarsson   Know IT
Preface


24 slides and Netbeans Demo

Contents are more towards avoiding pitfalls than learning the
basics.
"Simplicity"
JSON

json.org
http://www.json.org
+             -



json     size       validation




xml    validation     size
JAX-RS                                   JAX-WS



public class Tv {
  @GET
  @Path("/tv/")
  @Produces({"application/json"})
  public List<Channel> getChannels() {
    List<Channel> channels = getChannels();
    return channels;
  }
}
JAX-B

@XmlRootElement
public 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();
  }
}
{
    "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"
              }
          ]
}]}
SQLite

sqlite.org
SQLite

"SQLite is a software library that implements a self-contained,
server-less, zero-configuration, transactional SQL database
engine"

"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 a
replacement for fopen()"



                                   http://www.sqlite.org/about.html
Storage Classes

Values are one of the following storage classes:

  INTEGER (signed)
  REAL
  TEXT (UTF)
  NULL
  BLOB

BOOL (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
Type Affinity

Columns are one the following type affinities:

INTEGER
REAL
NUMERIC
TEXT (NULL, BLOB)
NONE

Internally values may be casted before stored




                            http://www.sqlite.org/datatype3.html
http://www.sqlite.org/lang_createtable.html
Foreign keys

"Foreign key constraints are disabled by default (for backwards
compatibility), so must be enabled separately for each
database 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());
As an in-memory-database

Class.forName("org.sqlite.JDBC");
final String url = "jdbc:sqlite::memory:";
Connection connection = DriverManager.getConnection(url);
JDBC

http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

<dependency>
  <groupId>org.xerial</groupId>
  <artifactId>sqlite-jdbc</artifactId>
</dependency>
1+1=3
JSON Persistence Framework

github.com/danieloskarsson/json-persistence
Characteristics

Key-value-based persistence

Zero configuration
  No database setup
  No mappings

No modifications of domain objects
  No serializable
  No annotations

Apache 2.0 License
Design decisions

Serialization & Deserialization
  JSON Serialization and Deserialization is NOT provided
  The user selects their favorite JSON library for the task

Versioning 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
A perfect match with Smartphones
SmartPhones often...

Comes bundled with support for JSON
Comes bundled with support for SQLite
Receive JSON data from a REST call


JSON Persistence Framework is forthcoming on
  Android
  iOS
  Windows Phone
github.com/danieloskarsson

   linkedin.com/in/danieloskarsson

More Related Content

What's hot

Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
dylanks
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
Marco Gralike
 

What's hot (20)

Xml 2
Xml  2 Xml  2
Xml 2
 
JAXP
JAXPJAXP
JAXP
 
Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operation
 
Intro to HTML5 Web Storage
Intro to HTML5 Web StorageIntro to HTML5 Web Storage
Intro to HTML5 Web Storage
 
Java and XML
Java and XMLJava and XML
Java and XML
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
 
Parsing XML Data
Parsing XML DataParsing XML Data
Parsing XML Data
 
How to search extracted data
How to search extracted dataHow to search extracted data
How to search extracted data
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
PHP with MYSQL
PHP with MYSQLPHP with MYSQL
PHP with MYSQL
 
.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving.Net Project Portfolio for Roger Loving
.Net Project Portfolio for Roger Loving
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
Php summary
Php summaryPhp summary
Php summary
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
XSLT
XSLTXSLT
XSLT
 
Sequel
SequelSequel
Sequel
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
 
XML and Web Services
XML and Web ServicesXML and Web Services
XML and Web Services
 

Similar to Json Persistence Framework

Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
 

Similar to Json Persistence Framework (20)

Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
 
Practical OData
Practical ODataPractical OData
Practical OData
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQL
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrity
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_davidd
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 

Json Persistence Framework

  • 1. JSON, SQLite & Persistence Daniel Oskarsson Know IT
  • 2. Preface 24 slides and Netbeans Demo Contents are more towards avoiding pitfalls than learning the basics.
  • 6. + - json size validation xml validation size
  • 7. JAX-RS JAX-WS public class Tv { @GET @Path("/tv/") @Produces({"application/json"}) public List<Channel> getChannels() { List<Channel> channels = getChannels(); return channels; } }
  • 8. JAX-B @XmlRootElement public 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. { "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" } ] }]}
  • 11. SQLite "SQLite is a software library that implements a self-contained, server-less, zero-configuration, transactional SQL database engine" "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 a replacement for fopen()" http://www.sqlite.org/about.html
  • 12. Storage Classes Values are one of the following storage classes: INTEGER (signed) REAL TEXT (UTF) NULL BLOB BOOL (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. Type Affinity Columns are one the following type affinities: INTEGER REAL NUMERIC TEXT (NULL, BLOB) NONE Internally values may be casted before stored http://www.sqlite.org/datatype3.html
  • 15. Foreign keys "Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database 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. As an in-memory-database Class.forName("org.sqlite.JDBC"); final String url = "jdbc:sqlite::memory:"; Connection connection = DriverManager.getConnection(url);
  • 18. 1+1=3
  • 20. Characteristics Key-value-based persistence Zero configuration No database setup No mappings No modifications of domain objects No serializable No annotations Apache 2.0 License
  • 21. Design decisions Serialization & Deserialization JSON Serialization and Deserialization is NOT provided The user selects their favorite JSON library for the task Versioning 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. A perfect match with Smartphones
  • 23. SmartPhones often... Comes bundled with support for JSON Comes bundled with support for SQLite Receive JSON data from a REST call JSON Persistence Framework is forthcoming on Android iOS Windows Phone
  • 24. github.com/danieloskarsson linkedin.com/in/danieloskarsson