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.startsWith( "'" )
&& 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,10 +615,9 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
return new TypedValue( getTypeUsingProjection( subcriteria, propertyName ), value );
}
private PropertyMapping getPropertyMapping(String entityName)
throws MappingException {
CriteriaInfoProvider info = nameCriteriaInfoMap.get(entityName);
if (info==null) {
private PropertyMapping getPropertyMapping(String entityName) throws MappingException {
final CriteriaInfoProvider info = nameCriteriaInfoMap.get(entityName);
if ( info == null ) {
throw new HibernateException( "Unknown entity: " + entityName );
}
return info.getPropertyMapping();
@ -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,32 +78,29 @@ 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" })
@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() + "]");
LOG.trace( "Building attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final AttributeMetadata<X,Y> attributeMetadata =
final AttributeMetadata<X, Y> attributeMetadata =
determineAttributeMetadata( attributeContext, normalMemberResolver );
if (attributeMetadata == null) {
if ( attributeMetadata == null ) {
return null;
}
if (attributeMetadata.isPlural()) {
return buildPluralAttribute((PluralAttributeMetadata)attributeMetadata);
if ( attributeMetadata.isPlural() ) {
return buildPluralAttribute( (PluralAttributeMetadata) attributeMetadata );
}
final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>)attributeMetadata;
final Type<Y> metaModelType = getMetaModelType(singularAttributeMetadata.getValueContext());
return new SingularAttributeImpl<X, Y>(
final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>) attributeMetadata;
final Type<Y> metaModelType = getMetaModelType( singularAttributeMetadata.getValueContext() );
return new SingularAttributeImpl<X, Y>(
attributeMetadata.getName(),
attributeMetadata.getJavaType(),
ownerType,
@ -135,15 +132,19 @@ 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) {
LOG.trace("Building identifier attribute [" + ownerType.getTypeName() + "." + property.getName() + "]");
@SuppressWarnings({"unchecked"})
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,
identifierMemberResolver
final SingularAttributeMetadata<X, Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata(
attributeContext,
identifierMemberResolver
);
final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
return new SingularAttributeImpl.Identifier(
@ -163,13 +164,16 @@ 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) {
LOG.trace("Building version attribute [ownerType.getTypeName()" + "." + "property.getName()]");
@SuppressWarnings({"unchecked"})
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 =
final SingularAttributeMetadata<X, Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext, versionMemberResolver );
final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
return new SingularAttributeImpl.Version(
@ -182,21 +186,35 @@ public class AttributeFactory {
);
}
@SuppressWarnings( "unchecked" )
private <X, Y, E, K> AttributeImplementor<X, Y> buildPluralAttribute(PluralAttributeMetadata<X,Y,E> attributeMetadata) {
@SuppressWarnings("unchecked")
private <X, Y, E, K> AttributeImplementor<X, Y> buildPluralAttribute(PluralAttributeMetadata<X, Y, E> attributeMetadata) {
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" )
@SuppressWarnings("unchecked")
private <Y> Type<Y> getMetaModelType(ValueContext typeContext) {
switch ( typeContext.getValueClassification() ) {
case BASIC: {
@ -236,17 +254,17 @@ public class AttributeFactory {
private EntityMetamodel getDeclarerEntityMetamodel(AbstractIdentifiableType<?> ownerType) {
final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
if ( persistenceType == Type.PersistenceType.ENTITY) {
if ( persistenceType == Type.PersistenceType.ENTITY ) {
return context.getSessionFactory()
.getEntityPersister( ownerType.getTypeName() )
.getEntityMetamodel();
}
else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS) {
else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
PersistentClass persistentClass =
context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
return context.getSessionFactory()
.getEntityPersister( persistentClass.getClassName() )
.getEntityMetamodel();
.getEntityPersister( persistentClass.getClassName() )
.getEntityMetamodel();
}
else {
throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
@ -300,7 +318,7 @@ public class AttributeFactory {
* @param <X> The attribute owner type
* @param <Y> The attribute type.
*/
private interface AttributeMetadata<X,Y> {
private interface AttributeMetadata<X, Y> {
/**
* Retrieve the name of the attribute
*
@ -353,10 +371,11 @@ public class AttributeFactory {
/**
* Attribute metadata contract for a non-plural attribute.
*
* @param <X> The owner type
* @param <Y> The attribute type
*/
private interface SingularAttributeMetadata<X,Y> extends AttributeMetadata<X,Y> {
private interface SingularAttributeMetadata<X, Y> extends AttributeMetadata<X, Y> {
/**
* Retrieve the value context for this attribute
*
@ -367,11 +386,13 @@ 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
*/
private interface PluralAttributeMetadata<X,Y,E> extends AttributeMetadata<X,Y> {
@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();
}
@ -434,93 +455,113 @@ public class AttributeFactory {
*
* @return The attribute description
*/
@SuppressWarnings({ "unchecked" })
private <X,Y> AttributeMetadata<X,Y> determineAttributeMetadata(
@SuppressWarnings({"unchecked"})
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 + "]");
LOG.trace( " Determined member [" + member + "]" );
final Value value = attributeContext.getPropertyMapping().getValue();
final org.hibernate.type.Type type = value.getType();
LOG.trace(" Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]");
LOG.trace( " Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]" );
if ( type.isAnyType() ) {
// ANY mappings are currently not supported in the JPA metamodel; see HHH-6589
if ( context.isIgnoreUnsupported() ) {
return null;
}
if ( context.isIgnoreUnsupported() ) {
return null;
}
else {
throw new UnsupportedOperationException( "ANY not supported" );
}
throw new UnsupportedOperationException( "ANY not supported" );
}
}
else if ( type.isAssociationType() ) {
// collection or entity
if ( type.isEntityType() ) {
// entity
return new SingularAttributeMetadataImpl<X,Y>(
return new SingularAttributeMetadataImpl<X, Y>(
attributeContext.getPropertyMapping(),
attributeContext.getOwnerType(),
member,
determineSingularAssociationAttributeType( member )
);
}
// collection
if (value instanceof Collection) {
final Collection collValue = (Collection)value;
final Value elementValue = collValue.getElement();
final org.hibernate.type.Type elementType = elementValue.getType();
// collection
if ( value instanceof Collection ) {
final Collection collValue = (Collection) value;
final Value elementValue = collValue.getElement();
final org.hibernate.type.Type elementType = elementValue.getType();
// First, determine the type of the elements and use that to help determine the
// collection type)
final Attribute.PersistentAttributeType elementPersistentAttributeType;
final Attribute.PersistentAttributeType persistentAttributeType;
if (elementType.isAnyType()) {
if ( context.isIgnoreUnsupported() ) {
return null;
}
else {
throw new UnsupportedOperationException("collection of any not supported yet");
}
}
final boolean isManyToMany = isManyToMany(member);
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;
persistentAttributeType = elementPersistentAttributeType;
} else {
elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
}
// First, determine the type of the elements and use that to help determine the
// collection type)
final Attribute.PersistentAttributeType elementPersistentAttributeType;
final Attribute.PersistentAttributeType persistentAttributeType;
if ( elementType.isAnyType() ) {
if ( context.isIgnoreUnsupported() ) {
return null;
}
else {
throw new UnsupportedOperationException( "collection of any not supported yet" );
}
}
final boolean isManyToMany = isManyToMany( member );
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;
persistentAttributeType = elementPersistentAttributeType;
}
else {
elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
}
final Attribute.PersistentAttributeType keyPersistentAttributeType;
final Attribute.PersistentAttributeType keyPersistentAttributeType;
// Finally, we determine the type of the map key (if needed)
if (value instanceof Map) {
final Value keyValue = ((Map)value).getIndex();
final org.hibernate.type.Type keyType = keyValue.getType();
// Finally, we determine the type of the map key (if needed)
if ( value instanceof Map ) {
final Value keyValue = ( (Map) value ).getIndex();
final org.hibernate.type.Type keyType = keyValue.getType();
if (keyType.isAnyType()) {
if ( context.isIgnoreUnsupported() ) {
return null;
}
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(),
member, persistentAttributeType, elementPersistentAttributeType,
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???");
if ( keyType.isAnyType() ) {
if ( context.isIgnoreUnsupported() ) {
return null;
}
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(),
member, persistentAttributeType, elementPersistentAttributeType,
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???" );
// final boolean isManyToMany = isManyToMany( member );
// //one to many with FK => entity
// return new PluralAttributeMetadataImpl(
@ -539,7 +580,7 @@ public class AttributeFactory {
}
else if ( attributeContext.getPropertyMapping().isComposite() ) {
// component
return new SingularAttributeMetadataImpl<X,Y>(
return new SingularAttributeMetadataImpl<X, Y>(
attributeContext.getPropertyMapping(),
attributeContext.getOwnerType(),
member,
@ -548,7 +589,7 @@ public class AttributeFactory {
}
else {
// basic type
return new SingularAttributeMetadataImpl<X,Y>(
return new SingularAttributeMetadataImpl<X, Y>(
attributeContext.getPropertyMapping(),
attributeContext.getOwnerType(),
member,
@ -564,9 +605,9 @@ public class AttributeFactory {
? Attribute.PersistentAttributeType.ONE_TO_ONE
: Attribute.PersistentAttributeType.MANY_TO_ONE;
}
else if (MapMember.class.isInstance( member )) {
return Attribute.PersistentAttributeType.MANY_TO_ONE; // curious to see how this works for non-annotated methods
}
else if ( MapMember.class.isInstance( member ) ) {
return Attribute.PersistentAttributeType.MANY_TO_ONE; // curious to see how this works for non-annotated methods
}
else {
return ( (Method) member ).getAnnotation( OneToOne.class ) != null
? Attribute.PersistentAttributeType.ONE_TO_ONE
@ -574,14 +615,14 @@ public class AttributeFactory {
}
}
private abstract class BaseAttributeMetadata<X,Y> implements AttributeMetadata<X,Y> {
private abstract class BaseAttributeMetadata<X, Y> implements AttributeMetadata<X, Y> {
private final Property propertyMapping;
private final AbstractManagedType<X> ownerType;
private final Member member;
private final Class<Y> javaType;
private final Attribute.PersistentAttributeType persistentAttributeType;
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({"unchecked"})
protected BaseAttributeMetadata(
Property propertyMapping,
AbstractManagedType<X> ownerType,
@ -604,9 +645,9 @@ public class AttributeFactory {
else if ( Method.class.isInstance( member ) ) {
declaredType = ( (Method) member ).getReturnType();
}
else if ( MapMember.class.isInstance( member ) ) {
declaredType = ((MapMember) member).getType();
}
else if ( MapMember.class.isInstance( member ) ) {
declaredType = ( (MapMember) member ).getType();
}
else {
throw new IllegalArgumentException( "Cannot determine java-type from given member [" + member + "]" );
}
@ -650,7 +691,7 @@ public class AttributeFactory {
}
}
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({"unchecked"})
protected <Y> Class<Y> accountForPrimitiveTypes(Class<Y> declaredType) {
// if ( !declaredType.isPrimitive() ) {
// return declaredType;
@ -686,9 +727,9 @@ public class AttributeFactory {
return declaredType;
}
private class SingularAttributeMetadataImpl<X,Y>
extends BaseAttributeMetadata<X,Y>
implements SingularAttributeMetadata<X,Y> {
private class SingularAttributeMetadataImpl<X, Y>
extends BaseAttributeMetadata<X, Y>
implements SingularAttributeMetadata<X, Y> {
private final ValueContext valueContext;
private SingularAttributeMetadataImpl(
@ -731,9 +772,9 @@ public class AttributeFactory {
}
}
private class PluralAttributeMetadataImpl<X,Y,E>
extends BaseAttributeMetadata<X,Y>
implements PluralAttributeMetadata<X,Y,E> {
private class PluralAttributeMetadataImpl<X, Y, E>
extends BaseAttributeMetadata<X, Y>
implements PluralAttributeMetadata<X, Y, E> {
private final PluralAttribute.CollectionType attributeCollectionType;
private final Attribute.PersistentAttributeType elementPersistentAttributeType;
private final Attribute.PersistentAttributeType keyPersistentAttributeType;
@ -838,7 +879,7 @@ public class AttributeFactory {
return (Class) type;
}
else if ( type instanceof TypeVariable ) {
final java.lang.reflect.Type upperBound = ( ( TypeVariable ) type ).getBounds()[0];
final java.lang.reflect.Type upperBound = ( (TypeVariable) type ).getBounds()[0];
return getClassFromGenericArgument( upperBound );
}
else if ( type instanceof ParameterizedType ) {
@ -866,21 +907,23 @@ public class AttributeFactory {
}
}
public static ParameterizedType getSignatureType(Member member) {
final java.lang.reflect.Type type;
if (Field.class.isInstance( member )) {
type = ( ( Field ) member ).getGenericType();
}
else if ( Method.class.isInstance( member ) ) {
type = ( ( Method ) member ).getGenericReturnType();
}
else {
type = ( (MapMember) member ).getType();
}
//this is a raw type
if ( type instanceof Class ) return null;
return (ParameterizedType) type;
}
public static ParameterizedType getSignatureType(Member member) {
final java.lang.reflect.Type type;
if ( Field.class.isInstance( member ) ) {
type = ( (Field) member ).getGenericType();
}
else if ( Method.class.isInstance( member ) ) {
type = ( (Method) member ).getGenericReturnType();
}
else {
type = ( (MapMember) member ).getType();
}
//this is a raw type
if ( type instanceof Class ) {
return null;
}
return (ParameterizedType) type;
}
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {
if ( java.util.List.class.isAssignableFrom( javaType ) ) {
@ -900,21 +943,21 @@ public class AttributeFactory {
}
}
public static boolean isManyToMany(Member member) {
if ( Field.class.isInstance( member ) ) {
return ( (Field) member ).getAnnotation( ManyToMany.class ) != null;
}
else if ( Method.class.isInstance( member ) ) {
return ( (Method) member ).getAnnotation( ManyToMany.class ) != null;
}
public static boolean isManyToMany(Member member) {
if ( Field.class.isInstance( member ) ) {
return ( (Field) member ).getAnnotation( ManyToMany.class ) != null;
}
else if ( Method.class.isInstance( member ) ) {
return ( (Method) member ).getAnnotation( ManyToMany.class ) != null;
}
return false;
}
return false;
}
private final MemberResolver embeddedMemberResolver = new MemberResolver() {
@Override
public Member resolveMember(AttributeContext attributeContext) {
final EmbeddableTypeImpl embeddableType = ( EmbeddableTypeImpl<?> ) attributeContext.getOwnerType();
final EmbeddableTypeImpl embeddableType = (EmbeddableTypeImpl<?>) attributeContext.getOwnerType();
final String attributeName = attributeContext.getPropertyMapping().getName();
final Getter getter = embeddableType.getHibernateType()
@ -930,13 +973,13 @@ public class AttributeFactory {
private final MemberResolver virtualIdentifierMemberResolver = new MemberResolver() {
@Override
public Member resolveMember(AttributeContext attributeContext) {
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
if ( ! entityMetamodel.getIdentifierProperty().isVirtual() ) {
if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
throw new IllegalArgumentException( "expecting IdClass mapping" );
}
org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType();
if ( ! EmbeddedComponentType.class.isInstance( type ) ) {
if ( !EmbeddedComponentType.class.isInstance( type ) ) {
throw new IllegalArgumentException( "expecting IdClass mapping" );
}
@ -966,7 +1009,7 @@ public class AttributeFactory {
}
else if ( Type.PersistenceType.ENTITY == persistenceType
|| Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) {
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) ownerType;
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) ownerType;
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
final String propertyName = property.getName();
final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName );
@ -990,9 +1033,9 @@ public class AttributeFactory {
private final MemberResolver identifierMemberResolver = new MemberResolver() {
@Override
public Member resolveMember(AttributeContext attributeContext) {
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
if ( ! attributeContext.getPropertyMapping().getName()
if ( !attributeContext.getPropertyMapping().getName()
.equals( entityMetamodel.getIdentifierProperty().getName() ) ) {
// this *should* indicate processing part of an IdClass...
return virtualIdentifierMemberResolver.resolveMember( attributeContext );
@ -1000,9 +1043,9 @@ public class AttributeFactory {
final Getter getter = entityMetamodel.getTuplizer().getIdentifierGetter();
return MapAccessor.MapGetter.class.isInstance( getter )
? new MapMember(
entityMetamodel.getIdentifierProperty().getName(),
entityMetamodel.getIdentifierProperty().getType().getReturnedClass()
)
entityMetamodel.getIdentifierProperty().getName(),
entityMetamodel.getIdentifierProperty().getType().getReturnedClass()
)
: getter.getMember();
}
};
@ -1010,17 +1053,20 @@ public class AttributeFactory {
private final MemberResolver versionMemberResolver = new MemberResolver() {
@Override
public Member resolveMember(AttributeContext attributeContext) {
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
final String versionPropertyName = attributeContext.getPropertyMapping().getName();
if ( ! versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) {
if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) {
// this should never happen, but to be safe...
throw new IllegalArgumentException( "Given property did not match declared version property" );
}
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
@ -1549,9 +1546,9 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
);
}
try {
if ( transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION ) {
transactionManager.setRollbackOnly();
}
if ( transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION ) {
transactionManager.setRollbackOnly();
}
}
catch (SystemException e) {
throw new PersistenceException( "Unable to set the JTA transaction as RollbackOnly", e );
@ -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 );
}
}