| Author | djarvis <email> |
|---|---|
| Date | 2016-06-20 00:32:07 GMT-0700 |
| Commit | cde658cdaedaf6c357c8c409303148e66473292e |
| Parent | 05d64a6 |
| </dependency> | ||
| <dependency> | ||
| - <groupId>org.hibernate</groupId> | ||
| - <artifactId>hibernate-entitymanager</artifactId> | ||
| - <version>4.3.1.Final</version> | ||
| - </dependency> | ||
| - <dependency> | ||
| <groupId>net.sourceforge.web-harvest</groupId> | ||
| <artifactId>webharvest</artifactId> | ||
| <version>2.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| - <groupId>unknown.binary</groupId> | ||
| - <artifactId>hibernate-jpamodelgen-4.3.1.Final</artifactId> | ||
| - <version>SNAPSHOT</version> | ||
| - <scope>provided</scope> | ||
| + <groupId>org.hibernate</groupId> | ||
| + <artifactId>hibernate-entitymanager</artifactId> | ||
| + <version>5.1.0.Final</version> | ||
| + </dependency> | ||
| + <dependency> | ||
| + <groupId>org.hibernate</groupId> | ||
| + <artifactId>hibernate-c3p0</artifactId> | ||
| + <version>5.1.0.Final</version> | ||
| </dependency> | ||
| </dependencies> |
| public abstract class ServiceImpl<T> implements Service { | ||
| + /** | ||
| + * Ensure only a single instance is created. | ||
| + */ | ||
| + private EntityManager entityManager; | ||
| + | ||
| private final static String PERSISTENCE_PASSWORD_PROPERTY | ||
| = "javax.persistence.jdbc.password"; | ||
| } | ||
| - private EntityManager getEntityManager() { | ||
| + private synchronized EntityManager getEntityManager() { | ||
| + if( this.entityManager == null ) { | ||
| + this.entityManager = createEntityManager(); | ||
| + } | ||
| + | ||
| + return this.entityManager; | ||
| + } | ||
| + | ||
| + private EntityManager createEntityManager() { | ||
| return getEntityManagerFactory().createEntityManager(); | ||
| } | ||
| private String getPersistencePassword() { | ||
| - return nullSafe( System.getProperty( PERSISTENCE_PASSWORD_PROPERTY ) ); | ||
| + return System.getProperty( PERSISTENCE_PASSWORD_PROPERTY ); | ||
| } | ||
| public List<Subscriber> list() throws AddressException { | ||
| return getResultList(Subscriber.class); | ||
| - | ||
| - /* | ||
| - Subscriber subscriber = new Subscriber.Builder() | ||
| - .withAddress( new InternetAddress( "Dave.Jarvis@gmail.com" ) ) | ||
| - .build(); | ||
| - | ||
| - result.add( subscriber ); | ||
| - return result; | ||
| - */ | ||
| } | ||
| } |
| <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> | ||
| <persistence-unit name="SALES" transaction-type="RESOURCE_LOCAL"> | ||
| - <provider>org.hibernate.ejb.HibernatePersistence</provider> | ||
| + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> | ||
| <properties> | ||
| <property name="javax.persistence.jdbc.url" value="jdbc:postgresql:sales"/> | ||
| <property name="javax.persistence.jdbc.user" value="sales"/> | ||
| <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/> | ||
| <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/> | ||
| <property name="hibernate.hbm2ddl.auto" value="validate"/> | ||
| <!-- Password is set using a command line property of the same name. --> | ||
| <!--property name="javax.persistence.jdbc.password" value=""/--> | ||
| + | ||
| + <!-- http://www.hibernate.org/214.html --> | ||
| + <!-- https://developer.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool --> | ||
| + <property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/> | ||
| + <property name="hibernate.c3p0.acquire_increment" value="1"/> | ||
| + <property name="hibernate.c3p0.idle_test_period" value="60"/> | ||
| + <property name="hibernate.c3p0.min_size" value="1"/> | ||
| + <property name="hibernate.c3p0.max_size" value="2"/> | ||
| + <property name="hibernate.c3p0.max_statements" value="50"/> | ||
| + <property name="hibernate.c3p0.timeout" value="0"/> | ||
| + <property name="hibernate.c3p0.acquireRetryAttempts" value="1"/> | ||
| + <property name="hibernate.c3p0.acquireRetryDelay" value="250"/> | ||
| + | ||
| + <!-- Show SQL statements for debugging purposes. --> | ||
| + <property name="hibernate.show_sql" value="false"/> | ||
| </properties> | ||
| </persistence-unit> |
| Delta | 39 lines added, 21 lines removed, 18-line increase |
|---|