HHH-7549 HHH-7318 support on new metamodel

This commit is contained in:
Strong Liu 2012-09-11 19:50:22 +08:00
parent 8bd17070ff
commit b939be3157
10 changed files with 50 additions and 14 deletions

View File

@ -354,7 +354,7 @@ public class AttributeBuilder {
final IndexedPluralAttributeBinding indexedPluralAttributeBinding
= (IndexedPluralAttributeBinding) pluralAttributeBinding;
final PluralAttributeIndexBinding.Nature indexNature
= indexedPluralAttributeBinding.getPluralAttributeIndexBinding().getPluralAttributeIndexNature();
= indexedPluralAttributeBinding.getPluralAttributeIndexBinding().getNature();
if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_ANY ) {
context.handleUnsupportedFeature( UnsupportedFeature.ANY );

View File

@ -239,7 +239,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
return PluralAttributeSource.Nature.MAP;
}
else if ( List.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
return PluralAttributeSource.Nature.LIST;
return associationAttribute.isIndexed()? Nature.LIST : Nature.BAG;
}
else if ( Set.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
return PluralAttributeSource.Nature.SET;

View File

@ -200,6 +200,24 @@ public class AssociationAttribute extends MappedAttribute {
public boolean isUpdatable() {
return true;
}
protected boolean hasOptimisticLockAnnotation(){
AnnotationInstance optimisticLockAnnotation = JandexHelper.getSingleAnnotation(
annotations(),
HibernateDotNames.OPTIMISTIC_LOCK
);
return optimisticLockAnnotation != null;
}
@Override
public boolean isOptimisticLockable() {
if(hasOptimisticLockAnnotation()){
return super.isOptimisticLockable();
} else {
Nature nature = getNature();
return (nature != Nature.ONE_TO_ONE && nature != Nature.MANY_TO_ONE ) || isInsertable();
}
}
@Override
public PropertyGeneration getPropertyGeneration() {

View File

@ -193,6 +193,19 @@ public class BasicAttribute extends MappedAttribute {
return versionSourceType;
}
@Override
public boolean isOptimisticLockable() {
boolean isOptimisticLockable = super.isOptimisticLockable();
if ( !isOptimisticLockable ) {
if ( isId() || isVersioned() ) {
throw new AnnotationException(
"@OptimisticLock.exclude=true incompatible with @Id, @EmbeddedId and @Version: "
+ getName()
);
}
}
return isOptimisticLockable;
}
@Override
public String toString() {

View File

@ -247,6 +247,11 @@ public class PluralAssociationAttribute extends AssociationAttribute {
return action;
}
@Override
public boolean isOptimisticLockable() {
return hasOptimisticLockAnnotation() ? super.isOptimisticLockable() : StringHelper.isEmpty( getMappedBy() );
}
private String determineCustomLoaderName() {
String loader = null;
final AnnotationInstance customLoaderAnnotation = JandexHelper.getSingleAnnotation(

View File

@ -55,7 +55,7 @@ public class BasicPluralAttributeIndexBinding implements PluralAttributeIndexBin
}
@Override
public IndexedPluralAttributeBinding getNature() {
public IndexedPluralAttributeBinding getIndexedPluralAttributeBinding() {
return pluralAttributeBinding;
}
@ -65,11 +65,11 @@ public class BasicPluralAttributeIndexBinding implements PluralAttributeIndexBin
@Override
public Type getPluralAttributeIndexType() {
return ( (IndexedPluralAttribute) getNature().getAttribute() ).getIndexType();
return ( (IndexedPluralAttribute) getIndexedPluralAttributeBinding().getAttribute() ).getIndexType();
}
@Override
public Nature getPluralAttributeIndexNature() {
public Nature getNature() {
return pluralAttributeIndexNature;
}
}

View File

@ -30,9 +30,9 @@ import org.hibernate.metamodel.spi.relational.Value;
* @author Steve Ebersole
*/
public interface PluralAttributeIndexBinding {
IndexedPluralAttributeBinding getNature();
IndexedPluralAttributeBinding getIndexedPluralAttributeBinding();
Nature getPluralAttributeIndexNature();
Nature getNature();
Value getIndexRelationalValue();

View File

@ -176,7 +176,7 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
}
protected PluralAttribute createPluralAttribute(String name, PluralAttribute.Nature nature) {
PluralAttribute attribute = nature.isIndexed()
PluralAttribute attribute = nature.isIndexable()
? new IndexedPluralAttributeImpl( this, name, nature )
: new PluralAttributeImpl( this, name, nature );
addAttribute( attribute );

View File

@ -54,12 +54,12 @@ public interface PluralAttribute extends Attribute {
private final String name;
private final Class javaContract;
private final boolean indexed;
private final boolean indexable;
Nature(String name, Class javaContract) {
this.name = name;
this.javaContract = javaContract;
this.indexed = Map.class.isAssignableFrom( javaContract )
this.indexable = Map.class.isAssignableFrom( javaContract )
|| List.class.isAssignableFrom( javaContract )
|| javaContract.isArray();
}
@ -72,8 +72,8 @@ public interface PluralAttribute extends Attribute {
return javaContract;
}
public boolean isIndexed() {
return indexed;
public boolean isIndexable() {
return indexable;
}
}
}

View File

@ -851,7 +851,7 @@ public abstract class AbstractCollectionPersister
// INDEX AND ROW SELECT
hasIndex = collection.getAttribute().getNature().isIndexed();
hasIndex = collection.getAttribute().getNature().isIndexable();
indexContainsFormula = false;
indexNodeName = null;
if ( hasIndex ) {
@ -958,7 +958,7 @@ public abstract class AbstractCollectionPersister
}
sqlSelectSizeString = generateSelectSizeString(
collection.getAttribute().getNature().isIndexed() &&
collection.getAttribute().getNature().isIndexable() &&
collection.getAttribute().getNature() != PluralAttribute.Nature.MAP
);
sqlDetectRowByIndexString = generateDetectRowByIndexString();