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 final IndexedPluralAttributeBinding indexedPluralAttributeBinding
= (IndexedPluralAttributeBinding) pluralAttributeBinding; = (IndexedPluralAttributeBinding) pluralAttributeBinding;
final PluralAttributeIndexBinding.Nature indexNature final PluralAttributeIndexBinding.Nature indexNature
= indexedPluralAttributeBinding.getPluralAttributeIndexBinding().getPluralAttributeIndexNature(); = indexedPluralAttributeBinding.getPluralAttributeIndexBinding().getNature();
if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_ANY ) { if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_ANY ) {
context.handleUnsupportedFeature( UnsupportedFeature.ANY ); context.handleUnsupportedFeature( UnsupportedFeature.ANY );

View File

@ -239,7 +239,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
return PluralAttributeSource.Nature.MAP; return PluralAttributeSource.Nature.MAP;
} }
else if ( List.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) { 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() ) ) { else if ( Set.class.isAssignableFrom( associationAttribute.getAttributeType() ) ) {
return PluralAttributeSource.Nature.SET; return PluralAttributeSource.Nature.SET;

View File

@ -200,6 +200,24 @@ public class AssociationAttribute extends MappedAttribute {
public boolean isUpdatable() { public boolean isUpdatable() {
return true; 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 @Override
public PropertyGeneration getPropertyGeneration() { public PropertyGeneration getPropertyGeneration() {

View File

@ -193,6 +193,19 @@ public class BasicAttribute extends MappedAttribute {
return versionSourceType; 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 @Override
public String toString() { public String toString() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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