Commit 0649065c7ebe0b7964dbc0935f2b2e00ac4b6d29

Authored by benruehl
1 parent aa62787f

Setup JPA and Hibernate with basic entities (not working though, persistence unit is not created)

.gitignore
... ... @@ -19,5 +19,7 @@ hs_err_pid*
19 19 .idea
20 20 .gradle
21 21 bht-chatbot.iml
  22 +BeuthBot.iml
22 23 target/
23 24 build
  25 +out
... ...
docker/docker-compose.yml
... ... @@ -15,7 +15,9 @@ services:
15 15 - ./wildfly/volumes/conf/:/opt/jboss/wildfly/standalone/conf/
16 16 links:
17 17 - rasa-server
  18 + - postgres-db
18 19 command: /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 --debug
  20 +
19 21 rasa-server:
20 22 build: ./rasa_nlu
21 23 container_name: rasa_nlu
... ... @@ -25,4 +27,24 @@ services:
25 27 volumes:
26 28 - ./rasa_nlu/volumes/data/api/:/app/data/api
27 29 - ./rasa_nlu/volumes/logs/:/app/logs/
28   - command: python -m rasa_nlu.server -c config/chatbot_config.json --server_model_dirs=default
29 30 \ No newline at end of file
  31 + command: python -m rasa_nlu.server -c config/chatbot_config.json --server_model_dirs=default
  32 +
  33 + postgres-db:
  34 + container_name: chatbot-postgres
  35 + image: postgres
  36 + restart: always
  37 + expose:
  38 + - "5432"
  39 + environment:
  40 + POSTGRES_USER: 'beuthbot_app'
  41 + POSTGRES_PASSWORD: 'VhS7WPVpdYEHYLpf'
  42 + POSTGRES_DB: 'beuthbot'
  43 + volumes:
  44 + - ./postgres/volumes/:/var/lib/postgresql
  45 +
  46 + adminer:
  47 + container_name: adminer_dbmanagement
  48 + image: adminer
  49 + restart: always
  50 + ports:
  51 + - "8081:8080"
... ...
docker/wildfly/standalone.xml
... ... @@ -417,6 +417,32 @@
417 417 <client-config name="Standard-Client-Config"/>
418 418 </subsystem>
419 419 <subsystem xmlns="urn:jboss:domain:weld:3.0"/>
  420 + <subsystem xmlns="urn:jboss:domain:datasources:1.0">
  421 + <datasources>
  422 + <datasource jndi-name="java:/PostgreSqlDS" pool-name="PostgreSqlDS_Pool" enabled="true" jta="false" use-ccm="false">
  423 + <connection-url>
  424 + jdbc:postgresql://postgres-db:5432/beuthbot
  425 + </connection-url>
  426 + <driver-class>
  427 + org.postgresql.Driver
  428 + </driver-class>
  429 + <driver>
  430 + postgresql
  431 + </driver>
  432 + <security>
  433 + <user-name>beuthbot_app</user-name>
  434 + <password>VhS7WPVpdYEHYLpf</password>
  435 + </security>
  436 + </datasource>
  437 + <drivers>
  438 + <driver name="postgresql" module="org.postgresql">
  439 + <xa-datasource-class>
  440 + org.postgresql.xa.PGXADataSource
  441 + </xa-datasource-class>
  442 + </driver>
  443 + </drivers>
  444 + </datasources>
  445 + </subsystem>
420 446 </profile>
421 447  
422 448 <interfaces>
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/Entity.java 0 → 100644
  1 +package de.bht.beuthbot.model.entities;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.Date;
  5 +
  6 +/**
  7 + * Created by Benjamin Rühl on 19.11.2017.
  8 + */
  9 +public interface Entity extends Serializable {
  10 +
  11 + Long getId();
  12 +
  13 + Date getCreationDate();
  14 +
  15 + Date getUpdateDate();
  16 +}
... ...
services/Common/src/main/java/de/bht/beuthbot/model/entities/User.java 0 → 100644
  1 +package de.bht.beuthbot.model.entities;
  2 +
  3 +/**
  4 + * Created by Benjamin Rühl on 19.11.2017.
  5 + */
  6 +public interface User extends Entity {
  7 +
  8 + String getFacebookUserId();
  9 + String getTelegramUserId();
  10 + boolean isVegetarian();
  11 +}
... ...
services/Global/build.gradle
... ... @@ -11,7 +11,9 @@ dependencies {
11 11 "org.jboss.spec:jboss-javaee-7.0:1.1.0.Final",
12 12 "com.google.code.gson:gson:2.8.1",
13 13 "org.apache.httpcomponents:httpclient:4.5.3",
14   - "commons-io:commons-io:2.5"
  14 + "commons-io:commons-io:2.5",
  15 + "org.hibernate:hibernate-core:5.2.12.Final",
  16 + "org.hibernate:hibernate-entitymanager:4.3.6.Final"
15 17  
16 18  
17 19 providedCompile "org.slf4j:slf4j-api:1.7.25"
... ...
services/Global/src/main/java/de/bht/beuthbot/entities/EntityBase.java 0 → 100644
  1 +package de.bht.beuthbot.entities;
  2 +
  3 +import de.bht.beuthbot.model.entities.Entity;
  4 +
  5 +import javax.persistence.*;
  6 +import java.util.Date;
  7 +import java.util.Objects;
  8 +
  9 +/**
  10 + * Created by Benjamin Rühl on 19.11.2017.
  11 + */
  12 +@MappedSuperclass
  13 +public class EntityBase implements Entity {
  14 +
  15 + @Id
  16 + @GeneratedValue
  17 + protected long id;
  18 +
  19 + @Temporal(TemporalType.TIMESTAMP)
  20 + protected Date creationDate;
  21 +
  22 + @Temporal(TemporalType.TIMESTAMP)
  23 + protected Date updateDate;
  24 +
  25 + @PrePersist
  26 + protected void onCreate() {
  27 + creationDate = new Date();
  28 + }
  29 +
  30 + @PreUpdate
  31 + protected void onUpdate() {
  32 + updateDate = new Date();
  33 + }
  34 +
  35 + @Override
  36 + public Long getId() {
  37 + return null;
  38 + }
  39 +
  40 + @Override
  41 + public Date getCreationDate() {
  42 + return creationDate;
  43 + }
  44 +
  45 + @Override
  46 + public Date getUpdateDate() {
  47 + return updateDate;
  48 + }
  49 +
  50 + @Override
  51 + public boolean equals(Object obj) {
  52 + if (this == obj)
  53 + return true;
  54 +
  55 + if (obj == null)
  56 + return false;
  57 +
  58 + if (obj.getClass() != getClass())
  59 + return false;
  60 +
  61 + EntityBase other = (EntityBase)obj;
  62 +
  63 + if (other.getId() == 0 && getId() == 0)
  64 + return super.equals(obj);
  65 +
  66 + return other.getId() == getId();
  67 + }
  68 +
  69 + @Override
  70 + public int hashCode(){
  71 + return Objects.hash(id);
  72 + }
  73 +}
... ...
services/Global/src/main/java/de/bht/beuthbot/entities/User.java 0 → 100644
  1 +package de.bht.beuthbot.entities;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Table;
  5 +
  6 +/**
  7 + * Created by Benjamin Rühl on 19.11.2017.
  8 + */
  9 +@Entity
  10 +@Table
  11 +public class User extends EntityBase implements de.bht.beuthbot.model.entities.User {
  12 +
  13 + private String facebookUserId;
  14 + private String telegramUserId;
  15 + private boolean isVegetarian;
  16 +
  17 + @Override
  18 + public String getFacebookUserId() {
  19 + return facebookUserId;
  20 + }
  21 +
  22 + @Override
  23 + public String getTelegramUserId() {
  24 + return telegramUserId;
  25 + }
  26 +
  27 + @Override
  28 + public boolean isVegetarian() {
  29 + return isVegetarian;
  30 + }
  31 +
  32 + public void setFacebookUserId(String facebookUserId) {
  33 + this.facebookUserId = facebookUserId;
  34 + }
  35 +
  36 + public void setTelegramUserId(String telegramUserId) {
  37 + this.telegramUserId = telegramUserId;
  38 + }
  39 +
  40 + public void setVegetarian(boolean vegetarian) {
  41 + isVegetarian = vegetarian;
  42 + }
  43 +}
... ...
services/Global/src/main/webapp/META-INF/persistence.xml 0 → 100644
  1 +<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  2 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
  4 + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  5 + version="2.1">
  6 +
  7 + <persistence-unit name="de.bht.beuthbot.jpa" transaction-type="RESOURCE_LOCAL">
  8 +
  9 + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  10 +
  11 + <properties>
  12 + <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> <!-- DB Driver -->
  13 + <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://postgres-server:5432/beuthbot" /> <!-- BD Name -->
  14 + <property name="javax.persistence.jdbc.user" value="beuthbot_app" /> <!-- DB User -->
  15 + <property name="javax.persistence.jdbc.password" value="VhS7WPVpdYEHYLpf" /> <!-- DB Password -->
  16 +
  17 + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/> <!-- DB Dialect -->
  18 + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> <!-- create / create-drop / update / none -->
  19 + <property name="hibernate.archive.autodetection" value="class"/>
  20 +
  21 + <property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
  22 + <property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->
  23 + </properties>
  24 +
  25 + </persistence-unit>
  26 +
  27 +</persistence>
0 28 \ No newline at end of file
... ...