Persistence

In the context of the online shopping project, we are going to create a simple data model with only two tables—the cart and product tables. The product represents what we would like to sell. It has a name, a code, a description, and a price.

The cart what a customer is about to buy. It has an ID, which is autoincremented for any new cart created, and a user, representing the user identification. For the purpose of this book, we are going to use the username sent during the login process. The cart also has a quantity and a code, representing a link to the product table.

The following diagram is a representation of our model:

For the purposes of this book, we will choose a database that requires no administration, is fast, with a small footprint, and can be deployed quickly and smoothly. The H2 database fulfills all of these requirements.

To access our data, we would like to take advantage of the Scala language to statically check our code at compile time. The Slick library is perfect for this task.

Slick can generate SQL for multiple databases, and it supports the following RDBMS (with the respective JDBC driver versions):

Database

JDBC Driver

SQLServer 2008, 2012, 2014

jTDS - SQL Server and Sybase JDBC driver (https://sourceforge.net/projects/jtds/) and Microsoft JDBC Driver 6.0 for SQL Server (https://www.microsoft.com/en-gb/download/details.aspx?id=11774)

Oracle 11g

http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html

DB2 10.5

http://www-01.ibm.com/support/docview.wss?uid=swg21363866

MySQL

mysql-connector-java:5.1.23https://dev.mysql.com/downloads/connector/j/)

PostgreSQL

PostgreSQL JDBC Driver: 9.1-901.jdbc4 (https://jdbc.postgresql.org)

SQLite

sqlite-jdbc:3.8.7 (https://bitbucket.org/xerial/sqlite-jdbc/downloads/)

Derby/JavaDB

derby:10.9.1.0 (https://db.apache.org/derby/derby_downloads.html)

HSQLDB/HyperSQL

hsqldb:2.2.8 (https://sourceforge.net/projects/hsqldb/)

H2

com.h2database.h2:1.4.187 (http://h2database.com/html/download.html)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset