Skip to content

Commit 0064e88

Browse files
author
Gerald Unterrainer
committed
Merge branch 'develop'
2 parents 3accd6f + 98e7ff1 commit 0064e88

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ hs_err_pid*
3939
/bin/
4040

4141
src/main/java/info/unterrainer/commons/httpserver/Information.java
42+
43+
antlr4/.antlr/

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,73 @@ A relational database (MariaDB) that holds your entities (we use Liquibase for g
2121

2222
### Minimal Example
2323

24+
#### Persistence.xml
25+
26+
Of course you can use your own. This example is only given as a reference and quick-start support.
27+
28+
```xml
29+
<?xml version="1.0" encoding="UTF-8"?>
30+
<persistence version="2.0"
31+
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
32+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
33+
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
34+
35+
<persistence-unit name="my-persistence-unit" transaction-type="RESOURCE_LOCAL">
36+
<!-- Hibernate specific -->
37+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
38+
39+
<class>info.unterrainer.commons.rdbutils.entities.BasicJpa</class>
40+
<class>info.unterrainer.commons.rdbutils.converters.LocalDateTimeConverter</class>
41+
42+
<properties>
43+
<!-- Hibernate-specific / MariaDB-JDBC-driver specific -->
44+
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
45+
<property name="javax.persistence.lock.timeout" value="10000" />
46+
<property name="javax.persistence.query.timeout" value="60000" />
47+
<property name="hibernate.connection.driver_class" value="org.mariadb.jdbc.Driver" />
48+
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect" />
49+
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
50+
<property name="hibernate.jdbc.time_zone" value="UTC"/>
51+
52+
<property name="hibernate.show_sql" value="false" />
53+
<property name="hibernate.format_sql" value="false" />
54+
<property name="hibernate.c3p0.min_size" value="5" />
55+
<property name="hibernate.c3p0.max_size" value="200" />
56+
<!-- Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire. -->
57+
<property name="hibernate.c3p0.timeout" value="300" />
58+
<!-- The size of c3p0’s global PreparedStatement cache over all connections. Zero means statement caching is turned off. -->
59+
<property name="hibernate.c3p0.max_statements" value="500" />
60+
<!-- If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds. -->
61+
<property name="hibernate.c3p0.idle_test_period" value="3000" />
62+
<!-- Is set to true, the connection is tested with a simple query before being returned to a user -->
63+
<property name="hibernate.c3p0.testConnectionOnCheckout" value="true" />
64+
<property name="hibernate.c3p0.statementCacheNumDeferredCloseThreads" value="1" />
65+
66+
</properties>
67+
</persistence-unit>
68+
</persistence>
69+
```
70+
71+
#### Code
72+
2473
```java
25-
// Get configuration containing necessary environment variables.
26-
configuration = MyProgramConfiguration.read();
74+
// To get the necessary configuration values, we use environment variables.
75+
// You can see the necessary fields in the java-rdb-utils project (configuration).
76+
// Those currently are:
77+
//
78+
// DB_SERVER the IP or URI of your server
79+
// DB_PORT
80+
// DB_NAME
81+
// DB_USER
82+
// DB_PASSWORD
83+
2784
// Create an EntityManagerFactory using java-rdb-utils.
2885
// Registers shutdownhook to close emf as well.
86+
// This method gets the connection data from the environment variables
87+
// as stated above.
88+
// "my-server" is the persistence-unit-name
2989
EntityManagerFactory emf =
30-
dbUtils.createAutoclosingEntityManagerFactory(MyProgram.class, "my-server");
90+
dbUtils.createAutoclosingEntityManagerFactory(MyProgram.class, "my-persistence-unit");
3191

3292
// Create the server.
3393
HttpServer server = HttpServer.builder()

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.2.40</version>
20+
<version>0.2.41</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

src/main/java/info/unterrainer/commons/httpserver/HandlerUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,6 @@ public boolean convertToBoolean(final String o) {
232232
return false;
233233

234234
String v = o.strip().toLowerCase();
235-
return !v.equals("false") || !v.equals("no") || !v.equals("0");
235+
return !v.equals("false") && !v.equals("no") && !v.equals("0");
236236
}
237237
}

0 commit comments

Comments
 (0)