Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Working two-source data binding
Browse files Browse the repository at this point in the history
  • Loading branch information
hernil committed Nov 28, 2017
1 parent e34a7eb commit a22ca80
Show file tree
Hide file tree
Showing 33 changed files with 189 additions and 105 deletions.
35 changes: 21 additions & 14 deletions vent-backend/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@

#spring.jpa.database=default

datasource:
vent:
jdbc-url: jdbc:mysql://172.17.0.2:3306/protus?verifyServerCertificate=false&useSSL=true
#url: jdbc:mysql://172.17.0.2:3306/protus?verifyServerCertificate=false&useSSL=true
username: root
password: stockli
# driver-class-name: com.mysql.jdbc.Driver
# validation-query: select 1
protus:
jdbc-url: jdbc:mysql://172.17.0.2:3306/vent?verifyServerCertificate=false&useSSL=true
#url: jdbc:mysql://172.17.0.2:3306/vent?verifyServerCertificate=false&useSSL=true
username: root
password: stockli
# driver-class-name: com.mysql.jdbc.Driver
# validation-query: select 1

spring:
datasource:
vent:
jdbc-url: jdbc:mysql://172.17.0.2:3306/vent?verifyServerCertificate=false&useSSL=true
#url: jdbc:mysql://172.17.0.2:3306/protus?verifyServerCertificate=false&useSSL=true
username: root
password: stockli
driver-class-name: com.mysql.jdbc.Driver
# validation-query: select 1
protus:
jdbc-url: jdbc:mysql://172.17.0.2:3306/protus?verifyServerCertificate=false&useSSL=true
#url: jdbc:mysql://172.17.0.2:3306/vent?verifyServerCertificate=false&useSSL=true
username: root
password: stockli
driver-class-name: com.mysql.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
naming:
implicit-strategy: default #org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
30 changes: 15 additions & 15 deletions vent-backend/src/main/kotlin/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.hernil.vent.protus.ActionTypeEntity</class>
<class>com.hernil.vent.protus.CoursesEntity</class>
<class>com.hernil.vent.protus.LearnersEntity</class>
<class>com.hernil.vent.protus.LearnersAnswersEntity</class>
<class>com.hernil.vent.protus.LessonsEntity</class>
<class>com.hernil.vent.protus.MessagesEntity</class>
<class>com.hernil.vent.protus.OfferedAnswersEntity</class>
<class>com.hernil.vent.protus.ResursEntity</class>
<class>com.hernil.vent.protus.SessionEntity</class>
<class>com.hernil.vent.protus.SettingsEntity</class>
<class>com.hernil.vent.protus.TagsEntity</class>
<class>com.hernil.vent.protus.TeachersEntity</class>
<class>com.hernil.vent.protus.TestEntity</class>
<class>com.hernil.vent.protus.UnitsEntity</class>
<class>com.hernil.vent.protus.UsersActionEntity</class>
<class>com.hernil.vent.protus.domain.ActionTypeEntity</class>
<class>com.hernil.vent.protus.domain.CoursesEntity</class>
<class>com.hernil.vent.protus.domain.LearnersEntity</class>
<class>com.hernil.vent.protus.domain.LearnersAnswersEntity</class>
<class>com.hernil.vent.protus.domain.LessonsEntity</class>
<class>com.hernil.vent.protus.domain.MessagesEntity</class>
<class>com.hernil.vent.protus.domain.OfferedAnswersEntity</class>
<class>com.hernil.vent.protus.domain.ResursEntity</class>
<class>com.hernil.vent.protus.domain.SessionEntity</class>
<class>com.hernil.vent.protus.domain.SettingsEntity</class>
<class>com.hernil.vent.protus.domain.TagsEntity</class>
<class>com.hernil.vent.protus.domain.TeachersEntity</class>
<class>com.hernil.vent.protus.domain.TestEntity</class>
<class>com.hernil.vent.protus.domain.UnitsEntity</class>
<class>com.hernil.vent.protus.domain.UsersActionEntity</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://172.17.0.2:3306/vent"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
Expand Down
49 changes: 49 additions & 0 deletions vent-backend/src/main/kotlin/com/hernil/vent/ProtusConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.hernil.vent;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "protusEntityManagerFactory",
transactionManagerRef = "protusTransactionManager",
basePackages = { "com.hernil.vent.protus" })
public class ProtusConfig {

@Bean(name = "protusDataSource")
@ConfigurationProperties(prefix="spring.datasource.protus")
public DataSource protusDataSource() {
return DataSourceBuilder.create().build();
}

@Bean(name = "protusEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean protusEntityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("protusDataSource") DataSource protusDataSource) {
return builder
.dataSource(protusDataSource)
.packages("com.hernil.vent.protus")
.persistenceUnit("protus")
.build();
}

@Bean(name = "protusTransactionManager")
public PlatformTransactionManager protusTransactionManager(
@Qualifier("protusEntityManagerFactory") EntityManagerFactory protusEntityManagerFactory) {
return new JpaTransactionManager(protusEntityManagerFactory);
}

}

This file was deleted.

54 changes: 54 additions & 0 deletions vent-backend/src/main/kotlin/com/hernil/vent/VentConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.hernil.vent;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactory",
basePackages = {"com.hernil.vent.application"})
public class VentConfig {

@Primary
@Bean(name = "dataSource")
@ConfigurationProperties(prefix="spring.datasource.vent")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}

@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder, JpaProperties jpaProperties,
@Qualifier("dataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.hernil.vent.application")
.persistenceUnit("vent")
.properties(jpaProperties.getHibernateProperties("dataSource"))
.build();
}

@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hernil.vent.controllers
package com.hernil.vent.application.controllers

import com.hernil.vent.domain.CourseRepository
import com.hernil.vent.application.domain.CourseRepository
import org.springframework.web.bind.annotation.*

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hernil.vent.controllers
package com.hernil.vent.application.controllers

import com.hernil.vent.domain.Data
import com.hernil.vent.services.DataRepository
import com.hernil.vent.application.domain.Data
import com.hernil.vent.application.services.DataRepository
import org.springframework.web.bind.annotation.*

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hernil.vent.controllers
package com.hernil.vent.application.controllers

import com.hernil.vent.domain.Greeting
import com.hernil.vent.services.DataRepository
import com.hernil.vent.application.domain.Greeting
import com.hernil.vent.application.services.DataRepository
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hernil.vent.controllers
package com.hernil.vent.application.controllers

import com.hernil.vent.domain.StudentRepository
import com.hernil.vent.protus.LearnersRepository
import com.hernil.vent.protus.domain.LearnersRepository
import org.springframework.web.bind.annotation.*

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

import com.hernil.vent.domain.mappers.CourseStudents
import com.hernil.vent.application.domain.mappers.CourseStudents
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import javax.persistence.*

@Entity
//@Table(name = "course")
data class Course(@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: Long = 0,
Expand All @@ -15,4 +17,5 @@ data class Course(@Id
) {
}

@Repository
interface CourseRepository : JpaRepository<Course, Long>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

import javax.persistence.*

@Entity
@Table(name = "data")
data class Data(val name: String = "",
@ElementCollection
val data: List<Double> = listOf(0.0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

data class Greeting(val id: Long, val content: String)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

open class Person(open val name: String) {
fun test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

import com.hernil.vent.domain.mappers.CourseStudents
import com.hernil.vent.application.domain.mappers.CourseStudents
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import javax.persistence.*

@Entity
Expand All @@ -14,4 +15,5 @@ data class Student(@Id
) : Person(name) {
}

@Repository
interface StudentRepository : JpaRepository<Student, Long>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.domain
package com.hernil.vent.application.domain

import javax.persistence.Entity
import javax.persistence.GeneratedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.hernil.vent.domain.mappers
package com.hernil.vent.application.domain.mappers

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.hernil.vent.domain.Course
import com.hernil.vent.domain.Student
import com.hernil.vent.application.domain.Course
import com.hernil.vent.application.domain.Student
import java.io.Serializable
import javax.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.hernil.vent.application.services

import com.hernil.vent.application.domain.Data
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface DataRepository : JpaRepository<Data, Long>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import org.springframework.data.jpa.repository.JpaRepository
import javax.persistence.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*
import java.sql.Timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hernil.vent.protus
package com.hernil.vent.protus.domain

import javax.persistence.*

Expand Down
Loading

0 comments on commit a22ca80

Please sign in to comment.