You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />
CREATE TABLE userdocument (<br />
userdocumentId varchar(36) NOT NULL,<br />
userId varchar(36) DEFAULT NULL,<br />
documentId varchar(36) DEFAULT NULL,<br />
PRIMARY KEY (userdocumentId),<br />
CONSTRAINT users FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE NO ACTION<br />
ON UPDATE NO ACTION,<br />
CONSTRAINT documents FOREIGN KEY (documentId) REFERENCES documents (documentId) ON DELETE NO<br />
ACTION ON UPDATE NO ACTION<br />
);<br />
Listing 9-8 shows the database schema where you specified the tables that will hold all the information about the<br />
documents, types, and users. If you need more information about database concepts, you can take a look at some of<br />
the SQL books from Apress. Next, you need to have some data (see Listing 9-9).<br />
Listing 9-9. data.sql<br />
INSERT INTO types (typeId, name, description, extension) VALUES<br />
('41e2d211-6396-4f23-9690-77bc2820d84b', 'PDF', 'Portable Document Format', '.pdf');<br />
INSERT INTO types (typeId, name, description, extension) VALUES<br />
('e8e5310b-6345-4d08-86b6-d5c3c299aa7f', 'NOTE', 'Text Notes', '.txt');<br />
INSERT INTO types (typeId, name, description, extension) VALUES<br />
('4980d2e4-a424-4ff4-a0b2-476039682f43', 'WEB', 'Web Link', '.url');<br />
INSERT INTO types (typeId, name, description, extension) VALUES<br />
('c9f1a16d-852d-4132-b4b8-ead20aafc6ef', 'WORD', 'Microsoft Word', '.doc?');<br />
INSERT INTO documents (documentId, name, location, description, typeId, created, modified) VALUES<br />
('1acbb68a-a859-49c9-ac88-d9e9322bac55', 'Book Template', '/docs/isfbook/Documents/Random/Book<br />
Template.pdf', 'A book template for creating new books', '41e2d211-6396-4f23-9690-77bc2820d84b',<br />
'2014-02-24 11:52', '2014-02-26 13:45');<br />
INSERT INTO documents (documentId, name, location, description, typeId, created, modified) VALUES<br />
('cf7fec3e-55bf-426d-8a6f-2ca752ae34ac', 'Sample Contract', '/docs/isfbook/Documents/Contracts/<br />
Sample Contract.pdf', 'Just a Contract', '41e2d211-6396-4f23-9690-77bc2820d84b', '2014-02-24 15:23',<br />
'2014-02-28 10:20');<br />
INSERT INTO documents (documentId, name, location, description, typeId, created, modified) VALUES<br />
('3580f482-7f12-4787-bb60-c98023d47b6c', 'Clustering with RabbitMQ', '/Users/isfbook/Documents/<br />
Random/Clustering with RabbitMQ.txt', 'Simple notes ', 'e8e5310b-6345-4d08-86b6-d5c3c299aa7f',<br />
'2014-02-18', '2014-02-20 14:50');<br />
INSERT INTO documents (documentId, name, location, description, typeId, created, modified)<br />
VALUES ('431cddbf-f3c0-4076-8c1c-564e7dce16c9', 'Pro <strong>Spring</strong> Security Book',<br />
'http://www.apress.com/9781430248187', 'Excellent Book', '4980d2e4-a424-4ff4-a0b2-476039682f43',<br />
'2014-02-14', '2014-02-20');<br />
Listing 9-9 shows the SQL statements you need, which in your case are the INSERT statements.<br />
■Note ■ You can find the files used in Listing 9-8 and Listing 9-9 in the book’s companion source code at the<br />
src/main/resources/META-INF/data path.<br />
121