Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. buildscript {
  2. ext {
  3. springBootVersion = '2.0.0.M7'
  4. }
  5. repositories {
  6. mavenCentral()
  7. maven { url "https://repo.spring.io/snapshot" }
  8. maven { url "https://repo.spring.io/milestone" }
  9. }
  10. dependencies {
  11. classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
  12. classpath 'gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9'
  13. }
  14. }
  15.  
  16. apply plugin: 'java'
  17. apply plugin: 'idea'
  18. apply plugin: 'org.springframework.boot'
  19. apply plugin: 'io.spring.dependency-management'
  20. apply plugin: 'com.ewerk.gradle.plugins.querydsl'
  21.  
  22. group = 'ru.example'
  23. version = '0.0.1-SNAPSHOT'
  24. sourceCompatibility = 1.8
  25.  
  26. repositories {
  27. mavenCentral()
  28. maven { url "https://repo.spring.io/snapshot" }
  29. maven { url "https://repo.spring.io/milestone" }
  30. }
  31.  
  32.  
  33. dependencies {
  34. compile('org.springframework.boot:spring-boot-starter-data-jpa')
  35. compile('org.springframework.kafka:spring-kafka')
  36. // compile('org.springframework.boot:spring-boot-starter-security')
  37. compile('org.springframework.boot:spring-boot-starter-web')
  38. runtime('org.postgresql:postgresql')
  39. testCompile('org.springframework.boot:spring-boot-starter-test')
  40. testCompile('org.springframework.security:spring-security-test')
  41. }
  42.  
  43. querydsl {
  44. jpa = true
  45. querydslSourcesDir = "$buildDir/generated/source/apt/main"
  46. }
  47.  
  48. # database connection
  49. spring.datasource.url=jdbc:postgresql://localhost:5432/example
  50. spring.datasource.driver-class-name=org.postgresql.Driver
  51. spring.datasource.username=user
  52. spring.datasource.password=12345
  53.  
  54. # jpa / hibernate
  55. spring.jpa.show-sql=true
  56. spring.jpa.hibernate.ddl-auto=none
  57. spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  58.  
  59. # Fix Postgres JPA Error:
  60. # Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
  61. spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
  62.  
  63. @EnableTransactionManagement
  64. @EnableAutoConfiguration
  65. @EnableJpaRepositories("ru.example.repository")
  66. @ComponentScan(basePackages = {
  67. "ru.example.controller",
  68. "ru.example.service",
  69. "ru.example.config",
  70. "ru.example.dto",
  71. "ru.example.util"})
  72. @EntityScan("ru.example.entity")
  73. @SpringBootApplication
  74. public class HealthMeterApplication {
  75.  
  76. public static void main(String[] args) {
  77. SpringApplication.run(HealthMeterApplication.class, args);
  78. }
  79. }
  80.  
  81. @Repository
  82. public interface TestRepository extends CrudRepository<TestEntity, Long> {
  83. }
  84.  
  85. @MappedSuperclass
  86. @JsonIgnoreProperties(value = {"created"}, ignoreUnknown = true)
  87. public abstract class AbstractEntity implements Serializable {
  88. private static final int START_SEQ = 1000000000;
  89.  
  90. private Long id;
  91. private LocalDateTime created;
  92.  
  93. @Id
  94. @SequenceGenerator(name = "global_seq", sequenceName = "global_seq", allocationSize = 1, initialValue = START_SEQ)
  95. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_seq")
  96. public Long getId() {
  97. return id;
  98. }
  99.  
  100. public void setId(Long id) {
  101. this.id = id;
  102. }
  103.  
  104. @Column(name = "created", updatable = false)
  105. public LocalDateTime getCreated() {
  106. return created;
  107. }
  108.  
  109. private void setCreated(LocalDateTime created) {
  110. this.created = created;
  111. }
  112.  
  113. @PrePersist
  114. void onCreate() {
  115. if (Objects.isNull(this.getCreated())) {
  116. this.setCreated(LocalDateTime.now());
  117. }
  118. }
  119.  
  120. @Override
  121. public boolean equals(Object o) {
  122. if (this == o) return true;
  123. if (o == null || getClass() != o.getClass()) return false;
  124.  
  125. AbstractEntity that = (AbstractEntity) o;
  126.  
  127. if (id != null ? !id.equals(that.id) : that.id != null) return false;
  128. return created != null ? created.equals(that.created) : that.created == null;
  129. }
  130.  
  131. @Override
  132. public int hashCode() {
  133. int result = id != null ? id.hashCode() : 0;
  134. result = 31 * result + (created != null ? created.hashCode() : 0);
  135. return result;
  136. }
  137.  
  138. @Entity
  139. @Table(name = "test")
  140. public class TestEntity extends AbstractEntity {
  141.  
  142. private Long name;
  143.  
  144. @Column(name = "name")
  145. public Long getName() {
  146. return name;
  147. }
  148.  
  149. public void setName(Long name) {
  150. this.name = name;
  151. }
  152.  
  153. @Override
  154. public boolean equals(Object o) {
  155. if (this == o) return true;
  156. if (o == null || getClass() != o.getClass()) return false;
  157. if (!super.equals(o)) return false;
  158.  
  159. TestEntity entity = (TestEntity) o;
  160.  
  161. return name != null ? name.equals(entity.name) : entity.name == null;
  162. }
  163.  
  164. @Override
  165. public int hashCode() {
  166. int result = super.hashCode();
  167. result = 31 * result + (name != null ? name.hashCode() : 0);
  168. return result;
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement