Upgrade libraries

This commit is contained in:
jendib 2016-01-29 01:55:59 +01:00
parent 0db4f1643d
commit a0f309c957
20 changed files with 69 additions and 271 deletions

View File

@ -28,7 +28,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<artifactId>hibernate-c3p0</artifactId>
</dependency>
<!-- Other external dependencies -->

View File

@ -1,21 +1,11 @@
package com.sismics.util.jpa;
import com.google.common.base.Strings;
import com.google.common.io.CharStreams;
import com.sismics.docs.core.util.ConfigUtil;
import com.sismics.util.ResourceUtil;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.engine.jdbc.internal.Formatter;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.ConnectionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -26,6 +16,22 @@ import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.engine.jdbc.internal.Formatter;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.service.ServiceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Strings;
import com.google.common.io.CharStreams;
import com.sismics.docs.core.util.ConfigUtil;
import com.sismics.util.ResourceUtil;
/**
* A helper to update the database incrementally.
*
@ -37,10 +43,10 @@ public abstract class DbOpenHelper {
*/
private static final Logger log = LoggerFactory.getLogger(DbOpenHelper.class);
private final ConnectionHelper connectionHelper;
private final SqlStatementLogger sqlStatementLogger;
private final JdbcConnectionAccess jdbcConnectionAccess;
private final List<Exception> exceptions = new ArrayList<Exception>();
private Formatter formatter;
@ -51,9 +57,8 @@ public abstract class DbOpenHelper {
public DbOpenHelper(ServiceRegistry serviceRegistry) throws HibernateException {
final JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
connectionHelper = new SuppliedConnectionProviderConnectionHelper(jdbcServices.getConnectionProvider());
sqlStatementLogger = jdbcServices.getSqlStatementLogger();
jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
formatter = (sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE).getFormatter();
}
@ -67,8 +72,7 @@ public abstract class DbOpenHelper {
try {
try {
connectionHelper.prepare(true);
connection = connectionHelper.getConnection();
connection = jdbcConnectionAccess.obtainConnection();
} catch (SQLException sqle) {
exceptions.add(sqle);
log.error("Unable to get database metadata", sqle);
@ -120,7 +124,7 @@ public abstract class DbOpenHelper {
stmt.close();
stmt = null;
}
connectionHelper.release();
jdbcConnectionAccess.releaseConnection(connection);
} catch (Exception e) {
exceptions.add(e);
log.error("Unable to close connection", e);

View File

@ -11,10 +11,10 @@ import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,7 +36,7 @@ public final class EMF {
Environment.verifyProperties(properties);
ConfigurationHelper.resolvePlaceHolders(properties);
ServiceRegistry reg = new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry();
ServiceRegistry reg = new StandardServiceRegistryBuilder().applySettings(properties).build();
DbOpenHelper openHelper = new DbOpenHelper(reg) {
@ -85,12 +85,16 @@ public final class EMF {
String dbFile = dbDirectory.resolve("docs").toAbsolutePath().toString();
props.put("hibernate.connection.url", "jdbc:h2:file:" + dbFile + ";CACHE_SIZE=65536");
props.put("hibernate.connection.username", "sa");
props.put("hibernate.hbm2ddl.auto", "none");
props.put("hibernate.hbm2ddl.auto", "");
props.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
props.put("hibernate.show_sql", "false");
props.put("hibernate.format_sql", "false");
props.put("hibernate.max_fetch_depth", "5");
props.put("hibernate.cache.use_second_level_cache", "false");
props.put("hibernate.c3p0.min_size", "1");
props.put("hibernate.c3p0.max_size", "10");
props.put("hibernate.c3p0.timeout", "0");
props.put("hibernate.c3p0.max_statements", "0");
return props;
}

View File

@ -1,108 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package com.sismics.util.jpa;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.tool.hbm2ddl.ConnectionHelper;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
/**
* A {@link ConnectionHelper} implementation based on an internally
* built and managed {@link ConnectionProvider}.
*
* @author Steve Ebersole
*/
class ManagedProviderConnectionHelper implements ConnectionHelper {
private Properties cfgProperties;
private StandardServiceRegistryImpl serviceRegistry;
private Connection connection;
public ManagedProviderConnectionHelper(Properties cfgProperties) {
this.cfgProperties = cfgProperties;
}
@Override
public void prepare(boolean needsAutoCommit) throws SQLException {
serviceRegistry = createServiceRegistry(cfgProperties);
connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
if (needsAutoCommit && !connection.getAutoCommit()) {
connection.commit();
connection.setAutoCommit(true);
}
}
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties(properties);
ConfigurationHelper.resolvePlaceHolders(properties);
return (StandardServiceRegistryImpl) new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry();
}
@Override
public Connection getConnection() throws SQLException {
return connection;
}
@Override
public void release() throws SQLException {
try {
releaseConnection();
} finally {
releaseServiceRegistry();
}
}
private void releaseConnection() throws SQLException {
if (connection != null) {
try {
new SqlExceptionHelper().logAndClearWarnings(connection);
} finally {
try {
serviceRegistry.getService(ConnectionProvider.class).closeConnection(connection);
} finally {
connection = null;
}
}
}
}
private void releaseServiceRegistry() {
if (serviceRegistry != null) {
try {
serviceRegistry.destroy();
} finally {
serviceRegistry = null;
}
}
}
}

View File

@ -1,28 +0,0 @@
package com.sismics.util.jpa;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.HibernateEntityManagerFactory;
/**
* Hibernate session utilities.
*
* @author jtremeaux
*/
public final class SessionUtil {
/**
* Private constructor.
*/
private SessionUtil() {
}
/**
* Returns an instance of the current session.
*
* @return Instance of the current session
*/
public static Session getCurrentSession() {
SessionFactory sessionFactory = ((HibernateEntityManagerFactory) EMF.get()).getSessionFactory();
return sessionFactory.getCurrentSession();
}
}

View File

@ -1,84 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package com.sismics.util.jpa;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.tool.hbm2ddl.ConnectionHelper;
import java.sql.Connection;
import java.sql.SQLException;
/**
* A {@link ConnectionHelper} implementation based on a provided
* {@link ConnectionProvider}. Essentially, ensures that the connection
* gets cleaned up, but that the provider itself remains usable since it
* was externally provided to us.
*
* @author Steve Ebersole
*/
class SuppliedConnectionProviderConnectionHelper implements ConnectionHelper {
private ConnectionProvider provider;
private Connection connection;
private boolean toggleAutoCommit;
public SuppliedConnectionProviderConnectionHelper(ConnectionProvider provider) {
this.provider = provider;
}
@Override
public void prepare(boolean needsAutoCommit) throws SQLException {
connection = provider.getConnection();
toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit();
if ( toggleAutoCommit ) {
try {
connection.commit();
}
catch( Throwable ignore ) {
// might happen with a managed connection
}
connection.setAutoCommit( true );
}
}
@Override
public Connection getConnection() throws SQLException {
return connection;
}
@Override
public void release() throws SQLException {
// we only release the connection
if ( connection != null ) {
new SqlExceptionHelper().logAndClearWarnings( connection );
if ( toggleAutoCommit ) {
connection.setAutoCommit( false );
}
provider.closeConnection( connection );
connection = null;
}
}
}

View File

@ -3,7 +3,7 @@ package com.sismics.docs.core.dao.jpa;
import com.sismics.docs.BaseTransactionalTest;
import com.sismics.docs.core.model.jpa.User;
import com.sismics.docs.core.util.TransactionUtil;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -5,8 +5,7 @@ import java.io.InputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import com.google.common.base.Strings;

View File

@ -11,7 +11,7 @@ import com.google.common.io.Resources;
import com.sismics.docs.core.model.jpa.File;
import com.sismics.util.mime.MimeType;
import junit.framework.Assert;
import org.junit.Assert;
/**
* Test of the file entity utilities.

View File

@ -1,6 +1,6 @@
package com.sismics.util;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -1,6 +1,6 @@
package com.sismics.util;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -1,6 +1,6 @@
package com.sismics.util;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;

View File

@ -2,9 +2,13 @@ hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:mem:docs
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.hbm2ddl.auto=none
hibernate.hbm2ddl.auto=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.max_fetch_depth=5
hibernate.cache.use_second_level_cache=false
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=10
hibernate.c3p0.timeout=0
hibernate.c3p0.max_statements=0

View File

@ -20,20 +20,20 @@
<commons-lang.commons-lang.version>2.6</commons-lang.commons-lang.version>
<commons-io.commons-io.version>2.4</commons-io.commons-io.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<com.google.guava.guava.version>18.0</com.google.guava.guava.version>
<com.google.guava.guava.version>19.0</com.google.guava.guava.version>
<log4j.log4j.version>1.2.16</log4j.log4j.version>
<org.slf4j.version>1.6.4</org.slf4j.version>
<org.slf4j.jcl-over-slf4j.version>1.6.6</org.slf4j.jcl-over-slf4j.version>
<junit.junit.version>4.7</junit.junit.version>
<com.h2database.h2.version>1.4.190</com.h2database.h2.version>
<junit.junit.version>4.12</junit.junit.version>
<com.h2database.h2.version>1.4.191</com.h2database.h2.version>
<org.glassfish.jersey.version>2.22.1</org.glassfish.jersey.version>
<org.mindrot.jbcrypt>0.3m</org.mindrot.jbcrypt>
<org.apache.lucene.version>4.2.0</org.apache.lucene.version>
<org.imgscalr.imgscalr-lib.version>4.2</org.imgscalr.imgscalr-lib.version>
<org.apache.pdfbox.pdfbox.version>2.0.0-RC2</org.apache.pdfbox.pdfbox.version>
<org.bouncycastle.bcprov-jdk15on.version>1.53</org.bouncycastle.bcprov-jdk15on.version>
<org.apache.pdfbox.pdfbox.version>2.0.0-RC3</org.apache.pdfbox.pdfbox.version>
<org.bouncycastle.bcprov-jdk15on.version>1.54</org.bouncycastle.bcprov-jdk15on.version>
<joda-time.joda-time.version>2.9.1</joda-time.joda-time.version>
<org.hibernate.hibernate.version>4.1.0.Final</org.hibernate.hibernate.version>
<org.hibernate.hibernate.version>5.0.7.Final</org.hibernate.hibernate.version>
<javax.servlet.javax.servlet-api.version>3.1.0</javax.servlet.javax.servlet-api.version>
<fr.opensagres.xdocreport.version>1.0.5</fr.opensagres.xdocreport.version>
<net.java.dev.jna.jna.version>4.2.1</net.java.dev.jna.jna.version>
@ -48,11 +48,10 @@
<!-- Plugins version -->
<org.apache.maven.plugins.maven-antrun-plugin.version>1.8</org.apache.maven.plugins.maven-antrun-plugin.version>
<org.apache.maven.plugins.maven-dependency-plugin.version>2.10</org.apache.maven.plugins.maven-dependency-plugin.version>
<org.apache.maven.plugins.maven-jar-plugin.version>2.4</org.apache.maven.plugins.maven-jar-plugin.version>
<org.apache.maven.plugins.maven-release-plugin.version>2.5.2</org.apache.maven.plugins.maven-release-plugin.version>
<org.apache.maven.plugins.maven-jar-plugin.version>2.6</org.apache.maven.plugins.maven-jar-plugin.version>
<org.apache.maven.plugins.maven-resources-plugin.version>2.7</org.apache.maven.plugins.maven-resources-plugin.version>
<org.apache.maven.plugins.maven-war-plugin.version>2.6</org.apache.maven.plugins.maven-war-plugin.version>
<org.apache.maven.plugins.maven-surefire-plugin.version>2.18.1</org.apache.maven.plugins.maven-surefire-plugin.version>
<org.apache.maven.plugins.maven-surefire-plugin.version>2.19.1</org.apache.maven.plugins.maven-surefire-plugin.version>
<org.eclipse.jetty.jetty-maven-plugin.version>9.2.13.v20150730</org.eclipse.jetty.jetty-maven-plugin.version>
</properties>
@ -306,7 +305,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<artifactId>hibernate-c3p0</artifactId>
<version>${org.hibernate.hibernate.version}</version>
</dependency>

View File

@ -17,7 +17,7 @@ import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import junit.framework.Assert;
import org.junit.Assert;
import org.glassfish.jersey.client.ClientResponse;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;

View File

@ -2,7 +2,7 @@ package com.sismics.docs.rest.util;
import com.sismics.rest.exception.ClientException;
import com.sismics.rest.util.ValidationUtil;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
/**

View File

@ -88,7 +88,7 @@
<groupId>com.twelvemonkeys.servlet</groupId>
<artifactId>servlet</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>com.sismics.docs</groupId>

View File

@ -2,9 +2,13 @@ hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:mem:docs
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.hbm2ddl.auto=none
hibernate.hbm2ddl.auto=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.max_fetch_depth=5
hibernate.cache.use_second_level_cache=false
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=10
hibernate.c3p0.timeout=0
hibernate.c3p0.max_statements=0

View File

@ -6,7 +6,7 @@ import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import junit.framework.Assert;
import org.junit.Assert;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;

View File

@ -2,9 +2,13 @@ hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:mem:docs
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.hbm2ddl.auto=none
hibernate.hbm2ddl.auto=
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.max_fetch_depth=5
hibernate.cache.use_second_level_cache=false
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=10
hibernate.c3p0.timeout=0
hibernate.c3p0.max_statements=0