Added used of @Cause to log messages

This commit is contained in:
JPAV 2011-01-25 14:54:39 -06:00
parent af24178145
commit c26763c2e9
108 changed files with 566 additions and 2595 deletions

View File

@ -62,7 +62,7 @@ libraries = [
// logging
logging: 'org.jboss.logging:jboss-logging:3.0.0.Beta4',
logging_tools: 'org.jboss.logging:jboss-logging-tools:1.0.0.Beta1',
// logging_tools: 'org.jboss.logging:jboss-logging-tools:1.0.0.Beta2',
slf4j_api: 'org.slf4j:slf4j-api:' + slf4jVersion,
slf4j_simple: 'org.slf4j:slf4j-simple:' + slf4jVersion,
jcl_slf4j: 'org.slf4j:jcl-over-slf4j:' + slf4jVersion,
@ -108,7 +108,7 @@ subprojects { subProject ->
// appropriately inject the common dependencies into each sub-project
dependencies {
compile(libraries.logging)
compile(libraries.logging_tools)
// compile(libraries.logging_tools)
compile( libraries.slf4j_api )
testCompile( libraries.junit )
testRuntime( libraries.slf4j_simple )
@ -136,7 +136,7 @@ subprojects { subProject ->
test {
systemProperties['hibernate.test.validatefailureexpected'] = true
// systemProperties['jboss.i18n.generate-proxies'] = true
systemProperties['jboss.i18n.generate-proxies'] = true
maxHeapSize = "1024m"
}

View File

@ -176,7 +176,7 @@ public class C3P0ConnectionProvider implements ConnectionProvider {
}
catch ( Exception e ) {
LOG.error(LOG.unableToInstantiateC3p0ConnectionPool(), e);
throw new HibernateException( "Could not instantiate C3P0 connection pool", e );
throw new HibernateException(LOG.unableToInstantiateC3p0ConnectionPool(), e);
}
String i = props.getProperty( Environment.ISOLATION );

View File

@ -57,5 +57,5 @@ public interface C3P0Logger extends BasicLogger {
Object unableToDestroyC3p0ConnectionPool();
@Message( value = "Could not instantiate C3P0 connection pool" )
Object unableToInstantiateC3p0ConnectionPool();
String unableToInstantiateC3p0ConnectionPool();
}

View File

@ -1,16 +0,0 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.hibernate;
/**
*
*/
public class LogUtil {
public static final org.jboss.logging.Logger TMP_LOG = org.jboss.logging.Logger.getLogger(LogUtil.class);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +0,0 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.hibernate.bytecode;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.WARN;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
public interface Logger extends BasicLogger {
@LogMessage( level = WARN )
@Message( value = "Per HHH-5451 support for cglib as a bytecode provider has been deprecated." )
void deprecated();
@LogMessage( level = DEBUG )
@Message( value = "Enhancing %s" )
void enhancingClass( String className );
@LogMessage( level = DEBUG )
@Message( value = "reflection optimizer disabled for: %s [%s: %s" )
void reflectionOptimizerDisabled( String className,
String simpleClassName,
String errorMessage );
@LogMessage( level = DEBUG )
@Message( value = "reflection optimizer disabled for: %s [%s: %s (property %s)" )
void reflectionOptimizerDisabledForBulkException( String className,
String simpleClassName,
String errorMessage,
String setterName );
@LogMessage( level = ERROR )
@Message( value = "Unable to build enhancement metamodel for %s" )
void unableToBuildEnhancementMetamodel( String className );
@LogMessage( level = ERROR )
@Message( value = "Unable to read class: %s" )
void unableToReadClass( String message );
@LogMessage( level = ERROR )
@Message( value = "Unable to transform class: %s" )
void unableToTransformClass( String message );
}

View File

@ -68,6 +68,7 @@ import org.hibernate.EmptyInterceptor;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.InvalidMappingException;
import org.hibernate.Logger;
import org.hibernate.MappingException;
import org.hibernate.MappingNotFoundException;
import org.hibernate.SessionFactory;
@ -1650,7 +1651,7 @@ public class Configuration implements Serializable {
applyMethod.invoke( validator, persistentClazz );
}
catch ( Exception e ) {
LOG.unableToApplyConstraints(className, e.getMessage());
LOG.warn(LOG.unableToApplyConstraints(className), e);
}
}
}
@ -2205,7 +2206,7 @@ public class Configuration implements Serializable {
stream.close();
}
catch (IOException ioe) {
LOG.unableToCloseInputStream(resourceName, ioe.getMessage());
LOG.warn(LOG.unableToCloseInputStreamForResource(resourceName), ioe);
}
}
return this;

View File

@ -619,7 +619,7 @@ public final class Environment {
stream.close();
}
catch (IOException ioe){
LOG.unableToCloseStream(ioe);
LOG.unableToCloseStreamError(ioe);
}
}
}

View File

@ -29,6 +29,7 @@ import java.util.Properties;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.bytecode.BytecodeProvider;
import org.hibernate.cache.QueryCacheFactory;
import org.hibernate.cache.RegionFactory;

View File

@ -44,6 +44,7 @@ import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.PropertyDescriptor;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.MappingException;
import org.hibernate.event.EventListeners;
import org.hibernate.event.PreDeleteEventListener;
@ -125,7 +126,7 @@ class TypeSafeActivator {
applyDDL( "", persistentClass, clazz, factory, groups, true );
}
catch (Exception e) {
LOG.unableToApplyConstraints(className, e.getMessage());
LOG.warn(LOG.unableToApplyConstraints(className), e);
}
}
}

View File

@ -1,256 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* 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 org.hibernate.connection;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
import org.hibernate.util.ReflectHelper;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* Instantiates a connection provider given either <tt>System</tt> properties or
* a <tt>java.util.Properties</tt> instance. The <tt>ConnectionProviderFactory</tt>
* first attempts to find a name of a <tt>ConnectionProvider</tt> subclass in the
* property <tt>hibernate.connection.provider_class</tt>. If missing, heuristics are used
* to choose either <tt>DriverManagerConnectionProvider</tt>,
* <tt>DatasourceConnectionProvider</tt>, <tt>C3P0ConnectionProvider</tt> or
* <tt>DBCPConnectionProvider</tt>.
*
* @author Gavin King
* @see ConnectionProvider
*/
public final class ConnectionProviderFactory {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
ConnectionProviderFactory.class.getPackage().getName());
/**
* Instantiate a <tt>ConnectionProvider</tt> using <tt>System</tt> properties.
*
* @return The created connection provider.
*
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider() throws HibernateException {
return newConnectionProvider( Environment.getProperties() );
}
/**
* Instantiate a <tt>ConnectionProvider</tt> using given properties.
* Method newConnectionProvider.
*
* @param properties hibernate <tt>SessionFactory</tt> properties
*
* @return ConnectionProvider
*
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider(Properties properties) throws HibernateException {
return newConnectionProvider( properties, null );
}
/**
* Create a connection provider based on the given information.
*
* @param properties Properties being used to build the {@link org.hibernate.SessionFactory}.
* @param connectionProviderInjectionData Something to be injected in the connection provided
*
* @return The created connection provider
*
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData)
throws HibernateException {
ConnectionProvider connections;
String providerClass = properties.getProperty( Environment.CONNECTION_PROVIDER );
if ( providerClass != null ) {
connections = initializeConnectionProviderFromConfig( providerClass );
}
else if ( c3p0ConfigDefined( properties ) && c3p0ProviderPresent() ) {
connections = initializeConnectionProviderFromConfig("org.hibernate.connection.C3P0ConnectionProvider");
}
else if ( properties.getProperty( Environment.DATASOURCE ) != null ) {
connections = new DatasourceConnectionProvider();
}
else if ( properties.getProperty( Environment.URL ) != null ) {
connections = new DriverManagerConnectionProvider();
}
else {
connections = new UserSuppliedConnectionProvider();
}
if ( connectionProviderInjectionData != null && connectionProviderInjectionData.size() != 0 ) {
//inject the data
try {
BeanInfo info = Introspector.getBeanInfo( connections.getClass() );
PropertyDescriptor[] descritors = info.getPropertyDescriptors();
int size = descritors.length;
for ( int index = 0; index < size; index++ ) {
String propertyName = descritors[index].getName();
if ( connectionProviderInjectionData.containsKey( propertyName ) ) {
Method method = descritors[index].getWriteMethod();
method.invoke(
connections, new Object[] { connectionProviderInjectionData.get( propertyName ) }
);
}
}
}
catch ( IntrospectionException e ) {
throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
catch ( IllegalAccessException e ) {
throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
catch ( InvocationTargetException e ) {
throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
}
connections.configure( properties );
return connections;
}
private static boolean c3p0ProviderPresent() {
try {
ReflectHelper.classForName( "org.hibernate.connection.C3P0ConnectionProvider" );
}
catch ( ClassNotFoundException e ) {
LOG.c3p0PropertiesIgnored();
return false;
}
return true;
}
private static boolean c3p0ConfigDefined(Properties properties) {
Iterator iter = properties.keySet().iterator();
while ( iter.hasNext() ) {
String property = (String) iter.next();
if ( property.startsWith( "hibernate.c3p0" ) ) {
return true;
}
}
return false;
}
private static ConnectionProvider initializeConnectionProviderFromConfig(String providerClass) {
ConnectionProvider connections;
try {
LOG.initializingConnectionProvider(providerClass);
connections = (ConnectionProvider) ReflectHelper.classForName( providerClass ).newInstance();
}
catch ( Exception e ) {
LOG.unableToInstantiateConnectionProvider(e.getMessage());
throw new HibernateException( "Could not instantiate connection provider: " + providerClass );
}
return connections;
}
// cannot be instantiated
private ConnectionProviderFactory() {
throw new UnsupportedOperationException();
}
/**
* Transform JDBC connection properties.
*
* Passed in the form <tt>hibernate.connection.*</tt> to the
* format accepted by <tt>DriverManager</tt> by trimming the leading "<tt>hibernate.connection</tt>".
*/
public static Properties getConnectionProperties(Properties properties) {
Iterator iter = properties.keySet().iterator();
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
if ( prop.startsWith( Environment.CONNECTION_PREFIX ) && !SPECIAL_PROPERTIES.contains( prop ) ) {
result.setProperty(
prop.substring( Environment.CONNECTION_PREFIX.length() + 1 ),
properties.getProperty( prop )
);
}
}
String userName = properties.getProperty( Environment.USER );
if ( userName != null ) {
result.setProperty( "user", userName );
}
return result;
}
private static final Set SPECIAL_PROPERTIES;
static {
SPECIAL_PROPERTIES = new HashSet();
SPECIAL_PROPERTIES.add( Environment.DATASOURCE );
SPECIAL_PROPERTIES.add( Environment.URL );
SPECIAL_PROPERTIES.add( Environment.CONNECTION_PROVIDER );
SPECIAL_PROPERTIES.add( Environment.POOL_SIZE );
SPECIAL_PROPERTIES.add( Environment.ISOLATION );
SPECIAL_PROPERTIES.add( Environment.DRIVER );
SPECIAL_PROPERTIES.add( Environment.USER );
}
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
interface Logger extends BasicLogger {
@LogMessage( level = WARN )
@Message( value = "c3p0 properties is specified, but could not find org.hibernate.connection.C3P0ConnectionProvider from the classpath, these properties are going to be ignored." )
void c3p0PropertiesIgnored();
@LogMessage( level = INFO )
@Message( value = "Initializing connection provider: %s" )
void initializingConnectionProvider( String providerClass );
@LogMessage( level = ERROR )
@Message( value = "Could not instantiate connection provider\n%s" )
void unableToInstantiateConnectionProvider( String message );
}
}

View File

@ -1,130 +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 org.hibernate.connection;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.jndi.JndiHelper;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* A connection provider that uses a <tt>DataSource</tt> registered with JNDI.
* Hibernate will use this <tt>ConnectionProvider</tt> by default if the
* property <tt>hibernate.connection.datasource</tt> is set.
* @see ConnectionProvider
* @author Gavin King
*/
public class DatasourceConnectionProvider implements ConnectionProvider {
private DataSource ds;
private String user;
private String pass;
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
DatasourceConnectionProvider.class.getPackage().getName());
public DataSource getDataSource() {
return ds;
}
public void setDataSource(DataSource ds) {
this.ds = ds;
}
public void configure(Properties props) throws HibernateException {
String jndiName = props.getProperty( Environment.DATASOURCE );
if ( jndiName == null ) {
String msg = "datasource JNDI name was not specified by property " + Environment.DATASOURCE;
LOG.unspecifiedJndiName(msg);
throw new HibernateException( msg );
}
user = props.getProperty( Environment.USER );
pass = props.getProperty( Environment.PASS );
try {
ds = ( DataSource ) JndiHelper.getInitialContext( props ).lookup( jndiName );
}
catch ( Exception e ) {
LOG.datasourceNotFound(jndiName, e.getMessage());
throw new HibernateException( "Could not find datasource", e );
}
if ( ds == null ) {
throw new HibernateException( "Could not find datasource: " + jndiName );
}
LOG.usingDatasource(jndiName);
}
public Connection getConnection() throws SQLException {
if (user != null || pass != null) {
return ds.getConnection(user, pass);
}
else {
return ds.getConnection();
}
}
public void closeConnection(Connection conn) throws SQLException {
conn.close();
}
public void close() {}
/**
* @see ConnectionProvider#supportsAggressiveRelease()
*/
public boolean supportsAggressiveRelease() {
return true;
}
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
interface Logger extends BasicLogger {
@LogMessage( level = ERROR )
@Message( value = "Could not find datasource: %s\n%s" )
void datasourceNotFound( String jndiName,
String message );
@LogMessage( level = ERROR )
@Message( value = "%s" )
void unspecifiedJndiName( String msg );
@LogMessage( level = INFO )
@Message( value = "Using datasource: %s" )
void usingDatasource( String jndiName );
}
}

View File

@ -1,275 +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 org.hibernate.connection;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.TRACE;
import static org.jboss.logging.Logger.Level.WARN;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.util.ReflectHelper;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* A connection provider that uses <tt>java.sql.DriverManager</tt>. This provider
* also implements a very rudimentary connection pool.
* @see ConnectionProvider
* @author Gavin King
*/
public class DriverManagerConnectionProvider implements ConnectionProvider {
private String url;
private Properties connectionProps;
private Integer isolation;
private final ArrayList pool = new ArrayList();
private int poolSize;
private int checkedOut = 0;
private boolean autocommit;
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
DriverManagerConnectionProvider.class.getPackage().getName());
public void configure(Properties props) throws HibernateException {
String driverClass = props.getProperty(Environment.DRIVER);
poolSize = ConfigurationHelper.getInt(Environment.POOL_SIZE, props, 20); //default pool size 20
LOG.usingHibernateConnectionPool();
LOG.hibernateConnectionPoolSize(poolSize);
autocommit = ConfigurationHelper.getBoolean(Environment.AUTOCOMMIT, props);
LOG.autocommmitMode(autocommit);
isolation = ConfigurationHelper.getInteger(Environment.ISOLATION, props);
if (isolation!=null)
LOG.jdbcIsolationLevel(Environment.isolationLevelToString(isolation.intValue()));
if (driverClass == null) LOG.unspecifiedJdbcDriver(Environment.DRIVER);
else {
try {
// trying via forName() first to be as close to DriverManager's semantics
Class.forName(driverClass);
}
catch (ClassNotFoundException cnfe) {
try {
ReflectHelper.classForName(driverClass);
}
catch (ClassNotFoundException e) {
String msg = "JDBC Driver class not found: " + driverClass;
LOG.jdbcDriverClassNotFound(msg, e.getMessage());
throw new HibernateException(msg, e);
}
}
}
url = props.getProperty( Environment.URL );
if ( url == null ) {
String msg = "JDBC URL was not specified by property " + Environment.URL;
LOG.unspecifiedJdbcUrl(msg);
throw new HibernateException( msg );
}
connectionProps = ConnectionProviderFactory.getConnectionProperties( props );
LOG.usingDriver(driverClass, url);
// if debug level is enabled, then log the password, otherwise mask it
if (LOG.isDebugEnabled()) LOG.connectionProperties(connectionProps);
else LOG.connectionProperties(ConfigurationHelper.maskOut(connectionProps, "password"));
}
public Connection getConnection() throws SQLException {
LOG.checkedOutConnections(checkedOut);
synchronized (pool) {
if ( !pool.isEmpty() ) {
int last = pool.size() - 1;
if (LOG.isTraceEnabled()) {
LOG.usingPooledJdbcConnection(last);
checkedOut++;
}
Connection pooled = (Connection) pool.remove(last);
if (isolation!=null) pooled.setTransactionIsolation( isolation.intValue() );
if ( pooled.getAutoCommit()!=autocommit ) pooled.setAutoCommit(autocommit);
return pooled;
}
}
LOG.openingNewJdbcConnection();
Connection conn = DriverManager.getConnection(url, connectionProps);
if (isolation!=null) conn.setTransactionIsolation( isolation.intValue() );
if ( conn.getAutoCommit()!=autocommit ) conn.setAutoCommit(autocommit);
LOG.createdConnection(url, conn.getTransactionIsolation());
if (LOG.isTraceEnabled()) checkedOut++;
return conn;
}
public void closeConnection(Connection conn) throws SQLException {
if (LOG.isDebugEnabled()) checkedOut--;
synchronized (pool) {
int currentSize = pool.size();
if ( currentSize < poolSize ) {
LOG.returningConnectionToPool(currentSize + 1);
pool.add(conn);
return;
}
}
LOG.closingJdbcConnection();
conn.close();
}
@Override
protected void finalize() {
close();
}
public void close() {
LOG.cleaningConnectionPool(url);
Iterator iter = pool.iterator();
while ( iter.hasNext() ) {
try {
( (Connection) iter.next() ).close();
}
catch (SQLException sqle) {
LOG.unableToClosePooledConnection(sqle.getMessage());
}
}
pool.clear();
}
/**
* @see ConnectionProvider#supportsAggressiveRelease()
*/
public boolean supportsAggressiveRelease() {
return false;
}
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
interface Logger extends BasicLogger {
@LogMessage( level = INFO )
@Message( value = "Autocommit mode: %s" )
void autocommmitMode( boolean autocommit );
@LogMessage( level = TRACE )
@Message( value = "Total checked-out connections: %d" )
void checkedOutConnections( int checkedOut );
@LogMessage( level = INFO )
@Message( value = "Cleaning up connection pool: %s" )
void cleaningConnectionPool( String url );
@LogMessage( level = DEBUG )
@Message( value = "Closing JDBC connection" )
void closingJdbcConnection();
@LogMessage( level = INFO )
@Message( value = "Connection properties: %s" )
void connectionProperties( Properties connectionProps );
@LogMessage( level = DEBUG )
@Message( value = "Created connection to: %s, Isolation Level: %d" )
void createdConnection( String url,
int transactionIsolation );
@LogMessage( level = INFO )
@Message( value = "Hibernate connection pool size: %s" )
void hibernateConnectionPoolSize( int poolSize );
@LogMessage( level = ERROR )
@Message( value = "%s\n%s" )
void jdbcDriverClassNotFound( String message,
String errorMessage );
@LogMessage( level = INFO )
@Message( value = "JDBC isolation level: %s" )
void jdbcIsolationLevel( String isolationLevelToString );
@LogMessage( level = DEBUG )
@Message( value = "Opening new JDBC connection" )
void openingNewJdbcConnection();
@LogMessage( level = TRACE )
@Message( value = "Returning connection to pool, pool size: %d" )
void returningConnectionToPool( int i );
@LogMessage( level = WARN )
@Message( value = "Problem closing pooled connection\n%s" )
void unableToClosePooledConnection( String message );
@LogMessage( level = WARN )
@Message( value = "No JDBC Driver class was specified by property %s" )
void unspecifiedJdbcDriver( String driver );
@LogMessage( level = ERROR )
@Message( value = "%s" )
void unspecifiedJdbcUrl( String message );
@LogMessage( level = INFO )
@Message( value = "Using driver: %s at URL: %s" )
void usingDriver( String driverClass,
String url );
@LogMessage( level = INFO )
@Message( value = "Using Hibernate built-in connection pool (not for production use!)" )
void usingHibernateConnectionPool();
@LogMessage( level = TRACE )
@Message( value = "Using pooled JDBC connection, pool size: %d" )
void usingPooledJdbcConnection( int last );
}
}

View File

@ -1,75 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* 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 org.hibernate.dialect.resolver;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.hibernate.JDBCException;
import org.hibernate.cfg.CollectionSecondPass;
import org.hibernate.dialect.Dialect;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.service.jdbc.dialect.spi.DialectResolver;
/**
* A templated resolver impl which delegates to the {@link #resolveDialectInternal} method
* and handles any thrown {@link SQLException}s.
*
* @author Steve Ebersole
*/
public abstract class AbstractDialectResolver implements DialectResolver {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
CollectionSecondPass.class.getPackage().getName());
/**
* {@inheritDoc}
* <p/>
* Here we template the resolution, delegating to {@link #resolveDialectInternal} and handling
* {@link java.sql.SQLException}s properly.
*/
public final Dialect resolveDialect(DatabaseMetaData metaData) {
try {
return resolveDialectInternal( metaData );
}
catch ( SQLException sqlException ) {
JDBCException jdbcException = BasicSQLExceptionConverter.INSTANCE.convert( sqlException );
if (jdbcException instanceof JDBCConnectionException) throw jdbcException;
LOG.unableToQueryDatabaseMetadata(BasicSQLExceptionConverter.MSG, sqlException.getMessage());
return null;
}
catch ( Throwable t ) {
LOG.unableToExecuteResolver(this, t.getMessage());
return null;
}
}
/**
* Perform the actual resolution without caring about handling {@link SQLException}s.
*
* @param metaData The database metadata
* @return The resolved dialect, or null if we could not resolve.
* @throws SQLException Indicates problems accessing the metadata.
*/
protected abstract Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException;
}

View File

@ -1,162 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* 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 org.hibernate.dialect.resolver;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.util.ReflectHelper;
/**
* A factory for generating Dialect instances.
*
* @author Steve Ebersole
* @author Tomoto Shimizu Washio
*/
public class DialectFactory {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
DialectFactory.class.getPackage().getName());
private static DialectResolverSet DIALECT_RESOLVERS = new DialectResolverSet();
static {
// register the standard dialect resolver
DIALECT_RESOLVERS.addResolver( new StandardDialectResolver() );
// register resolvers set via Environment property
String userSpecifedResolverSetting = Environment.getProperties().getProperty( Environment.DIALECT_RESOLVERS );
if ( userSpecifedResolverSetting != null ) {
String[] userSpecifedResolvers = userSpecifedResolverSetting.split( "\\s+" );
for ( int i = 0; i < userSpecifedResolvers.length; i++ ) {
registerDialectResolver( userSpecifedResolvers[i] );
}
}
}
/*package*/ static void registerDialectResolver(String resolverName) {
try {
DialectResolver resolver = ( DialectResolver ) ReflectHelper.classForName( resolverName ).newInstance();
DIALECT_RESOLVERS.addResolverAtFirst( resolver );
}
catch ( ClassNotFoundException cnfe ) {
LOG.dialectResolverNotFound(resolverName);
}
catch ( Exception e ) {
LOG.unableToInstantiateDialectResolver(e.getMessage());
}
}
/**
* Builds an appropriate Dialect instance.
* <p/>
* If a dialect is explicitly named in the incoming properties, it is used. Otherwise, it is
* determined by dialect resolvers based on the passed connection.
* <p/>
* An exception is thrown if a dialect was not explicitly set and no resolver could make
* the determination from the given connection.
*
* @param properties The configuration properties.
* @param connection The configured connection.
* @return The appropriate dialect instance.
* @throws HibernateException No dialect specified and no resolver could make the determination.
*/
public static Dialect buildDialect(Properties properties, Connection connection) throws HibernateException {
String dialectName = properties.getProperty( Environment.DIALECT );
if ( dialectName == null ) {
return determineDialect( connection );
}
else {
return constructDialect( dialectName );
}
}
public static Dialect buildDialect(Properties properties) {
String dialectName = properties.getProperty( Environment.DIALECT );
if ( dialectName == null ) {
throw new HibernateException( "'hibernate.dialect' must be set when no Connection available" );
}
return constructDialect( dialectName );
}
/**
* Determine the appropriate Dialect to use given the connection.
*
* @param connection The configured connection.
* @return The appropriate dialect instance.
*
* @throws HibernateException No connection given or no resolver could make
* the determination from the given connection.
*/
private static Dialect determineDialect(Connection connection) {
if ( connection == null ) {
throw new HibernateException( "Connection cannot be null when 'hibernate.dialect' not set" );
}
try {
final DatabaseMetaData databaseMetaData = connection.getMetaData();
final Dialect dialect = DIALECT_RESOLVERS.resolveDialect( databaseMetaData );
if ( dialect == null ) {
throw new HibernateException(
"Unable to determine Dialect to use [name=" + databaseMetaData.getDatabaseProductName() +
", majorVersion=" + databaseMetaData.getDatabaseMajorVersion() +
"]; user must register resolver or explicitly set 'hibernate.dialect'"
);
}
return dialect;
}
catch ( SQLException sqlException ) {
throw new HibernateException(
"Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use",
sqlException
);
}
}
/**
* Returns a dialect instance given the name of the class to use.
*
* @param dialectName The name of the dialect class.
*
* @return The dialect instance.
*/
public static Dialect constructDialect(String dialectName) {
try {
return ( Dialect ) ReflectHelper.classForName( dialectName ).newInstance();
}
catch ( ClassNotFoundException cnfe ) {
throw new HibernateException( "Dialect class not found: " + dialectName, cnfe );
}
catch ( Exception e ) {
throw new HibernateException( "Could not instantiate dialect class", e );
}
}
}

View File

@ -1,91 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* 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 org.hibernate.dialect.resolver;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.cfg.CollectionSecondPass;
import org.hibernate.dialect.Dialect;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.service.jdbc.dialect.spi.DialectResolver;
/**
* A {@link DialectResolver} implementation which coordinates resolution by delegating to its
* registered sub-resolvers. Sub-resolvers may be registered by calling either {@link #addResolver} or
* {@link #addResolverAtFirst}.
*
* @author Tomoto Shimizu Washio
*/
public class DialectResolverSet implements DialectResolver {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
CollectionSecondPass.class.getPackage().getName());
private List resolvers = new ArrayList();
/**
* {@inheritDoc}
*/
public Dialect resolveDialect(DatabaseMetaData metaData) {
Iterator i = resolvers.iterator();
while ( i.hasNext() ) {
final DialectResolver resolver = ( DialectResolver ) i.next();
try {
Dialect dialect = resolver.resolveDialect( metaData );
if ( dialect != null ) {
return dialect;
}
}
catch ( JDBCConnectionException e ) {
throw e;
}
catch ( Throwable t ) {
LOG.subResolverException(t.getMessage());
}
}
return null;
}
/**
* Add a resolver at the end of the underlying resolver list. The resolver added by this method is at lower
* priority than any other existing resolvers.
*
* @param resolver The resolver to add.
*/
public void addResolver(DialectResolver resolver) {
resolvers.add( resolver );
}
/**
* Add a resolver at the beginning of the underlying resolver list. The resolver added by this method is at higher
* priority than any other existing resolvers.
*
* @param resolver The resolver to add.
*/
public void addResolverAtFirst(DialectResolver resolver) {
resolvers.add( 0, resolver );
}
}

View File

@ -1,137 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* 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 org.hibernate.dialect.resolver;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.hibernate.Logger;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.dialect.Ingres10Dialect;
import org.hibernate.dialect.Ingres9Dialect;
import org.hibernate.dialect.IngresDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseASE15Dialect;
import org.hibernate.dialect.SybaseAnywhereDialect;
/**
* The standard Hibernate resolver.
*
* @author Steve Ebersole
*/
public class StandardDialectResolver extends AbstractDialectResolver{
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
StandardDialectResolver.class.getPackage().getName());
@Override
protected Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException {
String databaseName = metaData.getDatabaseProductName();
int databaseMajorVersion = metaData.getDatabaseMajorVersion();
if ( "HSQL Database Engine".equals( databaseName ) ) {
return new HSQLDialect();
}
if ( "H2".equals( databaseName ) ) {
return new H2Dialect();
}
if ( "MySQL".equals( databaseName ) ) {
return new MySQLDialect();
}
if ( "PostgreSQL".equals( databaseName ) ) {
return new PostgreSQLDialect();
}
if ( "Apache Derby".equals( databaseName ) ) {
return new DerbyDialect();
}
if ( "ingres".equalsIgnoreCase( databaseName ) ) {
switch( databaseMajorVersion ) {
case 9:
int databaseMinorVersion = metaData.getDatabaseMinorVersion();
if (databaseMinorVersion > 2) {
return new Ingres9Dialect();
}
return new IngresDialect();
case 10:
LOG.unsupportedIngresVersion();
return new Ingres10Dialect();
default:
LOG.unknownIngresVersion(databaseMajorVersion);
}
return new IngresDialect();
}
if ( databaseName.startsWith( "Microsoft SQL Server" ) ) {
return new SQLServerDialect();
}
if ( "Sybase SQL Server".equals( databaseName ) || "Adaptive Server Enterprise".equals( databaseName ) ) {
return new SybaseASE15Dialect();
}
if ( databaseName.startsWith( "Adaptive Server Anywhere" ) ) {
return new SybaseAnywhereDialect();
}
if ( "Informix Dynamic Server".equals( databaseName ) ) {
return new InformixDialect();
}
if ( databaseName.startsWith( "DB2/" ) ) {
return new DB2Dialect();
}
if ( "Oracle".equals( databaseName ) ) {
switch ( databaseMajorVersion ) {
case 11:
LOG.unsupportedOracleVersion();
return new Oracle10gDialect();
case 10:
return new Oracle10gDialect();
case 9:
return new Oracle9iDialect();
case 8:
return new Oracle8iDialect();
default:
LOG.unknownOracleVersion(databaseMajorVersion);
}
}
return null;
}
}

View File

@ -27,6 +27,7 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.batch.spi.Batch;
import org.hibernate.engine.jdbc.batch.spi.BatchObserver;
import org.hibernate.engine.jdbc.spi.SQLExceptionHelper;
@ -120,7 +121,7 @@ public abstract class AbstractBatchImpl implements Batch {
if ( statement != null ) {
LOG.debug("Reusing prepared statement");
statementLogger.logStatement( sql );
}
}
return statement;
}
@ -131,12 +132,8 @@ public abstract class AbstractBatchImpl implements Batch {
@Override
public void addBatchStatement(Object key, String sql, PreparedStatement preparedStatement) {
checkConsistentBatchKey( key );
if ( sql == null ) {
throw new IllegalArgumentException( "sql must be non-null." );
}
if ( statements.put( sql, preparedStatement ) != null ) {
log.error( "PreparedStatement was already in the batch, [" + sql + "]." );
}
if (sql == null) throw new IllegalArgumentException("sql must be non-null.");
if (statements.put(sql, preparedStatement) != null) LOG.preparedStatementAlreadyInBatch(sql);
}
protected void checkConsistentBatchKey(Object key) {
@ -175,7 +172,7 @@ public abstract class AbstractBatchImpl implements Batch {
}
catch ( SQLException e ) {
LOG.unableToReleaseBatchStatement();
LOG.sqlExceptionEscapedProxy(e.getMessage());
LOG.sqlExceptionEscapedProxy(e);
}
}
getStatements().clear();

View File

@ -23,6 +23,7 @@
*/
package org.hibernate.engine.jdbc.batch.internal;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.batch.spi.Batch;
import org.hibernate.engine.jdbc.spi.SQLExceptionHelper;
import org.hibernate.engine.jdbc.spi.SQLStatementLogger;

View File

@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.spi.SQLExceptionHelper;
import org.hibernate.engine.jdbc.spi.SQLStatementLogger;
import org.hibernate.jdbc.Expectation;
@ -81,7 +82,7 @@ public class BatchingBatch extends AbstractBatchImpl {
statement.addBatch();
}
catch ( SQLException e ) {
LOG.error( LOG.sqlExceptionEscapedProxy(), e );
LOG.sqlExceptionEscapedProxy(e);
throw getSqlExceptionHelper().convert( e, "could not perform addBatch", sql );
}
List<Expectation> expectations = expectationsBySql.get( sql );
@ -152,7 +153,7 @@ public class BatchingBatch extends AbstractBatchImpl {
checkRowCounts( sql, ps.executeBatch(), ps, expectations );
}
catch ( SQLException e ) {
log.error( "sqlexception escaped proxy", e );
LOG.sqlExceptionEscapedProxy(e);
throw getSqlExceptionHelper()
.convert( e, "could not execute statement: " + sql );
}
@ -160,16 +161,14 @@ public class BatchingBatch extends AbstractBatchImpl {
private void checkRowCounts(String sql, int[] rowCounts, PreparedStatement ps, List<Expectation> expectations) {
int numberOfRowCounts = rowCounts.length;
if ( numberOfRowCounts != expectations.size() ) {
log.warn( "JDBC driver did not return the expected number of row counts" );
}
if (numberOfRowCounts != expectations.size()) LOG.unexpectedRowCounts();
try {
for ( int i = 0; i < numberOfRowCounts; i++ ) {
expectations.get( i ).verifyOutcome( rowCounts[i], ps, i );
}
}
catch ( SQLException e ) {
log.error( "sqlexception escaped proxy", e );
LOG.sqlExceptionEscapedProxy(e);
throw getSqlExceptionHelper()
.convert( e, "row count verification failed for statement: ", sql );
}

View File

@ -1,61 +0,0 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.hibernate.engine.jdbc.batch.internal;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.TRACE;
import static org.jboss.logging.Logger.Level.WARN;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
interface Logger extends BasicLogger {
@LogMessage( level = INFO )
@Message( value = "On release of batch it still contained JDBC statements" )
void batchContainedStatementsOnRelease();
@LogMessage( level = TRACE )
@Message( value = "building batch [size=%d]" )
void buildingBatch( int size );
@LogMessage( level = DEBUG )
@Message( value = "Executing batch size: %d" )
void executingBatchSize( int batchPosition );
@LogMessage( level = DEBUG )
@Message( value = "No batched statements to execute" )
void noBatchesToExecute();
@LogMessage( level = DEBUG )
@Message( value = "Reusing batch statement" )
void reusingBatchStatement();
@LogMessage( level = ERROR )
@Message( value = "SqlException escaped proxy : %s" )
void sqlExceptionEscapedProxy( String message );
@LogMessage( level = ERROR )
@Message( value = "Exception executing batch [%s]" )
void unableToExecuteBatch( String message );
@LogMessage( level = ERROR )
@Message( value = "Unable to release batch statement..." )
void unableToReleaseBatchStatement();
@LogMessage( level = WARN )
@Message( value = "JDBC driver did not return the expected number of row counts" )
void unexpectedRowCounts();
}

View File

@ -59,7 +59,7 @@ public class NonBatchingBatch extends AbstractBatchImpl {
expectation.verifyOutcome( rowCount, statement, 0 );
}
catch ( SQLException e ) {
log.error( "sqlexception escaped proxy", e );
LOG.sqlExceptionEscapedProxy(e);
throw getSqlExceptionHelper().convert( e, "could not execute batch statement", sql );
}
}

View File

@ -27,7 +27,6 @@ package org.hibernate.engine.jdbc.internal;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import javax.transaction.TransactionManager;
@ -38,6 +37,7 @@ import org.hibernate.Logger;
import org.hibernate.SessionException;
import org.hibernate.Transaction;
import org.hibernate.TransactionException;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.jdbc.spi.ConnectionManager;
import org.hibernate.engine.jdbc.spi.JDBCContext;
import org.hibernate.transaction.synchronization.CallbackCoordinator;
@ -144,12 +144,6 @@ public class JDBCContextImpl implements ConnectionManagerImpl.Callback, JDBCCont
public Connection borrowConnection() {
return connectionManager.borrowConnection();
}
@Override
public Connection connection() throws HibernateException {
if ( owner.isClosed() ) {
throw new SessionException( "Session is closed" );
}
public Connection connection() throws HibernateException {
if (owner.isClosed()) throw new SessionException("Session is closed");

View File

@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.spi.InvalidatableWrapper;
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
import org.hibernate.engine.jdbc.spi.JdbcWrapper;

View File

@ -33,6 +33,7 @@ import java.util.List;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -361,21 +362,12 @@ public class LogicalConnectionImpl implements LogicalConnectionImplementor {
* This form is used for user-supplied connections.
*/
public void reconnect(Connection suppliedConnection) {
if ( isClosed ) {
throw new IllegalStateException( "cannot manually reconnect because logical connection is already closed" );
}
if (isClosed) throw new IllegalStateException("cannot manually reconnect because logical connection is already closed");
if ( isUserSuppliedConnection ) {
if ( suppliedConnection == null ) {
throw new IllegalArgumentException( "cannot reconnect a null user-supplied connection" );
}
else if ( suppliedConnection == physicalConnection ) {
log.warn( "reconnecting the same connection that is already connected; should this connection have been disconnected?" );
}
else if ( physicalConnection != null ) {
throw new IllegalArgumentException(
"cannot reconnect to a new user-supplied connection because currently connected; must disconnect before reconnecting."
);
}
if (suppliedConnection == null) throw new IllegalArgumentException("cannot reconnect a null user-supplied connection");
else if (suppliedConnection == physicalConnection) LOG.reconnectingConnectedConnection();
else if (physicalConnection != null) throw new IllegalArgumentException(
"cannot reconnect to a new user-supplied connection because currently connected; must disconnect before reconnecting.");
physicalConnection = suppliedConnection;
LOG.debug("Reconnected JDBC connection");
}

View File

@ -85,7 +85,7 @@ public class StatementPreparer {
return ps;
}
catch ( SQLException sqle ) {
LOG.error(LOG.sqlExceptionEscapedProxy(), sqle);
LOG.sqlExceptionEscapedProxy(sqle);
throw sqlExceptionHelper.convert(
sqle, "could not prepare statement", sql
);
@ -109,7 +109,7 @@ public class StatementPreparer {
proxiedConnection.close();
}
catch (SQLException sqle) {
LOG.error(LOG.sqlExceptionEscapedProxy(), sqle);
LOG.sqlExceptionEscapedProxy(sqle);
throw sqlExceptionHelper.convert( sqle, "could not close connection proxy" );
}
}

View File

@ -32,6 +32,7 @@ import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import org.hibernate.Logger;
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
import org.hibernate.engine.jdbc.spi.JdbcResourceRegistry;
import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -46,7 +47,7 @@ import org.hibernate.stat.StatisticsImplementor;
public class ConnectionProxyHandler extends AbstractProxyHandler implements InvocationHandler, ConnectionObserver {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
AbstractProxyHandler.class.getPackage().getName());
ConnectionProxyHandler.class.getPackage().getName());
private LogicalConnectionImplementor logicalConnection;

View File

@ -23,11 +23,11 @@
*/
package org.hibernate.engine.jdbc.internal.proxy;
import static org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.LOG;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Arrays;
import org.hibernate.Logger;
/**
* Invocation handler for {@link java.sql.PreparedStatement} proxies
@ -35,7 +35,9 @@ import java.util.Arrays;
* @author Steve Ebersole
*/
public class PreparedStatementProxyHandler extends AbstractStatementProxyHandler {
private static final Logger log = LoggerFactory.getLogger( ConnectionProxyHandler.class );
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
PreparedStatementProxyHandler.class.getPackage().getName());
private final String sql;

View File

@ -130,7 +130,7 @@ public class SQLExceptionHelper {
}
catch ( SQLException sqle ) {
//workaround for WebLogic
LOG.unableToLogWarnings(sqle);
LOG.warn(LOG.unableToLogWarnings(), sqle);
}
}
try {
@ -193,12 +193,7 @@ public class SQLExceptionHelper {
if (LOG.isEnabled(ERROR)) {
LOG.debug((StringHelper.isNotEmpty(message) ? message : DEFAULT_EXCEPTION_MSG) + " : " + sqlException);
while ( sqlException != null ) {
StringBuffer buf = new StringBuffer( 30 )
.append( "SQL Error: " )
.append( sqlException.getErrorCode() )
.append( ", SQLState: " )
.append( sqlException.getSQLState() );
LOG.warn(buf.toString());
LOG.sqlException(sqlException.getErrorCode(), sqlException.getSQLState());
LOG.error(sqlException.getMessage());
sqlException = sqlException.getNextException();
}

View File

@ -128,7 +128,7 @@ public class LoadContexts {
Iterator itr = collectionLoadContexts.values().iterator();
while ( itr.hasNext() ) {
CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) itr.next();
LOG.failSafeCleanup(collectionLoadContext);
LOG.failSafeCollectionsCleanup(collectionLoadContext);
collectionLoadContext.cleanup();
}
collectionLoadContexts.clear();
@ -137,7 +137,7 @@ public class LoadContexts {
Iterator itr = entityLoadContexts.values().iterator();
while ( itr.hasNext() ) {
EntityLoadContext entityLoadContext = ( EntityLoadContext ) itr.next();
LOG.failSafeCleanup(entityLoadContext);
LOG.failSafeEntitiesCleanup(entityLoadContext);
entityLoadContext.cleanup();
}
entityLoadContexts.clear();

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Set;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.ObjectDeletedException;
import org.hibernate.PropertyValueException;
import org.hibernate.StaleObjectStateException;

View File

@ -169,7 +169,7 @@ public class MultipleHiLoPerTableGenerator
rs.close();
}
catch (SQLException sqle) {
LOG.error(LOG.unableToReadOrInitHiValue(), sqle);
LOG.unableToReadOrInitHiValue(sqle);
throw sqle;
}
finally {

View File

@ -198,7 +198,7 @@ public class TableGenerator extends TransactionHelper
rs.close();
}
catch (SQLException sqle) {
LOG.error(LOG.unableToReadHiValue(), sqle);
LOG.error(LOG.unableToReadHiValue(tableName), sqle);
throw sqle;
}
finally {

View File

@ -503,7 +503,7 @@ public class TableGenerator extends TransactionHelper implements PersistentIdent
selectRS.close();
}
catch ( SQLException sqle ) {
LOG.error(LOG.unableToReadOrInitHiValue(), sqle);
LOG.unableToReadOrInitHiValue(sqle);
throw sqle;
}
finally {
@ -526,7 +526,7 @@ public class TableGenerator extends TransactionHelper implements PersistentIdent
rows = updatePS.executeUpdate();
}
catch ( SQLException sqle ) {
LOG.error(LOG.unableToUpdateQueryHiValue(tableName), sqle);
LOG.unableToUpdateQueryHiValue(tableName, sqle);
throw sqle;
}
finally {

View File

@ -178,7 +178,7 @@ public class TableStructure extends TransactionHelper implements DatabaseStructu
selectRS.close();
}
catch ( SQLException sqle ) {
LOG.error(LOG.unableToReadHiValue(), sqle);
LOG.error(LOG.unableToReadHiValue(tableName), sqle);
throw sqle;
}
finally {
@ -195,7 +195,7 @@ public class TableStructure extends TransactionHelper implements DatabaseStructu
rows = updatePS.executeUpdate();
}
catch ( SQLException sqle ) {
LOG.error(LOG.unableToUpdateQueryHiValue(tableName), sqle);
LOG.unableToUpdateQueryHiValue(tableName, sqle);
throw sqle;
}
finally {

View File

@ -30,6 +30,7 @@ import java.sql.SQLException;
import java.util.NoSuchElementException;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.Logger;
import org.hibernate.engine.HibernateIterator;
import org.hibernate.event.EventSource;
import org.hibernate.hql.HolderInstantiator;
@ -90,7 +91,7 @@ public final class IteratorImpl implements HibernateIterator {
hasNext = false;
}
catch (SQLException e) {
log.info( "Unable to close iterator", e );
LOG.info(LOG.unableToCloseIterator(), e);
throw session.getFactory().getSQLExceptionHelper().convert(
e,
"Unable to close iterator"

View File

@ -413,7 +413,7 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
HibernateException e = ( HibernateException ) errors.get( queryName );
failingQueries.append( queryName );
if (iterator.hasNext()) failingQueries.append(", ");
LOG.error(LOG.namedQueryError(queryName), e);
LOG.namedQueryError(queryName, e);
}
throw new HibernateException( failingQueries.toString() );
}
@ -1231,7 +1231,7 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
.newInstance( new Object[] { this } );
}
catch( Throwable t ) {
LOG.error(LOG.unableToConstructCurrentSessionContext(impl), t);
LOG.unableToConstructCurrentSessionContext(impl, t);
return null;
}
}

View File

@ -108,7 +108,7 @@ public class SessionFactoryObjectFactory implements ObjectFactory {
( (EventContext) ctx ).addNamingListener(name, EventContext.OBJECT_SCOPE, LISTENER);
}
catch (InvalidNameException ine) {
LOG.error(LOG.invalidJndiName(name), ine);
LOG.invalidJndiName(name, ine);
}
catch (NamingException ne) {
LOG.warn(LOG.unableToBindFactoryToJndi(), ne);
@ -131,7 +131,7 @@ public class SessionFactoryObjectFactory implements ObjectFactory {
LOG.factoryUnboundFromJndiName(name);
}
catch (InvalidNameException ine) {
LOG.error(LOG.invalidJndiName(name), ine);
LOG.invalidJndiName(name, ine);
}
catch (NamingException ne) {
LOG.warn(LOG.unableToUnbindFactoryFromJndi(), ne);

View File

@ -556,7 +556,7 @@ public final class SessionImpl extends AbstractSessionImpl
interceptor.beforeTransactionCompletion(tx);
}
catch (Throwable t) {
LOG.error(LOG.exceptionInBeforeTransactionCompletionInterceptor(), t);
LOG.exceptionInBeforeTransactionCompletionInterceptor(t);
}
}
}
@ -587,7 +587,7 @@ public final class SessionImpl extends AbstractSessionImpl
interceptor.afterTransactionCompletion(tx);
}
catch (Throwable t) {
LOG.error(LOG.exceptionInAfterTransactionCompletionInterceptor(), t);
LOG.exceptionInAfterTransactionCompletionInterceptor(t);
}
}
if ( autoClear ) {

View File

@ -189,7 +189,7 @@ public final class JndiHelper {
new InitialContext(hash);
}
catch (NamingException e) {
LOG.error(LOG.unableToObtainInitialContext(), e);
LOG.unableToObtainInitialContext(e);
throw e;
}
}

View File

@ -1,598 +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 org.hibernate.jdbc;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.TRACE;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.util.JDBCExceptionReporter;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* Encapsulates JDBC Connection management logic needed by Hibernate.
* <p/>
* The lifecycle is intended to span a logical series of interactions with the
* database. Internally, this means the the lifecycle of the Session.
*
* @author Steve Ebersole
*/
public class ConnectionManager implements Serializable {
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
ConnectionManager.class.getPackage().getName());
public static interface Callback {
public void connectionOpened();
public void connectionCleanedUp();
public boolean isTransactionInProgress();
}
private transient SessionFactoryImplementor factory;
private final Callback callback;
private final ConnectionReleaseMode releaseMode;
private transient Connection connection;
private transient Connection borrowedConnection;
private final boolean wasConnectionSupplied;
private transient Batcher batcher;
private transient Interceptor interceptor;
private boolean isClosed;
private transient boolean isFlushing;
/**
* Constructs a ConnectionManager.
* <p/>
* This is the form used internally.
*
* @param factory The SessionFactory.
* @param callback An observer for internal state change.
* @param releaseMode The mode by which to release JDBC connections.
* @param connection An externally supplied connection.
*/
public ConnectionManager(
SessionFactoryImplementor factory,
Callback callback,
ConnectionReleaseMode releaseMode,
Connection connection,
Interceptor interceptor) {
this.factory = factory;
this.callback = callback;
this.interceptor = interceptor;
this.batcher = factory.getSettings().getBatcherFactory().createBatcher( this, interceptor );
this.connection = connection;
wasConnectionSupplied = ( connection != null );
this.releaseMode = wasConnectionSupplied ? ConnectionReleaseMode.ON_CLOSE : releaseMode;
}
/**
* Private constructor used exclusively from custom serialization
*/
private ConnectionManager(
SessionFactoryImplementor factory,
Callback callback,
ConnectionReleaseMode releaseMode,
Interceptor interceptor,
boolean wasConnectionSupplied,
boolean isClosed) {
this.factory = factory;
this.callback = callback;
this.interceptor = interceptor;
this.batcher = factory.getSettings().getBatcherFactory().createBatcher( this, interceptor );
this.wasConnectionSupplied = wasConnectionSupplied;
this.isClosed = isClosed;
this.releaseMode = wasConnectionSupplied ? ConnectionReleaseMode.ON_CLOSE : releaseMode;
}
/**
* The session factory.
*
* @return the session factory.
*/
public SessionFactoryImplementor getFactory() {
return factory;
}
/**
* The batcher managed by this ConnectionManager.
*
* @return The batcher.
*/
public Batcher getBatcher() {
return batcher;
}
/**
* Was the connection being used here supplied by the user?
*
* @return True if the user supplied the JDBC connection; false otherwise
*/
public boolean isSuppliedConnection() {
return wasConnectionSupplied;
}
/**
* Retrieves the connection currently managed by this ConnectionManager.
* <p/>
* Note, that we may need to obtain a connection to return here if a
* connection has either not yet been obtained (non-UserSuppliedConnectionProvider)
* or has previously been aggressively released (if supported in this environment).
*
* @return The current Connection.
*
* @throws HibernateException Indicates a connection is currently not
* available (we are currently manually disconnected).
*/
public Connection getConnection() throws HibernateException {
if ( isClosed ) {
throw new HibernateException( "connection manager has been closed" );
}
if ( connection == null ) {
openConnection();
}
return connection;
}
public boolean hasBorrowedConnection() {
// used from testsuite
return borrowedConnection != null;
}
public Connection borrowConnection() {
if ( isClosed ) {
throw new HibernateException( "connection manager has been closed" );
}
if ( isSuppliedConnection() ) {
return connection;
}
else {
if ( borrowedConnection == null ) {
borrowedConnection = BorrowedConnectionProxy.generateProxy( this );
}
return borrowedConnection;
}
}
public void releaseBorrowedConnection() {
if ( borrowedConnection != null ) {
try {
BorrowedConnectionProxy.renderUnuseable( borrowedConnection );
}
finally {
borrowedConnection = null;
}
}
}
/**
* Is the connection considered "auto-commit"?
*
* @return True if we either do not have a connection, or the connection
* really is in auto-commit mode.
*
* @throws SQLException Can be thrown by the Connection.isAutoCommit() check.
*/
public boolean isAutoCommit() throws SQLException {
return connection == null
|| connection.isClosed()
|| connection.getAutoCommit();
}
/**
* Will connections be released after each statement execution?
* <p/>
* Connections will be released after each statement if either:<ul>
* <li>the defined release-mode is {@link ConnectionReleaseMode#AFTER_STATEMENT}; or
* <li>the defined release-mode is {@link ConnectionReleaseMode#AFTER_TRANSACTION} but
* we are in auto-commit mode.
* <p/>
* release-mode = {@link ConnectionReleaseMode#ON_CLOSE} should [b]never[/b] release
* a connection.
*
* @return True if the connections will be released after each statement; false otherwise.
*/
public boolean isAggressiveRelease() {
if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
return true;
}
else if ( releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
boolean inAutoCommitState;
try {
inAutoCommitState = isAutoCommit()&& !callback.isTransactionInProgress();
}
catch( SQLException e ) {
// assume we are in an auto-commit state
inAutoCommitState = true;
}
return inAutoCommitState;
}
return false;
}
/**
* Modified version of {@link #isAggressiveRelease} which does not force a
* transaction check. This is solely used from our {@link #afterTransaction}
* callback, so no need to do the check; plus it seems to cause problems on
* websphere (god i love websphere ;)
* </p>
* It uses this information to decide if an aggressive release was skipped
* do to open resources, and if so forces a release.
*
* @return True if the connections will be released after each statement; false otherwise.
*/
private boolean isAggressiveReleaseNoTransactionCheck() {
if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
return true;
}
else {
boolean inAutoCommitState;
try {
inAutoCommitState = isAutoCommit();
}
catch( SQLException e ) {
// assume we are in an auto-commit state
inAutoCommitState = true;
}
return releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION && inAutoCommitState;
}
}
/**
* Is this ConnectionManager instance "logically" connected. Meaning
* do we either have a cached connection available or do we have the
* ability to obtain a connection on demand.
*
* @return True if logically connected; false otherwise.
*/
public boolean isCurrentlyConnected() {
return wasConnectionSupplied ? connection != null : !isClosed;
}
/**
* To be called after execution of each JDBC statement. Used to
* conditionally release the JDBC connection aggressively if
* the configured release mode indicates.
*/
public void afterStatement() {
if ( isAggressiveRelease() ) {
if (isFlushing) LOG.skippingAggressiveReleaseDueToFlushCycle();
else if (batcher.hasOpenResources()) LOG.skippingAggressiveReleaseDueToOpenResources();
else if (borrowedConnection != null) LOG.skippingAggressiveReleaseDueToBorrowedConnection();
else aggressiveRelease();
}
}
/**
* To be called after local transaction completion. Used to conditionally
* release the JDBC connection aggressively if the configured release mode
* indicates.
*/
public void afterTransaction() {
if (isAfterTransactionRelease()) aggressiveRelease();
else if ( isAggressiveReleaseNoTransactionCheck() && batcher.hasOpenResources() ) {
LOG.forcingBatcherResourceCleanup();
batcher.closeStatements();
aggressiveRelease();
} else if (isOnCloseRelease()) LOG.transactionCompletedWithOnCloseConnectionReleaseMode();
batcher.unsetTransactionTimeout();
}
private boolean isAfterTransactionRelease() {
return releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION;
}
private boolean isOnCloseRelease() {
return releaseMode == ConnectionReleaseMode.ON_CLOSE;
}
/**
* To be called after Session completion. Used to release the JDBC
* connection.
*
* @return The connection mantained here at time of close. Null if
* there was no connection cached internally.
*/
public Connection close() {
try {
return cleanup();
}
finally {
isClosed = true;
}
}
/**
* Manually disconnect the underlying JDBC Connection. The assumption here
* is that the manager will be reconnected at a later point in time.
*
* @return The connection mantained here at time of disconnect. Null if
* there was no connection cached internally.
*/
public Connection manualDisconnect() {
return cleanup();
}
/**
* Manually reconnect the underlying JDBC Connection. Should be called at
* some point after manualDisconnect().
* <p/>
* This form is used for ConnectionProvider-supplied connections.
*/
public void manualReconnect() {
}
/**
* Manually reconnect the underlying JDBC Connection. Should be called at
* some point after manualDisconnect().
* <p/>
* This form is used for user-supplied connections.
*/
public void manualReconnect(Connection suppliedConnection) {
this.connection = suppliedConnection;
}
/**
* Releases the Connection and cleans up any resources associated with
* that Connection. This is intended for use:
* 1) at the end of the session
* 2) on a manual disconnect of the session
* 3) from afterTransaction(), in the case of skipped aggressive releasing
*
* @return The released connection.
* @throws HibernateException
*/
private Connection cleanup() throws HibernateException {
releaseBorrowedConnection();
if ( connection == null ) {
LOG.connectionAlreadyNullInCleanup();
return null;
}
try {
LOG.performingCleanup();
batcher.closeStatements();
Connection c = null;
if ( !wasConnectionSupplied ) {
closeConnection();
}
else {
c = connection;
}
connection = null;
return c;
}
finally {
callback.connectionCleanedUp();
}
}
/**
* Performs actions required to perform an aggressive release of the
* JDBC Connection.
*/
private void aggressiveRelease() {
if ( !wasConnectionSupplied ) {
LOG.aggressivelyReleasingJdbcConnection();
if (connection != null) closeConnection();
}
}
/**
* Pysically opens a JDBC Connection.
*
* @throws HibernateException
*/
private void openConnection() throws HibernateException {
if (connection != null) return;
LOG.openingJdbcConnection();
try {
connection = factory.getConnectionProvider().getConnection();
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
factory.getSQLExceptionConverter(),
sqle,
"Cannot open connection"
);
}
callback.connectionOpened(); // register synch; stats.connect()
}
/**
* Physically closes the JDBC Connection.
*/
private void closeConnection() {
if (LOG.isDebugEnabled()) LOG.releasingJdbcConnection(batcher.openResourceStatsAsString());
try {
if ( !connection.isClosed() ) {
JDBCExceptionReporter.logAndClearWarnings( connection );
}
factory.getConnectionProvider().closeConnection( connection );
connection = null;
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
factory.getSQLExceptionConverter(),
sqle,
"Cannot release connection"
);
}
}
/**
* Callback to let us know that a flush is beginning. We use this fact
* to temporarily circumvent aggressive connection releasing until after
* the flush cycle is complete {@link #flushEnding()}
*/
public void flushBeginning() {
LOG.registeringFlushBegin();
isFlushing = true;
}
/**
* Callback to let us know that a flush is ending. We use this fact to
* stop circumventing aggressive releasing connections.
*/
public void flushEnding() {
LOG.registeringFlushEnd();
isFlushing = false;
afterStatement();
}
public boolean isReadyForSerialization() {
return wasConnectionSupplied ? connection == null : !batcher.hasOpenResources();
}
/**
* Used during serialization.
*
* @param oos The stream to which we are being written.
* @throws IOException Indicates an I/O error writing to the stream
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
if ( !isReadyForSerialization() ) {
throw new IllegalStateException( "Cannot serialize a ConnectionManager while connected" );
}
oos.writeObject( factory );
oos.writeObject( interceptor );
oos.defaultWriteObject();
}
/**
* Used during deserialization.
*
* @param ois The stream from which we are being read.
* @throws IOException Indicates an I/O error reading the stream
* @throws ClassNotFoundException Indicates resource class resolution.
*/
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
factory = (SessionFactoryImplementor) ois.readObject();
interceptor = (Interceptor) ois.readObject();
ois.defaultReadObject();
this.batcher = factory.getSettings().getBatcherFactory().createBatcher( this, interceptor );
}
public void serialize(ObjectOutputStream oos) throws IOException {
oos.writeBoolean( wasConnectionSupplied );
oos.writeBoolean( isClosed );
}
public static ConnectionManager deserialize(
ObjectInputStream ois,
SessionFactoryImplementor factory,
Interceptor interceptor,
ConnectionReleaseMode connectionReleaseMode,
JDBCContext jdbcContext) throws IOException {
return new ConnectionManager(
factory,
jdbcContext,
connectionReleaseMode,
interceptor,
ois.readBoolean(),
ois.readBoolean()
);
}
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
interface Logger extends BasicLogger {
@LogMessage( level = DEBUG )
@Message( value = "Aggressively releasing JDBC connection" )
void aggressivelyReleasingJdbcConnection();
@LogMessage( level = TRACE )
@Message( value = "Connection already null in cleanup : no action" )
void connectionAlreadyNullInCleanup();
@LogMessage( level = INFO )
@Message( value = "Forcing batcher resource cleanup on transaction completion; forgot to close ScrollableResults/Iterator?" )
void forcingBatcherResourceCleanup();
@LogMessage( level = DEBUG )
@Message( value = "Opening JDBC connection" )
void openingJdbcConnection();
@LogMessage( level = TRACE )
@Message( value = "Performing cleanup" )
void performingCleanup();
@LogMessage( level = TRACE )
@Message( value = "Registering flush begin" )
void registeringFlushBegin();
@LogMessage( level = TRACE )
@Message( value = "Registering flush end" )
void registeringFlushEnd();
@LogMessage( level = DEBUG )
@Message( value = "Releasing JDBC connection [%s]" )
void releasingJdbcConnection( String openResourceStatsAsString );
@LogMessage( level = DEBUG )
@Message( value = "Skipping aggresive-release due to borrowed connection" )
void skippingAggressiveReleaseDueToBorrowedConnection();
@LogMessage( level = DEBUG )
@Message( value = "Skipping aggressive-release due to flush cycle" )
void skippingAggressiveReleaseDueToFlushCycle();
@LogMessage( level = DEBUG )
@Message( value = "Skipping aggresive-release due to open resources on batcher" )
void skippingAggressiveReleaseDueToOpenResources();
@LogMessage( level = DEBUG )
@Message( value = "Transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!" )
void transactionCompletedWithOnCloseConnectionReleaseMode();
}
}

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Properties;
import javax.naming.InitialContext;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.internal.ServicesRegistryBootstrap;
@ -50,7 +51,7 @@ public class HibernateService extends ExternalSessionFactoryConfig implements Hi
//context.unbind(boundName);
}
catch (Exception e) {
LOG.warn(LOG.unableToStopService(), e);
LOG.warn(LOG.unableToStopHibernateService(), e);
}
}

View File

@ -73,15 +73,15 @@ public class StatisticsService implements StatisticsServiceMBean {
}
}
catch (NameNotFoundException e) {
LOG.error(LOG.noSessionFactoryWithJndiName(sfJNDIName), e);
LOG.noSessionFactoryWithJndiName(sfJNDIName, e);
setSessionFactory(null);
}
catch (NamingException e) {
LOG.error(LOG.unableToAccessSessionFactory(sfJNDIName), e);
LOG.unableToAccessSessionFactory(sfJNDIName, e);
setSessionFactory(null);
}
catch (ClassCastException e) {
LOG.error(LOG.jndiNameDoesNotHandleSessionFactoryReference(sfJNDIName), e);
LOG.jndiNameDoesNotHandleSessionFactoryReference(sfJNDIName, e);
setSessionFactory(null);
}
}

View File

@ -32,6 +32,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.beans.BeanInfoHelper;
import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -60,14 +61,14 @@ public class ConnectionProviderInitiator implements ServiceInitiator<ConnectionP
"org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider";
public static final String INJECTION_DATA = "hibernate.connection_provider.injection_data";
// mapping from legacy connection provider name to actual
// connection provider that will be used
private static final Map<String,String> LEGACY_CONNECTION_PROVIDER_MAPPING;
static {
LEGACY_CONNECTION_PROVIDER_MAPPING = new HashMap<String,String>( 5 );
LEGACY_CONNECTION_PROVIDER_MAPPING.put(
"org.hibernate.connection.DatasourceConnectionProvider",
DatasourceConnectionProviderImpl.class.getName()
@ -82,7 +83,7 @@ public class ConnectionProviderInitiator implements ServiceInitiator<ConnectionP
);
LEGACY_CONNECTION_PROVIDER_MAPPING.put(
"org.hibernate.connection.C3P0ConnectionProvider",
C3P0_PROVIDER_CLASS_NAME
C3P0_PROVIDER_CLASS_NAME
);
LEGACY_CONNECTION_PROVIDER_MAPPING.put(
"org.hibernate.connection.ProxoolConnectionProvider",
@ -170,14 +171,7 @@ public class ConnectionProviderInitiator implements ServiceInitiator<ConnectionP
String providerClassName = ( String ) configurationValues.get( Environment.CONNECTION_PROVIDER );
if ( LEGACY_CONNECTION_PROVIDER_MAPPING.containsKey( providerClassName ) ) {
String actualProviderClassName = LEGACY_CONNECTION_PROVIDER_MAPPING.get( providerClassName );
if ( log.isWarnEnabled() ) {
StringBuffer buf = new StringBuffer()
.append( providerClassName )
.append( " has been deprecated in favor of ")
.append( actualProviderClassName )
.append( "; that provider will be used instead." );
log.warn( buf.toString() );
}
LOG.providerClassDeprecated(providerClassName, actualProviderClassName);
providerClassName = actualProviderClassName;
}
return providerClassName;

View File

@ -25,6 +25,7 @@ package org.hibernate.service.jdbc.dialect.internal;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.hibernate.Logger;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
@ -98,14 +99,14 @@ public class StandardDialectResolver extends AbstractDialectResolver {
if ( databaseName.startsWith( "Microsoft SQL Server" ) ) {
switch ( databaseMajorVersion ) {
case 8:
return new SQLServerDialect();
case 9:
return new SQLServer2005Dialect();
case 10:
return new SQLServer2008Dialect();
default:
log.warn( "Unknown Microsoft SQL Server major version [" + databaseMajorVersion + "] using SQL Server 2000 dialect" );
case 8:
return new SQLServerDialect();
case 9:
return new SQLServer2005Dialect();
case 10:
return new SQLServer2008Dialect();
default:
LOG.unknownSqlServerVersion(databaseMajorVersion);
}
return new SQLServerDialect();
}

View File

@ -537,33 +537,33 @@ public class ConcurrentStatisticsImpl implements Statistics, StatisticsImplement
public void logSummary() {
LOG.loggingStatistics();
LOG.startTime(startTime);
LOG.sessionsOpened(sessionOpenCount);
LOG.sessionsClosed(sessionCloseCount);
LOG.transactions(transactionCount);
LOG.successfulTransactions(committedTransactionCount);
LOG.optimisticLockFailures(optimisticFailureCount);
LOG.flushes(flushCount);
LOG.connectionsObtained(connectCount);
LOG.statementsPrepared(prepareStatementCount);
LOG.statementsClosed(closeStatementCount);
LOG.secondLevelCachePuts(secondLevelCachePutCount);
LOG.secondLevelCacheHits(secondLevelCacheHitCount);
LOG.secondLevelCacheMisses(secondLevelCacheMissCount);
LOG.entitiesLoaded(entityLoadCount);
LOG.entitiesUpdated(entityUpdateCount);
LOG.entitiesInserted(entityInsertCount);
LOG.entitiesDeleted(entityDeleteCount);
LOG.entitiesFetched(entityFetchCount);
LOG.collectionsLoaded(collectionLoadCount);
LOG.collectionsUpdated(collectionUpdateCount);
LOG.collectionsRemoved(collectionRemoveCount);
LOG.collectionsRecreated(collectionRecreateCount);
LOG.collectionsFetched(collectionFetchCount);
LOG.queriesExecuted(queryExecutionCount);
LOG.queryCachePuts(queryCachePutCount);
LOG.queryCacheHits(queryCacheHitCount);
LOG.queryCacheMisses(queryCacheMissCount);
LOG.maxQueryTime(queryExecutionMaxTime);
LOG.sessionsOpened(sessionOpenCount.get());
LOG.sessionsClosed(sessionCloseCount.get());
LOG.transactions(transactionCount.get());
LOG.successfulTransactions(committedTransactionCount.get());
LOG.optimisticLockFailures(optimisticFailureCount.get());
LOG.flushes(flushCount.get());
LOG.connectionsObtained(connectCount.get());
LOG.statementsPrepared(prepareStatementCount.get());
LOG.statementsClosed(closeStatementCount.get());
LOG.secondLevelCachePuts(secondLevelCachePutCount.get());
LOG.secondLevelCacheHits(secondLevelCacheHitCount.get());
LOG.secondLevelCacheMisses(secondLevelCacheMissCount.get());
LOG.entitiesLoaded(entityLoadCount.get());
LOG.entitiesUpdated(entityUpdateCount.get());
LOG.entitiesInserted(entityInsertCount.get());
LOG.entitiesDeleted(entityDeleteCount.get());
LOG.entitiesFetched(entityFetchCount.get());
LOG.collectionsLoaded(collectionLoadCount.get());
LOG.collectionsUpdated(collectionUpdateCount.get());
LOG.collectionsRemoved(collectionRemoveCount.get());
LOG.collectionsRecreated(collectionRecreateCount.get());
LOG.collectionsFetched(collectionFetchCount.get());
LOG.queriesExecuted(queryExecutionCount.get());
LOG.queryCachePuts(queryCachePutCount.get());
LOG.queryCacheHits(queryCacheHitCount.get());
LOG.queryCacheMisses(queryCacheMissCount.get());
LOG.maxQueryTime(queryExecutionMaxTime.get());
}
/**

View File

@ -287,7 +287,7 @@ public class SchemaExport {
catch ( Exception e ) {
exceptions.add( e );
LOG.error(LOG.schemaExportUnsuccessful(), e);
LOG.schemaExportUnsuccessful(e);
}
finally {
@ -302,7 +302,7 @@ public class SchemaExport {
}
catch ( Exception e ) {
exceptions.add( e );
LOG.error(LOG.unableToCloseConnection(), e);
LOG.unableToCloseConnection(e);
}
try {
@ -312,19 +312,16 @@ public class SchemaExport {
}
catch ( IOException ioe ) {
exceptions.add( ioe );
LOG.error(LOG.unableToCloseOutputFile(outputFile), ioe);
LOG.unableToCloseOutputFile(outputFile, ioe);
}
for (NamedReader reader : importFileReaders) {
try {
reader.getReader().close();
}
catch ( IOException ioe ) {
exceptions.add( ioe );
LOG.error(LOG.unableToCloseInputFiles(reader.getName()), ioe);
}
for (NamedReader reader : importFileReaders) {
try {
reader.getReader().close();
} catch (IOException ioe) {
exceptions.add(ioe);
LOG.unableToCloseInputFiles(reader.getName(), ioe);
}
}
}
}
@ -522,7 +519,7 @@ public class SchemaExport {
}
catch ( Exception e ) {
LOG.error(LOG.unableToCreateSchema(), e);
LOG.unableToCreateSchema(e);
e.printStackTrace();
}
}

View File

@ -139,7 +139,7 @@ public class SchemaUpdate {
new SchemaUpdate( cfg ).execute( script, doUpdate );
}
catch ( Exception e ) {
LOG.error(LOG.unableToRunSchemaUpdate(), e);
LOG.unableToRunSchemaUpdate(e);
e.printStackTrace();
}
}
@ -171,7 +171,7 @@ public class SchemaUpdate {
}
catch ( SQLException sqle ) {
exceptions.add( sqle );
LOG.error(LOG.unableToGetDatabaseMetadata(), sqle);
LOG.unableToGetDatabaseMetadata(sqle);
throw sqle;
}
@ -218,7 +218,7 @@ public class SchemaUpdate {
}
catch ( Exception e ) {
exceptions.add( e );
LOG.error(LOG.unableToCompleteSchemaUpdate(), e);
LOG.unableToCompleteSchemaUpdate(e);
}
finally {
@ -230,7 +230,7 @@ public class SchemaUpdate {
}
catch ( Exception e ) {
exceptions.add( e );
LOG.error(LOG.unableToCloseConnection(), e);
LOG.unableToCloseConnection(e);
}
try {
if( outputFileWriter != null ) {
@ -239,7 +239,7 @@ public class SchemaUpdate {
}
catch(Exception e) {
exceptions.add(e);
LOG.error(LOG.unableToCloseConnection(), e);
LOG.unableToCloseConnection(e);
}
}
}

View File

@ -108,7 +108,7 @@ public class SchemaValidator {
new SchemaValidator( cfg ).validate();
}
catch ( Exception e ) {
LOG.error(LOG.unableToRunSchemaUpdate(), e);
LOG.unableToRunSchemaUpdate(e);
e.printStackTrace();
}
}
@ -132,7 +132,7 @@ public class SchemaValidator {
meta = new DatabaseMetadata( connection, dialect, false );
}
catch ( SQLException sqle ) {
LOG.error(LOG.unableToGetDatabaseMetadata(), sqle);
LOG.unableToGetDatabaseMetadata(sqle);
throw sqle;
}
@ -140,7 +140,7 @@ public class SchemaValidator {
}
catch ( SQLException e ) {
LOG.error(LOG.unableToCompleteSchemaValidation(), e);
LOG.unableToCompleteSchemaValidation(e);
}
finally {
@ -148,7 +148,7 @@ public class SchemaValidator {
connectionHelper.release();
}
catch ( Exception e ) {
LOG.error(LOG.unableToCloseConnection(), e);
LOG.unableToCloseConnection(e);
}
}

View File

@ -115,7 +115,7 @@ public class CMTTransaction implements Transaction {
getTransaction().setRollbackOnly();
}
catch (SystemException se) {
LOG.error(LOG.unableToSetTransactionToRollbackOnly(), se);
LOG.unableToSetTransactionToRollbackOnly(se);
throw new TransactionException("Could not set transaction to rollback only", se);
}

View File

@ -100,7 +100,7 @@ public final class CacheSynchronization implements Synchronization {
transaction.setRollbackOnly();
}
catch (SystemException se) {
LOG.error(LOG.unableToSetTransactionToRollbackOnly(), se);
LOG.unableToSetTransactionToRollbackOnly(se);
}
}

View File

@ -109,7 +109,7 @@ public class JDBCTransaction implements Transaction {
transactionContext.managedClose();
}
catch (HibernateException he) {
LOG.error(LOG.unableToCloseSession(), he);
LOG.unableToCloseSession(he);
//swallow, the transaction was finished
}
}
@ -221,7 +221,7 @@ public class JDBCTransaction implements Transaction {
}
}
catch (Exception sqle) {
LOG.error(LOG.unableToToggleAutoCommit(), sqle);
LOG.unableToToggleAutoCommit(sqle);
//swallow it (the transaction _was_ successful or successfully rolled back)
}
}

View File

@ -185,7 +185,7 @@ public class JTATransaction implements Transaction {
}
catch ( Exception e ) {
// swallow it, and continue to roll back JTA transaction
LOG.error(LOG.unableToCloseSessionDuringRollback(), e);
LOG.unableToCloseSessionDuringRollback(e);
}
try {

View File

@ -63,16 +63,16 @@ public final class TransactionFactoryFactory {
factory = ( TransactionFactory ) ReflectHelper.classForName( strategyClassName ).newInstance();
}
catch ( ClassNotFoundException e ) {
LOG.error(LOG.transactionFactoryClassNotFound(), e);
LOG.error(LOG.transactionFactoryClassNotFound(strategyClassName), e);
throw new HibernateException(LOG.transactionFactoryClassNotFound(strategyClassName));
}
catch ( IllegalAccessException e ) {
LOG.error(LOG.unableToInstantiateTransactionFactory(), e);
throw new HibernateException(LOG.unableToInstantiateTransactionFactory(e));
throw new HibernateException(LOG.unableToInstantiateTransactionFactory(), e);
}
catch ( java.lang.InstantiationException e ) {
LOG.error(LOG.unableToInstantiateTransactionFactory(), e);
throw new HibernateException(LOG.unableToInstantiateTransactionFactory(e));
throw new HibernateException(LOG.unableToInstantiateTransactionFactory(), e);
}
factory.configure( transactionProps );
return factory;

View File

@ -83,7 +83,7 @@ public final class TransactionManagerLookupFactory {
LOG.instantiatedTransactionManagerLookup();
return lookup;
} catch (Exception e) {
LOG.error(LOG.unableToInstantiateTransactionManagerLookup(), e);
LOG.error(LOG.unableToInstantiateTransactionManagerLookup(tmLookupClass), e);
throw new HibernateException(LOG.unableToInstantiateTransactionManagerLookup(tmLookupClass));
}
}

View File

@ -129,7 +129,7 @@ public class CallbackCoordinator {
}
catch ( SystemException se ) {
// best effort
LOG.error( LOG.unableToSetTransactionToRollbackOnly(), se );
LOG.unableToSetTransactionToRollbackOnly(se);
}
}
@ -166,7 +166,7 @@ public class CallbackCoordinator {
private static final ExceptionMapper STANDARD_EXCEPTION_MAPPER = new ExceptionMapper() {
public RuntimeException mapStatusCheckFailure(String message, SystemException systemException) {
LOG.unableToDetermineTransactionStatus(systemException.getMessage());
LOG.error(LOG.unableToDetermineTransactionStatus(), systemException);
return new TransactionException( "could not determine transaction status in beforeCompletion()", systemException );
}

View File

@ -24,7 +24,6 @@
*/
package org.hibernate.util;
import static org.hibernate.LogUtil.TMP_LOG;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -118,7 +117,7 @@ public final class SerializationHelper {
throw new IllegalArgumentException( "The OutputStream must not be null" );
}
if (TMP_LOG.isTraceEnabled()) {
if (LOG.isTraceEnabled()) {
if (Hibernate.isInitialized(obj)) LOG.trace("Starting serialization of object [" + obj + "]");
else LOG.trace("Starting serialization of [uninitialized proxy]");
}

View File

@ -86,14 +86,14 @@ public final class XMLHelper {
this.errors = errors;
}
public void error(SAXParseException error) {
LOG.parsingXmlError(file, error.getLineNumber(), error.getMessage());
LOG.parsingXmlErrorForFile(file, error.getLineNumber(), error.getMessage());
errors.add(error);
}
public void fatalError(SAXParseException error) {
error(error);
}
public void warning(SAXParseException warn) {
LOG.parsingXmlWarning(file, warn.getLineNumber(), warn.getMessage());
LOG.parsingXmlWarningForFile(file, warn.getLineNumber(), warn.getMessage());
}
}

View File

@ -69,7 +69,7 @@ public class ErrorLogger implements ErrorHandler, Serializable {
* {@inheritDoc}
*/
public void warning(SAXParseException warn) {
LOG.parsingXmlError(error.getLineNumber(), error.getMessage());
LOG.parsingXmlWarning(error.getLineNumber(), error.getMessage());
}
public void reset() {

View File

@ -1,19 +0,0 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.hibernate;
import org.jboss.logging.BasicLogger;
/**
*
*/
public interface aTestLogger extends BasicLogger {
public static final aTestLogger LOG = org.jboss.logging.Logger.getMessageLogger(aTestLogger.class,
aTestLogger.class.getPackage().getName());
}

View File

@ -1,6 +1,7 @@
//$Id$
package org.hibernate.test.annotations.backquotes;
import static org.hibernate.TestLogger.LOG;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase;

View File

@ -25,7 +25,7 @@
*/
package org.hibernate.test.annotations.fetchprofile;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.InputStream;
import junit.framework.TestCase;
import org.hibernate.MappingException;

View File

@ -1,7 +1,7 @@
// $Id$
package org.hibernate.test.annotations.fkcircularity;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.PrintWriter;
import java.io.StringWriter;
import junit.framework.TestCase;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.id;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.id;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hibernate.cfg.AnnotationConfiguration;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.id.sequences;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.id.sequences;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hibernate.cfg.AnnotationConfiguration;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.immutable;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.AnnotationException;

View File

@ -1,7 +1,7 @@
// $Id$
package org.hibernate.test.annotations.namingstrategy;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.naturalid;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

View File

@ -1,7 +1,7 @@
//$Id: A320.java 14736 2008-06-04 14:23:42Z hardy.ferentschik $
package org.hibernate.test.annotations.onetoone.primarykey;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import junit.framework.TestCase;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.reflection;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import javax.persistence.PostPersist;
import javax.persistence.PrePersist;

View File

@ -1,7 +1,7 @@
//$Id$
package org.hibernate.test.annotations.reflection;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import javax.persistence.PostPersist;
import javax.persistence.PrePersist;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.test.dialect.functional.cache;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;

View File

@ -1,7 +1,7 @@
// $Id: DynamicFilterTest.java 11398 2007-04-10 14:54:07Z steve.ebersole@jboss.com $
package org.hibernate.test.filter;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

View File

@ -1,7 +1,7 @@
// $Id: ASTParserLoadingTest.java 11373 2007-03-29 19:09:07Z steve.ebersole@jboss.com $
package org.hibernate.test.hql;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;

View File

@ -1,7 +1,7 @@
// $Id: BulkManipulationTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.hql;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.test.jdbc.proxies;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

View File

@ -1,6 +1,6 @@
package org.hibernate.test.jpa.cascade;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import junit.framework.Test;
import org.hibernate.Session;
import org.hibernate.TransientObjectException;

View File

@ -1,7 +1,7 @@
//$Id: FooBarTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.Time;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.test.legacy;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

View File

@ -21,7 +21,7 @@
*/
package org.hibernate.test.stateless.fetching;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.Date;
import junit.framework.Test;
import org.hibernate.Hibernate;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.testing.junit;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.testing.junit.functional;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
/**
* {@inheritDoc}

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.testing.junit.functional;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.sql.Connection;
import java.util.Collections;
import java.util.HashMap;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.testing.junit.functional;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.util.Collections;
import java.util.Map;
import junit.framework.Test;

View File

@ -26,7 +26,7 @@
package org.hibernate.testing.junit.functional.annotations;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.testing.tm;
import static org.hibernate.aTestLogger.LOG;
import static org.hibernate.TestLogger.LOG;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.LinkedList;

View File

@ -68,6 +68,7 @@ import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Logger;
import org.hibernate.MappingException;
import org.hibernate.ObjectDeletedException;
import org.hibernate.ObjectNotFoundException;
@ -113,8 +114,8 @@ import org.hibernate.util.ReflectHelper;
@SuppressWarnings("unchecked")
public abstract class AbstractEntityManagerImpl implements HibernateEntityManagerImplementor, Serializable {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
AbstractEntityManagerImpl.class.getName());
private static final List<String> entityManagerSpecificProperties = new ArrayList<String>();
@ -1114,7 +1115,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
}
catch ( Exception ne ) {
//we do not want the subsequent exception to swallow the original one
LOG.error(LOG.unableToMarkForRollbackOnPersistenceException(), ne);
LOG.unableToMarkForRollbackOnPersistenceException(ne);
}
}
@ -1193,7 +1194,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
}
catch ( Exception ne ) {
//we do not want the subsequent exception to swallow the original one
LOG.error(LOG.unableToMarkForRollbackOnTransientObjectException(), ne);
LOG.unableToMarkForRollbackOnTransientObjectException(ne);
}
return new IllegalStateException( e ); //Spec 3.2.3 Synchronization rules
}

View File

@ -46,6 +46,7 @@ import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Logger;
import org.hibernate.TypeMismatchException;
import org.hibernate.ejb.util.CacheModeHelper;
import org.hibernate.ejb.util.ConfigurationHelper;
@ -63,8 +64,7 @@ import org.hibernate.hql.QueryExecutionRequestException;
*/
public abstract class AbstractQueryImpl<X> implements TypedQuery<X> {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, AbstractQueryImpl.class.getName());
private final HibernateEntityManagerImplementor entityManager;

View File

@ -60,6 +60,7 @@ import javax.sql.DataSource;
import org.dom4j.Element;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.Logger;
import org.hibernate.MappingException;
import org.hibernate.MappingNotFoundException;
import org.hibernate.SessionFactory;
@ -117,8 +118,7 @@ import org.xml.sax.InputSource;
*/
public class Ejb3Configuration implements Serializable, Referenceable {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, Ejb3Configuration.class.getName());
private static final String IMPLEMENTATION_NAME = HibernatePersistence.class.getName();
private static final String META_INF_ORM_XML = "META-INF/orm.xml";
private static final String PARSED_MAPPING_DOMS = "hibernate.internal.mapping_doms";

View File

@ -28,6 +28,7 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.transaction.Synchronization;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.Logger;
import org.hibernate.Session;
import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.cfg.Environment;
@ -40,8 +41,8 @@ import org.hibernate.engine.SessionImplementor;
*/
public class EntityManagerImpl extends AbstractEntityManagerImpl {
public static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerImpl.class.getPackage().getName());
public static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
EntityManagerImpl.class.getPackage().getName());
protected Session session;
protected boolean open;

View File

@ -1,172 +0,0 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.hibernate.ejb;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;
import java.net.URL;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;
/**
* Interface defining messages that may be logged by the outer class
*/
@MessageLogger
public interface EntityManagerLogger extends BasicLogger {
@LogMessage( level = INFO )
@Message( value = "Bound Ejb3Configuration to JNDI name: %s" )
void boundEjb3ConfigurationToJndiName( String name );
@LogMessage( level = WARN )
@Message( value = "Calling joinTransaction() on a non JTA EntityManager" )
void callingJoinTransactionOnNonJtaEntityManager();
@LogMessage( level = ERROR )
@Message( value = "Container is providing a null PersistenceUnitRootUrl: discovery impossible" )
void containerProvidingNullPersistenceUnitRootUrl();
@LogMessage( level = WARN )
@Message( value = "Defining %s=true ignored in HEM" )
void definingFlushBeforeCompletionIgnoredInHem( String flushBeforeCompletion );
@LogMessage( level = INFO )
@Message( value = "Ejb3Configuration name: %s" )
void ejb3ConfigurationName( String name );
@LogMessage( level = INFO )
@Message( value = "An Ejb3Configuration was renamed from name: %s" )
void ejb3ConfigurationRenamedFromName( String name );
@LogMessage( level = INFO )
@Message( value = "An Ejb3Configuration was unbound from name: %s" )
void ejb3ConfigurationUnboundFromName( String name );
@LogMessage( level = WARN )
@Message( value = "Entity Manager closed by someone else (%s must not be used)" )
void entityManagerClosedBySomeoneElse( String autoCloseSession );
@LogMessage( level = INFO )
@Message( value = "Hibernate EntityManager %s" )
void entityManagerVersion( String versionString );
@LogMessage( level = INFO )
@Message( value = "%s %s found" )
void exceptionHeaderFound( String exceptionHeader,
String metaInfOrmXml );
@LogMessage( level = INFO )
@Message( value = "%s No %s found" )
void exceptionHeaderNotFound( String exceptionHeader,
String metaInfOrmXml );
@LogMessage( level = WARN )
@Message( value = "Exploded jar file does not exist (ignored): %s" )
void explodedJarDoesNotExist( URL jarUrl );
@LogMessage( level = WARN )
@Message( value = "Exploded jar file not a directory (ignored): %s" )
void explodedJarNotDirectory( URL jarUrl );
@LogMessage( level = INFO )
@Message( value = "Ignoring unrecognized query hint [%s]" )
void ignoringUnrecognizedQueryHint( String hintName );
@LogMessage( level = ERROR )
@Message( value = "Illegal argument on static metamodel field injection : %s#%s; expected type : %s; encountered type : %s" )
void illegalArgumentOnStaticMetamodelFieldInjection( String name,
String name2,
String name3,
String name4 );
@LogMessage( level = WARN )
@Message( value = "InitialContext did not implement EventContext" )
void initialContextDoesNotImplementEventContext();
@Message( value = "Invalid JNDI name: %s" )
Object invalidJndiName( String name );
@LogMessage( level = WARN )
@Message( value = "%s = false break the EJB3 specification" )
void jdbcAutoCommitFalseBreaksEjb3Spec( String autocommit );
@Message( value = "Malformed URL: %s" )
Object malformedUrl( URL jarUrl );
@LogMessage( level = WARN )
@Message( value = "Overriding %s is dangerous, this might break the EJB3 specification implementation" )
void overridingTransactionStrategyDangerous( String transactionStrategy );
@LogMessage( level = WARN )
@Message( value = "Parameter position [%s] occurred as both JPA and Hibernate positional parameter" )
void parameterPositionOccurredAsBothJpaAndHibernatePositionalParameter( Integer position );
@LogMessage( level = WARN )
@Message( value = "Persistence provider caller does not implement the EJB3 spec correctly."
+ "PersistenceUnitInfo.getNewTempClassLoader() is null." )
void persistenceProviderCallerDoesNotImplementEjb3SpecCorrectly();
@LogMessage( level = INFO )
@Message( value = "Processing PersistenceUnitInfo [\n\tname: %s\n\t...]" )
void processingPersistenceUnitInfoName( String persistenceUnitName );
@LogMessage( level = INFO )
@Message( value = "Required a different provider: %s" )
void requiredDifferentProvider( String provider );
@LogMessage( level = WARN )
@Message( value = "Transaction not available on beforeCompletion: assuming valid" )
void transactionNotAvailableOnBeforeCompletion();
@Message( value = "Naming exception occurred accessing Ejb3Configuration" )
Object unableToAccessEjb3Configuration();
@Message( value = "Could not bind Ejb3Configuration to JNDI" )
Object unableToBindEjb3ConfigurationToJndi();
@Message( value = "Could not close input stream" )
Object unableToCloseInputStream();
@LogMessage( level = INFO )
@Message( value = "Unable to determine lock mode value : %s -> %s" )
void unableToDetermineLockModeValue( String hintName,
Object value );
@Message( value = "Unable to find file (ignored): %s" )
Object unableToFindFile( URL jarUrl );
@LogMessage( level = INFO )
@Message( value = "Could not find any META-INF/persistence.xml file in the classpath" )
void unableToFindPersistenceXmlInClasspath();
@LogMessage( level = WARN )
@Message( value = "Cannot join transaction: do not override %s" )
void unableToJoinTransaction( String transactionStrategy );
@LogMessage( level = ERROR )
@Message( value = "Unable to locate static metamodel field : %s#%s" )
void unableToLocateStaticMetamodelField( String name,
String name2 );
@Message( value = "Unable to mark for rollback on PersistenceException: " )
Object unableToMarkForRollbackOnPersistenceException();
@Message( value = "Unable to mark for rollback on TransientObjectException: " )
Object unableToMarkForRollbackOnTransientObjectException();
@LogMessage( level = INFO )
@Message( value = "Unable to resolve mapping file [%s]" )
void unableToResolveMappingFile( String xmlFile );
@LogMessage( level = INFO )
@Message( value = "Using provided datasource" )
void usingProvidedDataSource();
}

View File

@ -46,6 +46,7 @@ import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Logger;
import org.hibernate.QueryParameterException;
import org.hibernate.SQLQuery;
import org.hibernate.TypeMismatchException;
@ -65,8 +66,7 @@ import org.hibernate.impl.AbstractQueryImpl;
*/
public class QueryImpl<X> extends org.hibernate.ejb.AbstractQueryImpl<X> implements TypedQuery<X>, HibernateQuery {
public static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
QueryImpl.class.getPackage().getName());
public static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, QueryImpl.class.getPackage().getName());
private org.hibernate.Query query;
private Set<Integer> jpaPositionalIndices;

View File

@ -24,14 +24,15 @@
//$Id$
package org.hibernate.ejb;
import org.hibernate.Logger;
/**
* @author Emmanuel Bernard
*/
public class Version {
public static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
Version.class.getPackage().getName());
public static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, Version.class.getPackage().getName());
public static String getVersionString() {
return "[WORKING]";

View File

@ -26,8 +26,8 @@ import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.HibernateException;
import org.hibernate.Logger;
import org.hibernate.cfg.Environment;
import org.hibernate.ejb.EntityManagerLogger;
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
/**
@ -42,8 +42,8 @@ import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProvi
*/
public class InjectedDataSourceConnectionProvider extends DatasourceConnectionProviderImpl {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class,
InjectedDataSourceConnectionProvider.class.getName());
private String user;
private String pass;

View File

@ -38,7 +38,7 @@ import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import org.hibernate.ejb.EntityManagerLogger;
import org.hibernate.Logger;
import org.hibernate.ejb.HibernateEntityManagerImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.Type;
@ -55,8 +55,7 @@ import org.hibernate.util.StringHelper;
*/
public class CriteriaQueryCompiler implements Serializable {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, CriteriaQueryCompiler.class.getName());
/**
* Used to describe implicit (not defined in criteria query) parameters.

View File

@ -33,18 +33,17 @@ import javax.persistence.ExcludeDefaultListeners;
import javax.persistence.ExcludeSuperclassListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.PersistenceException;
import org.hibernate.Logger;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMethod;
import org.hibernate.ejb.EntityManagerLogger;
/**
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
*/
public final class CallbackResolver {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, CallbackResolver.class.getName());
private static boolean useAnnotationAnnotatedByListener;

View File

@ -36,8 +36,8 @@ import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.Type;
import org.hibernate.EntityMode;
import org.hibernate.Logger;
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.ejb.EntityManagerLogger;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Map;
@ -62,8 +62,7 @@ import org.hibernate.type.EntityType;
*/
public class AttributeFactory {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, AttributeFactory.class.getName());
private final MetadataContext context;

View File

@ -33,8 +33,8 @@ import java.util.Set;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.SingularAttribute;
import org.hibernate.Logger;
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.ejb.EntityManagerLogger;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
@ -57,8 +57,7 @@ import org.hibernate.mapping.Property;
*/
class MetadataContext {
private static final EntityManagerLogger LOG = org.jboss.logging.Logger.getMessageLogger(EntityManagerLogger.class,
EntityManagerLogger.class.getPackage().getName());
private static final Logger LOG = org.jboss.logging.Logger.getMessageLogger(Logger.class, MetadataContext.class.getName());
private final SessionFactoryImplementor sessionFactory;
private final AttributeFactory attributeFactory = new AttributeFactory( this );

Some files were not shown because too many files have changed in this diff Show More