HHH-8159 - Apply fixups indicated by analysis tools
This commit is contained in:
parent
20866585f3
commit
459c061eb6
|
@ -217,7 +217,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
|
|||
// nothing to do
|
||||
}
|
||||
|
||||
private static class EntityCleanup {
|
||||
private static class EntityCleanup implements Serializable {
|
||||
private final EntityRegionAccessStrategy cacheAccess;
|
||||
private final SoftLock cacheLock;
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private static class CollectionCleanup {
|
||||
private static class CollectionCleanup implements Serializable {
|
||||
private final CollectionRegionAccessStrategy cacheAccess;
|
||||
private final SoftLock cacheLock;
|
||||
|
||||
|
@ -247,7 +247,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private class NaturalIdCleanup {
|
||||
private class NaturalIdCleanup implements Serializable {
|
||||
private final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy;
|
||||
private final SoftLock cacheLock;
|
||||
|
||||
|
|
|
@ -2969,7 +2969,7 @@ public final class HbmBinder {
|
|||
boolean inheritable = Boolean
|
||||
.valueOf( metaNode.attributeValue( "inherit" ) )
|
||||
.booleanValue();
|
||||
if ( onlyInheritable & !inheritable ) {
|
||||
if ( onlyInheritable && !inheritable ) {
|
||||
continue;
|
||||
}
|
||||
String name = metaNode.attributeValue( "attribute" );
|
||||
|
|
|
@ -1111,7 +1111,11 @@ public abstract class CollectionBinder {
|
|||
XProperty property,
|
||||
PropertyHolder parentPropertyHolder,
|
||||
Mappings mappings) throws MappingException {
|
||||
PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( collType.getName() );
|
||||
if ( property == null ) {
|
||||
throw new IllegalArgumentException( "null was passed for argument property" );
|
||||
}
|
||||
|
||||
final PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( collType.getName() );
|
||||
final String hqlOrderBy = extractHqlOrderBy( jpaOrderBy );
|
||||
|
||||
boolean isCollectionOfEntities = collectionEntity != null;
|
||||
|
@ -1241,9 +1245,11 @@ public abstract class CollectionBinder {
|
|||
buildOrderByClauseFromHql( hqlOrderBy, collectionEntity, collValue.getRole() )
|
||||
);
|
||||
}
|
||||
ForeignKey fk = property != null ? property.getAnnotation( ForeignKey.class ) : null;
|
||||
final ForeignKey fk = property.getAnnotation( ForeignKey.class );
|
||||
String fkName = fk != null ? fk.inverseName() : "";
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( fkName ) ) element.setForeignKeyName( fkName );
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( fkName ) ) {
|
||||
element.setForeignKeyName( fkName );
|
||||
}
|
||||
}
|
||||
else if ( anyAnn != null ) {
|
||||
//@ManyToAny
|
||||
|
|
|
@ -354,7 +354,7 @@ public class NaturalIdXrefDelegate {
|
|||
/**
|
||||
* Used to put natural id values into collections. Useful mainly to apply equals/hashCode implementations.
|
||||
*/
|
||||
private static class CachedNaturalId {
|
||||
private static class CachedNaturalId implements Serializable {
|
||||
private final EntityPersister persister;
|
||||
private final Object[] values;
|
||||
private final Type[] naturalIdTypes;
|
||||
|
|
|
@ -348,7 +348,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
// snapshot-cached.
|
||||
final int[] props = persister.getNaturalIdentifierProperties();
|
||||
final Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
|
||||
if ( entitySnapshot == NO_ROW ) {
|
||||
if ( entitySnapshot == NO_ROW || entitySnapshot == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
|
||||
private final HashMap<Statement,Set<ResultSet>> xref = new HashMap<Statement,Set<ResultSet>>();
|
||||
private final Set<ResultSet> unassociatedResultSets = new HashSet<ResultSet>();
|
||||
private final SqlExceptionHelper exceptionHelper;
|
||||
private final transient SqlExceptionHelper exceptionHelper;
|
||||
|
||||
private Statement lastQuery;
|
||||
|
||||
|
|
|
@ -33,13 +33,14 @@ import org.hibernate.engine.jdbc.spi.ResultSetWrapper;
|
|||
* Standard Hibernate implementation for wrapping a {@link ResultSet} in a
|
||||
" column name cache" wrapper.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ResultSetWrapperImpl implements ResultSetWrapper {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static ResultSetWrapper INSTANCE = new ResultSetWrapperImpl();
|
||||
public static final ResultSetWrapper INSTANCE = new ResultSetWrapperImpl();
|
||||
|
||||
private ResultSetWrapperImpl() {
|
||||
}
|
||||
|
|
|
@ -44,13 +44,15 @@ import org.hibernate.internal.util.StringHelper;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SqlExceptionHelper {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
SqlExceptionHelper.class.getName()
|
||||
);
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, SqlExceptionHelper.class.getName());
|
||||
private static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
|
||||
private static final String DEFAULT_WARNING_MSG = "SQL Warning";
|
||||
|
||||
public static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
|
||||
public static final String DEFAULT_WARNING_MSG = "SQL Warning";
|
||||
|
||||
public static final SQLExceptionConverter DEFAULT_CONVERTER = new SQLStateConverter(
|
||||
private static final SQLExceptionConverter DEFAULT_CONVERTER = new SQLStateConverter(
|
||||
new ViolatedConstraintNameExtracter() {
|
||||
public String extractConstraintName(SQLException e) {
|
||||
return null;
|
||||
|
@ -93,206 +95,236 @@ public class SqlExceptionHelper {
|
|||
* @param sqlExceptionConverter The converter to use.
|
||||
*/
|
||||
public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter) {
|
||||
this.sqlExceptionConverter = ( sqlExceptionConverter == null ? DEFAULT_CONVERTER : sqlExceptionConverter );
|
||||
this.sqlExceptionConverter = (sqlExceptionConverter == null ? DEFAULT_CONVERTER : sqlExceptionConverter);
|
||||
}
|
||||
|
||||
// SQLException ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// SQLException ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* Convert an SQLException using the current converter, doing some logging first.
|
||||
*
|
||||
* @param sqlException The exception to convert
|
||||
* @param message An error message.
|
||||
* @return The converted exception
|
||||
*/
|
||||
public JDBCException convert( SQLException sqlException,
|
||||
String message ) {
|
||||
return convert(sqlException, message, "n/a");
|
||||
}
|
||||
/**
|
||||
* Convert an SQLException using the current converter, doing some logging first.
|
||||
*
|
||||
* @param sqlException The exception to convert
|
||||
* @param message An error message.
|
||||
*
|
||||
* @return The converted exception
|
||||
*/
|
||||
public JDBCException convert(SQLException sqlException, String message) {
|
||||
return convert( sqlException, message, "n/a" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an SQLException using the current converter, doing some logging first.
|
||||
*
|
||||
* @param sqlException The exception to convert
|
||||
* @param message An error message.
|
||||
* @param sql The SQL being executed when the exception occurred
|
||||
* @return The converted exception
|
||||
*/
|
||||
public JDBCException convert( SQLException sqlException,
|
||||
String message,
|
||||
String sql ) {
|
||||
logExceptions(sqlException, message + " [" + sql + "]");
|
||||
return sqlExceptionConverter.convert(sqlException, message, sql);
|
||||
}
|
||||
/**
|
||||
* Convert an SQLException using the current converter, doing some logging first.
|
||||
*
|
||||
* @param sqlException The exception to convert
|
||||
* @param message An error message.
|
||||
* @param sql The SQL being executed when the exception occurred
|
||||
*
|
||||
* @return The converted exception
|
||||
*/
|
||||
public JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
logExceptions( sqlException, message + " [" + sql + "]" );
|
||||
return sqlExceptionConverter.convert( sqlException, message, sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the given (and any nested) exception.
|
||||
*
|
||||
* @param sqlException The exception to log
|
||||
* @param message The message text to use as a preamble.
|
||||
*/
|
||||
public void logExceptions( SQLException sqlException,
|
||||
String message ) {
|
||||
if (LOG.isEnabled(Level.ERROR)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
message = StringHelper.isNotEmpty(message) ? message : DEFAULT_EXCEPTION_MSG;
|
||||
LOG.debug( message, sqlException );
|
||||
}
|
||||
final boolean warnEnabled = LOG.isEnabled( Level.WARN );
|
||||
while (sqlException != null) {
|
||||
if ( warnEnabled ) {
|
||||
StringBuilder buf = new StringBuilder(30).append("SQL Error: ").append(sqlException.getErrorCode()).append(", SQLState: ").append(sqlException.getSQLState());
|
||||
LOG.warn(buf.toString());
|
||||
}
|
||||
LOG.error(sqlException.getMessage());
|
||||
sqlException = sqlException.getNextException();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Log the given (and any nested) exception.
|
||||
*
|
||||
* @param sqlException The exception to log
|
||||
* @param message The message text to use as a preamble.
|
||||
*/
|
||||
public void logExceptions(
|
||||
SQLException sqlException,
|
||||
String message) {
|
||||
if ( LOG.isEnabled( Level.ERROR ) ) {
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_EXCEPTION_MSG;
|
||||
LOG.debug( message, sqlException );
|
||||
}
|
||||
final boolean warnEnabled = LOG.isEnabled( Level.WARN );
|
||||
while ( sqlException != null ) {
|
||||
if ( warnEnabled ) {
|
||||
LOG.warn( "SQL Error: " + sqlException.getErrorCode() + ", SQLState: " + sqlException.getSQLState() );
|
||||
}
|
||||
LOG.error( sqlException.getMessage() );
|
||||
sqlException = sqlException.getNextException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SQLWarning ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// SQLWarning ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* Contract for handling {@link SQLWarning warnings}
|
||||
*/
|
||||
public static interface WarningHandler {
|
||||
/**
|
||||
* Should processing be done? Allows short-circuiting if not.
|
||||
*
|
||||
* @return True to process warnings, false otherwise.
|
||||
*/
|
||||
public boolean doProcess();
|
||||
/**
|
||||
* Contract for handling {@link SQLWarning warnings}
|
||||
*/
|
||||
public static interface WarningHandler {
|
||||
/**
|
||||
* Should processing be done? Allows short-circuiting if not.
|
||||
*
|
||||
* @return True to process warnings, false otherwise.
|
||||
*/
|
||||
public boolean doProcess();
|
||||
|
||||
/**
|
||||
* Prepare for processing of a {@link SQLWarning warning} stack.
|
||||
* <p/>
|
||||
* Note that the warning here is also the first passed to {@link #handleWarning}
|
||||
*
|
||||
* @param warning The first warning in the stack.
|
||||
*/
|
||||
public void prepare( SQLWarning warning );
|
||||
/**
|
||||
* Prepare for processing of a {@link SQLWarning warning} stack.
|
||||
* <p/>
|
||||
* Note that the warning here is also the first passed to {@link #handleWarning}
|
||||
*
|
||||
* @param warning The first warning in the stack.
|
||||
*/
|
||||
public void prepare(SQLWarning warning);
|
||||
|
||||
/**
|
||||
* Handle an individual warning in the stack.
|
||||
*
|
||||
* @param warning The warning to handle.
|
||||
*/
|
||||
public void handleWarning( SQLWarning warning );
|
||||
}
|
||||
/**
|
||||
* Handle an individual warning in the stack.
|
||||
*
|
||||
* @param warning The warning to handle.
|
||||
*/
|
||||
public void handleWarning(SQLWarning warning);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic support for {@link WarningHandler} implementations which log
|
||||
*/
|
||||
public static abstract class WarningHandlerLoggingSupport implements WarningHandler {
|
||||
public final void handleWarning( SQLWarning warning ) {
|
||||
StringBuilder buf = new StringBuilder(30).append("SQL Warning Code: ").append(warning.getErrorCode()).append(", SQLState: ").append(warning.getSQLState());
|
||||
logWarning(buf.toString(), warning.getMessage());
|
||||
}
|
||||
/**
|
||||
* Basic support for {@link WarningHandler} implementations which handle {@link SQLWarning warnings}
|
||||
*/
|
||||
public abstract static class WarningHandlerLoggingSupport implements WarningHandler {
|
||||
@Override
|
||||
public final void handleWarning(SQLWarning warning) {
|
||||
logWarning(
|
||||
"SQL Warning Code: " + warning.getErrorCode() + ", SQLState: " + warning.getSQLState(),
|
||||
warning.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate to log common details of a {@link SQLWarning warning}
|
||||
*
|
||||
* @param description A description of the warning
|
||||
* @param message The warning message
|
||||
*/
|
||||
protected abstract void logWarning( String description,
|
||||
String message );
|
||||
}
|
||||
/**
|
||||
* Delegate to log common details of a {@link SQLWarning warning}
|
||||
*
|
||||
* @param description A description of the warning
|
||||
* @param message The warning message
|
||||
*/
|
||||
protected abstract void logWarning(String description, String message);
|
||||
}
|
||||
|
||||
public static class StandardWarningHandler extends WarningHandlerLoggingSupport {
|
||||
private final String introMessage;
|
||||
/**
|
||||
* Standard SQLWarning handler for logging warnings
|
||||
*/
|
||||
public static class StandardWarningHandler extends WarningHandlerLoggingSupport {
|
||||
private final String introMessage;
|
||||
|
||||
public StandardWarningHandler( String introMessage ) {
|
||||
this.introMessage = introMessage;
|
||||
}
|
||||
/**
|
||||
* Creates a StandardWarningHandler
|
||||
*
|
||||
* @param introMessage The introduction message for the hierarchy
|
||||
*/
|
||||
public StandardWarningHandler(String introMessage) {
|
||||
this.introMessage = introMessage;
|
||||
}
|
||||
|
||||
public boolean doProcess() {
|
||||
return LOG.isEnabled(Level.WARN);
|
||||
}
|
||||
@Override
|
||||
public boolean doProcess() {
|
||||
return LOG.isEnabled( Level.WARN );
|
||||
}
|
||||
|
||||
public void prepare( SQLWarning warning ) {
|
||||
LOG.debug(introMessage, warning);
|
||||
}
|
||||
@Override
|
||||
public void prepare(SQLWarning warning) {
|
||||
LOG.debug( introMessage, warning );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logWarning( String description,
|
||||
String message ) {
|
||||
LOG.warn(description);
|
||||
LOG.warn(message);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void logWarning(
|
||||
String description,
|
||||
String message) {
|
||||
LOG.warn( description );
|
||||
LOG.warn( message );
|
||||
}
|
||||
}
|
||||
|
||||
public static StandardWarningHandler STANDARD_WARNING_HANDLER = new StandardWarningHandler(DEFAULT_WARNING_MSG);
|
||||
/**
|
||||
* Static access to the standard handler for logging warnings
|
||||
*/
|
||||
public static final StandardWarningHandler STANDARD_WARNING_HANDLER = new StandardWarningHandler( DEFAULT_WARNING_MSG );
|
||||
|
||||
public void walkWarnings( SQLWarning warning,
|
||||
WarningHandler handler ) {
|
||||
if (warning == null || handler.doProcess()) {
|
||||
return;
|
||||
}
|
||||
handler.prepare(warning);
|
||||
while (warning != null) {
|
||||
handler.handleWarning(warning);
|
||||
warning = warning.getNextWarning();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generic algorithm to walk the hierarchy of SQLWarnings
|
||||
*
|
||||
* @param warning The warning to walk
|
||||
* @param handler The handler
|
||||
*/
|
||||
public void walkWarnings(
|
||||
SQLWarning warning,
|
||||
WarningHandler handler) {
|
||||
if ( warning == null || handler.doProcess() ) {
|
||||
return;
|
||||
}
|
||||
handler.prepare( warning );
|
||||
while ( warning != null ) {
|
||||
handler.handleWarning( warning );
|
||||
warning = warning.getNextWarning();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard (legacy) behavior for logging warnings associated with a JDBC {@link Connection} and clearing them.
|
||||
* <p/>
|
||||
* Calls {@link #handleAndClearWarnings(Connection, WarningHandler)} using {@link #STANDARD_WARNING_HANDLER}
|
||||
*
|
||||
* @param connection The JDBC connection potentially containing warnings
|
||||
*/
|
||||
public void logAndClearWarnings( Connection connection ) {
|
||||
handleAndClearWarnings(connection, STANDARD_WARNING_HANDLER);
|
||||
}
|
||||
/**
|
||||
* Standard (legacy) behavior for logging warnings associated with a JDBC {@link Connection} and clearing them.
|
||||
* <p/>
|
||||
* Calls {@link #handleAndClearWarnings(Connection, WarningHandler)} using {@link #STANDARD_WARNING_HANDLER}
|
||||
*
|
||||
* @param connection The JDBC connection potentially containing warnings
|
||||
*/
|
||||
public void logAndClearWarnings(Connection connection) {
|
||||
handleAndClearWarnings( connection, STANDARD_WARNING_HANDLER );
|
||||
}
|
||||
|
||||
/**
|
||||
* General purpose handling of warnings associated with a JDBC {@link Connection}.
|
||||
*
|
||||
* @param connection The JDBC connection potentially containing warnings
|
||||
* @param handler The handler for each individual warning in the stack.
|
||||
* @see #walkWarnings
|
||||
*/
|
||||
@SuppressWarnings( {"ThrowableResultOfMethodCallIgnored"} )
|
||||
public void handleAndClearWarnings( Connection connection,
|
||||
WarningHandler handler ) {
|
||||
try {
|
||||
walkWarnings(connection.getWarnings(), handler);
|
||||
} catch (SQLException sqle) {
|
||||
// workaround for WebLogic
|
||||
LOG.debug("could not log warnings", sqle);
|
||||
}
|
||||
try {
|
||||
// Sybase fail if we don't do that, sigh...
|
||||
connection.clearWarnings();
|
||||
} catch (SQLException sqle) {
|
||||
LOG.debug("could not clear warnings", sqle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* General purpose handling of warnings associated with a JDBC {@link Connection}.
|
||||
*
|
||||
* @param connection The JDBC connection potentially containing warnings
|
||||
* @param handler The handler for each individual warning in the stack.
|
||||
*
|
||||
* @see #walkWarnings
|
||||
*/
|
||||
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
|
||||
public void handleAndClearWarnings(
|
||||
Connection connection,
|
||||
WarningHandler handler) {
|
||||
try {
|
||||
walkWarnings( connection.getWarnings(), handler );
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
// workaround for WebLogic
|
||||
LOG.debug( "could not log warnings", sqle );
|
||||
}
|
||||
try {
|
||||
// Sybase fail if we don't do that, sigh...
|
||||
connection.clearWarnings();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
LOG.debug( "could not clear warnings", sqle );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General purpose handling of warnings associated with a JDBC {@link Statement}.
|
||||
*
|
||||
* @param statement The JDBC statement potentially containing warnings
|
||||
* @param handler The handler for each individual warning in the stack.
|
||||
* @see #walkWarnings
|
||||
*/
|
||||
@SuppressWarnings( {"ThrowableResultOfMethodCallIgnored"} )
|
||||
public void handleAndClearWarnings( Statement statement,
|
||||
WarningHandler handler ) {
|
||||
try {
|
||||
walkWarnings(statement.getWarnings(), handler);
|
||||
} catch (SQLException sqlException) {
|
||||
// workaround for WebLogic
|
||||
LOG.debug("could not log warnings", sqlException);
|
||||
}
|
||||
try {
|
||||
// Sybase fail if we don't do that, sigh...
|
||||
statement.clearWarnings();
|
||||
} catch (SQLException sqle) {
|
||||
LOG.debug("could not clear warnings", sqle);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* General purpose handling of warnings associated with a JDBC {@link Statement}.
|
||||
*
|
||||
* @param statement The JDBC statement potentially containing warnings
|
||||
* @param handler The handler for each individual warning in the stack.
|
||||
*
|
||||
* @see #walkWarnings
|
||||
*/
|
||||
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
|
||||
public void handleAndClearWarnings(
|
||||
Statement statement,
|
||||
WarningHandler handler) {
|
||||
try {
|
||||
walkWarnings( statement.getWarnings(), handler );
|
||||
}
|
||||
catch (SQLException sqlException) {
|
||||
// workaround for WebLogic
|
||||
LOG.debug( "could not log warnings", sqlException );
|
||||
}
|
||||
try {
|
||||
// Sybase fail if we don't do that, sigh...
|
||||
statement.clearWarnings();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
LOG.debug( "could not clear warnings", sqle );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* Copyright (c) 2008, 2013, 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,7 +20,6 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.engine.query.spi;
|
||||
|
||||
|
@ -53,22 +52,30 @@ import org.hibernate.type.Type;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQueryPlan implements Serializable {
|
||||
private final String sourceQuery;
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
NativeSQLQueryPlan.class.getName()
|
||||
);
|
||||
|
||||
private final String sourceQuery;
|
||||
private final SQLCustomQuery customQuery;
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, NativeSQLQueryPlan.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs a NativeSQLQueryPlan
|
||||
*
|
||||
* @param specification The query spec
|
||||
* @param factory The SessionFactory
|
||||
*/
|
||||
public NativeSQLQueryPlan(
|
||||
NativeSQLQuerySpecification specification,
|
||||
SessionFactoryImplementor factory) {
|
||||
this.sourceQuery = specification.getQueryString();
|
||||
|
||||
customQuery = new SQLCustomQuery(
|
||||
this.customQuery = new SQLCustomQuery(
|
||||
specification.getQueryString(),
|
||||
specification.getQueryReturns(),
|
||||
specification.getQuerySpaces(),
|
||||
factory );
|
||||
factory
|
||||
);
|
||||
}
|
||||
|
||||
public String getSourceQuery() {
|
||||
|
|
|
@ -35,19 +35,36 @@ import java.io.Serializable;
|
|||
public final class AssociationKey implements Serializable {
|
||||
private EntityKey ownerKey;
|
||||
private String propertyName;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an AssociationKey
|
||||
*
|
||||
* @param ownerKey The EntityKey of the association owner
|
||||
* @param propertyName The name of the property on the owner which defines the association
|
||||
*/
|
||||
public AssociationKey(EntityKey ownerKey, String propertyName) {
|
||||
this.ownerKey = ownerKey;
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public boolean equals(Object that) {
|
||||
AssociationKey key = (AssociationKey) that;
|
||||
return key.propertyName.equals(propertyName) &&
|
||||
key.ownerKey.equals(ownerKey);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final AssociationKey that = (AssociationKey) o;
|
||||
return ownerKey.equals( that.ownerKey )
|
||||
&& propertyName.equals( that.propertyName );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ownerKey.hashCode() + propertyName.hashCode();
|
||||
int result = ownerKey.hashCode();
|
||||
result = 31 * result + propertyName.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -62,34 +62,26 @@ public final class CollectionKey implements Serializable {
|
|||
|
||||
private CollectionKey(
|
||||
String role,
|
||||
Serializable key,
|
||||
Type keyType,
|
||||
EntityMode entityMode,
|
||||
SessionFactoryImplementor factory) {
|
||||
Serializable key,
|
||||
Type keyType,
|
||||
EntityMode entityMode,
|
||||
SessionFactoryImplementor factory) {
|
||||
this.role = role;
|
||||
this.key = key;
|
||||
this.keyType = keyType;
|
||||
this.entityMode = entityMode;
|
||||
this.factory = factory;
|
||||
this.hashCode = generateHashCode(); //cache the hashcode
|
||||
//cache the hash-code
|
||||
this.hashCode = generateHashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
CollectionKey that = (CollectionKey) other;
|
||||
return that.role.equals(role) &&
|
||||
keyType.isEqual(that.key, key, factory);
|
||||
}
|
||||
|
||||
public int generateHashCode() {
|
||||
private int generateHashCode() {
|
||||
int result = 17;
|
||||
result = 37 * result + role.hashCode();
|
||||
result = 37 * result + keyType.getHashCode(key, factory);
|
||||
result = 37 * result + keyType.getHashCode( key, factory );
|
||||
return result;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
|
@ -99,16 +91,38 @@ public final class CollectionKey implements Serializable {
|
|||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CollectionKey" +
|
||||
MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory );
|
||||
return "CollectionKey"
|
||||
+ MessageHelper.collectionInfoString( factory.getCollectionPersister( role ), key, factory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if ( this == other ) {
|
||||
return true;
|
||||
}
|
||||
if ( other == null || getClass() != other.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final CollectionKey that = (CollectionKey) other;
|
||||
return that.role.equals( role )
|
||||
&& keyType.isEqual( that.key, key, factory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom serialization routine used during serialization of a
|
||||
* Session/PersistenceContext for increased performance.
|
||||
*
|
||||
* @param oos The stream to which we should write the serial data.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void serialize(ObjectOutputStream oos) throws IOException {
|
||||
|
@ -124,19 +138,21 @@ public final class CollectionKey implements Serializable {
|
|||
*
|
||||
* @param ois The stream from which to read the entry.
|
||||
* @param session The session being deserialized.
|
||||
*
|
||||
* @return The deserialized CollectionKey
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static CollectionKey deserialize(
|
||||
ObjectInputStream ois,
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
return new CollectionKey(
|
||||
( String ) ois.readObject(),
|
||||
( Serializable ) ois.readObject(),
|
||||
( Type ) ois.readObject(),
|
||||
EntityMode.parse( ( String ) ois.readObject() ),
|
||||
( session == null ? null : session.getFactory() )
|
||||
(String) ois.readObject(),
|
||||
(Serializable) ois.readObject(),
|
||||
(Type) ois.readObject(),
|
||||
EntityMode.parse( (String) ois.readObject() ),
|
||||
(session == null ? null : session.getFactory())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ public final class EntityKey implements Serializable {
|
|||
|
||||
/**
|
||||
* Construct a unique identifier for an entity class instance.
|
||||
* <p>
|
||||
* <p/>
|
||||
* NOTE : This signature has changed to accommodate both entity mode and multi-tenancy, both of which relate to
|
||||
* the Session to which this key belongs. To help minimize the impact of these changes in the future, the
|
||||
* {@link SessionImplementor#generateEntityKey} method was added to hide the session-specific changes.
|
||||
|
@ -68,7 +68,7 @@ public final class EntityKey implements Serializable {
|
|||
if ( id == null ) {
|
||||
throw new AssertionFailure( "null identifier" );
|
||||
}
|
||||
this.identifier = id;
|
||||
this.identifier = id;
|
||||
this.rootEntityName = persister.getRootEntityName();
|
||||
this.entityName = persister.getEntityName();
|
||||
this.tenantId = tenantId;
|
||||
|
@ -92,11 +92,11 @@ public final class EntityKey implements Serializable {
|
|||
*/
|
||||
private EntityKey(
|
||||
Serializable identifier,
|
||||
String rootEntityName,
|
||||
String entityName,
|
||||
Type identifierType,
|
||||
boolean batchLoadable,
|
||||
SessionFactoryImplementor factory,
|
||||
String rootEntityName,
|
||||
String entityName,
|
||||
Type identifierType,
|
||||
boolean batchLoadable,
|
||||
SessionFactoryImplementor factory,
|
||||
String tenantId) {
|
||||
this.identifier = identifier;
|
||||
this.rootEntityName = rootEntityName;
|
||||
|
@ -129,10 +129,17 @@ public final class EntityKey implements Serializable {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
EntityKey otherKey = (EntityKey) other;
|
||||
return otherKey.rootEntityName.equals(this.rootEntityName) &&
|
||||
identifierType.isEqual(otherKey.identifier, this.identifier, factory) &&
|
||||
EqualsHelper.equals( tenantId, otherKey.tenantId );
|
||||
if ( this == other ) {
|
||||
return true;
|
||||
}
|
||||
if ( other == null || getClass() != other.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final EntityKey otherKey = (EntityKey) other;
|
||||
return otherKey.rootEntityName.equals( this.rootEntityName )
|
||||
&& identifierType.isEqual( otherKey.identifier, this.identifier, factory )
|
||||
&& EqualsHelper.equals( tenantId, otherKey.tenantId );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,8 +149,8 @@ public final class EntityKey implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityKey" +
|
||||
MessageHelper.infoString( factory.getEntityPersister( entityName ), identifier, factory );
|
||||
return "EntityKey" +
|
||||
MessageHelper.infoString( factory.getEntityPersister( entityName ), identifier, factory );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,14 +184,14 @@ public final class EntityKey implements Serializable {
|
|||
*/
|
||||
public static EntityKey deserialize(
|
||||
ObjectInputStream ois,
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
return new EntityKey(
|
||||
( Serializable ) ois.readObject(),
|
||||
(String) ois.readObject(),
|
||||
(Serializable) ois.readObject(),
|
||||
(String) ois.readObject(),
|
||||
( Type ) ois.readObject(),
|
||||
ois.readBoolean(),
|
||||
( session == null ? null : session.getFactory() ),
|
||||
(String) ois.readObject(),
|
||||
(Type) ois.readObject(),
|
||||
ois.readBoolean(),
|
||||
(session == null ? null : session.getFactory()),
|
||||
(String) ois.readObject()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
* outside the context of any influencers. One such example is
|
||||
* anything created by the session factory.
|
||||
*/
|
||||
public static LoadQueryInfluencers NONE = new LoadQueryInfluencers();
|
||||
public static final LoadQueryInfluencers NONE = new LoadQueryInfluencers();
|
||||
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
private String internalFetchProfile;
|
||||
|
|
|
@ -74,12 +74,15 @@ public final class TypedValue implements Serializable {
|
|||
}
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if ( !(other instanceof TypedValue) ) return false;
|
||||
TypedValue that = (TypedValue) other;
|
||||
/*return that.type.equals(type) &&
|
||||
EqualsHelper.equals(that.value, value);*/
|
||||
return type.getReturnedClass() == that.type.getReturnedClass() &&
|
||||
type.isEqual(that.value, value );
|
||||
if ( this == other ) {
|
||||
return true;
|
||||
}
|
||||
if ( other == null || getClass() != other.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
final TypedValue that = (TypedValue) other;
|
||||
return type.getReturnedClass() == that.type.getReturnedClass()
|
||||
&& type.isEqual( that.value, value );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* Copyright (c) 2008, 2013, 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 Middleware LLC.
|
||||
* 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
|
||||
|
@ -20,9 +20,9 @@
|
|||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.loader.custom.sql;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -50,7 +50,7 @@ import org.hibernate.persister.entity.SQLLoadable;
|
|||
* @author Max Andersen
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SQLCustomQuery implements CustomQuery {
|
||||
public class SQLCustomQuery implements CustomQuery, Serializable {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, SQLCustomQuery.class.getName() );
|
||||
|
||||
|
|
Loading…
Reference in New Issue