2.7. Prepare Event Records to Populate the Database
This web project uses H2 for data storage by default. H2 is a Java database integrated with the application servers of JBoss EAP 6.x. It is an in-memory database which means that the data does not persist once the application using the database stops running. For this reason, seed data must be stored in a file within the project and added to the database each time the application starts. While it might not seem practical to have to construct the database each time the application starts, this type of data storage is useful during development for testing purposes.
Warning
The use of H2 for data storage is for testing purposes only and must not be used during production.
The procedure below demonstrates preparing two sample Event records for addition to the H2 database once the TicketMonster application starts.
Procedure 2.7. Prepare Event Records
- In the Project Explorer view, expand ticket-monster→Java Resources→src/main/resources.
- Double-click the
import.sql
file to open it for editing. - Double-click the import.sql view label to make the editor fill the window.
- Create a new Event record by copying the following on one line after the existing Member record
insert into Event (id, name, description, major, picture, version) values (1, 'Shane''s Sock Puppets', 'This critically acclaimed masterpiece...', true, 'http://dl.dropbox.com/u/65660684/640px-Carnival_Puppets.jpg', 1);
- Create a second new Event record by copying the following on one line after the first new Event record
insert into Event (id, name, description, major, picture, version) values (2, 'Rock concert of the decade', 'Get ready to rock...', true, 'http://dl.dropbox.com/u/65660684/640px-Weir%2C_Bob_(2007)_2.jpg', 1);
Figure 2.12. Content of the
import.sql
File for this TicketMonster Workflow - Save the
import.sql
file. - Double-click the import.sql view label to make the editor return to its previous size.