25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />

}<br />

}<br />

assertEquals(webType.getName(),documents.get(0).getType().getName());<br />

assertEquals(webType.getExtension(),documents.get(0).getType().getExtension());<br />

log.debug("Found WEB Document: " + documents.get(0));<br />

Before you run your test, you need to add the HSDQLDB jar file in the class path or even better, use the gradle<br />

tool, the build.gradle file, to include it. So, in the build.gradle file let’s add in the libraries you need in the<br />

dependencies section (you can find the complete source in the book’s companion source code):<br />

dependencies {<br />

//other libraries here<br />

runtime 'hsqldb:hsqldb:1.8.0.10'<br />

}<br />

120<br />

If you run Listing 9-7 with<br />

gradle :ch09:test<br />

it will fail, but why? Well, you need to add some data first, right? Yes, you don’t have any data to use for this test; you<br />

need to add some documents and their types. So let’s create the database schema (see Listing 9-8) and add some data<br />

(see Listing 9-9) as separate files, and then you can read them to initialize your database.<br />

Listing 9-8. schema.sql<br />

CREATE TABLE types (<br />

typeId varchar(36) NOT NULL,<br />

name varchar(45) NOT NULL,<br />

description varchar(255) DEFAULT NULL,<br />

extension varchar(10) DEFAULT NULL,<br />

PRIMARY KEY (typeId)<br />

);<br />

CREATE TABLE documents (<br />

documentId varchar(36) NOT NULL,<br />

name varchar(255) NOT NULL,<br />

location varchar(600) NOT NULL,<br />

description varchar(600),<br />

typeId varchar(36) NOT NULL,<br />

created datetime NOT NULL,<br />

modified datetime NOT NULL,<br />

PRIMARY KEY (documentId),<br />

CONSTRAINT documentType FOREIGN KEY (typeId) REFERENCES types (typeId)<br />

);<br />

CREATE TABLE users (<br />

userId varchar(36) NOT NULL,<br />

email varchar(100) NOT NULL,<br />

password varchar(45) NOT NULL,<br />

name varchar(45) NOT NULL,<br />

userdocumentId varchar(36) DEFAULT NULL,<br />

PRIMARY KEY (userId)<br />

);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!