Commit e02720c5e090acc2901ed6f58a429b2d4523f383

Authored by hausdoerfer
1 parent e9888632

first database connection from the backend

docker/wildfly/standalone.xml
@@ -161,7 +161,7 @@ @@ -161,7 +161,7 @@
161 <managed-scheduled-executor-service name="default" jndi-name="java:jboss/ee/concurrency/scheduler/default" context-service="default" hung-task-threshold="60000" keepalive-time="3000"/> 161 <managed-scheduled-executor-service name="default" jndi-name="java:jboss/ee/concurrency/scheduler/default" context-service="default" hung-task-threshold="60000" keepalive-time="3000"/>
162 </managed-scheduled-executor-services> 162 </managed-scheduled-executor-services>
163 </concurrent> 163 </concurrent>
164 - <default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/ExampleDS" jms-connection-factory="java:jboss/DefaultJMSConnectionFactory" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/> 164 + <default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/PostgreSQLDS" jms-connection-factory="java:jboss/DefaultJMSConnectionFactory" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>
165 </subsystem> 165 </subsystem>
166 <subsystem xmlns="urn:jboss:domain:ejb3:4.0"> 166 <subsystem xmlns="urn:jboss:domain:ejb3:4.0">
167 <session-bean> 167 <session-bean>
services/Global/build.gradle
@@ -11,14 +11,15 @@ dependencies { @@ -11,14 +11,15 @@ dependencies {
11 "org.jboss.spec:jboss-javaee-7.0:1.1.0.Final", 11 "org.jboss.spec:jboss-javaee-7.0:1.1.0.Final",
12 "com.google.code.gson:gson:2.8.1", 12 "com.google.code.gson:gson:2.8.1",
13 "org.apache.httpcomponents:httpclient:4.5.3", 13 "org.apache.httpcomponents:httpclient:4.5.3",
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" 14 + "commons-io:commons-io:2.5"
17 15
18 compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1100-jdbc4' 16 compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1100-jdbc4'
19 17
20 providedCompile "org.slf4j:slf4j-api:1.7.25" 18 providedCompile "org.slf4j:slf4j-api:1.7.25"
21 19
  20 + compileOnly group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
  21 + compileOnly group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.6.Final'
  22 +
22 testCompile "org.jboss.arquillian.junit:arquillian-junit-container:1.1.13.Final", 23 testCompile "org.jboss.arquillian.junit:arquillian-junit-container:1.1.13.Final",
23 "junit:junit:4.12" 24 "junit:junit:4.12"
24 25
services/Global/src/main/java/de/bht/beuthbot/entities/User.java
1 package de.bht.beuthbot.entities; 1 package de.bht.beuthbot.entities;
2 2
3 -import de.bht.beuthbot.persistence.JsonHelper;  
4 -import org.hibernate.annotations.Type;  
5 -  
6 import javax.persistence.Entity; 3 import javax.persistence.Entity;
7 import javax.persistence.Table; 4 import javax.persistence.Table;
8 -import java.util.HashMap;  
9 -import java.util.Map;  
10 5
11 /** 6 /**
12 * Created by Benjamin Rühl on 19.11.2017. 7 * Created by Benjamin Rühl on 19.11.2017.
13 */ 8 */
14 @Entity 9 @Entity
15 -@Table 10 +@Table(name = "user_entity")
16 public class User extends EntityBase implements de.bht.beuthbot.model.entities.User { 11 public class User extends EntityBase implements de.bht.beuthbot.model.entities.User {
17 12
18 private String facebookUserId; 13 private String facebookUserId;
19 private String telegramUserId; 14 private String telegramUserId;
20 15
21 - @Type(type = "JsonMapType")  
22 - private Map<String, String> additionalData = new HashMap<>(); 16 + //@Type(type = "JsonMapType")
  17 + //private Map<String, String> additionalData = new HashMap<>();
23 18
24 @Override 19 @Override
25 public String getFacebookUserId() { 20 public String getFacebookUserId() {
@@ -32,20 +27,30 @@ public class User extends EntityBase implements de.bht.beuthbot.model.entities.U @@ -32,20 +27,30 @@ public class User extends EntityBase implements de.bht.beuthbot.model.entities.U
32 } 27 }
33 28
34 @Override 29 @Override
35 - public <T extends Object> T getProperty(String propertyName, Class<T> propertyType) { 30 + public <T> T getProperty(String propertyName, Class<T> propertyType) {
  31 + return null;
  32 + }
  33 +
  34 + @Override
  35 + public void setProperty(String propertyName, Object propertyValue) {
  36 +
  37 + }
  38 +
  39 + //@Override
  40 + /*public <T extends Object> T getProperty(String propertyName, Class<T> propertyType) {
36 String propertyValue = additionalData.getOrDefault(propertyName, null); 41 String propertyValue = additionalData.getOrDefault(propertyName, null);
37 42
38 if (propertyValue == null) 43 if (propertyValue == null)
39 return null; 44 return null;
40 45
41 return (T) JsonHelper.fromJson(propertyValue, propertyType); 46 return (T) JsonHelper.fromJson(propertyValue, propertyType);
42 - } 47 + }*/
43 48
44 - @Override  
45 - public void setProperty(String propertyName, Object propertyValue) { 49 + //@Override
  50 + /*public void setProperty(String propertyName, Object propertyValue) {
46 String valueAsJson = JsonHelper.toJson(propertyValue, propertyValue.getClass()); 51 String valueAsJson = JsonHelper.toJson(propertyValue, propertyValue.getClass());
47 additionalData.put(propertyName, valueAsJson); 52 additionalData.put(propertyName, valueAsJson);
48 - } 53 + }*/
49 54
50 public void setFacebookUserId(String facebookUserId) { 55 public void setFacebookUserId(String facebookUserId) {
51 this.facebookUserId = facebookUserId; 56 this.facebookUserId = facebookUserId;
services/Global/src/main/java/de/bht/beuthbot/persistence/UserManager.java
@@ -6,10 +6,10 @@ import javax.ejb.Stateless; @@ -6,10 +6,10 @@ import javax.ejb.Stateless;
6 import javax.persistence.EntityManager; 6 import javax.persistence.EntityManager;
7 import javax.persistence.PersistenceContext; 7 import javax.persistence.PersistenceContext;
8 8
9 -@Stateless 9 +//@Stateless
10 public class UserManager { 10 public class UserManager {
11 11
12 - @PersistenceContext(unitName="de.bht.beuthbot.jpa") 12 + /*@PersistenceContext(unitName="PostgreSQLDS")
13 protected EntityManager entityManager; 13 protected EntityManager entityManager;
14 14
15 public void createUser() { 15 public void createUser() {
@@ -18,5 +18,5 @@ public class UserManager { @@ -18,5 +18,5 @@ public class UserManager {
18 user.setTelegramUserId("TelegramUserId"); 18 user.setTelegramUserId("TelegramUserId");
19 19
20 entityManager.persist(user); 20 entityManager.persist(user);
21 - } 21 + }*/
22 } 22 }
services/Global/src/main/resources/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="PostgreSQLDS" transaction-type="RESOURCE_LOCAL">
  8 +
  9 + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  10 +
  11 + <jta-data-source>java:jboss/datasources/PostgreSQLDS</jta-data-source>
  12 +
  13 + <class>de.bht.beuthbot.entities.User</class>
  14 +
  15 + <properties>
  16 +
  17 + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <!-- 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 \ No newline at end of file 28 \ No newline at end of file