HHH-8741 - More checkstyle cleanups

This commit is contained in:
Steve Ebersole 2013-11-24 17:20:23 -06:00
parent b103b2a0ad
commit 3a2c9f83e6
4 changed files with 281 additions and 241 deletions

View File

@ -218,13 +218,15 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
private void createCriteriaEntityNameMap() {
// initialize the rootProvider first
CriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider(( Queryable ) sessionFactory.getEntityPersister( rootEntityName ) );
final CriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider(
(Queryable) sessionFactory.getEntityPersister( rootEntityName )
);
criteriaInfoMap.put( rootCriteria, rootProvider);
nameCriteriaInfoMap.put( rootProvider.getName(), rootProvider );
for ( final String key : associationPathCriteriaMap.keySet() ) {
Criteria value = associationPathCriteriaMap.get( key );
CriteriaInfoProvider info = getPathInfo( key );
final Criteria value = associationPathCriteriaMap.get( key );
final CriteriaInfoProvider info = getPathInfo( key );
criteriaInfoMap.put( value, info );
nameCriteriaInfoMap.put( info.getName(), info );
}
@ -240,12 +242,12 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
while ( tokens.hasMoreTokens() ) {
componentPath += tokens.nextToken();
Type type = provider.getType( componentPath );
final Type type = provider.getType( componentPath );
if ( type.isAssociationType() ) {
// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
AssociationType atype = ( AssociationType ) type;
CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null;
Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null;
final AssociationType atype = ( AssociationType ) type;
final CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null;
final Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null;
// is the association a collection of components or value-types? (i.e a colloction of valued types?)
if ( ctype != null && elementType.isComponentType() ) {
provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) );
@ -264,7 +266,8 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
else if ( type.isComponentType() ) {
if (!tokens.hasMoreTokens()) {
throw new QueryException("Criteria objects cannot be created directly on components. Create a criteria on owning entity and use a dotted property to access component property: "+path);
} else {
}
else {
componentPath += '.';
}
}
@ -283,10 +286,11 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
private void createCriteriaSQLAliasMap() {
int i = 0;
for(final Criteria crit : criteriaInfoMap.keySet()){
CriteriaInfoProvider value = criteriaInfoMap.get( crit );
final CriteriaInfoProvider value = criteriaInfoMap.get( crit );
String alias = crit.getAlias();
if ( alias == null ) {
alias = value.getName(); // the entity name
// the entity name
alias = value.getName();
}
criteriaSQLAliasMap.put( crit, StringHelper.generateAlias( alias, i++ ) );
}
@ -299,28 +303,30 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
}
public QueryParameters getQueryParameters() {
LockOptions lockOptions = new LockOptions();
RowSelection selection = new RowSelection();
final RowSelection selection = new RowSelection();
selection.setFirstRow( rootCriteria.getFirstResult() );
selection.setMaxRows( rootCriteria.getMaxResults() );
selection.setTimeout( rootCriteria.getTimeout() );
selection.setFetchSize( rootCriteria.getFetchSize() );
final LockOptions lockOptions = new LockOptions();
final Map<String, LockMode> lockModeMap = rootCriteria.getLockModes();
for ( final String key : lockModeMap.keySet() ) {
final Criteria subcriteria = getAliasedCriteria( key );
lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lockModeMap.get( key ) );
}
final List<Object> values = new ArrayList<Object>();
final List<Type> types = new ArrayList<Type>();
final Iterator<CriteriaImpl.Subcriteria> subcriteriaIterator = rootCriteria.iterateSubcriteria();
while ( subcriteriaIterator.hasNext() ) {
CriteriaImpl.Subcriteria subcriteria = subcriteriaIterator.next();
LockMode lm = subcriteria.getLockMode();
final CriteriaImpl.Subcriteria subcriteria = subcriteriaIterator.next();
final LockMode lm = subcriteria.getLockMode();
if ( lm != null ) {
lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lm );
}
if ( subcriteria.getWithClause() != null ) {
TypedValue[] tv = subcriteria.getWithClause().getTypedValues( subcriteria, this );
final TypedValue[] tv = subcriteria.getWithClause().getTypedValues( subcriteria, this );
for ( TypedValue aTv : tv ) {
values.add( aTv.getValue() );
types.add( aTv.getType() );
@ -331,18 +337,18 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
// Type and value gathering for the WHERE clause needs to come AFTER lock mode gathering,
// because the lock mode gathering loop now contains join clauses which can contain
// parameter bindings (as in the HQL WITH clause).
Iterator<CriteriaImpl.CriterionEntry> iter = rootCriteria.iterateExpressionEntries();
final Iterator<CriteriaImpl.CriterionEntry> iter = rootCriteria.iterateExpressionEntries();
while ( iter.hasNext() ) {
CriteriaImpl.CriterionEntry ce = iter.next();
TypedValue[] tv = ce.getCriterion().getTypedValues( ce.getCriteria(), this );
final CriteriaImpl.CriterionEntry ce = iter.next();
final TypedValue[] tv = ce.getCriterion().getTypedValues( ce.getCriteria(), this );
for ( TypedValue aTv : tv ) {
values.add( aTv.getValue() );
types.add( aTv.getType() );
}
}
Object[] valueArray = values.toArray();
Type[] typeArray = ArrayHelper.toTypeArray( types );
final Object[] valueArray = values.toArray();
final Type[] typeArray = ArrayHelper.toTypeArray( types );
return new QueryParameters(
typeArray,
valueArray,
@ -579,26 +585,24 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
* Get the a typed value for the given property value.
*/
@Override
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value)
throws HibernateException {
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value) throws HibernateException {
// Detect discriminator values...
if ( value instanceof Class ) {
Class entityClass = ( Class ) value;
Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() );
final Class entityClass = ( Class ) value;
final Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() );
if ( q != null ) {
Type type = q.getDiscriminatorType();
final Type type = q.getDiscriminatorType();
String stringValue = q.getDiscriminatorSQLValue();
if (stringValue != null && stringValue.length() > 2
&& stringValue.startsWith( "'" )
&& stringValue.endsWith("'")) { // remove the single
// quotes
stringValue = stringValue.substring(1,
stringValue.length() - 1);
&& stringValue.endsWith( "'" )) {
// remove the single quotes
stringValue = stringValue.substring( 1, stringValue.length() - 1 );
}
// Convert the string value into the proper type.
if ( type instanceof StringRepresentableType ) {
StringRepresentableType nullableType = (StringRepresentableType) type;
final StringRepresentableType nullableType = (StringRepresentableType) type;
value = nullableType.fromStringValue( stringValue );
}
else {
@ -611,9 +615,8 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
return new TypedValue( getTypeUsingProjection( subcriteria, propertyName ), value );
}
private PropertyMapping getPropertyMapping(String entityName)
throws MappingException {
CriteriaInfoProvider info = nameCriteriaInfoMap.get(entityName);
private PropertyMapping getPropertyMapping(String entityName) throws MappingException {
final CriteriaInfoProvider info = nameCriteriaInfoMap.get(entityName);
if ( info == null ) {
throw new HibernateException( "Unknown entity: " + entityName );
}
@ -624,8 +627,8 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
@Override
public String getEntityName(Criteria subcriteria, String propertyName) {
if ( propertyName.indexOf( '.' ) > 0 ) {
String root = StringHelper.root( propertyName );
Criteria crit = getAliasedCriteria( root );
final String root = StringHelper.root( propertyName );
final Criteria crit = getAliasedCriteria( root );
if ( crit != null ) {
return getEntityName( crit );
}
@ -635,8 +638,8 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
@Override
public String getSQLAlias(Criteria criteria, String propertyName) {
if ( propertyName.indexOf( '.' ) > 0 ) {
String root = StringHelper.root( propertyName );
Criteria subcriteria = getAliasedCriteria( root );
final String root = StringHelper.root( propertyName );
final Criteria subcriteria = getAliasedCriteria( root );
if ( subcriteria != null ) {
return getSQLAlias( subcriteria );
}
@ -646,9 +649,9 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
@Override
public String getPropertyName(String propertyName) {
if ( propertyName.indexOf( '.' ) > 0 ) {
String root = StringHelper.root( propertyName );
Criteria crit = getAliasedCriteria( root );
if ( crit != null ) {
final String root = StringHelper.root( propertyName );
final Criteria criteria = getAliasedCriteria( root );
if ( criteria != null ) {
return propertyName.substring( root.length() + 1 );
}
}
@ -656,13 +659,13 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
}
public String getWithClause(String path) {
final Criterion crit = withClauseMap.get(path);
return crit == null ? null : crit.toSqlString(getCriteria(path), this);
final Criterion criterion = withClauseMap.get( path );
return criterion == null ? null : criterion.toSqlString( getCriteria( path ), this );
}
public boolean hasRestriction(String path) {
final CriteriaImpl.Subcriteria crit = ( CriteriaImpl.Subcriteria ) getCriteria( path );
return crit != null && crit.hasRestriction();
final CriteriaImpl.Subcriteria subcriteria = (CriteriaImpl.Subcriteria) getCriteria( path );
return subcriteria != null && subcriteria.hasRestriction();
}
}

View File

@ -78,17 +78,14 @@ public class AttributeFactory {
* @param property The Hibernate property descriptor for the attribute
* @param <X> The type of the owner
* @param <Y> The attribute type
*
* @return The built attribute descriptor or null if the attribute is not part of the JPA 2 model (eg backrefs)
*/
@SuppressWarnings({"unchecked"})
public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
if ( property.isSynthetic() ) {
// hide synthetic/virtual properties (fabricated by Hibernate) from the JPA metamodel.
LOG.tracef(
"Skipping synthetic property %s(%s)",
ownerType.getTypeName(),
property.getName()
);
LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() );
return null;
}
LOG.trace( "Building attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
@ -135,14 +132,18 @@ public class AttributeFactory {
* @param property The Hibernate property descriptor for the identifier attribute
* @param <X> The type of the owner
* @param <Y> The attribute type
*
* @return The built attribute descriptor
*/
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(
AbstractIdentifiableType<X> ownerType,
Property property) {
LOG.trace( "Building identifier attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X, Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext,
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata(
attributeContext,
identifierMemberResolver
);
final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
@ -163,10 +164,13 @@ public class AttributeFactory {
* @param property The Hibernate property descriptor for the version attribute
* @param <X> The type of the owner
* @param <Y> The attribute type
*
* @return The built attribute descriptor
*/
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(
AbstractIdentifiableType<X> ownerType,
Property property) {
LOG.trace( "Building version attribute [ownerType.getTypeName()" + "." + "property.getName()]" );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X, Y> attributeMetadata =
@ -187,13 +191,27 @@ public class AttributeFactory {
final Type<E> elementType = getMetaModelType( attributeMetadata.getElementValueContext() );
if ( java.util.Map.class.isAssignableFrom( attributeMetadata.getJavaType() ) ) {
final Type<K> keyType = getMetaModelType( attributeMetadata.getMapKeyValueContext() );
return PluralAttributeImpl.create( attributeMetadata.getOwnerType(), elementType, attributeMetadata.getJavaType(), keyType )
return PluralAttributeImpl.create(
attributeMetadata.getOwnerType(),
elementType,
attributeMetadata.getJavaType(),
keyType
)
.member( attributeMetadata.getMember() )
.property( attributeMetadata.getPropertyMapping() )
.persistentAttributeType( attributeMetadata.getPersistentAttributeType() )
.build();
}
return PluralAttributeImpl.create(attributeMetadata.getOwnerType(), elementType, attributeMetadata.getJavaType(), null).member(attributeMetadata.getMember()).property(attributeMetadata.getPropertyMapping()).persistentAttributeType(attributeMetadata.getPersistentAttributeType()).build();
return PluralAttributeImpl.create(
attributeMetadata.getOwnerType(),
elementType,
attributeMetadata.getJavaType(),
null
)
.member( attributeMetadata.getMember() )
.property( attributeMetadata.getPropertyMapping() )
.persistentAttributeType( attributeMetadata.getPersistentAttributeType() )
.build();
}
@SuppressWarnings("unchecked")
@ -353,6 +371,7 @@ public class AttributeFactory {
/**
* Attribute metadata contract for a non-plural attribute.
*
* @param <X> The owner type
* @param <Y> The attribute type
*/
@ -367,10 +386,12 @@ public class AttributeFactory {
/**
* Attribute metadata contract for a plural attribute.
*
* @param <X> The owner type
* @param <Y> The attribute type (the collection type)
* @param <E> The collection element type
*/
@SuppressWarnings("UnusedDeclaration")
private interface PluralAttributeMetadata<X, Y, E> extends AttributeMetadata<X, Y> {
/**
* Retrieve the JPA collection type classification for this attribute
@ -411,7 +432,7 @@ public class AttributeFactory {
/**
* Retrieve the Hibernate property mapping.
*
* @return The Hibvernate property mapping.
* @return The Hibernate property mapping.
*/
public Property getPropertyMapping();
}
@ -438,7 +459,10 @@ public class AttributeFactory {
private <X, Y> AttributeMetadata<X, Y> determineAttributeMetadata(
AttributeContext<X> attributeContext,
MemberResolver memberResolver) {
LOG.trace("Starting attribute metadata determination [" + attributeContext.getPropertyMapping().getName() + "]");
LOG.trace(
"Starting attribute metadata determination [" + attributeContext.getPropertyMapping()
.getName() + "]"
);
final Member member = memberResolver.resolveMember( attributeContext );
LOG.trace( " Determined member [" + member + "]" );
@ -488,10 +512,14 @@ public class AttributeFactory {
if ( elementValue instanceof Component ) {
elementPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
} else if (elementType.isAssociationType()) {
elementPersistentAttributeType = isManyToMany ? Attribute.PersistentAttributeType.MANY_TO_MANY : Attribute.PersistentAttributeType.ONE_TO_MANY;
}
else if ( elementType.isAssociationType() ) {
elementPersistentAttributeType = isManyToMany ?
Attribute.PersistentAttributeType.MANY_TO_MANY :
Attribute.PersistentAttributeType.ONE_TO_MANY;
persistentAttributeType = elementPersistentAttributeType;
} else {
}
else {
elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
}
@ -510,14 +538,27 @@ public class AttributeFactory {
else {
throw new UnsupportedOperationException( "collection of any not supported yet" );
}
} if (keyValue instanceof Component) keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
else if (keyType.isAssociationType()) keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE;
else keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
} else keyPersistentAttributeType = null;
return new PluralAttributeMetadataImpl(attributeContext.getPropertyMapping(), attributeContext.getOwnerType(),
}
if ( keyValue instanceof Component ) {
keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
}
else if ( keyType.isAssociationType() ) {
keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE;
}
else {
keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
}
}
else {
keyPersistentAttributeType = null;
}
return new PluralAttributeMetadataImpl(
attributeContext.getPropertyMapping(), attributeContext.getOwnerType(),
member, persistentAttributeType, elementPersistentAttributeType,
keyPersistentAttributeType);
} else if (value instanceof OneToMany) {
keyPersistentAttributeType
);
}
else if ( value instanceof OneToMany ) {
// TODO : is this even possible??? Really OneToMany should be describing the
// element value within a o.h.mapping.Collection (see logic branch above)
throw new IllegalArgumentException( "HUH???" );
@ -878,7 +919,9 @@ public class AttributeFactory {
type = ( (MapMember) member ).getType();
}
//this is a raw type
if ( type instanceof Class ) return null;
if ( type instanceof Class ) {
return null;
}
return (ParameterizedType) type;
}
@ -1020,7 +1063,10 @@ public class AttributeFactory {
final Getter getter = entityMetamodel.getTuplizer().getVersionGetter();
return MapAccessor.MapGetter.class.isInstance( getter )
? new MapMember( versionPropertyName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
? new MapMember(
versionPropertyName,
attributeContext.getPropertyMapping().getType().getReturnedClass()
)
: getter.getMember();
}
};

View File

@ -75,10 +75,10 @@ public final class XmlHelper {
* @throws Exception Child was not found or was not unique.
*/
public static Element getUniqueChild(Element element, String tagName) throws Exception {
Iterator goodChildren = getChildrenByTagName( element, tagName );
final Iterator goodChildren = getChildrenByTagName( element, tagName );
if ( goodChildren != null && goodChildren.hasNext() ) {
Element child = (Element) goodChildren.next();
final Element child = (Element) goodChildren.next();
if ( goodChildren.hasNext() ) {
throw new Exception( "expected only one " + tagName + " tag" );
}
@ -117,10 +117,10 @@ public final class XmlHelper {
Element element,
String tagName,
Element defaultElement) throws Exception {
Iterator goodChildren = getChildrenByTagName( element, tagName );
final Iterator goodChildren = getChildrenByTagName( element, tagName );
if ( goodChildren != null && goodChildren.hasNext() ) {
Element child = (Element) goodChildren.next();
final Element child = (Element) goodChildren.next();
if ( goodChildren.hasNext() ) {
throw new Exception( "expected only one " + tagName + " tag" );
}
@ -137,8 +137,7 @@ public final class XmlHelper {
* @param element The element to get the content for.
* @return The content of the element or null.
*/
public static String getElementContent(final Element element)
throws Exception {
public static String getElementContent(final Element element) throws Exception {
return getElementContent( element, null );
}
@ -149,14 +148,13 @@ public final class XmlHelper {
* @param defaultStr The default to return when there is no content.
* @return The content of the element or the default.
*/
public static String getElementContent(Element element, String defaultStr)
throws Exception {
public static String getElementContent(Element element, String defaultStr) throws Exception {
if ( element == null ) {
return defaultStr;
}
NodeList children = element.getChildNodes();
StringBuilder result = new StringBuilder("");
final NodeList children = element.getChildNodes();
final StringBuilder result = new StringBuilder("");
for ( int i = 0; i < children.getLength() ; i++ ) {
if ( children.item( i ).getNodeType() == Node.TEXT_NODE
|| children.item( i ).getNodeType() == Node.CDATA_SECTION_NODE ) {
@ -176,9 +174,7 @@ public final class XmlHelper {
* @param tagName The name of the desired child.
* @return The element content or null.
*/
public static String getUniqueChildContent(
Element element,
String tagName) throws Exception {
public static String getUniqueChildContent(Element element, String tagName) throws Exception {
return getElementContent( getUniqueChild( element, tagName ) );
}
@ -189,9 +185,7 @@ public final class XmlHelper {
* @param tagName The name of the desired child.
* @return The element content or null.
*/
public static String getOptionalChildContent(
Element element,
String tagName) throws Exception {
public static String getOptionalChildContent(Element element, String tagName) throws Exception {
return getElementContent( getOptionalChild( element, tagName ) );
}

View File

@ -132,9 +132,6 @@ import org.hibernate.proxy.HibernateProxy;
import org.hibernate.transform.BasicTransformerAdapter;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:gavin@hibernate.org">Gavin King</a>
* @author Emmanuel Bernard
@ -1623,7 +1620,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
}
// register behavior changes
SynchronizationCallbackCoordinator callbackCoordinator = transactionCoordinator.getSynchronizationCallbackCoordinator();
final SynchronizationCallbackCoordinator callbackCoordinator = transactionCoordinator.getSynchronizationCallbackCoordinator();
callbackCoordinator.setManagedFlushChecker( new ManagedFlushCheckerImpl() );
callbackCoordinator.setExceptionMapper( new CallbackExceptionMapperImpl() );
callbackCoordinator.setAfterCompletionAction( new AfterCompletionActionImpl( session, transactionType ) );
@ -1711,47 +1708,47 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
@Override
public RuntimeException convert(HibernateException e, LockOptions lockOptions) {
if ( e instanceof StaleStateException ) {
PersistenceException converted = wrapStaleStateException( (StaleStateException) e );
final PersistenceException converted = wrapStaleStateException( (StaleStateException) e );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof LockingStrategyException ) {
PersistenceException converted = wrapLockException( e, lockOptions );
final PersistenceException converted = wrapLockException( e, lockOptions );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof org.hibernate.exception.LockTimeoutException ) {
PersistenceException converted = wrapLockException( e, lockOptions );
final PersistenceException converted = wrapLockException( e, lockOptions );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof org.hibernate.PessimisticLockException ) {
PersistenceException converted = wrapLockException( e, lockOptions );
final PersistenceException converted = wrapLockException( e, lockOptions );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof org.hibernate.QueryTimeoutException ) {
QueryTimeoutException converted = new QueryTimeoutException( e.getMessage(), e );
final QueryTimeoutException converted = new QueryTimeoutException( e.getMessage(), e );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof ObjectNotFoundException ) {
EntityNotFoundException converted = new EntityNotFoundException( e.getMessage() );
final EntityNotFoundException converted = new EntityNotFoundException( e.getMessage() );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof org.hibernate.NonUniqueObjectException ) {
EntityExistsException converted = new EntityExistsException( e.getMessage() );
final EntityExistsException converted = new EntityExistsException( e.getMessage() );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof org.hibernate.NonUniqueResultException ) {
NonUniqueResultException converted = new NonUniqueResultException( e.getMessage() );
final NonUniqueResultException converted = new NonUniqueResultException( e.getMessage() );
handlePersistenceException( converted );
return converted;
}
else if ( e instanceof UnresolvableObjectException ) {
EntityNotFoundException converted = new EntityNotFoundException( e.getMessage() );
final EntityNotFoundException converted = new EntityNotFoundException( e.getMessage() );
handlePersistenceException( converted );
return converted;
}
@ -1769,7 +1766,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
return new IllegalStateException( e ); //Spec 3.2.3 Synchronization rules
}
else {
PersistenceException converted = new PersistenceException( e );
final PersistenceException converted = new PersistenceException( e );
handlePersistenceException( converted );
return converted;
}
@ -1784,11 +1781,11 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
public PersistenceException wrapStaleStateException(StaleStateException e) {
PersistenceException pe;
if ( e instanceof StaleObjectStateException ) {
StaleObjectStateException sose = ( StaleObjectStateException ) e;
Serializable identifier = sose.getIdentifier();
final StaleObjectStateException sose = ( StaleObjectStateException ) e;
final Serializable identifier = sose.getIdentifier();
if ( identifier != null ) {
try {
Object entity = internalGetSession().load( sose.getEntityName(), identifier );
final Object entity = internalGetSession().load( sose.getEntityName(), identifier );
if ( entity instanceof Serializable ) {
//avoid some user errors regarding boundary crossing
pe = new OptimisticLockException( e.getMessage(), e, entity );
@ -1821,7 +1818,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
pe = new LockTimeoutException( e.getMessage(), e, null );
}
else if ( e instanceof PessimisticEntityLockException ) {
PessimisticEntityLockException lockException = (PessimisticEntityLockException) e;
final PessimisticEntityLockException lockException = (PessimisticEntityLockException) e;
if ( lockOptions != null && lockOptions.getTimeOut() > -1 ) {
// assume lock timeout occurred if a timeout or NO WAIT was specified
pe = new LockTimeoutException( lockException.getMessage(), lockException, lockException.getEntity() );
@ -1831,7 +1828,7 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
}
}
else if ( e instanceof org.hibernate.PessimisticLockException ) {
org.hibernate.PessimisticLockException jdbcLockException = ( org.hibernate.PessimisticLockException ) e;
final org.hibernate.PessimisticLockException jdbcLockException = ( org.hibernate.PessimisticLockException ) e;
if ( lockOptions != null && lockOptions.getTimeOut() > -1 ) {
// assume lock timeout occurred if a timeout or NO WAIT was specified
pe = new LockTimeoutException( jdbcLockException.getMessage(), jdbcLockException, null );
@ -1873,9 +1870,9 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
private static class ManagedFlushCheckerImpl implements ManagedFlushChecker {
@Override
public boolean shouldDoManagedFlush(TransactionCoordinator coordinator, int jtaStatus) {
return ! coordinator.getTransactionContext().isClosed() &&
! coordinator.getTransactionContext().isFlushModeNever() &&
! JtaStatusHelper.isRollback( jtaStatus );
return !coordinator.getTransactionContext().isClosed()
&& !coordinator.getTransactionContext().isFlushModeNever()
&& !JtaStatusHelper.isRollback( jtaStatus );
}
}