1 00:00:01,300 --> 00:00:07,065 Welcome to a new episode of my High-Performance Java Persistence video course. In this lesson, you are going to see how you 2 00:00:07,066 --> 00:00:12,832 can setup the high-performance-java-persistence project, which we will use throughout this video course 3 00:00:13,734 --> 00:00:19,832 First of all, you need to go to my GitHub account and choose the high-performance-java-persistence repository. 4 00:00:20,600 --> 00:00:27,232 Perfect. Now, you can either clone the project or simply download it. For simplicity sake, we will just download it. 5 00:00:35,700 --> 00:00:39,565 Now, let's unzip the project we have just downloaded from GitHub. 6 00:00:55,066 --> 00:01:00,599 Perfect. We can now delete the ZIP file since we will no longer need it. 7 00:01:05,000 --> 00:01:09,665 Now, we can open IntelliJ IDEA and import the project using Maven. 8 00:01:13,266 --> 00:01:20,265 We are going to choose Create module groups and Import Maven projects automatically, as well as choosing Java 1.8 since, 9 00:01:20,266 --> 00:01:24,932 as you will soon see, I'm making heavy use of lambdas in this project. 10 00:01:27,266 --> 00:01:29,099 And, that's it! 11 00:01:32,466 --> 00:01:38,565 Now, open the Terminal and run "mvn clean test-compile". It's not a good idea to run the "install" 12 00:01:38,566 --> 00:01:44,665 Maven phase because it will run all tests, and some of those, were designed to run for minutes. 13 00:01:49,566 --> 00:01:54,999 We can now go to the test folder and open a test class. Let's pick the FindEntityTest. 14 00:01:55,801 --> 00:02:00,899 There are many tests in this projects, some for JDBC, others for JPA and Hibernate. Luckily, tests are grouped by folders, 15 00:02:00,900 --> 00:02:05,999 so you can easily find whatever you might be interested in. 16 00:02:07,800 --> 00:02:14,565 Now, back to our FindEntityTest, the entities method declares what entities are used by this test. 17 00:02:15,200 --> 00:02:23,132 We are also explicitly declaring the entity name to avoid Hibernate choosing the nested class fully-qualified name as the entity name. 18 00:02:26,666 --> 00:02:33,999 If we scroll back to the beginning of this test class, we can find the init method which is called before every test execution. 19 00:02:34,634 --> 00:02:40,099 If you override the init method, you have to make sure you call the base class init method as well. 20 00:02:40,767 --> 00:02:47,865 There's also an afterlnit callback method which you can use to execute some logic after the base class init method was called. 21 00:02:47,866 --> 00:02:55,866 The dolnJPA template method is declared in AbstractTest and executes the provided Java 1.8 lambda in the context of a new EntityManager and EntityTransaction. 22 00:03:00,700 --> 00:03:08,700 If you execute the testFind method, you will see it runs on PostgreSQL. That's because the test extends AbstractPostgreSQLintegrationTest. 23 00:03:25,066 --> 00:03:31,599 If you scroll to the beginning of the test log, you will see that the PostgreSQL 9.5 Dialect was used by Hibernate. 24 00:03:33,166 --> 00:03:37,732 All executed statements rely on PostgreSQL syntax and features like creating and 25 00:03:37,733 --> 00:03:42,332 calling a PostgreSQL database sequence for the entity identifier. 26 00:03:50,233 --> 00:03:58,065 If you choose to extend AbstractTest instead of the PostgreSQL-specific one, the test will run on the Hypersonic in-memory database. 27 00:03:58,633 --> 00:04:06,465 When rerunning testFind and verifying the test log, we can see that the HypersonicSQL Dialect was used this time. 28 00:04:12,800 --> 00:04:19,432 You can also override the database method and declare what database type you'd like this test to run against. 29 00:04:27,600 --> 00:04:33,199 If we choose MySQL, tests are going to be run on the local MySQL database server. 30 00:04:44,366 --> 00:04:50,465 Notice that Hibernate used the MySQL57Dialect this time. The generated SQL statements 31 00:04:50,466 --> 00:04:56,565 don't use database sequences since they are not supported by MySQL 5.7. 32 00:04:57,167 --> 00:05:03,199 Running a data access logic test using this GitHub repository is very easy and flexible as well.