Skip to content

Commit

Permalink
Update samples to use new generator mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhave committed May 12, 2017
1 parent f15cf4b commit dc7b3f6
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

@Entity
public class City implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.NaturalId;

Expand All @@ -35,7 +36,8 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;

@ManyToOne(optional = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

Expand All @@ -37,7 +38,8 @@ public class Review implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@SequenceGenerator(name="review_generator", sequenceName="review_sequence", initialValue = 64)
@GeneratedValue(generator = "review_generator")
private Long id;

@ManyToOne(optional = false)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
@SpringBootTest
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
@TestPropertySource(properties = { "spring.jmx.enabled:true",
"spring.datasource.jmx-enabled:true",
"spring.jpa.hibernate.use-new-id-generator-mappings=false" })
"spring.datasource.jmx-enabled:true" })
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataJpaApplicationTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -35,7 +34,6 @@
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class CityRepositoryIntegrationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -42,7 +41,6 @@
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class HotelRepositoryIntegrationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

@Entity
public class City implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.NaturalId;

Expand All @@ -32,7 +33,8 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;

@ManyToOne(optional = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,118 +6,116 @@
-- AUSTRALIA

-- Brisbane
insert into city(country, name, state, map) values ('Australia', 'Brisbane', 'Queensland', '-27.470933, 153.023502')
insert into hotel(city_id, name, address, zip) values (1, 'Conrad Treasury Place', 'William & George Streets', '4001')
insert into city(id, country, name, state, map) values (1, 'Australia', 'Brisbane', 'Queensland', '-27.470933, 153.023502')
insert into hotel(id, city_id, name, address, zip) values (1, 1, 'Conrad Treasury Place', 'William & George Streets', '4001')

-- Melbourne
insert into city(country, name, state, map) values ('Australia', 'Melbourne', 'Victoria', '-37.813187, 144.96298')
insert into hotel(city_id, name, address, zip) values (2, 'The Langham', '1 Southgate Ave, Southbank', '3006')
insert into city(id, country, name, state, map) values (2, 'Australia', 'Melbourne', 'Victoria', '-37.813187, 144.96298')
insert into hotel(id, city_id, name, address, zip) values (2, 2, 'The Langham', '1 Southgate Ave, Southbank', '3006')

-- Sydney
insert into city(country, name, state, map) values ('Australia', 'Sydney', 'New South Wales', '-33.868901, 151.207091')
insert into hotel(city_id, name, address, zip) values (3, 'Swissotel', '68 Market Street', '2000')
insert into city(id, country, name, state, map) values (3, 'Australia', 'Sydney', 'New South Wales', '-33.868901, 151.207091')
insert into hotel(id, city_id, name, address, zip) values (3, 3, 'Swissotel', '68 Market Street', '2000')


-- =================================================================================================
-- CANADA

-- Montreal
insert into city(country, name, state, map) values ('Canada', 'Montreal', 'Quebec', '45.508889, -73.554167')
insert into hotel(city_id, name, address, zip) values (4, 'Ritz Carlton', '1228 Sherbrooke St', 'H3G1H6')
insert into city(id, country, name, state, map) values (4, 'Canada', 'Montreal', 'Quebec', '45.508889, -73.554167')
insert into hotel(id, city_id, name, address, zip) values (4, 4, 'Ritz Carlton', '1228 Sherbrooke St', 'H3G1H6')


-- =================================================================================================
-- ISRAEL

-- Tel Aviv
insert into city(country, name, state, map) values ('Israel', 'Tel Aviv', '', '32.066157, 34.777821')
insert into hotel(city_id, name, address, zip) values (5, 'Hilton Tel Aviv', 'Independence Park', '63405')
insert into city(id, country, name, state, map) values (5, 'Israel', 'Tel Aviv', '', '32.066157, 34.777821')
insert into hotel(id, city_id, name, address, zip) values (5, 5, 'Hilton Tel Aviv', 'Independence Park', '63405')


-- =================================================================================================
-- JAPAN

-- Tokyo
insert into city(country, name, state, map) values ('Japan', 'Tokyo', '', '35.689488, 139.691706')
insert into hotel(city_id, name, address, zip) values (6, 'InterContinental Tokyo Bay', 'Takeshiba Pier', '105')
insert into city(id, country, name, state, map) values (6, 'Japan', 'Tokyo', '', '35.689488, 139.691706')
insert into hotel(id, city_id, name, address, zip) values (6, 6, 'InterContinental Tokyo Bay', 'Takeshiba Pier', '105')


-- =================================================================================================
-- SPAIN

-- Barcelona
insert into city(country, name, state, map) values ('Spain', 'Barcelona', 'Catalunya', '41.387917, 2.169919')
insert into hotel(city_id, name, address, zip) values (7, 'Hilton Diagonal Mar', 'Passeig del Taulat 262-264', '08019')
insert into city(id, country, name, state, map) values (7, 'Spain', 'Barcelona', 'Catalunya', '41.387917, 2.169919')
insert into hotel(id, city_id, name, address, zip) values (7, 7, 'Hilton Diagonal Mar', 'Passeig del Taulat 262-264', '08019')

-- =================================================================================================
-- SWITZERLAND

-- Neuchatel
insert into city(country, name, state, map) values ('Switzerland', 'Neuchatel', '', '46.992979, 6.931933')
insert into hotel(city_id, name, address, zip) values (8, 'Hotel Beaulac', ' Esplanade Leopold-Robert 2', '2000')
insert into city(id, country, name, state, map) values (8, 'Switzerland', 'Neuchatel', '', '46.992979, 6.931933')
insert into hotel(id, city_id, name, address, zip) values (8, 8, 'Hotel Beaulac', ' Esplanade Leopold-Robert 2', '2000')


-- =================================================================================================
-- UNITED KINGDOM

-- Bath
insert into city(country, name, state, map) values ('UK', 'Bath', 'Somerset', '51.381428, -2.357454')
insert into hotel(city_id, name, address, zip) values (9, 'The Bath Priory Hotel', 'Weston Road', 'BA1 2XT')
insert into hotel(city_id, name, address, zip) values (9, 'Bath Travelodge', 'Rossiter Road, Widcombe Basin', 'BA2 4JP')
insert into city(id, country, name, state, map) values (9, 'UK', 'Bath', 'Somerset', '51.381428, -2.357454')
insert into hotel(id, city_id, name, address, zip) values (9, 9, 'The Bath Priory Hotel', 'Weston Road', 'BA1 2XT')
insert into hotel(id, city_id, name, address, zip) values (10, 9, 'Bath Travelodge', 'Rossiter Road, Widcombe Basin', 'BA2 4JP')

-- London
insert into city(country, name, state, map) values ('UK', 'London', '', '51.500152, -0.126236')
insert into hotel(city_id, name, address, zip) values (10, 'Melia White House', 'Albany Street', 'NW1 3UP')
insert into city(id, country, name, state, map) values (10, 'UK', 'London', '', '51.500152, -0.126236')
insert into hotel(id, city_id, name, address, zip) values (11, 10, 'Melia White House', 'Albany Street', 'NW1 3UP')

-- Southampton
insert into city(country, name, state, map) values ('UK', 'Southampton', 'Hampshire', '50.902571, -1.397238')
insert into hotel(city_id, name, address, zip) values (11, 'Chilworth Manor', 'The Cottage, Southampton Business Park', 'SO16 7JF')
insert into city(id, country, name, state, map) values (11, 'UK', 'Southampton', 'Hampshire', '50.902571, -1.397238')
insert into hotel(id, city_id, name, address, zip) values (12, 11, 'Chilworth Manor', 'The Cottage, Southampton Business Park', 'SO16 7JF')


-- =================================================================================================
-- USA

-- Atlanta
insert into city(country, name, state, map) values ('USA', 'Atlanta', 'GA', '33.748995, -84.387982')
insert into hotel(city_id, name, address, zip) values (12, 'Marriott Courtyard', 'Tower Place, Buckhead', '30305')
insert into hotel(city_id, name, address, zip) values (12, 'Ritz Carlton', 'Peachtree Rd, Buckhead', '30326')
insert into hotel(city_id, name, address, zip) values (12, 'Doubletree', 'Tower Place, Buckhead', '30305')
insert into city(id, country, name, state, map) values (12, 'USA', 'Atlanta', 'GA', '33.748995, -84.387982')
insert into hotel(id, city_id, name, address, zip) values (13, 12, 'Marriott Courtyard', 'Tower Place, Buckhead', '30305')

-- Chicago
insert into city(country, name, state, map) values ('USA', 'Chicago', 'IL', '41.878114, -87.629798')
insert into hotel(city_id, name, address, zip) values (13, 'Hotel Allegro', '171 West Randolph Street', '60601')
insert into city(id, country, name, state, map) values (13, 'USA', 'Chicago', 'IL', '41.878114, -87.629798')
insert into hotel(id, city_id, name, address, zip) values (16, 13, 'Hotel Allegro', '171 West Randolph Street', '60601')

-- Eau Claire
insert into city(country, name, state, map) values ('USA', 'Eau Claire', 'WI', '44.811349, -91.498494')
insert into hotel(city_id, name, address, zip) values (14, 'Sea Horse Inn', '2106 N Clairemont Ave', '54703')
insert into hotel(city_id, name, address, zip) values (14, 'Super 8 Eau Claire Campus Area', '1151 W Macarthur Ave', '54701')
insert into city(id, country, name, state, map) values (14, 'USA', 'Eau Claire', 'WI', '44.811349, -91.498494')
insert into hotel(id, city_id, name, address, zip) values (17, 14, 'Sea Horse Inn', '2106 N Clairemont Ave', '54703')
insert into hotel(id, city_id, name, address, zip) values (18, 14, 'Super 8 Eau Claire Campus Area', '1151 W Macarthur Ave', '54701')

-- Hollywood
insert into city(country, name, state, map) values ('USA', 'Hollywood', 'FL', '26.011201, -80.14949')
insert into hotel(city_id, name, address, zip) values (15, 'Westin Diplomat', '3555 S. Ocean Drive', '33019')
insert into city(id, country, name, state, map) values (15, 'USA', 'Hollywood', 'FL', '26.011201, -80.14949')
insert into hotel(id, city_id, name, address, zip) values (19, 15, 'Westin Diplomat', '3555 S. Ocean Drive', '33019')

-- Miami
insert into city(country, name, state, map) values ('USA', 'Miami', 'FL', '25.788969, -80.226439')
insert into hotel(city_id, name, address, zip) values (16, 'Conrad Miami', '1395 Brickell Ave', '33131')
insert into city(id, country, name, state, map) values (16, 'USA', 'Miami', 'FL', '25.788969, -80.226439')
insert into hotel(id, city_id, name, address, zip) values (20, 16, 'Conrad Miami', '1395 Brickell Ave', '33131')

-- Melbourne
insert into city(country, name, state, map) values ('USA', 'Melbourne', 'FL', '28.083627, -80.608109')
insert into hotel(city_id, name, address, zip) values (17, 'Radisson Suite Hotel Oceanfront', '3101 North Hwy', '32903')
insert into city(id, country, name, state, map) values (17, 'USA', 'Melbourne', 'FL', '28.083627, -80.608109')
insert into hotel(id, city_id, name, address, zip) values (21, 17, 'Radisson Suite Hotel Oceanfront', '3101 North Hwy', '32903')

-- New York
insert into city(country, name, state, map) values ('USA', 'New York', 'NY', '40.714353, -74.005973')
insert into hotel(city_id, name, address, zip) values (18, 'W Union Hotel', 'Union Square, Manhattan', '10011')
insert into hotel(city_id, name, address, zip) values (18, 'W Lexington Hotel', 'Lexington Ave, Manhattan', '10011')
insert into hotel(city_id, name, address, zip) values (18, '70 Park Avenue Hotel', '70 Park Avenue', '10011')
insert into city(id, country, name, state, map) values (18, 'USA', 'New York', 'NY', '40.714353, -74.005973')
insert into hotel(id, city_id, name, address, zip) values (22, 18, 'W Union Hotel', 'Union Square, Manhattan', '10011')
insert into hotel(id, city_id, name, address, zip) values (23, 18, 'W Lexington Hotel', 'Lexington Ave, Manhattan', '10011')
insert into hotel(id, city_id, name, address, zip) values (24, 18, '70 Park Avenue Hotel', '70 Park Avenue', '10011')

-- Palm Bay
insert into city(country, name, state, map) values ('USA', 'Palm Bay', 'FL', '28.034462, -80.588665')
insert into hotel(city_id, name, address, zip) values (19, 'Jameson Inn', '890 Palm Bay Rd NE', '32905')
insert into city(id, country, name, state, map) values (19, 'USA', 'Palm Bay', 'FL', '28.034462, -80.588665')
insert into hotel(id, city_id, name, address, zip) values (25, 19, 'Jameson Inn', '890 Palm Bay Rd NE', '32905')

-- San Francisco
insert into city(country, name, state, map) values ('USA', 'San Francisco', 'CA', '37.77493, -122.419415')
insert into hotel(city_id, name, address, zip) values (20, 'Marriot Downtown', '55 Fourth Street', '94103')
insert into city(id, country, name, state, map) values (20, 'USA', 'San Francisco', 'CA', '37.77493, -122.419415')
insert into hotel(id, city_id, name, address, zip) values (26, 20, 'Marriot Downtown', '55 Fourth Street', '94103')

-- Washington
insert into city(country, name, state, map) values ('USA', 'Washington', 'DC', '38.895112, -77.036366')
insert into hotel(city_id, name, address, zip) values (21, 'Hotel Rouge', '1315 16th Street NW', '20036')
insert into city(id, country, name, state, map) values (21, 'USA', 'Washington', 'DC', '38.895112, -77.036366')
insert into hotel(id, city_id, name, address, zip) values (27, 21, 'Hotel Rouge', '1315 16th Street NW', '20036')
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand All @@ -45,8 +43,6 @@
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataRestApplicationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -37,7 +36,6 @@
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class CityRepositoryIntegrationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

@Entity
public class Person {
@Id
@GeneratedValue
@SequenceGenerator(name="person_generator", sequenceName="person_sequence", allocationSize = 1)
@GeneratedValue(generator = "person_generator")
private Long id;
private String firstName;
private String lastName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ CREATE TABLE PERSON (
last_name varchar(255) not null
);

create sequence person_sequence start with 1 increment by 1;

insert into PERSON (first_name, last_name) values ('Dave', 'Syer');
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class SampleFlywayApplicationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;

@Entity
public class Note {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@SequenceGenerator(name="note_generator", sequenceName="note_sequence", initialValue = 5)
@GeneratedValue(generator = "note_generator")
private long id;

private String title;
Expand Down
Loading

0 comments on commit dc7b3f6

Please sign in to comment.