Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.38 KB | None | 0 0
  1. @Configuration
  2. @EnableTransactionManagement
  3. @EnableJpaRepositories(basePackages = arrayOf("com.apache.vaadin.model"))
  4. @ComponentScan(basePackages = arrayOf("com.apache.vaadin.model"))
  5. open class DataSourceConfig {
  6. @Autowired
  7. lateinit var environment: Environment
  8.  
  9. @Bean
  10. open fun entityManagerFactory(): LocalContainerEntityManagerFactoryBean {
  11. var entityManagerFactory: LocalContainerEntityManagerFactoryBean = LocalContainerEntityManagerFactoryBean()
  12.  
  13. entityManagerFactory.apply {
  14. dataSource = dataSource()
  15. setPackagesToScan("com.apache.vaadin.model")
  16.  
  17. var vendorAdapter: HibernateJpaVendorAdapter = HibernateJpaVendorAdapter()
  18.  
  19. vendorAdapter.apply {
  20. setGenerateDdl(true)
  21. setShowSql(true)
  22. }
  23.  
  24. var properties: Properties = Properties()
  25.  
  26. properties.apply {
  27. put("database.dialet", "org.hibernate.dialect.PostgreSQL95Dialect")
  28. put("database.globally_quoted_identifiers", "false")
  29. put("database.enable_lazy_load_no_trans", "true")
  30. put("database.show_sql", "true")
  31. }
  32.  
  33. jpaVendorAdapter = vendorAdapter
  34. setJpaProperties(properties)
  35. }
  36.  
  37. return entityManagerFactory
  38. }
  39.  
  40. @Primary
  41. @Bean
  42. open fun dataSource(): DataSource {
  43. var source: ComboPooledDataSource = ComboPooledDataSource()
  44.  
  45. source.apply {
  46. driverClass = "org.postgresql.Driver"
  47. jdbcUrl = "jdbc:postgresql://localhost:5432/ignite"
  48. user = "postgres"
  49. password = "1111"
  50. acquireIncrement = 5
  51. idleConnectionTestPeriod = 60
  52. maxPoolSize = 20
  53. minPoolSize = 10
  54. initialPoolSize = 10
  55. }
  56.  
  57. return source
  58. }
  59.  
  60. @Bean
  61. open fun transactionManager() : PlatformTransactionManager {
  62. var manager: JpaTransactionManager = JpaTransactionManager()
  63.  
  64. manager.apply {
  65. entityManagerFactory = entityManagerFactory().nativeEntityManagerFactory
  66. }
  67.  
  68. return manager
  69. }
  70.  
  71. @Bean
  72. open fun exceptionTranslator(): PersistenceExceptionTranslationPostProcessor = PersistenceExceptionTranslationPostProcessor()
  73. }
  74.  
  75. @SpringUI
  76. @Title(value = "Apache")
  77. class Navigator : UI() {
  78. @Autowired
  79. lateinit var viewProvider: SpringViewProvider
  80.  
  81. init {
  82. }
  83.  
  84. private val INDEX = ""
  85.  
  86. override fun init(p0: VaadinRequest?) {
  87. navigator = Navigator(this, this)
  88. navigator.addProvider(viewProvider)
  89. navigator.addView(INDEX, Index::class.java)
  90. }
  91. }
  92.  
  93. @UIScope
  94. @SpringView
  95. open class Index : VerticalLayout(), View {
  96. private val logger: Logger = Logger.getLogger(Index::class.java)
  97.  
  98. @Autowired
  99. lateinit var clientService: IClientService // <--- error is here
  100.  
  101. init {
  102. var menuBar: MenuBar = MenuBar()
  103. var file = menuBar.addItem("File", null, null)
  104. file.addItem("Save", {_ -> logger.info("Save clicked")})
  105. file.addItem("Load", {_ -> logger.info("Load clicked")})
  106. file.addItem("Open", {_ -> logger.info("Open clicked")})
  107. file.addItem("Close", {_ -> logger.info("Close clicked")})
  108.  
  109. var settings = menuBar.addItem("Settings", null, null)
  110. settings.addItem("DataBase", {_ -> logger.info("DataBase clicked")})
  111.  
  112. addComponent(menuBar)
  113.  
  114. var createButton: Button = Button("Create", { _ -> logger.info("Create clicked")})
  115. var readButton: Button = Button("Read", { _ -> logger.info(clientService.findAll())})
  116. var updateButton: Button = Button("Update", { _ -> logger.info("Update clicked")})
  117. var deleteButton: Button = Button("Delete", { _ -> logger.info("Delete clicked")})
  118.  
  119. addComponent(createButton)
  120. addComponent(readButton)
  121. addComponent(updateButton)
  122. addComponent(deleteButton)
  123. }
  124.  
  125. override fun enter(p0: ViewChangeListener.ViewChangeEvent?) {
  126. Notification.show("Welcome to the main com.ignite.app.view")
  127. }
  128. }
  129.  
  130. <?xml version="1.0" encoding="UTF-8"?>
  131. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  132. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  133. <modelVersion>4.0.0</modelVersion>
  134.  
  135. <groupId>com.apache.vaadin</groupId>
  136. <artifactId>ignite</artifactId>
  137. <version>0.0.1-SNAPSHOT</version>
  138. <packaging>jar</packaging>
  139.  
  140. <name>ignite</name>
  141. <description></description>
  142.  
  143. <parent>
  144. <groupId>org.springframework.boot</groupId>
  145. <artifactId>spring-boot-starter-parent</artifactId>
  146. <version>1.5.4.RELEASE</version>
  147. <relativePath/> <!-- lookup parent from repository -->
  148. </parent>
  149.  
  150. <properties>
  151. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  152. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  153. <java.version>1.8</java.version>
  154. <vaadin.version>8.0.6</vaadin.version>
  155. <kotlin.version>1.1.3-2</kotlin.version>
  156. <hibernate>5.2.9.Final</hibernate>
  157. <hibernate-validator>5.4.1.Final</hibernate-validator>
  158. <postgres>42.1.1</postgres>
  159. </properties>
  160.  
  161. <dependencies>
  162. <dependency>
  163. <groupId>com.vaadin</groupId>
  164. <artifactId>vaadin-spring-boot-starter</artifactId>
  165. </dependency>
  166.  
  167. <dependency>
  168. <groupId>org.springframework.boot</groupId>
  169. <artifactId>spring-boot-starter-test</artifactId>
  170. <scope>test</scope>
  171. </dependency>
  172.  
  173. <dependency>
  174. <groupId>org.springframework.boot</groupId>
  175. <artifactId>spring-boot-starter-data-jpa</artifactId>
  176. </dependency>
  177.  
  178. <dependency>
  179. <groupId>org.jetbrains.kotlin</groupId>
  180. <artifactId>kotlin-stdlib-jre8</artifactId>
  181. <version>${kotlin.version}</version>
  182. </dependency>
  183.  
  184. <dependency>
  185. <groupId>org.jetbrains.kotlin</groupId>
  186. <artifactId>kotlin-test</artifactId>
  187. <version>${kotlin.version}</version>
  188. <scope>test</scope>
  189. </dependency>
  190.  
  191. <dependency>
  192. <groupId>org.hibernate</groupId>
  193. <artifactId>hibernate-ehcache</artifactId>
  194. <version>${hibernate}</version>
  195. </dependency>
  196.  
  197. <dependency>
  198. <groupId>org.hibernate</groupId>
  199. <artifactId>hibernate-c3p0</artifactId>
  200. <version>${hibernate}</version>
  201. </dependency>
  202.  
  203. <dependency>
  204. <groupId>org.hibernate</groupId>
  205. <artifactId>hibernate-validator</artifactId>
  206. <version>${hibernate-validator}</version>
  207. </dependency>
  208.  
  209. <dependency>
  210. <groupId>org.postgresql</groupId>
  211. <artifactId>postgresql</artifactId>
  212. <version>${postgres}</version>
  213. </dependency>
  214. </dependencies>
  215.  
  216. <dependencyManagement>
  217. <dependencies>
  218. <dependency>
  219. <groupId>com.vaadin</groupId>
  220. <artifactId>vaadin-bom</artifactId>
  221. <version>${vaadin.version}</version>
  222. <type>pom</type>
  223. <scope>import</scope>
  224. </dependency>
  225. </dependencies>
  226. </dependencyManagement>
  227.  
  228. <build>
  229. <plugins>
  230. <plugin>
  231. <groupId>org.springframework.boot</groupId>
  232. <artifactId>spring-boot-maven-plugin</artifactId>
  233. </plugin>
  234. <plugin>
  235. <groupId>org.jetbrains.kotlin</groupId>
  236. <artifactId>kotlin-maven-plugin</artifactId>
  237. <version>${kotlin.version}</version>
  238. <executions>
  239. <execution>
  240. <id>compile</id>
  241. <phase>compile</phase>
  242. <goals>
  243. <goal>compile</goal>
  244. </goals>
  245. </execution>
  246. <execution>
  247. <id>test-compile</id>
  248. <phase>test-compile</phase>
  249. <goals>
  250. <goal>test-compile</goal>
  251. </goals>
  252. </execution>
  253. </executions>
  254. <configuration>
  255. <jvmTarget>1.8</jvmTarget>
  256. </configuration>
  257. </plugin>
  258. <plugin>
  259. <groupId>org.apache.maven.plugins</groupId>
  260. <artifactId>maven-compiler-plugin</artifactId>
  261. <executions>
  262. <execution>
  263. <id>compile</id>
  264. <phase>compile</phase>
  265. <goals>
  266. <goal>compile</goal>
  267. </goals>
  268. </execution>
  269. <execution>
  270. <id>testCompile</id>
  271. <phase>test-compile</phase>
  272. <goals>
  273. <goal>testCompile</goal>
  274. </goals>
  275. </execution>
  276. </executions>
  277. </plugin>
  278. </plugins>
  279. </build>
  280. </project>
  281.  
  282. @NoRepositoryBean
  283. interface IClientService : CrudRepository<Client, Long>
  284. @Service
  285. class ClientService : IClientService {
  286. private val logger: Logger = Logger.getLogger(ClientService::class.java)
  287.  
  288. @Autowired
  289. lateinit var clientRepository: ClientRepository
  290.  
  291. override fun delete(p0: Long?) {
  292. clientRepository.delete(p0)
  293. }
  294.  
  295. override fun delete(p0: MutableIterable<Client>?) {
  296. clientRepository.delete(p0)
  297. }
  298.  
  299. override fun delete(p0: Client?) {
  300. clientRepository.delete(p0)
  301. }
  302.  
  303. override fun <S : Client?> save(p0: MutableIterable<S>?): MutableIterable<S> = clientRepository.save(p0)
  304.  
  305. override fun <S : Client?> save(p0: S): S = clientRepository.save(p0)
  306.  
  307. override fun findAll(p0: MutableIterable<Long>?): MutableIterable<Client> = clientRepository.findAll(p0)
  308.  
  309. override fun findAll(): MutableIterable<Client> = clientRepository.findAll()
  310.  
  311. override fun exists(p0: Long?): Boolean = clientRepository.exists(p0)
  312.  
  313. override fun findOne(p0: Long?): Client = clientRepository.findOne(p0)
  314.  
  315. override fun count(): Long = clientRepository.count()
  316.  
  317. override fun deleteAll() {
  318. clientRepository.deleteAll()
  319. }
  320. }
  321.  
  322. @Repository
  323. interface ClientRepository : CrudRepository<Client, Long>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement