Skip to content

Commit

Permalink
got teiid-spring-boot version of orders service working wiht h2 -- we…
Browse files Browse the repository at this point in the history
… can spin up service now without external deps on mysql
  • Loading branch information
christian-posta committed Oct 13, 2017
1 parent c2e4352 commit 645a208
Show file tree
Hide file tree
Showing 9 changed files with 712 additions and 6 deletions.
6 changes: 6 additions & 0 deletions orders-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ticketmonster.orders.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;

import javax.sql.DataSource;

@Configuration
@Profile({"!mysql", "!kube"})
public class TeiidTestDataSources {

@Bean
public DataSource legacyDS() {

DataSource dataSource = DataSourceBuilder.create().driverClassName("org.h2.Driver").username("sa").password("").url("jdbc:h2:mem:legacydb;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=FALSE;MODE=MYSQL").build();

Resource initSchema = new ClassPathResource("h2/scripts/legacydb-schema.sql");
Resource initData = new ClassPathResource("h2/scripts/legacydb-data.sql");
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema, initData);
DatabasePopulatorUtils.execute(databasePopulator, dataSource);
return dataSource;
}

@Bean
public DataSource ordersDS() {
DataSource dataSource = DataSourceBuilder.create().driverClassName("org.h2.Driver").username("sa").password("").url("jdbc:h2:mem:ordersdb;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=FALSE;MODE=MYSQL").build();

Resource initSchema = new ClassPathResource("h2/scripts/ordersdb-schema.sql");
Resource initData = new ClassPathResource("h2/scripts/ordersdb-data.sql");
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema, initData);
DatabasePopulatorUtils.execute(databasePopulator, dataSource);
return dataSource;
}

@Bean
@Autowired
public JdbcTemplate teiidJdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
JdbcTemplate tc = new JdbcTemplate(dataSource);
return tc;
}
}
6 changes: 1 addition & 5 deletions orders-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver

spring.jpa.hibernate.ddl-auto=none
spring.teiid.model.package=org.ticketmonster.orders.domain

management.security.enabled=false
server.port=8080
Expand Down
326 changes: 326 additions & 0 deletions orders-service/src/main/resources/h2/scripts/legacydb-data.sql

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions orders-service/src/main/resources/h2/scripts/legacydb-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
CREATE TABLE `MediaItem` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`mediaType` varchar(255) DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_4hr5wsvx6wqc3x7f62hi4icwk` (`url`)
) ;

CREATE TABLE `EventCategory` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_pcd6hbptlq9jx8t5l135k2mev` (`description`)
) ;


CREATE TABLE `Event` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(1000) NOT NULL,
`name` varchar(50) NOT NULL,
`category_id` bigint(20) NOT NULL,
`mediaItem_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_ij7n685n8qbung3jvhw3rifm7` (`name`),
KEY `FK8csjtmgirbl21kpwsxo6x66nh` (`category_id`),
KEY `FK6nof7ckcmem31bk5t3poa9nnf` (`mediaItem_id`),
CONSTRAINT `FK6nof7ckcmem31bk5t3poa9nnf` FOREIGN KEY (`mediaItem_id`) REFERENCES `MediaItem` (`id`),
CONSTRAINT `FK8csjtmgirbl21kpwsxo6x66nh` FOREIGN KEY (`category_id`) REFERENCES `EventCategory` (`id`)
) ;


CREATE TABLE `Venue` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`city` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`street` varchar(255) DEFAULT NULL,
`capacity` int(11) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`mediaItem_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_k049njfy1fdk2svm5m54ulorx` (`name`),
KEY `FKn88gt1fcwaa14l0r0p41vh2nr` (`mediaItem_id`),
CONSTRAINT `FKn88gt1fcwaa14l0r0p41vh2nr` FOREIGN KEY (`mediaItem_id`) REFERENCES `MediaItem` (`id`)
) ;


CREATE TABLE `Appearance` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`event_id` bigint(20) NOT NULL,
`venue_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKb2ol0eoqtadvfoxhsnqcajgqa` (`event_id`,`venue_id`),
KEY `FK43wxxxwigwlxjucwsyg4e7t4p` (`venue_id`),
CONSTRAINT `FK43wxxxwigwlxjucwsyg4e7t4p` FOREIGN KEY (`venue_id`) REFERENCES `Venue` (`id`),
CONSTRAINT `FKl28e6wqudihnxsyqhmj9jdepw` FOREIGN KEY (`event_id`) REFERENCES `Event` (`id`)
) ;

CREATE TABLE `Performance` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL,
`show_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKo9uuea91geqwv8cnwi1uq625w` (`date`,`show_id`),
KEY `FKfyal296q9uqmwdtgchsblvt79` (`show_id`),
CONSTRAINT `FKfyal296q9uqmwdtgchsblvt79` FOREIGN KEY (`show_id`) REFERENCES `Appearance` (`id`)
) ;

CREATE TABLE `Section` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`numberOfRows` int(11) NOT NULL,
`rowCapacity` int(11) NOT NULL,
`venue_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKruosqireipse41rdsuvhqj050` (`name`,`venue_id`),
KEY `FKjspvs4wkh7pcqfpfler1vgvwh` (`venue_id`),
CONSTRAINT `FKjspvs4wkh7pcqfpfler1vgvwh` FOREIGN KEY (`venue_id`) REFERENCES `Venue` (`id`)
) ;


CREATE TABLE `Booking` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`cancellationCode` varchar(255) NOT NULL,
`contactEmail` varchar(255) NOT NULL,
`createdOn` datetime NOT NULL,
`performance_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKedg6lddbdlf8nsk7jrxvq4s48` (`performance_id`),
CONSTRAINT `FKedg6lddbdlf8nsk7jrxvq4s48` FOREIGN KEY (`performance_id`) REFERENCES `Performance` (`id`)
) ;

CREATE TABLE `SectionAllocation` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`allocated` longblob,
`occupiedCount` int(11) NOT NULL,
`version` bigint(20) NOT NULL,
`performance_id` bigint(20) NOT NULL,
`section_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK25wlm457x8dmc00we5uw7an3s` (`performance_id`,`section_id`),
KEY `FK60388cvbhb1xyrdhhe546t6dl` (`section_id`),
CONSTRAINT `FK60388cvbhb1xyrdhhe546t6dl` FOREIGN KEY (`section_id`) REFERENCES `Section` (`id`),
CONSTRAINT `FKa9q2pu832scr9n9be1tkgex34` FOREIGN KEY (`performance_id`) REFERENCES `Performance` (`id`)
) ;

CREATE TABLE `TicketCategory` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_43455ipnchbn6r4bg8pviai3g` (`description`)
) ;


CREATE TABLE `TicketPrice` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`price` float NOT NULL,
`section_id` bigint(20) NOT NULL,
`show_id` bigint(20) NOT NULL,
`ticketCategory_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK6v6we3djkskvbac7e9ctbylap` (`section_id`,`show_id`,`ticketCategory_id`),
KEY `FKslfwrt774iadqwitd7d8l97vg` (`show_id`),
KEY `FKcuvr00xp47bs81u95aq2amomn` (`ticketCategory_id`),
CONSTRAINT `FKa4etyq878vwpxp4rhwkg65rgt` FOREIGN KEY (`section_id`) REFERENCES `Section` (`id`),
CONSTRAINT `FKcuvr00xp47bs81u95aq2amomn` FOREIGN KEY (`ticketCategory_id`) REFERENCES `TicketCategory` (`id`),
CONSTRAINT `FKslfwrt774iadqwitd7d8l97vg` FOREIGN KEY (`show_id`) REFERENCES `Appearance` (`id`)
) ;

CREATE TABLE `Ticket` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`price` float NOT NULL,
`number` int(11) NOT NULL,
`rowNumber` int(11) NOT NULL,
`section_id` bigint(20) DEFAULT NULL,
`ticketCategory_id` bigint(20) NOT NULL,
`tickets_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK7xoel6i5b4nrphore8ns2jtld` (`section_id`),
KEY `FK88jejylfnpfqcslai19n4naqf` (`ticketCategory_id`),
KEY `FKolbt9u28gyshci6ek9ep0rl5d` (`tickets_id`),
CONSTRAINT `FK7xoel6i5b4nrphore8ns2jtld` FOREIGN KEY (`section_id`) REFERENCES `Section` (`id`),
CONSTRAINT `FK88jejylfnpfqcslai19n4naqf` FOREIGN KEY (`ticketCategory_id`) REFERENCES `TicketCategory` (`id`),
CONSTRAINT `FKolbt9u28gyshci6ek9ep0rl5d` FOREIGN KEY (`tickets_id`) REFERENCES `Booking` (`id`)
) ;

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INSERT INTO id_generator(IDKEY, IDVALUE) VALUES ('booking', 1);
INSERT INTO id_generator(IDKEY, IDVALUE) VALUES ('ticket', 1);
INSERT INTO id_generator(IDKEY, IDVALUE) VALUES ('section_allocation', 1);
91 changes: 91 additions & 0 deletions orders-service/src/main/resources/h2/scripts/ordersdb-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
CREATE TABLE `section` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`number_of_rows` int(11) NOT NULL,
`row_capacity` int(11) NOT NULL,
`venue_id` bigint(20) DEFAULT NULL,
`venue_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKbdpgnn9f25eootvop4cqics0i` (`name`,`venue_id`)
) ;


CREATE TABLE `appearance` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`event_id` bigint(20) DEFAULT NULL,
`event_name` varchar(255) DEFAULT NULL,
`venue_id` bigint(20) DEFAULT NULL,
`venue_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKfgr2nkyi0qpjhjvji0mdfvudc` (`event_id`,`venue_id`)
) ;


CREATE TABLE `booking` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`cancellation_code` varchar(255) NOT NULL,
`contact_email` varchar(255) NOT NULL,
`created_on` datetime NOT NULL,
`performance_id` bigint(20) DEFAULT NULL,
`performance_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ;

CREATE TABLE `section_allocation` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`allocated` longblob,
`occupied_count` int(11) NOT NULL,
`performance_id` bigint(20) DEFAULT NULL,
`performance_name` varchar(255) DEFAULT NULL,
`version` bigint(20) NOT NULL,
`section_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKcbyh3leaebtlwfc4eiotooopq` (`performance_id`,`section_id`),
KEY `FK3rw79cvgssmpg21ds219dydrp` (`section_id`),
CONSTRAINT `FK3rw79cvgssmpg21ds219dydrp` FOREIGN KEY (`section_id`) REFERENCES `section` (`id`)
) ;

CREATE TABLE `ticket_category` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_hbsjuus8lw4socklmianxb00r` (`description`)
) ;

-- we write to this table, so definitely need it
CREATE TABLE `ticket` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`price` float NOT NULL,
`number` int(11) NOT NULL,
`row_number` int(11) NOT NULL,
`section_id` bigint(20) DEFAULT NULL,
`ticket_category_id` bigint(20) NOT NULL,
`booking_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK43lerp18busrqen2gd43vhepi` (`section_id`),
KEY `FKbt7yntrpp48qd82aubrq6lbx8` (`ticket_category_id`),
KEY `FK8h02qtjhsys9q4ibyomkoctu6` (`booking_id`),
CONSTRAINT `FK8h02qtjhsys9q4ibyomkoctu6` FOREIGN KEY (`booking_id`) REFERENCES `booking` (`id`)
) ;

CREATE TABLE `ticket_price_guide` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`price` float NOT NULL,
`section_id` bigint(20) NOT NULL,
`show_id` bigint(20) NOT NULL,
`ticketcategory_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UKqgjl8uim31mh6vop6pnt188b4` (`section_id`,`show_id`,`ticketcategory_id`),
KEY `FKt21lxux6lmhmw6jyx3schteio` (`show_id`),
KEY `FKbdxqxoxov15nyypxdryur5fs5` (`ticketcategory_id`),
CONSTRAINT `FK60ub03ab2r2j6d5v8v3v0dprr` FOREIGN KEY (`section_id`) REFERENCES `section` (`id`),
CONSTRAINT `FKbdxqxoxov15nyypxdryur5fs5` FOREIGN KEY (`ticketcategory_id`) REFERENCES `ticket_category` (`id`),
CONSTRAINT `FKt21lxux6lmhmw6jyx3schteio` FOREIGN KEY (`show_id`) REFERENCES `appearance` (`id`)
) ;

CREATE TABLE id_generator
(
IDKEY char(20) NOT NULL,
IDVALUE bigint NOT NULL
);
Loading

0 comments on commit 645a208

Please sign in to comment.