Hibernate SVN: r17884 - in search/trunk/src: main/java/org/hibernate/search and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-10-30 09:58:05 -0400 (Fri, 30 Oct 2009)
New Revision: 17884
Modified:
search/trunk/src/main/docbook/en-US/modules/batchindex.xml
search/trunk/src/main/docbook/en-US/modules/configuration.xml
search/trunk/src/main/java/org/hibernate/search/Environment.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
Log:
HSEARCH-327 Capability to reuse IndexWriter instances across transactions - name changes and documentation fix
Modified: search/trunk/src/main/docbook/en-US/modules/batchindex.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/batchindex.xml 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/docbook/en-US/modules/batchindex.xml 2009-10-30 13:58:05 UTC (rev 17884)
@@ -261,7 +261,7 @@
<itemizedlist>
<listitem>
- <literal>hibernate.search.[default|<indexname>].enable_greedy_locking</literal>
+ <literal>hibernate.search.[default|<indexname>].exclusive_index_use</literal>
</listitem>
<listitem>
Modified: search/trunk/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-10-30 13:58:05 UTC (rev 17884)
@@ -764,10 +764,10 @@
<tbody>
<row>
- <entry><literal>hibernate.search.[default|<indexname>].enable_greedy_locking</literal></entry>
+ <entry><literal>hibernate.search.[default|<indexname>].exclusive_index_use</literal></entry>
<entry><para>Set to <literal>true</literal> when no other
- application uses the same index, this will enable
+ process will need to write to the same index: this will enable
Hibernate Search to work in exlusive mode on the index and
improve performance in writing changes to the index.</para></entry>
@@ -892,7 +892,7 @@
</table>
<tip><para>When your architecture permits it, always set
- <literal>hibernate.search.default.enable_greedy_locking=true</literal>
+ <literal>hibernate.search.default.exclusive_index_use=true</literal>
as it greatly improves efficiency in index writing.</para>
</tip>
Modified: search/trunk/src/main/java/org/hibernate/search/Environment.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/Environment.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/Environment.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -109,6 +109,6 @@
* can access the index in write mode while Hibernate Search is running.
* This is an index-scoped property and defaults to false.
*/
- public static final String ENABLE_GREEDY_LOCKING = "enable_greedy_locking";
+ public static final String EXCLUSIVE_INDEX_USE = "exclusive_index_use";
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -50,7 +50,7 @@
private final Workspace workspace;
private final LuceneWorkVisitor worker;
private final ExecutorService executor;
- private final boolean useGreedyLocks;
+ private final boolean exclusiveIndexUsage;
private final List<LuceneWork> workOnWriter = new ArrayList<LuceneWork>();
// if any work needs batchmode, set corresponding flag to true:
@@ -64,7 +64,7 @@
this.worker = resources.getVisitor();
this.workspace = resources.getWorkspace();
this.executor = resources.getExecutor();
- this.useGreedyLocks = resources.isLockingGreedy();
+ this.exclusiveIndexUsage = resources.isExclusiveIndexUsageEnabled();
}
/**
@@ -96,7 +96,7 @@
performOptimizations();
}
finally {
- if ( ! useGreedyLocks )
+ if ( ! exclusiveIndexUsage )
workspace.closeIndexWriter();
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -43,13 +43,13 @@
private final ExecutorService executor;
private final LuceneWorkVisitor visitor;
private final Workspace workspace;
- private final boolean lockingIsGreedy;
+ private final boolean exclusiveIndexUsage;
PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider<?> dp) {
workspace = new Workspace( searchFactoryImp, dp );
visitor = new LuceneWorkVisitor( workspace );
executor = Executors.newFixedThreadPool( 1 );
- lockingIsGreedy = searchFactoryImp.isLockingGreedy( dp );
+ exclusiveIndexUsage = searchFactoryImp.isExclusiveIndexUsageEnabled( dp );
}
public ExecutorService getExecutor() {
@@ -64,13 +64,13 @@
return workspace;
}
- public boolean isLockingGreedy() {
- return lockingIsGreedy;
+ public boolean isExclusiveIndexUsageEnabled() {
+ return exclusiveIndexUsage;
}
public void shutdown() {
//sets the index to be closed after all current jobs are processed:
- if ( lockingIsGreedy ) {
+ if ( exclusiveIndexUsage ) {
executor.execute( new CloseIndexRunnable( workspace ) );
}
executor.shutdown();
Modified: search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -74,7 +74,7 @@
void close();
- void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean useGreedyLocking);
+ void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean exclusiveIndexUsage);
Set<Class<?>> getClassesInDirectoryProvider(DirectoryProvider<?> directoryProvider);
@@ -82,7 +82,7 @@
ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp);
- void addDirectoryProvider(DirectoryProvider<?> provider, boolean usesGreedyLocking);
+ void addDirectoryProvider(DirectoryProvider<?> provider, boolean exclusiveIndexUsage);
int getFilterCacheBitResultsSize();
@@ -92,5 +92,5 @@
Similarity getSimilarity(DirectoryProvider<?> directoryProvider);
- boolean isLockingGreedy(DirectoryProvider<?> provider);
+ boolean isExclusiveIndexUsageEnabled(DirectoryProvider<?> provider);
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -252,7 +252,7 @@
}
}
- public void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean useGreedyLocking) {
+ public void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean exclusiveIndexUsage) {
//no need to set a read barrier, we only use this class in the init thread
DirectoryProviderData data = dirProviderData.get( directoryProvider );
if ( data == null ) {
@@ -260,7 +260,7 @@
dirProviderData.put( directoryProvider, data );
}
data.classes.add( clazz );
- data.usesGreedyLocking = useGreedyLocking;
+ data.exclusiveIndexUsage = exclusiveIndexUsage;
}
public Set<Class<?>> getClassesInDirectoryProvider(DirectoryProvider<?> directoryProvider) {
@@ -557,7 +557,7 @@
public OptimizerStrategy optimizerStrategy;
public final Set<Class<?>> classes = new HashSet<Class<?>>( 2 );
public Similarity similarity = null;
- private boolean usesGreedyLocking;
+ private boolean exclusiveIndexUsage;
}
public ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp) {
@@ -566,10 +566,10 @@
return this.dirProviderData.get( dp ).dirLock;
}
- public void addDirectoryProvider(DirectoryProvider<?> provider, boolean usesGreedyLocking) {
+ public void addDirectoryProvider(DirectoryProvider<?> provider, boolean exclusiveIndexUsage) {
//no need to set a barrier we use this method in the init thread
DirectoryProviderData dirConfiguration = new DirectoryProviderData();
- dirConfiguration.usesGreedyLocking = usesGreedyLocking;
+ dirConfiguration.exclusiveIndexUsage = exclusiveIndexUsage;
this.dirProviderData.put( provider, dirConfiguration );
}
@@ -657,10 +657,10 @@
return similarity;
}
- public boolean isLockingGreedy(DirectoryProvider<?> provider) {
+ public boolean isExclusiveIndexUsageEnabled(DirectoryProvider<?> provider) {
if ( barrier != 0 ) {
} //read barrier
- return dirProviderData.get( provider ).usesGreedyLocking;
+ return dirProviderData.get( provider ).exclusiveIndexUsage;
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -132,18 +132,18 @@
throw new SearchException( "Unable to initialize directory provider: " + directoryProviderName, e );
}
int index = providers.indexOf( provider );
- boolean useGreedyLocking = isGreedyLockingEnabled( directoryProviderName, indexProps );
+ boolean exclusiveIndexUsage = isExclusiveIndexUsageEnabled( directoryProviderName, indexProps );
if ( index != -1 ) {
//share the same Directory provider for the same underlying store
final DirectoryProvider<?> directoryProvider = providers.get( index );
- searchFactoryImplementor.addClassToDirectoryProvider( entity, directoryProvider, useGreedyLocking);
+ searchFactoryImplementor.addClassToDirectoryProvider( entity, directoryProvider, exclusiveIndexUsage);
return directoryProvider;
}
else {
configureOptimizerStrategy( searchFactoryImplementor, indexProps, provider );
configureIndexingParameters( searchFactoryImplementor, indexProps, provider );
providers.add( provider );
- searchFactoryImplementor.addClassToDirectoryProvider( entity, provider, useGreedyLocking );
+ searchFactoryImplementor.addClassToDirectoryProvider( entity, provider, exclusiveIndexUsage );
return provider;
}
}
@@ -265,11 +265,11 @@
}
}
- private static boolean isGreedyLockingEnabled(String directoryProviderName, Properties indexProps) {
- String usesGreedyLockingProperty = indexProps.getProperty( Environment.ENABLE_GREEDY_LOCKING, "false" );
- boolean usesGreedyLocking = ConfigurationParseHelper.parseBoolean( usesGreedyLockingProperty,
- "Illegal value for property " + Environment.ENABLE_GREEDY_LOCKING + " on index " + directoryProviderName );
- return usesGreedyLocking;
+ private static boolean isExclusiveIndexUsageEnabled(String directoryProviderName, Properties indexProps) {
+ String exclusiveIndexUsageProperty = indexProps.getProperty( Environment.EXCLUSIVE_INDEX_USE, "false" );
+ boolean exclusiveIndexUsage = ConfigurationParseHelper.parseBoolean( exclusiveIndexUsageProperty,
+ "Illegal value for property " + Environment.EXCLUSIVE_INDEX_USE + " on index " + directoryProviderName );
+ return exclusiveIndexUsage;
}
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2009-10-30 13:00:07 UTC (rev 17883)
+++ search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2009-10-30 13:58:05 UTC (rev 17884)
@@ -107,7 +107,7 @@
cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() );
cfg.setProperty( "hibernate.search.default.optimizer.transaction_limit.max", "10" ); // workaround too many open files
- cfg.setProperty( "hibernate.search.default." + Environment.ENABLE_GREEDY_LOCKING, "true" );
+ cfg.setProperty( "hibernate.search.default." + Environment.EXCLUSIVE_INDEX_USE, "true" );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
cfg.setProperty( Environment.READER_STRATEGY, getReaderStrategyName() );
}
15 years, 1 month
Hibernate SVN: r17883 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-10-30 09:00:07 -0400 (Fri, 30 Oct 2009)
New Revision: 17883
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
HHH-4537 Add support for MappedSuperclassType Members in JPA 2
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-10-30 11:49:13 UTC (rev 17882)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-10-30 13:00:07 UTC (rev 17883)
@@ -27,6 +27,7 @@
import java.util.Iterator;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Type;
+import javax.persistence.metamodel.IdentifiableType;
import org.hibernate.EntityMode;
import org.hibernate.type.EmbeddedComponentType;
@@ -38,6 +39,7 @@
import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.entity.EntityMetamodel;
/**
@@ -144,7 +146,7 @@
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property, boolean getMember) {
final AttributeContext attrContext = getAttributeContext( property );
final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
final Class<Y> idJavaType = property.getType().getReturnedClass();
@@ -158,7 +160,7 @@
);
}
- private Member determineIdentifierJavaMember(AbstractManagedType ownerType, Property property) {
+ private Member determineIdentifierJavaMember(IdentifiableType ownerType, Property property) {
// see below
// final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( property );
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( ownerType );
@@ -191,12 +193,26 @@
// .getEntityMetamodel();
// }
// so we use the owner's java class to lookup the persister/entitymetamodel
- private EntityMetamodel getDeclarerEntityMetamodel(AbstractManagedType ownerType) {
- return context.getSessionFactory()
- .getEntityPersister( ownerType.getJavaType().getName() )
+ private EntityMetamodel getDeclarerEntityMetamodel(IdentifiableType<?> ownerType) {
+ final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
+ if ( persistenceType == Type.PersistenceType.ENTITY) {
+ return context.getSessionFactory()
+ .getEntityPersister( ownerType.getJavaType().getName() )
+ .getEntityMetamodel();
+ }
+ else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS) {
+ PersistentClass persistentClass =
+ context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
+ return context.getSessionFactory()
+ .getEntityPersister( persistentClass.getClassName() )
.getEntityMetamodel();
+ }
+ else {
+ throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
+ }
}
+
// getting the owning PersistentClass from the Property is broken in certain cases with annotations...
// private Member determineStandardJavaMember(Property property) {
// final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( property );
@@ -206,33 +222,39 @@
// return entityMetamodel.getTuplizer( EntityMode.POJO ).getGetter( index ).getMember();
// }
// so we use the owner's java class to lookup the persister/entitymetamodel
- private Member determineStandardJavaMember(AbstractManagedType ownerType, Property property) {
- if ( Type.PersistenceType.EMBEDDABLE == ownerType.getPersistenceType() ) {
- EmbeddableTypeImpl embeddableType = ( EmbeddableTypeImpl ) ownerType;
+ private Member determineStandardJavaMember(AbstractManagedType<?> ownerType, Property property) {
+ final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
+ if ( Type.PersistenceType.EMBEDDABLE == persistenceType ) {
+ EmbeddableTypeImpl embeddableType = ( EmbeddableTypeImpl<?> ) ownerType;
return embeddableType.getHibernateType().getTuplizerMapping()
.getTuplizer( EntityMode.POJO )
.getGetter( embeddableType.getHibernateType().getPropertyIndex( property.getName() ) )
.getMember();
}
- else if ( Type.PersistenceType.ENTITY == ownerType.getPersistenceType() ) {
- final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( ownerType );
- final String propertyName = property.getName();
- final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName );
- if ( index == null ) {
- // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping
- return determineVirtualIdentifierJavaMember( entityMetamodel, property );
- }
- else {
- return entityMetamodel.getTuplizer( EntityMode.POJO ).getGetter( index ).getMember();
- }
+ else if ( Type.PersistenceType.ENTITY == persistenceType
+ || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) {
+ return determineStandardJavaMemberOutOfIdentifiableType( (IdentifiableType<?>) ownerType, property );
}
else {
- throw new IllegalArgumentException( "Unexpected owner type : " + ownerType.getPersistenceType() );
+ throw new IllegalArgumentException( "Unexpected owner type : " + persistenceType );
}
}
+ private Member determineStandardJavaMemberOutOfIdentifiableType(IdentifiableType<?> ownerType, Property property) {
+ final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( ownerType );
+ final String propertyName = property.getName();
+ final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName );
+ if ( index == null ) {
+ // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping
+ return determineVirtualIdentifierJavaMember( entityMetamodel, property );
+ }
+ else {
+ return entityMetamodel.getTuplizer( EntityMode.POJO ).getGetter( index ).getMember();
+ }
+ }
+
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property, boolean getMember) {
final AttributeContext attrContext = getAttributeContext( property );
final Class<Y> javaType = property.getType().getReturnedClass();
final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
@@ -246,7 +268,7 @@
);
}
- private Member determineVersionJavaMember(AbstractManagedType ownerType, Property property) {
+ private Member determineVersionJavaMember(IdentifiableType ownerType, Property property) {
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( ownerType );
if ( ! property.getName().equals( entityMetamodel.getVersionProperty().getName() ) ) {
// this should never happen, but to be safe...
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-30 11:49:13 UTC (rev 17882)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-30 13:00:07 UTC (rev 17883)
@@ -31,12 +31,14 @@
import java.util.ArrayList;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.SingularAttribute;
+import javax.swing.*;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.AnnotationException;
/**
* Defines a context for storing information during the building of the {@link MetamodelImpl}.
@@ -67,6 +69,14 @@
= new HashMap<MappedSuperclass,MappedSuperclassTypeImpl<?>>();
//this list contains MappedSuperclass and EntityTypes ordered by superclass first
private List<Object> orderedMappings = new ArrayList<Object>();
+ /**
+ * Stack of PersistentClass being process. Last in the list is the highest in the stack.
+ *
+ */
+ private List<PersistentClass> stackOfPersistentClassesBeingProcessed
+ = new ArrayList<PersistentClass>();
+ private Map<MappedSuperclassTypeImpl<?>, PersistentClass> mappedSuperClassTypeToPersistentClass
+ = new HashMap<MappedSuperclassTypeImpl<?>, PersistentClass>();
public MetadataContext(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
@@ -104,6 +114,7 @@
MappedSuperclassTypeImpl<?> mappedSuperclassType) {
mappedSuperclassByMappedSuperclassMapping.put( mappedSuperclass, mappedSuperclassType );
orderedMappings.add( mappedSuperclass );
+ mappedSuperClassTypeToPersistentClass.put( mappedSuperclassType, getEntityWorkedOn() );
}
/**
@@ -169,7 +180,7 @@
Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
while ( properties.hasNext() ) {
final Property property = properties.next();
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, false );
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, true );
jpa2Mapping.getBuilder().addAttribute( attribute );
}
jpa2Mapping.lock();
@@ -200,7 +211,7 @@
final Property declaredIdentifierProperty = mappingType.getDeclaredIdentifierProperty();
if (declaredIdentifierProperty != null) {
jpaMappingType.getBuilder().applyIdAttribute(
- attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty, false )
+ attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty, true )
);
}
}
@@ -226,7 +237,7 @@
final Property declaredVersion = mappingType.getDeclaredVersion();
if ( declaredVersion != null ) {
jpaMappingType.getBuilder().applyVersionAttribute(
- attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion, false )
+ attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion, true )
);
}
}
@@ -250,7 +261,7 @@
@SuppressWarnings( "unchecked" )
Iterator<Property> properties = mappingType.getIdentifierMapper().getPropertyIterator();
while ( properties.hasNext() ) {
- attributes.add( attributeFactory.buildIdAttribute( jpaMappingType, properties.next(), false ) );
+ attributes.add( attributeFactory.buildIdAttribute( jpaMappingType, properties.next(), true ) );
}
return attributes;
}
@@ -288,4 +299,33 @@
public MappedSuperclassTypeImpl<?> locateMappedSuperclassType(MappedSuperclass mappedSuperclass) {
return mappedSuperclassByMappedSuperclassMapping.get(mappedSuperclass);
}
+
+ public void pushEntityWorkedOn(PersistentClass persistentClass) {
+ stackOfPersistentClassesBeingProcessed.add(persistentClass);
+ }
+
+ public void popEntityWorkedOn(PersistentClass persistentClass) {
+ final PersistentClass stackTop = stackOfPersistentClassesBeingProcessed.remove(
+ stackOfPersistentClassesBeingProcessed.size() - 1
+ );
+ if (stackTop != persistentClass) {
+ throw new AssertionFailure( "Inconsistent popping: "
+ + persistentClass.getEntityName() + " instead of " + stackTop.getEntityName() );
+ }
+ }
+
+ private PersistentClass getEntityWorkedOn() {
+ return stackOfPersistentClassesBeingProcessed.get(
+ stackOfPersistentClassesBeingProcessed.size() - 1
+ );
+ }
+
+ public PersistentClass getPersistentClassHostingProperties(MappedSuperclassTypeImpl<?> mappedSuperclassType) {
+ final PersistentClass persistentClass = mappedSuperClassTypeToPersistentClass.get( mappedSuperclassType );
+ if (persistentClass == null) {
+ throw new AssertionFailure( "Could not find PersistentClass for MappedSuperclassType: "
+ + mappedSuperclassType.getJavaType() );
+ }
+ return persistentClass;
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-30 11:49:13 UTC (rev 17882)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-30 13:00:07 UTC (rev 17883)
@@ -78,6 +78,8 @@
//TODO remove / reduce @SW scope
@SuppressWarnings( "unchecked" )
private static EntityTypeImpl<?> buildEntityType(PersistentClass persistentClass, MetadataContext context) {
+ final Class javaType = persistentClass.getMappedClass();
+ context.pushEntityWorkedOn(persistentClass);
final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass();
AbstractIdentifiableType<?> superType = superMappedSuperclass == null
? null
@@ -89,7 +91,6 @@
? null
: locateOrBuildEntityType( superPersistentClass, context );
}
- final Class javaType = persistentClass.getMappedClass();
EntityTypeImpl entityType = new EntityTypeImpl(
javaType,
superType,
@@ -98,6 +99,7 @@
persistentClass.isVersioned()
);
context.registerEntityType( persistentClass, entityType );
+ context.popEntityWorkedOn(persistentClass);
return entityType;
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-10-30 11:49:13 UTC (rev 17882)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-10-30 13:00:07 UTC (rev 17883)
@@ -169,6 +169,7 @@
assertNotNull( cat );
assertEquals( 7, cat.getAttributes().size() );
assertEquals( 1, cat.getDeclaredAttributes().size() );
+ ensureProperMember(cat.getDeclaredAttributes());
assertTrue( cat.hasVersionAttribute() );
assertEquals( "version", cat.getVersion(Long.class).getName() );
@@ -179,6 +180,7 @@
MappedSuperclassType<Cattish> cattish = (MappedSuperclassType<Cattish>) cat.getSupertype();
assertEquals( 6, cattish.getAttributes().size() );
assertEquals( 1, cattish.getDeclaredAttributes().size() );
+ ensureProperMember(cattish.getDeclaredAttributes());
assertTrue( cattish.hasVersionAttribute() );
assertEquals( "version", cattish.getVersion(Long.class).getName() );
@@ -189,6 +191,7 @@
EntityType<Feline> feline = (EntityType<Feline>) cattish.getSupertype();
assertEquals( 5, feline.getAttributes().size() );
assertEquals( 1, feline.getDeclaredAttributes().size() );
+ ensureProperMember(feline.getDeclaredAttributes());
assertTrue( feline.hasVersionAttribute() );
assertEquals( "version", feline.getVersion(Long.class).getName() );
@@ -199,27 +202,44 @@
MappedSuperclassType<Animal> animal = (MappedSuperclassType<Animal>) feline.getSupertype();
assertEquals( 4, animal.getAttributes().size() );
assertEquals( 2, animal.getDeclaredAttributes().size() );
+ ensureProperMember(animal.getDeclaredAttributes());
assertTrue( animal.hasVersionAttribute() );
assertEquals( "version", animal.getVersion(Long.class).getName() );
verifyDeclaredVersiobnNotPresent( animal );
assertEquals( "id", animal.getId(Long.class).getName() );
- assertEquals( "id", animal.getDeclaredId(Long.class).getName() );
+ final SingularAttribute<Animal, Long> id = animal.getDeclaredId( Long.class );
+ assertEquals( "id", id.getName() );
+ assertNotNull( id.getJavaMember() );
assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, animal.getSupertype().getPersistenceType() );
MappedSuperclassType<Thing> thing = (MappedSuperclassType<Thing>) animal.getSupertype();
assertEquals( 2, thing.getAttributes().size() );
assertEquals( 2, thing.getDeclaredAttributes().size() );
+ ensureProperMember(thing.getDeclaredAttributes());
final SingularAttribute<Thing, Double> weight = thing.getDeclaredSingularAttribute( "weight", Double.class );
assertEquals( Double.class, weight.getJavaType() );
assertEquals( "version", thing.getVersion(Long.class).getName() );
- assertEquals( "version", thing.getDeclaredVersion(Long.class).getName() );
+ final SingularAttribute<Thing, Long> version = thing.getDeclaredVersion( Long.class );
+ assertEquals( "version", version.getName() );
+ assertNotNull( version.getJavaMember() );
assertNull( thing.getId( Long.class ) );
assertNull( thing.getSupertype() );
}
+ private void ensureProperMember(Set<?> attributes) {
+ //we do not update the set so we are safe
+ @SuppressWarnings( "unchecked" )
+ final Set<Attribute<?, ?>> safeAttributes = ( Set<Attribute<?, ?>> ) attributes;
+ for (Attribute<?,?> attribute : safeAttributes ) {
+ final String name = attribute.getJavaMember().getName();
+ assertNotNull( attribute.getJavaMember() );
+ assertTrue( name.toLowerCase().endsWith( attribute.getName().toLowerCase() ) );
+ }
+ }
+
private void verifyDeclaredIdNotPresentAndIdPresent(IdentifiableType<?> type) {
assertEquals( "id", type.getId(Long.class).getName() );
try {
15 years, 1 month
Hibernate SVN: r17882 - in search/trunk/src: main/java/org/hibernate/search and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-10-30 07:49:13 -0400 (Fri, 30 Oct 2009)
New Revision: 17882
Added:
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/CloseIndexRunnable.java
Modified:
search/trunk/src/main/docbook/en-US/modules/batchindex.xml
search/trunk/src/main/docbook/en-US/modules/configuration.xml
search/trunk/src/main/java/org/hibernate/search/Environment.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/works/DeleteExtWorkDelegate.java
search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
Log:
HSEARCH-327 Capability to reuse IndexWriter instances across transactions
Modified: search/trunk/src/main/docbook/en-US/modules/batchindex.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/batchindex.xml 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/docbook/en-US/modules/batchindex.xml 2009-10-30 11:49:13 UTC (rev 17882)
@@ -238,12 +238,12 @@
performance if the main entity is relating to enum-like data included in the index.</para>
</example>
- <tip>The "sweet spot" of number of threads to achieve best performance is
+ <tip><para>The "sweet spot" of number of threads to achieve best performance is
highly dependent on your overall architecture, database design and even data
values.
To find out the best number of threads for your application it is recommended
to use a profiler: all internal thread groups have meaningful names
- to be easily identified with most tools.
+ to be easily identified with most tools.</para>
</tip>
<note>
@@ -256,11 +256,15 @@
</section>
- <para>Other parameters which also can affect indexing time and memory
+ <para>Other parameters which also affect indexing time and memory
consumption are:</para>
<itemizedlist>
<listitem>
+ <literal>hibernate.search.[default|<indexname>].enable_greedy_locking</literal>
+ </listitem>
+
+ <listitem>
<literal>hibernate.search.[default|<indexname>].indexwriter.batch.max_buffered_docs</literal>
</listitem>
@@ -285,8 +289,8 @@
</listitem>
</itemizedlist>
- <para>These parameters are Lucene specific and Hibernate Search is just
- passing these parameters through - see <xref
+ <para>All <literal>.indexwriter</literal> parameters are Lucene specific and
+ Hibernate Search is just passing these parameters through - see <xref
linkend="lucene-indexing-performance" /> for more details.</para>
</section>
Modified: search/trunk/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/docbook/en-US/modules/configuration.xml 2009-10-30 11:49:13 UTC (rev 17882)
@@ -762,6 +762,18 @@
</thead>
<tbody>
+
+ <row>
+ <entry><literal>hibernate.search.[default|<indexname>].enable_greedy_locking</literal></entry>
+
+ <entry><para>Set to <literal>true</literal> when no other
+ application uses the same index, this will enable
+ Hibernate Search to work in exlusive mode on the index and
+ improve performance in writing changes to the index.</para></entry>
+
+ <entry><literal>false</literal> (releases locks as soon as possible)</entry>
+ </row>
+
<row>
<entry><literal>hibernate.search.[default|<indexname>].indexwriter.[transaction|batch].max_buffered_delete_terms</literal></entry>
@@ -878,6 +890,11 @@
</tbody>
</tgroup>
</table>
+
+ <tip><para>When your architecture permits it, always set
+ <literal>hibernate.search.default.enable_greedy_locking=true</literal>
+ as it greatly improves efficiency in index writing.</para>
+ </tip>
<para>To tune the indexing speed it might be useful to time the object
loading from database in isolation from the writes to the index. To
Modified: search/trunk/src/main/java/org/hibernate/search/Environment.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/Environment.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/Environment.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -102,4 +102,13 @@
*/
public static final String BATCH_BACKEND = "hibernate.search.batchbackend";
+ /**
+ * When set to true a lock on the index will not be released until the
+ * SearchFactory (or SessionFactory) is closed.
+ * This improves performance in applying changes to the index, but no other application
+ * can access the index in write mode while Hibernate Search is running.
+ * This is an index-scoped property and defaults to false.
+ */
+ public static final String ENABLE_GREEDY_LOCKING = "enable_greedy_locking";
+
}
Added: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/CloseIndexRunnable.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/CloseIndexRunnable.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/CloseIndexRunnable.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -0,0 +1,52 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, 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
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.search.backend.impl.lucene;
+
+import org.slf4j.Logger;
+import org.hibernate.search.backend.Workspace;
+import org.hibernate.search.util.LoggerFactory;
+
+/**
+ * Runnable to close the IndexWriter of a Workspace, if open.
+ * Used when a close operation needs scheduling for after other Runnables in an executor queue.
+ *
+ * @author Sanne Grinovero
+ */
+public class CloseIndexRunnable implements Runnable {
+
+ private static final Logger log = LoggerFactory.make();
+ private final Workspace workspace;
+
+ public CloseIndexRunnable(Workspace workspace) {
+ this.workspace = workspace;
+ }
+
+ public void run() {
+ log.debug( "Closing IndexWriter if needed" );
+ workspace.closeIndexWriter();
+ }
+
+}
+
Property changes on: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/CloseIndexRunnable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ LF
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -78,10 +78,9 @@
}
public void close() {
- // needs to stop all used ThreadPools
+ // needs to stop all used ThreadPools and cleanup locks
for (PerDPResources res : resourcesMap.values() ) {
- ExecutorService executor = res.getExecutor();
- executor.shutdown();
+ res.shutdown();
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPQueueProcessor.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -50,6 +50,7 @@
private final Workspace workspace;
private final LuceneWorkVisitor worker;
private final ExecutorService executor;
+ private final boolean useGreedyLocks;
private final List<LuceneWork> workOnWriter = new ArrayList<LuceneWork>();
// if any work needs batchmode, set corresponding flag to true:
@@ -63,6 +64,7 @@
this.worker = resources.getVisitor();
this.workspace = resources.getWorkspace();
this.executor = resources.getExecutor();
+ this.useGreedyLocks = resources.isLockingGreedy();
}
/**
@@ -91,11 +93,11 @@
lw.getWorkDelegate( worker ).performWork( lw, indexWriter );
}
workspace.commitIndexWriter();
- //TODO skip this when indexing in batches:
performOptimizations();
}
finally {
- workspace.closeIndexWriter();
+ if ( ! useGreedyLocks )
+ workspace.closeIndexWriter();
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -43,11 +43,13 @@
private final ExecutorService executor;
private final LuceneWorkVisitor visitor;
private final Workspace workspace;
+ private final boolean lockingIsGreedy;
- PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider dp) {
+ PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider<?> dp) {
workspace = new Workspace( searchFactoryImp, dp );
visitor = new LuceneWorkVisitor( workspace );
executor = Executors.newFixedThreadPool( 1 );
+ lockingIsGreedy = searchFactoryImp.isLockingGreedy( dp );
}
public ExecutorService getExecutor() {
@@ -61,5 +63,17 @@
public Workspace getWorkspace() {
return workspace;
}
+
+ public boolean isLockingGreedy() {
+ return lockingIsGreedy;
+ }
+
+ public void shutdown() {
+ //sets the index to be closed after all current jobs are processed:
+ if ( lockingIsGreedy ) {
+ executor.execute( new CloseIndexRunnable( workspace ) );
+ }
+ executor.shutdown();
+ }
}
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/QueueProcessors.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -74,7 +74,7 @@
}
/**
- * Runs all PerDPQueueProcessor and don't wait fot them to finish.
+ * Runs all PerDPQueueProcessor and don't wait for them to finish.
*/
private void runAllAsync() {
// execute all work in parallel on each DirectoryProvider;
Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/works/DeleteExtWorkDelegate.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/works/DeleteExtWorkDelegate.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/works/DeleteExtWorkDelegate.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -53,9 +53,6 @@
DeleteExtWorkDelegate(Workspace workspace) {
super( workspace );
- if ( workspace.getEntitiesInDirectory().size() != 1 ) {
- throw new AssertionFailure( "Can't use this delegate on shared indexes" );
- }
managedType = workspace.getEntitiesInDirectory().iterator().next();
builder = workspace.getDocumentBuilder( managedType );
}
Modified: search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -74,7 +74,7 @@
void close();
- void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider);
+ void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean useGreedyLocking);
Set<Class<?>> getClassesInDirectoryProvider(DirectoryProvider<?> directoryProvider);
@@ -82,7 +82,7 @@
ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp);
- void addDirectoryProvider(DirectoryProvider<?> provider);
+ void addDirectoryProvider(DirectoryProvider<?> provider, boolean usesGreedyLocking);
int getFilterCacheBitResultsSize();
@@ -91,4 +91,6 @@
BatchBackend makeBatchBackend(MassIndexerProgressMonitor progressMonitor);
Similarity getSimilarity(DirectoryProvider<?> directoryProvider);
+
+ boolean isLockingGreedy(DirectoryProvider<?> provider);
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -252,7 +252,7 @@
}
}
- public void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider) {
+ public void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider, boolean useGreedyLocking) {
//no need to set a read barrier, we only use this class in the init thread
DirectoryProviderData data = dirProviderData.get( directoryProvider );
if ( data == null ) {
@@ -260,6 +260,7 @@
dirProviderData.put( directoryProvider, data );
}
data.classes.add( clazz );
+ data.usesGreedyLocking = useGreedyLocking;
}
public Set<Class<?>> getClassesInDirectoryProvider(DirectoryProvider<?> directoryProvider) {
@@ -556,6 +557,7 @@
public OptimizerStrategy optimizerStrategy;
public final Set<Class<?>> classes = new HashSet<Class<?>>( 2 );
public Similarity similarity = null;
+ private boolean usesGreedyLocking;
}
public ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp) {
@@ -564,9 +566,11 @@
return this.dirProviderData.get( dp ).dirLock;
}
- public void addDirectoryProvider(DirectoryProvider<?> provider) {
+ public void addDirectoryProvider(DirectoryProvider<?> provider, boolean usesGreedyLocking) {
//no need to set a barrier we use this method in the init thread
- this.dirProviderData.put( provider, new DirectoryProviderData() );
+ DirectoryProviderData dirConfiguration = new DirectoryProviderData();
+ dirConfiguration.usesGreedyLocking = usesGreedyLocking;
+ this.dirProviderData.put( provider, dirConfiguration );
}
public int getFilterCacheBitResultsSize() {
@@ -653,4 +657,10 @@
return similarity;
}
+ public boolean isLockingGreedy(DirectoryProvider<?> provider) {
+ if ( barrier != 0 ) {
+ } //read barrier
+ return dirProviderData.get( provider ).usesGreedyLocking;
+ }
+
}
Modified: search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -31,6 +31,7 @@
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
+import org.hibernate.search.Environment;
import org.hibernate.search.SearchException;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.backend.LuceneIndexingParameters;
@@ -131,20 +132,18 @@
throw new SearchException( "Unable to initialize directory provider: " + directoryProviderName, e );
}
int index = providers.indexOf( provider );
+ boolean useGreedyLocking = isGreedyLockingEnabled( directoryProviderName, indexProps );
if ( index != -1 ) {
//share the same Directory provider for the same underlying store
final DirectoryProvider<?> directoryProvider = providers.get( index );
- searchFactoryImplementor.addClassToDirectoryProvider( entity, directoryProvider );
+ searchFactoryImplementor.addClassToDirectoryProvider( entity, directoryProvider, useGreedyLocking);
return directoryProvider;
}
else {
configureOptimizerStrategy( searchFactoryImplementor, indexProps, provider );
configureIndexingParameters( searchFactoryImplementor, indexProps, provider );
providers.add( provider );
- searchFactoryImplementor.addClassToDirectoryProvider( entity, provider );
- if ( !searchFactoryImplementor.getDirectoryProviders().contains( provider ) ) {
- searchFactoryImplementor.addDirectoryProvider( provider );
- }
+ searchFactoryImplementor.addClassToDirectoryProvider( entity, provider, useGreedyLocking );
return provider;
}
}
@@ -265,5 +264,12 @@
return providers;
}
}
+
+ private static boolean isGreedyLockingEnabled(String directoryProviderName, Properties indexProps) {
+ String usesGreedyLockingProperty = indexProps.getProperty( Environment.ENABLE_GREEDY_LOCKING, "false" );
+ boolean usesGreedyLocking = ConfigurationParseHelper.parseBoolean( usesGreedyLockingProperty,
+ "Illegal value for property " + Environment.ENABLE_GREEDY_LOCKING + " on index " + directoryProviderName );
+ return usesGreedyLocking;
+ }
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2009-10-30 10:52:10 UTC (rev 17881)
+++ search/trunk/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2009-10-30 11:49:13 UTC (rev 17882)
@@ -71,10 +71,6 @@
super.setUp();
}
- public void testFakeTest(){
- //to make JUnit happy when disabling performance test
- }
-
private void buildBigIndex() throws InterruptedException, CorruptIndexException, LockObtainFailedException, IOException {
System.out.println( "Going to create fake index..." );
FSDirectory directory = FSDirectory.getDirectory(new File(getBaseIndexDir(), Detective.class.getCanonicalName()));
@@ -111,14 +107,14 @@
cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() );
cfg.setProperty( "hibernate.search.default.optimizer.transaction_limit.max", "10" ); // workaround too many open files
+ cfg.setProperty( "hibernate.search.default." + Environment.ENABLE_GREEDY_LOCKING, "true" );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
cfg.setProperty( Environment.READER_STRATEGY, getReaderStrategyName() );
}
protected abstract String getReaderStrategyName();
- //this test is disabled as it is very slow (and someone should read the output)
- public final void disabled_testPerformance() throws InterruptedException, CorruptIndexException, LockObtainFailedException, IOException {
+ public final void testPerformance() throws InterruptedException, CorruptIndexException, LockObtainFailedException, IOException {
buildBigIndex();
for (int i=0; i<WARMUP_CYCLES; i++) {
timeMs();
15 years, 1 month
Hibernate SVN: r17881 - in search/trunk: src/test/java/org/hibernate/search/test/batchindexing and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-10-30 06:52:10 -0400 (Fri, 30 Oct 2009)
New Revision: 17881
Added:
search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyPerfTest.java
search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java
Removed:
search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyTest.java
search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java
Modified:
search/trunk/pom.xml
search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
Log:
HSEARCH-408 Improve execution speed of functional tests: disabled some performance-only tests, reduced size of data generated in some bigger functional tests.
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2009-10-29 20:44:57 UTC (rev 17880)
+++ search/trunk/pom.xml 2009-10-30 10:52:10 UTC (rev 17881)
@@ -51,7 +51,7 @@
</contributors>
<properties>
- <slf4jVersion>1.5.6</slf4jVersion>
+ <slf4jVersion>1.5.8</slf4jVersion>
<luceneVersion>2.4.1</luceneVersion>
<hibernateVersion>3.5.0.Beta-1</hibernateVersion>
<hibernateCommonsAnnotationVersion>3.2.0.Beta1</hibernateCommonsAnnotationVersion>
@@ -799,6 +799,7 @@
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/classloading/*.java</exclude>
+ <exclude>**/*PerfTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -825,6 +826,7 @@
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>none</exclude>
+ <exclude>**/*PerfTest.java</exclude>
</excludes>
<includes>
<include>**/classloading/*Test.java</include>
Modified: search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2009-10-29 20:44:57 UTC (rev 17880)
+++ search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2009-10-30 10:52:10 UTC (rev 17881)
@@ -29,7 +29,6 @@
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.hibernate.Transaction;
-import org.hibernate.search.Environment;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
@@ -44,9 +43,9 @@
*/
public class IndexingGeneratedCorpusTest extends TestCase {
- private final int BOOK_NUM = 3000;
- private final int ANCIENTBOOK_NUM = 200;
- private final int DVD_NUM = 2000;
+ private final int BOOK_NUM = 300;
+ private final int ANCIENTBOOK_NUM = 60;
+ private final int DVD_NUM = 200;
private SentenceInventor sentenceInventor = new SentenceInventor( 7L, 10000 );
private FullTextSessionBuilder builder;
Copied: search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyPerfTest.java (from rev 17850, search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyTest.java)
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyPerfTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyPerfTest.java 2009-10-30 10:52:10 UTC (rev 17881)
@@ -0,0 +1,36 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, 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
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.search.test.optimizer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+//having name end in *PerfTest disables it from functional tests
+public class IncrementalOptimizerStrategyPerfTest extends OptimizerPerfTest {
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( "hibernate.search.default.optimizer.transaction_limit.max", "10" );
+ }
+}
Deleted: search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyTest.java 2009-10-29 20:44:57 UTC (rev 17880)
+++ search/trunk/src/test/java/org/hibernate/search/test/optimizer/IncrementalOptimizerStrategyTest.java 2009-10-30 10:52:10 UTC (rev 17881)
@@ -1,35 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, 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
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.search.test.optimizer;
-
-/**
- * @author Emmanuel Bernard
- */
-public class IncrementalOptimizerStrategyTest extends OptimizerTestCase {
- protected void configure(org.hibernate.cfg.Configuration cfg) {
- super.configure( cfg );
- cfg.setProperty( "hibernate.search.default.optimizer.transaction_limit.max", "10" );
- }
-}
Copied: search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java (from rev 17850, search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java)
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java 2009-10-30 10:52:10 UTC (rev 17881)
@@ -0,0 +1,210 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, 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
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.search.test.optimizer;
+
+import java.io.File;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.impl.FullTextSessionImpl;
+import org.hibernate.search.store.FSDirectoryProvider;
+import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.util.FileHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+//having name end in *PerfTest disables it from functional tests
+public class OptimizerPerfTest extends SearchTestCase {
+ protected void setUp() throws Exception {
+ File sub = getBaseIndexDir();
+ FileHelper.delete( sub );
+ sub.mkdir();
+ File[] files = sub.listFiles();
+ for (File file : files) {
+ if ( file.isDirectory() ) {
+ FileHelper.delete( file );
+ }
+ }
+ //super.setUp(); //we need a fresh session factory each time for index set up
+ buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ File sub = getBaseIndexDir();
+ FileHelper.delete( sub );
+ }
+
+ public void testConcurrency() throws Exception {
+ int nThreads = 15;
+ ExecutorService es = Executors.newFixedThreadPool( nThreads );
+ Work work = new Work( getSessions() );
+ ReverseWork reverseWork = new ReverseWork( getSessions() );
+ long start = System.currentTimeMillis();
+ int iteration = 100;
+ for (int i = 0; i < iteration; i++) {
+ es.execute( work );
+ es.execute( reverseWork );
+ }
+ while ( work.count < iteration - 1 ) {
+ Thread.sleep( 20 );
+ }
+ System.out.println( iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
+ .currentTimeMillis() - start ) );
+ }
+
+ protected static class Work implements Runnable {
+ private final SessionFactory sf;
+ public volatile int count = 0;
+
+ public Work(SessionFactory sf) {
+ this.sf = sf;
+ }
+
+ public void run() {
+ try {
+ Session s = sf.openSession();
+ Transaction tx = s.beginTransaction();
+ Worker w = new Worker( "Emmanuel", 65 );
+ s.persist( w );
+ Construction c = new Construction( "Bellagio", "Las Vagas Nevada" );
+ s.persist( c );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ w = (Worker) s.get( Worker.class, w.getId() );
+ w.setName( "Gavin" );
+ c = (Construction) s.get( Construction.class, c.getId() );
+ c.setName( "W Hotel" );
+ tx.commit();
+ s.close();
+
+ try {
+ Thread.sleep( 50 );
+ }
+ catch (InterruptedException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ FullTextSession fts = new FullTextSessionImpl( s );
+ QueryParser parser = new QueryParser( "id", new StopAnalyzer() );
+ Query query;
+ try {
+ query = parser.parse( "name:Gavin" );
+ }
+ catch (ParseException e) {
+ throw new RuntimeException( e );
+ }
+ boolean results = fts.createFullTextQuery( query ).list().size() > 0;
+ //don't test because in case of async, it query happens before actual saving
+ //if ( !results ) throw new RuntimeException( "No results!" );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ w = (Worker) s.get( Worker.class, w.getId() );
+ s.delete( w );
+ c = (Construction) s.get( Construction.class, c.getId() );
+ s.delete( c );
+ tx.commit();
+ s.close();
+ count++;
+ } catch (Throwable t) {
+ t.printStackTrace( );
+ }
+ }
+ }
+
+ protected static class ReverseWork implements Runnable {
+ private SessionFactory sf;
+
+ public ReverseWork(SessionFactory sf) {
+ this.sf = sf;
+ }
+
+ public void run() {
+ try {
+ Session s = sf.openSession();
+ Transaction tx = s.beginTransaction();
+ Worker w = new Worker( "Mladen", 70 );
+ s.persist( w );
+ Construction c = new Construction( "Hover Dam", "Croatia" );
+ s.persist( c );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ w = (Worker) s.get( Worker.class, w.getId() );
+ w.setName( "Remi" );
+ c = (Construction) s.get( Construction.class, c.getId() );
+ c.setName( "Palais des festivals" );
+ tx.commit();
+ s.close();
+
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ w = (Worker) s.get( Worker.class, w.getId() );
+ s.delete( w );
+ c = (Construction) s.get( Construction.class, c.getId() );
+ s.delete( c );
+ tx.commit();
+ s.close();
+ } catch (Throwable t) {
+ t.printStackTrace( );
+ }
+ }
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ File sub = getBaseIndexDir();
+ cfg.setProperty( "hibernate.search.default.indexBase", sub.getAbsolutePath() );
+ cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
+ cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Worker.class,
+ Construction.class
+ };
+ }
+}
Deleted: search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java 2009-10-29 20:44:57 UTC (rev 17880)
+++ search/trunk/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java 2009-10-30 10:52:10 UTC (rev 17881)
@@ -1,209 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, 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
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.search.test.optimizer;
-
-import java.io.File;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.lucene.analysis.StopAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.search.Environment;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.impl.FullTextSessionImpl;
-import org.hibernate.search.store.FSDirectoryProvider;
-import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.util.FileHelper;
-
-/**
- * @author Emmanuel Bernard
- */
-public class OptimizerTestCase extends SearchTestCase {
- protected void setUp() throws Exception {
- File sub = getBaseIndexDir();
- FileHelper.delete( sub );
- sub.mkdir();
- File[] files = sub.listFiles();
- for (File file : files) {
- if ( file.isDirectory() ) {
- FileHelper.delete( file );
- }
- }
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- File sub = getBaseIndexDir();
- FileHelper.delete( sub );
- }
-
- public void testConcurrency() throws Exception {
- int nThreads = 15;
- ExecutorService es = Executors.newFixedThreadPool( nThreads );
- Work work = new Work( getSessions() );
- ReverseWork reverseWork = new ReverseWork( getSessions() );
- long start = System.currentTimeMillis();
- int iteration = 100;
- for (int i = 0; i < iteration; i++) {
- es.execute( work );
- es.execute( reverseWork );
- }
- while ( work.count < iteration - 1 ) {
- Thread.sleep( 20 );
- }
- System.out.println( iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
- .currentTimeMillis() - start ) );
- }
-
- protected static class Work implements Runnable {
- private final SessionFactory sf;
- public volatile int count = 0;
-
- public Work(SessionFactory sf) {
- this.sf = sf;
- }
-
- public void run() {
- try {
- Session s = sf.openSession();
- Transaction tx = s.beginTransaction();
- Worker w = new Worker( "Emmanuel", 65 );
- s.persist( w );
- Construction c = new Construction( "Bellagio", "Las Vagas Nevada" );
- s.persist( c );
- tx.commit();
- s.close();
-
- s = sf.openSession();
- tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
- w.setName( "Gavin" );
- c = (Construction) s.get( Construction.class, c.getId() );
- c.setName( "W Hotel" );
- tx.commit();
- s.close();
-
- try {
- Thread.sleep( 50 );
- }
- catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
-
- s = sf.openSession();
- tx = s.beginTransaction();
- FullTextSession fts = new FullTextSessionImpl( s );
- QueryParser parser = new QueryParser( "id", new StopAnalyzer() );
- Query query;
- try {
- query = parser.parse( "name:Gavin" );
- }
- catch (ParseException e) {
- throw new RuntimeException( e );
- }
- boolean results = fts.createFullTextQuery( query ).list().size() > 0;
- //don't test because in case of async, it query happens before actual saving
- //if ( !results ) throw new RuntimeException( "No results!" );
- tx.commit();
- s.close();
-
- s = sf.openSession();
- tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
- s.delete( w );
- c = (Construction) s.get( Construction.class, c.getId() );
- s.delete( c );
- tx.commit();
- s.close();
- count++;
- } catch (Throwable t) {
- t.printStackTrace( );
- }
- }
- }
-
- protected static class ReverseWork implements Runnable {
- private SessionFactory sf;
-
- public ReverseWork(SessionFactory sf) {
- this.sf = sf;
- }
-
- public void run() {
- try {
- Session s = sf.openSession();
- Transaction tx = s.beginTransaction();
- Worker w = new Worker( "Mladen", 70 );
- s.persist( w );
- Construction c = new Construction( "Hover Dam", "Croatia" );
- s.persist( c );
- tx.commit();
- s.close();
-
- s = sf.openSession();
- tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
- w.setName( "Remi" );
- c = (Construction) s.get( Construction.class, c.getId() );
- c.setName( "Palais des festivals" );
- tx.commit();
- s.close();
-
- s = sf.openSession();
- tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
- s.delete( w );
- c = (Construction) s.get( Construction.class, c.getId() );
- s.delete( c );
- tx.commit();
- s.close();
- } catch (Throwable t) {
- t.printStackTrace( );
- }
- }
- }
-
- protected void configure(org.hibernate.cfg.Configuration cfg) {
- super.configure( cfg );
- File sub = getBaseIndexDir();
- cfg.setProperty( "hibernate.search.default.indexBase", sub.getAbsolutePath() );
- cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
- cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- }
-
- protected Class[] getMappings() {
- return new Class[] {
- Worker.class,
- Construction.class
- };
- }
-}
15 years, 1 month
Hibernate SVN: r17880 - core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-10-29 16:44:57 -0400 (Thu, 29 Oct 2009)
New Revision: 17880
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Basic.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/BasicForcedTableSequenceTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLo.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLoForcedTableSequenceTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Pooled.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/PooledForcedTableSequenceTest.java
Log:
HHH-4532 - Unit Tests in test/idgen/enhanced/forcedtable need update
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Basic.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Basic.hbm.xml 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Basic.hbm.xml 2009-10-29 20:44:57 UTC (rev 17880)
@@ -19,7 +19,7 @@
<param name="initial_value">1</param>
<param name="increment_size">1</param>
<param name="optimizer">none</param>
- <param name="force_tbl_use">true</param>
+ <param name="force_table_use">true</param>
</generator>
</id>
<property name="name" type="string"/>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/BasicForcedTableSequenceTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/BasicForcedTableSequenceTest.java 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/BasicForcedTableSequenceTest.java 2009-10-29 20:44:57 UTC (rev 17880)
@@ -6,6 +6,8 @@
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
+import org.hibernate.id.enhanced.TableStructure;
+import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.Session;
/**
@@ -28,8 +30,19 @@
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
- assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
+ assertTrue(
+ "sequence style generator was not used",
+ SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
+ );
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
+ assertTrue(
+ "table structure was not used",
+ TableStructure.class.isInstance( generator.getDatabaseStructure() )
+ );
+ assertTrue(
+ "no-op optimizer was not used",
+ OptimizerFactory.NoopOptimizer.class.isInstance( generator.getOptimizer() )
+ );
int count = 5;
Entity[] entities = new Entity[count];
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLo.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLo.hbm.xml 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLo.hbm.xml 2009-10-29 20:44:57 UTC (rev 17880)
@@ -18,7 +18,7 @@
<param name="initial_value">1</param>
<param name="increment_size">10</param>
<param name="optimizer">hilo</param>
- <param name="force_tbl_use">true</param>
+ <param name="force_table_use">true</param>
</generator>
</id>
<property name="name" type="string"/>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLoForcedTableSequenceTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLoForcedTableSequenceTest.java 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/HiLoForcedTableSequenceTest.java 2009-10-29 20:44:57 UTC (rev 17880)
@@ -7,6 +7,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
+import org.hibernate.id.enhanced.TableStructure;
import org.hibernate.Session;
/**
@@ -29,9 +30,19 @@
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
- assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
+ assertTrue(
+ "sequence style generator was not used",
+ SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
+ );
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
- assertClassAssignability( OptimizerFactory.HiLoOptimizer.class, generator.getOptimizer().getClass() );
+ assertTrue(
+ "table structure was not used",
+ TableStructure.class.isInstance( generator.getDatabaseStructure() )
+ );
+ assertTrue(
+ "hilo optimizer was not used",
+ OptimizerFactory.HiLoOptimizer.class.isInstance( generator.getOptimizer() )
+ );
OptimizerFactory.HiLoOptimizer optimizer = ( OptimizerFactory.HiLoOptimizer ) generator.getOptimizer();
int increment = optimizer.getIncrementSize();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Pooled.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Pooled.hbm.xml 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/Pooled.hbm.xml 2009-10-29 20:44:57 UTC (rev 17880)
@@ -18,7 +18,7 @@
<param name="initial_value">1</param>
<param name="increment_size">10</param>
<param name="optimizer">pooled</param>
- <param name="force_tbl_use">true</param>
+ <param name="force_table_use">true</param>
</generator>
</id>
<property name="name" type="string"/>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/PooledForcedTableSequenceTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/PooledForcedTableSequenceTest.java 2009-10-29 18:57:24 UTC (rev 17879)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/forcedtable/PooledForcedTableSequenceTest.java 2009-10-29 20:44:57 UTC (rev 17880)
@@ -7,6 +7,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
+import org.hibernate.id.enhanced.TableStructure;
import org.hibernate.Session;
/**
@@ -29,9 +30,19 @@
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
- assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
+ assertTrue(
+ "sequence style generator was not used",
+ SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
+ );
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
- assertClassAssignability( OptimizerFactory.PooledOptimizer.class, generator.getOptimizer().getClass() );
+ assertTrue(
+ "table structure was not used",
+ TableStructure.class.isInstance( generator.getDatabaseStructure() )
+ );
+ assertTrue(
+ "pooled optimizer was not used",
+ OptimizerFactory.PooledOptimizer.class.isInstance( generator.getOptimizer() )
+ );
OptimizerFactory.PooledOptimizer optimizer = ( OptimizerFactory.PooledOptimizer ) generator.getOptimizer();
int increment = optimizer.getIncrementSize();
15 years, 1 month
Hibernate SVN: r17879 - in core/trunk: core/src/main/java/org/hibernate/mapping and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-10-29 14:57:24 -0400 (Thu, 29 Oct 2009)
New Revision: 17879
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MappedSuperclassTypeImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Animal.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cat.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cattish.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Dog.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Feline.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SubThing.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Thing.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java
core/trunk/core/src/main/java/org/hibernate/mapping/MappedSuperclass.java
core/trunk/core/src/main/java/org/hibernate/mapping/PersistentClass.java
core/trunk/core/src/main/java/org/hibernate/mapping/RootClass.java
core/trunk/core/src/main/java/org/hibernate/mapping/Subclass.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
HHH-4533 Populate the JPA 2 metamodel with the new mapping.MappedSuperclass metadata
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -775,6 +775,21 @@
);
entityBinder.setIgnoreIdAnnotations( ignoreIdAnnotations );
persistentClass.setIdentifierMapper( mapper );
+
+ //If id definition is on a mapped superclass, update the mapping
+ final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
+ inferredData.getDeclaringClass(),
+ inheritanceStatePerClass,
+ mappings
+ );
+ if (superclass != null) {
+ superclass.setDeclaredIdentifierMapper(mapper);
+ }
+ else {
+ //we are for sure on the entity
+ persistentClass.setDeclaredIdentifierMapper( mapper );
+ }
+
Property property = new Property();
property.setName( "_identifierMapper" );
property.setNodeName( "id" );
@@ -1462,6 +1477,20 @@
Property prop = propBinder.bind();
propBinder.getSimpleValueBinder().setVersion(true);
rootClass.setVersion( prop );
+
+ //If version is on a mapped superclass, update the mapping
+ final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
+ inferredData.getDeclaringClass(),
+ inheritanceStatePerClass,
+ mappings
+ );
+ if (superclass != null) {
+ superclass.setDeclaredVersion(prop);
+ }
+ else {
+ //we know the property is on the actual entity
+ rootClass.setDeclaredVersion( prop );
+ }
SimpleValue simpleValue = (SimpleValue) prop.getValue();
simpleValue.setNullValue( "undefined" );
@@ -2202,6 +2231,19 @@
binder.setProperty( inferredData.getProperty() );
Property prop = binder.make();
rootClass.setIdentifierProperty( prop );
+ //if the id property is on a superclass, update the metamodel
+ final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
+ inferredData.getDeclaringClass(),
+ inheritanceStatePerClass,
+ mappings
+ );
+ if (superclass != null) {
+ superclass.setDeclaredIdentifierProperty(prop);
+ }
+ else {
+ //we know the property is on the actual entity
+ rootClass.setDeclaredIdentifierProperty( prop );
+ }
}
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -60,6 +60,7 @@
import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
+import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.type.TypeFactory;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
@@ -575,4 +576,24 @@
log.info( "Binding Any Meta definition: {}", defAnn.name() );
mappings.addAnyMetaDef( defAnn );
}
+
+ public static MappedSuperclass getMappedSuperclassOrNull(XClass declaringClass,
+ Map<XClass, InheritanceState> inheritanceStatePerClass,
+ ExtendedMappings mappings) {
+ boolean retrieve = false;
+ if ( declaringClass != null ) {
+ final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
+ if ( inheritanceState == null ) {
+ throw new org.hibernate.annotations.common.AssertionFailure(
+ "Declaring class is not found in the inheritance state hierarchy: " + declaringClass
+ );
+ }
+ if ( inheritanceState.isEmbeddableSuperclass ) {
+ retrieve = true;
+ }
+ }
+ return retrieve ?
+ mappings.getMappedSuperclass( mappings.getReflectionManager().toClass( declaringClass ) ) :
+ null;
+ }
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -130,7 +130,7 @@
final ExtendedMappings mappings = getMappings();
final Class type = mappings.getReflectionManager().toClass( declaringClass );
MappedSuperclass superclass = mappings.getMappedSuperclass( type );
- superclass.addProperty( prop );
+ superclass.addDeclaredProperty( prop );
}
private void addPropertyToJoin(Property prop, XClass declaringClass, Join join) {
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/MappedSuperclass.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/MappedSuperclass.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/MappedSuperclass.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -12,20 +12,27 @@
*
* Do not use outside this use case.
*
- * A proper redesign will be evluated in Hibernate 4
+ *
+ * A proper redesign will be evaluated in Hibernate 4
*
+ * Implementation details:
+ * properties are copies of their closest sub-persistentClass versions
+ *
* @author Emmanuel Bernard
*/
public class MappedSuperclass {
private final MappedSuperclass superMappedSuperclass;
private final PersistentClass superPersistentClass;
- private final List properties;
+ private final List declaredProperties;
private Class mappedClass;
+ private Property identifierProperty;
+ private Property version;
+ private Component identifierMapper;
public MappedSuperclass(MappedSuperclass superMappedSuperclass, PersistentClass superPersistentClass) {
this.superMappedSuperclass = superMappedSuperclass;
this.superPersistentClass = superPersistentClass;
- this.properties = new ArrayList();
+ this.declaredProperties = new ArrayList();
}
/**
@@ -39,6 +46,14 @@
return superMappedSuperclass;
}
+ public boolean hasIdentifierProperty() {
+ return getIdentifierProperty() != null;
+ }
+
+ public boolean isVersioned() {
+ return getVersion() != null;
+ }
+
/**
* Returns the PersistentClass of the first superclass marked as @Entity
* or null if none exists
@@ -49,21 +64,21 @@
return superPersistentClass;
}
- public Iterator getPropertyIterator() {
- return properties.iterator();
+ public Iterator getDeclaredPropertyIterator() {
+ return declaredProperties.iterator();
}
- public void addProperty(Property p) {
+ public void addDeclaredProperty(Property p) {
//Do not add duplicate properties
//TODO is it efficient enough?
String name = p.getName();
- Iterator it = properties.iterator();
+ Iterator it = declaredProperties.iterator();
while (it.hasNext()) {
if ( name.equals( ((Property)it.next()).getName() ) ) {
return;
}
}
- properties.add(p);
+ declaredProperties.add(p);
}
public Class getMappedClass() {
@@ -73,4 +88,73 @@
public void setMappedClass(Class mappedClass) {
this.mappedClass = mappedClass;
}
+
+ public Property getIdentifierProperty() {
+ //get direct identifiermapper or the one from the super mappedSuperclass
+ // or the one from the super persistentClass
+ Property propagatedIdentifierProp = identifierProperty;
+ if ( propagatedIdentifierProp == null ) {
+ if ( superMappedSuperclass != null ) {
+ propagatedIdentifierProp = superMappedSuperclass.getIdentifierProperty();
+ }
+ if (propagatedIdentifierProp == null && superPersistentClass != null){
+ propagatedIdentifierProp = superPersistentClass.getIdentifierProperty();
+ }
+ }
+ return propagatedIdentifierProp;
+ }
+
+ public Property getDeclaredIdentifierProperty() {
+ return identifierProperty;
+ }
+
+ public void setDeclaredIdentifierProperty(Property prop) {
+ this.identifierProperty = prop;
+ }
+
+ public Property getVersion() {
+ //get direct version or the one from the super mappedSuperclass
+ // or the one from the super persistentClass
+ Property propagatedVersion = version;
+ if (propagatedVersion == null) {
+ if ( superMappedSuperclass != null ) {
+ propagatedVersion = superMappedSuperclass.getVersion();
+ }
+ if (propagatedVersion == null && superPersistentClass != null){
+ propagatedVersion = superPersistentClass.getVersion();
+ }
+ }
+ return propagatedVersion;
+ }
+
+ public Property getDeclaredVersion() {
+ return version;
+ }
+
+ public void setDeclaredVersion(Property prop) {
+ this.version = prop;
+ }
+
+ public Component getIdentifierMapper() {
+ //get direct identifiermapper or the one from the super mappedSuperclass
+ // or the one from the super persistentClass
+ Component propagatedMapper = identifierMapper;
+ if ( propagatedMapper == null ) {
+ if ( superMappedSuperclass != null ) {
+ propagatedMapper = superMappedSuperclass.getIdentifierMapper();
+ }
+ if (propagatedMapper == null && superPersistentClass != null){
+ propagatedMapper = superPersistentClass.getIdentifierMapper();
+ }
+ }
+ return propagatedMapper;
+ }
+
+ public Component getDeclaredIdentifierMapper() {
+ return identifierMapper;
+ }
+
+ public void setDeclaredIdentifierMapper(Component identifierMapper) {
+ this.identifierMapper = identifierMapper;
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/PersistentClass.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/PersistentClass.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/PersistentClass.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -98,6 +98,7 @@
protected int optimisticLockMode;
private MappedSuperclass superMappedSuperclass;
+ private Component declaredIdentifierMapper;
public String getClassName() {
return className;
@@ -236,8 +237,10 @@
public abstract boolean isMutable();
public abstract boolean hasIdentifierProperty();
public abstract Property getIdentifierProperty();
+ public abstract Property getDeclaredIdentifierProperty();
public abstract KeyValue getIdentifier();
public abstract Property getVersion();
+ public abstract Property getDeclaredVersion();
public abstract Value getDiscriminator();
public abstract boolean isInherited();
public abstract boolean isPolymorphic();
@@ -776,6 +779,14 @@
return identifierMapper;
}
+ public Component getDeclaredIdentifierMapper() {
+ return declaredIdentifierMapper;
+ }
+
+ public void setDeclaredIdentifierMapper(Component declaredIdentifierMapper) {
+ this.declaredIdentifierMapper = declaredIdentifierMapper;
+ }
+
public boolean hasIdentifierMapper() {
return identifierMapper != null;
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/RootClass.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/RootClass.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/RootClass.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -61,7 +61,9 @@
private Table table;
private boolean discriminatorInsertable = true;
private int nextSubclassId = 0;
-
+ private Property declaredIdentifierProperty;
+ private Property declaredVersion;
+
int nextSubclassId() {
return ++nextSubclassId;
}
@@ -80,6 +82,15 @@
public Property getIdentifierProperty() {
return identifierProperty;
}
+
+ public Property getDeclaredIdentifierProperty() {
+ return declaredIdentifierProperty;
+ }
+
+ public void setDeclaredIdentifierProperty(Property declaredIdentifierProperty) {
+ this.declaredIdentifierProperty = declaredIdentifierProperty;
+ }
+
public KeyValue getIdentifier() {
return identifier;
}
@@ -128,6 +139,15 @@
public Property getVersion() {
return version;
}
+
+ public Property getDeclaredVersion() {
+ return declaredVersion;
+ }
+
+ public void setDeclaredVersion(Property declaredVersion) {
+ this.declaredVersion = declaredVersion;
+ }
+
public void setVersion(Property version) {
this.version = version;
}
@@ -181,6 +201,7 @@
public void setIdentifierProperty(Property identifierProperty) {
this.identifierProperty = identifierProperty;
identifierProperty.setPersistentClass(this);
+
}
public void setMutable(boolean mutable) {
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/Subclass.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/Subclass.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/Subclass.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -70,6 +70,11 @@
public Property getIdentifierProperty() {
return getSuperclass().getIdentifierProperty();
}
+
+ public Property getDeclaredIdentifierProperty() {
+ return null;
+ }
+
public KeyValue getIdentifier() {
return getSuperclass().getIdentifier();
}
@@ -143,6 +148,10 @@
return getSuperclass().getVersion();
}
+ public Property getDeclaredVersion() {
+ return null;
+ }
+
public boolean hasEmbeddedIdentifier() {
return getSuperclass().hasEmbeddedIdentifier();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AbstractIdentifiableType.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -97,7 +97,19 @@
}
}
else {
- id_ = requireSupertype().getId( javaType );
+ //yuk yuk bad me
+ if (this instanceof MappedSuperclassTypeImpl) {
+ final AbstractIdentifiableType<? super X> supertype = getSupertype();
+ if (supertype != null) {
+ id_ = supertype.getId( javaType );
+ }
+ else {
+ id_ = null;
+ }
+ }
+ else {
+ id_ = requireSupertype().getId( javaType );
+ }
}
return id_;
}
@@ -227,6 +239,7 @@
return new Builder<X>() {
public void applyIdAttribute(SingularAttributeImpl<X, ?> idAttribute) {
AbstractIdentifiableType.this.id = idAttribute;
+ managedBuilder.addAttribute( idAttribute );
}
public void applyIdClassAttributes(Set<SingularAttribute<? super X,?>> idClassAttributes) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -54,19 +54,19 @@
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
+ public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
AttributeContext attrContext = getAttributeContext( property );
final AttributeImplementor<X, Y> attribute;
if ( attrContext.isCollection() ) {
- attribute = buildPluralAttribute( ownerType, property, attrContext );
+ attribute = buildPluralAttribute( ownerType, property, attrContext, getMember );
}
else {
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
attribute = new SingularAttributeImpl<X,Y>(
property.getName(),
property.getType().getReturnedClass(),
ownerType,
- determineStandardJavaMember( ownerType, property ),
+ getMember ? determineStandardJavaMember( ownerType, property ) : null,
false,
false,
property.isOptional(),
@@ -78,21 +78,21 @@
}
@SuppressWarnings( "unchecked" )
- private <X, Y, V, K> AttributeImplementor<X, Y> buildPluralAttribute(AbstractManagedType<X> ownerType, Property property, AttributeContext attrContext) {
+ private <X, Y, V, K> AttributeImplementor<X, Y> buildPluralAttribute(AbstractManagedType<X> ownerType, Property property, AttributeContext attrContext, boolean getMember) {
AttributeImplementor<X, Y> attribute;
- final Type<V> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Type<V> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
final Class<Y> collectionClass = (Class<Y>) attrContext.getCollectionClass();
if ( java.util.Map.class.isAssignableFrom( collectionClass ) ) {
- final Type<K> keyType = getType( ownerType, attrContext.getKeyTypeStatus(), attrContext.getKeyValue() );
+ final Type<K> keyType = getType( ownerType, attrContext.getKeyTypeStatus(), attrContext.getKeyValue(), getMember );
attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, keyType )
- .member( determineStandardJavaMember( ownerType, property ) )
+ .member( getMember ? determineStandardJavaMember( ownerType, property ) : null )
.property( property )
.persistentAttributeType( attrContext.getElementAttributeType() )
.build();
}
else {
attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, null )
- .member( determineStandardJavaMember( ownerType, property ) )
+ .member( getMember ? determineStandardJavaMember( ownerType, property ) : null )
.property( property )
.persistentAttributeType( attrContext.getElementAttributeType() )
.build();
@@ -100,13 +100,13 @@
return attribute;
}
- private <X> Type<X> getType(AbstractManagedType owner, AttributeContext.TypeStatus elementTypeStatus, Value value) {
+ private <X> Type<X> getType(AbstractManagedType owner, AttributeContext.TypeStatus elementTypeStatus, Value value, boolean getMember) {
final org.hibernate.type.Type type = value.getType();
switch ( elementTypeStatus ) {
case BASIC:
return buildBasicType( type );
case EMBEDDABLE:
- return buildEmbeddableType( owner, value, type );
+ return buildEmbeddableType( owner, value, type, getMember );
case ENTITY:
return buildEntityType( type );
default:
@@ -128,7 +128,7 @@
}
@SuppressWarnings( "unchecked" )
- private <X> Type<X> buildEmbeddableType(AbstractManagedType owner, Value value, org.hibernate.type.Type type) {
+ private <X> Type<X> buildEmbeddableType(AbstractManagedType owner, Value value, org.hibernate.type.Type type, boolean getMember) {
//build embedable type
final Class<X> clazz = type.getReturnedClass();
final EmbeddableTypeImpl<X> embeddableType = new EmbeddableTypeImpl<X>( clazz, owner, (ComponentType) type );
@@ -137,22 +137,22 @@
final Iterator<Property> subProperties = component.getPropertyIterator();
while ( subProperties.hasNext() ) {
final Property property = subProperties.next();
- embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property ) );
+ embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property, getMember ) );
}
embeddableType.lock();
return embeddableType;
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractManagedType<X> ownerType, Property property) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
final AttributeContext attrContext = getAttributeContext( property );
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
final Class<Y> idJavaType = property.getType().getReturnedClass();
return new SingularAttributeImpl.Identifier(
property.getName(),
idJavaType,
ownerType,
- determineIdentifierJavaMember( ownerType, property ),
+ getMember ? determineIdentifierJavaMember( ownerType, property ) : null,
attrType,
attrContext.getElementAttributeType()
);
@@ -232,15 +232,15 @@
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildVerisonAttribute(AbstractManagedType<X> ownerType, Property property) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
final AttributeContext attrContext = getAttributeContext( property );
final Class<Y> javaType = property.getType().getReturnedClass();
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
return new SingularAttributeImpl.Version(
property.getName(),
javaType,
ownerType,
- determineVersionJavaMember( ownerType, property ),
+ getMember ? determineVersionJavaMember( ownerType, property ) : null,
attrType,
attrContext.getElementAttributeType()
);
@@ -252,7 +252,7 @@
// this should never happen, but to be safe...
throw new IllegalArgumentException( "Given property did not match declared version property" );
}
- return entityMetamodel.getTuplizer( EntityMode.POJO ).getIdentifierGetter().getMember();
+ return entityMetamodel.getTuplizer( EntityMode.POJO ).getVersionGetter().getMember();
}
private static class AttributeContext {
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MappedSuperclassTypeImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MappedSuperclassTypeImpl.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MappedSuperclassTypeImpl.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,21 @@
+package org.hibernate.ejb.metamodel;
+
+import javax.persistence.metamodel.MappedSuperclassType;
+import javax.persistence.metamodel.Type;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MappedSuperclassTypeImpl<X> extends AbstractIdentifiableType<X> implements MappedSuperclassType<X> {
+ public MappedSuperclassTypeImpl(
+ Class<X> javaType,
+ AbstractIdentifiableType<? super X> superType,
+ boolean hasIdentifierProperty,
+ boolean versioned) {
+ super( javaType, superType, hasIdentifierProperty, versioned );
+ }
+
+ public PersistenceType getPersistenceType() {
+ return PersistenceType.MAPPED_SUPERCLASS;
+ }
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -25,16 +25,18 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.MappedSuperclass;
+import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.annotations.common.AssertionFailure;
/**
* Defines a context for storing information during the building of the {@link MetamodelImpl}.
@@ -53,14 +55,18 @@
private final SessionFactoryImplementor sessionFactory;
private final AttributeFactory attributeFactory = new AttributeFactory( this );
- private HashMap<Class<?>,EntityTypeImpl<?>> entityTypes
+ private Map<Class<?>,EntityTypeImpl<?>> entityTypes
= new HashMap<Class<?>, EntityTypeImpl<?>>();
- private HashMap<String,EntityTypeImpl<?>> entityTypesByEntityName
+ private Map<String,EntityTypeImpl<?>> entityTypesByEntityName
= new HashMap<String, EntityTypeImpl<?>>();
- private LinkedHashMap<PersistentClass,EntityTypeImpl<?>> entityTypesByPersistentClass
- = new LinkedHashMap<PersistentClass,EntityTypeImpl<?>>();
- private HashMap<Class<?>, EmbeddableTypeImpl<?>> embeddables
+ private Map<PersistentClass,EntityTypeImpl<?>> entityTypesByPersistentClass
+ = new HashMap<PersistentClass,EntityTypeImpl<?>>();
+ private Map<Class<?>, EmbeddableTypeImpl<?>> embeddables
= new HashMap<Class<?>, EmbeddableTypeImpl<?>>();
+ private Map<MappedSuperclass, MappedSuperclassTypeImpl<?>> mappedSuperclassByMappedSuperclassMapping
+ = new HashMap<MappedSuperclass,MappedSuperclassTypeImpl<?>>();
+ //this list contains MappedSuperclass and EntityTypes ordered by superclass first
+ private List<Object> orderedMappings = new ArrayList<Object>();
public MetadataContext(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
@@ -87,12 +93,19 @@
entityTypes.put( entityType.getBindableJavaType(), entityType );
entityTypesByEntityName.put( persistentClass.getEntityName(), entityType );
entityTypesByPersistentClass.put( persistentClass, entityType );
+ orderedMappings.add( persistentClass );
}
/*package*/ void registerEmbeddedableType(EmbeddableTypeImpl<?> embeddableType) {
embeddables.put( embeddableType.getJavaType(), embeddableType );
}
+ /*package*/ void registerMappedSuperclassType(MappedSuperclass mappedSuperclass,
+ MappedSuperclassTypeImpl<?> mappedSuperclassType) {
+ mappedSuperclassByMappedSuperclassMapping.put( mappedSuperclass, mappedSuperclassType );
+ orderedMappings.add( mappedSuperclass );
+ }
+
/**
* Given a Hibernate {@link PersistentClass}, locate the corresponding JPA {@link org.hibernate.type.EntityType}
* implementation. May retur null if the given {@link PersistentClass} has not yet been processed.
@@ -128,54 +141,120 @@
@SuppressWarnings({ "unchecked" })
public void wrapUp() {
- // IMPL NOTE : entityTypesByPersistentClass is a insertion-ordered map, where the insertion order
- // ensures that a type's super type is already processed...
- for ( Map.Entry<PersistentClass,EntityTypeImpl<?>> entry : entityTypesByPersistentClass.entrySet() ) {
- applyIdMetadata( entry.getKey(), entry.getValue() );
- applyVersionAttribute( entry.getKey(), entry.getValue() );
- Iterator<Property> properties = ( Iterator<Property> ) entry.getKey().getPropertyIterator();
- while ( properties.hasNext() ) {
- final Property property = properties.next();
- final Attribute attribute = attributeFactory.buildAttribute( entry.getValue(), property );
- entry.getValue().getBuilder().addAttribute( attribute );
+ //we need to process types from superclasses to subclasses
+ for (Object mapping : orderedMappings) {
+ if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
+ @SuppressWarnings( "unchecked" )
+ final PersistentClass safeMapping = (PersistentClass) mapping;
+ final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, true );
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
}
- entry.getValue().lock();
- populateStaticMetamodel( entry.getValue() );
+ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
+ @SuppressWarnings( "unchecked" )
+ final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
+ final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
+ safeMapping
+ );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, false );
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
+ }
+ else {
+ throw new AssertionFailure( "Unexpected mapping type: " + mapping.getClass() );
+ }
}
}
private <X> void applyIdMetadata(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
if ( persistentClass.hasIdentifierProperty() ) {
- jpaEntityType.getBuilder().applyIdAttribute(
- attributeFactory.buildIdAttribute( jpaEntityType, persistentClass.getIdentifierProperty() )
- );
+ final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty();
+ if (declaredIdentifierProperty != null) {
+ jpaEntityType.getBuilder().applyIdAttribute(
+ attributeFactory.buildIdAttribute( jpaEntityType, declaredIdentifierProperty, true )
+ );
+ }
}
else {
jpaEntityType.getBuilder().applyIdClassAttributes( buildIdClassAttributes( jpaEntityType, persistentClass ) );
}
}
+ private <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassTypeImpl<X> jpaMappingType) {
+ if ( mappingType.hasIdentifierProperty() ) {
+ final Property declaredIdentifierProperty = mappingType.getDeclaredIdentifierProperty();
+ if (declaredIdentifierProperty != null) {
+ jpaMappingType.getBuilder().applyIdAttribute(
+ attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty, false )
+ );
+ }
+ }
+ //an MappedSuperclass can have no identifier if the id is set below in the hierarchy
+ else if ( mappingType.getIdentifierMapper() != null ){
+ final Set<SingularAttribute<? super X, ?>> attributes = buildIdClassAttributes(
+ jpaMappingType, mappingType
+ );
+ jpaMappingType.getBuilder().applyIdClassAttributes( attributes );
+ }
+ }
+
private <X> void applyVersionAttribute(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
- if ( ! persistentClass.isVersioned() ) {
- return;
+ final Property declaredVersion = persistentClass.getDeclaredVersion();
+ if (declaredVersion != null) {
+ jpaEntityType.getBuilder().applyVersionAttribute(
+ attributeFactory.buildVersionAttribute( jpaEntityType, declaredVersion, true )
+ );
}
- jpaEntityType.getBuilder().applyVersionAttribute(
- attributeFactory.buildVerisonAttribute( jpaEntityType, persistentClass.getVersion() )
- );
}
- @SuppressWarnings( "unchecked")
+ private <X> void applyVersionAttribute(MappedSuperclass mappingType, MappedSuperclassTypeImpl<X> jpaMappingType) {
+ final Property declaredVersion = mappingType.getDeclaredVersion();
+ if ( declaredVersion != null ) {
+ jpaMappingType.getBuilder().applyVersionAttribute(
+ attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion, false )
+ );
+ }
+ }
+
private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
EntityTypeImpl<X> jpaEntityType,
PersistentClass persistentClass) {
Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
+ @SuppressWarnings( "unchecked")
Iterator<Property> properties = persistentClass.getIdentifierMapper().getPropertyIterator();
while ( properties.hasNext() ) {
- attributes.add( attributeFactory.buildIdAttribute( jpaEntityType, properties.next() ) );
+ attributes.add( attributeFactory.buildIdAttribute( jpaEntityType, properties.next(), true ) );
}
return attributes;
}
+ private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
+ MappedSuperclassTypeImpl<X> jpaMappingType,
+ MappedSuperclass mappingType) {
+ Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
+ @SuppressWarnings( "unchecked" )
+ Iterator<Property> properties = mappingType.getIdentifierMapper().getPropertyIterator();
+ while ( properties.hasNext() ) {
+ attributes.add( attributeFactory.buildIdAttribute( jpaMappingType, properties.next(), false ) );
+ }
+ return attributes;
+ }
+
private <X> void populateStaticMetamodel(AbstractManagedType<X> managedType) {
final Class<X> managedTypeClass = managedType.getJavaType();
final String metamodelClassName = managedTypeClass.getName() + "_";
@@ -206,4 +285,7 @@
// push the attributes on to the metamodel class...
}
+ public MappedSuperclassTypeImpl<?> locateMappedSuperclassType(MappedSuperclass mappedSuperclass) {
+ return mappedSuperclassByMappedSuperclassMapping.get(mappedSuperclass);
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetamodelImpl.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -32,6 +32,7 @@
import javax.persistence.metamodel.EmbeddableType;
import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.engine.SessionFactoryImplementor;
/**
@@ -46,7 +47,7 @@
/**
* Build the metamodel using the information from the collection of Hibernate
- * {@link PersistentClass} models as well as the Hibernate {@link SessionFactory}.
+ * {@link PersistentClass} models as well as the Hibernate {@link org.hibernate.SessionFactory}.
*
* @param persistentClasses Iterator over the Hibernate (config-time) metamodel
* @param sessionFactory The Hibernate session factry.
@@ -74,16 +75,24 @@
return entityType;
}
- @SuppressWarnings({ "unchecked" })
+ //TODO remove / reduce @SW scope
+ @SuppressWarnings( "unchecked" )
private static EntityTypeImpl<?> buildEntityType(PersistentClass persistentClass, MetadataContext context) {
- final PersistentClass superPersistentClass = persistentClass.getSuperclass();
- final EntityTypeImpl superEntityType = superPersistentClass == null
+ final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass();
+ AbstractIdentifiableType<?> superType = superMappedSuperclass == null
? null
- : locateOrBuildEntityType( superPersistentClass, context );
+ : locateOrBuildMappedsuperclassType( superMappedSuperclass, context );
+ //no mappedSuperclass, check for a super entity
+ if (superType == null) {
+ final PersistentClass superPersistentClass = persistentClass.getSuperclass();
+ superType = superPersistentClass == null
+ ? null
+ : locateOrBuildEntityType( superPersistentClass, context );
+ }
final Class javaType = persistentClass.getMappedClass();
EntityTypeImpl entityType = new EntityTypeImpl(
javaType,
- superEntityType,
+ superType,
persistentClass.getClassName(),
persistentClass.hasIdentifierProperty(),
persistentClass.isVersioned()
@@ -92,6 +101,41 @@
return entityType;
}
+ private static MappedSuperclassTypeImpl<?> locateOrBuildMappedsuperclassType(
+ MappedSuperclass mappedSuperclass, MetadataContext context) {
+ MappedSuperclassTypeImpl<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
+ if ( mappedSuperclassType == null ) {
+ mappedSuperclassType = buildMappedSuperclassType(mappedSuperclass, context);
+ }
+ return mappedSuperclassType;
+ }
+
+ //TODO remove / reduce @SW scope
+ @SuppressWarnings( "unchecked" )
+ private static MappedSuperclassTypeImpl<?> buildMappedSuperclassType(MappedSuperclass mappedSuperclass,
+ MetadataContext context) {
+ final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
+ AbstractIdentifiableType<?> superType = superMappedSuperclass == null
+ ? null
+ : locateOrBuildMappedsuperclassType( superMappedSuperclass, context );
+ //no mappedSuperclass, check for a super entity
+ if (superType == null) {
+ final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass();
+ superType = superPersistentClass == null
+ ? null
+ : locateOrBuildEntityType( superPersistentClass, context );
+ }
+ final Class javaType = mappedSuperclass.getMappedClass();
+ MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
+ javaType,
+ superType,
+ mappedSuperclass.hasIdentifierProperty(),
+ mappedSuperclass.isVersioned()
+ );
+ context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType );
+ return mappedSuperclassType;
+ }
+
/**
* Instantiate the metamodel.
*
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Animal.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Animal.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Animal.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,31 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Animal extends SubThing {
+ private Long id;
+ private int legNbr;
+
+ @Id @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public int getLegNbr() {
+ return legNbr;
+ }
+
+ public void setLegNbr(int legNbr) {
+ this.legNbr = legNbr;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cat.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cat.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cat.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,19 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Cat extends Cattish {
+ private String nickname;
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cattish.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cattish.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Cattish.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,19 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Cattish extends Feline {
+ private long hoursOfSleep;
+
+ public long getHoursOfSleep() {
+ return hoursOfSleep;
+ }
+
+ public void setHoursOfSleep(long hoursOfSleep) {
+ this.hoursOfSleep = hoursOfSleep;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Dog.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Dog.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Dog.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,19 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Dog extends Animal {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Feline.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Feline.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Feline.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,19 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Feline extends Animal {
+ private String color;
+
+ public String getColor() {
+ return color;
+ }
+
+ public void setColor(String color) {
+ this.color = color;
+ }
+}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-10-29 17:22:00 UTC (rev 17878)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -12,6 +12,9 @@
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MappedSuperclassType;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.IdentifiableType;
import org.hibernate.ejb.test.TestCase;
@@ -53,6 +56,8 @@
assertFalse( fridgeType.hasVersionAttribute() );
assertEquals( Type.PersistenceType.ENTITY, fridgeType.getPersistenceType() );
+ assertEquals( 3, fridgeType.getDeclaredAttributes().size() );
+
final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
assertTrue( houseType.hasSingleIdAttribute() );
final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
@@ -74,6 +79,7 @@
final SingularAttribute<? super FoodItem, Long> version = foodType.getVersion( Long.class );
assertNotNull( version );
assertTrue( version.isVersion() );
+ assertEquals( 3, foodType.getDeclaredAttributes().size() );
}
@@ -158,15 +164,96 @@
assertEquals( PluralAttribute.CollectionType.LIST, roomsBySize.getCollectionType() );
}
- //todo test plural
+ public void testHierarchy() {
+ final EntityType<Cat> cat = factory.getMetamodel().entity( Cat.class );
+ assertNotNull( cat );
+ assertEquals( 7, cat.getAttributes().size() );
+ assertEquals( 1, cat.getDeclaredAttributes().size() );
+ assertTrue( cat.hasVersionAttribute() );
+ assertEquals( "version", cat.getVersion(Long.class).getName() );
+ verifyDeclaredVersiobnNotPresent( cat );
+ verifyDeclaredIdNotPresentAndIdPresent(cat);
+
+ assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, cat.getSupertype().getPersistenceType() );
+ MappedSuperclassType<Cattish> cattish = (MappedSuperclassType<Cattish>) cat.getSupertype();
+ assertEquals( 6, cattish.getAttributes().size() );
+ assertEquals( 1, cattish.getDeclaredAttributes().size() );
+
+ assertTrue( cattish.hasVersionAttribute() );
+ assertEquals( "version", cattish.getVersion(Long.class).getName() );
+ verifyDeclaredVersiobnNotPresent( cattish );
+ verifyDeclaredIdNotPresentAndIdPresent(cattish);
+
+ assertEquals( Type.PersistenceType.ENTITY, cattish.getSupertype().getPersistenceType() );
+ EntityType<Feline> feline = (EntityType<Feline>) cattish.getSupertype();
+ assertEquals( 5, feline.getAttributes().size() );
+ assertEquals( 1, feline.getDeclaredAttributes().size() );
+
+ assertTrue( feline.hasVersionAttribute() );
+ assertEquals( "version", feline.getVersion(Long.class).getName() );
+ verifyDeclaredVersiobnNotPresent( feline );
+ verifyDeclaredIdNotPresentAndIdPresent(feline);
+
+ assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, feline.getSupertype().getPersistenceType() );
+ MappedSuperclassType<Animal> animal = (MappedSuperclassType<Animal>) feline.getSupertype();
+ assertEquals( 4, animal.getAttributes().size() );
+ assertEquals( 2, animal.getDeclaredAttributes().size() );
+
+ assertTrue( animal.hasVersionAttribute() );
+ assertEquals( "version", animal.getVersion(Long.class).getName() );
+ verifyDeclaredVersiobnNotPresent( animal );
+ assertEquals( "id", animal.getId(Long.class).getName() );
+ assertEquals( "id", animal.getDeclaredId(Long.class).getName() );
+
+ assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, animal.getSupertype().getPersistenceType() );
+ MappedSuperclassType<Thing> thing = (MappedSuperclassType<Thing>) animal.getSupertype();
+ assertEquals( 2, thing.getAttributes().size() );
+ assertEquals( 2, thing.getDeclaredAttributes().size() );
+ final SingularAttribute<Thing, Double> weight = thing.getDeclaredSingularAttribute( "weight", Double.class );
+ assertEquals( Double.class, weight.getJavaType() );
+
+ assertEquals( "version", thing.getVersion(Long.class).getName() );
+ assertEquals( "version", thing.getDeclaredVersion(Long.class).getName() );
+ assertNull( thing.getId( Long.class ) );
+
+ assertNull( thing.getSupertype() );
+ }
+
+ private void verifyDeclaredIdNotPresentAndIdPresent(IdentifiableType<?> type) {
+ assertEquals( "id", type.getId(Long.class).getName() );
+ try {
+ type.getDeclaredId(Long.class);
+ fail("Should not have a declared id");
+ }
+ catch (IllegalArgumentException e) {
+ //success
+ }
+ }
+
+ private void verifyDeclaredVersiobnNotPresent(IdentifiableType<?> type) {
+ try {
+ type.getDeclaredVersion(Long.class);
+ fail("Should not have a declared version");
+ }
+ catch (IllegalArgumentException e) {
+ //success
+ }
+ }
+
+ //todo test plural
+
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Fridge.class,
FoodItem.class,
Person.class,
- House.class
+ House.class,
+ Dog.class,
+ Cat.class,
+ Cattish.class,
+ Feline.class
};
}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SubThing.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SubThing.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SubThing.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,17 @@
+package org.hibernate.ejb.test.metadata;
+
+/**
+ * @author Emmanuel Bernard
+ */
+//not an entity but in between mapped superclass and entity
+public class SubThing extends Thing {
+ private String blah;
+
+ public String getBlah() {
+ return blah;
+ }
+
+ public void setBlah(String blah) {
+ this.blah = blah;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Thing.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Thing.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Thing.java 2009-10-29 18:57:24 UTC (rev 17879)
@@ -0,0 +1,30 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Thing {
+ private Double weight;
+ private Long version;
+
+ public Double getWeight() {
+ return weight;
+ }
+
+ public void setWeight(Double weight) {
+ this.weight = weight;
+ }
+
+ @Version
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+}
15 years, 1 month
Hibernate SVN: r17878 - in core/trunk: entitymanager and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-10-29 13:22:00 -0400 (Thu, 29 Oct 2009)
New Revision: 17878
Modified:
core/trunk/annotations/pom.xml
core/trunk/entitymanager/pom.xml
Log:
Removed link to issue tracker. Defined in parent
Updated BV version
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2009-10-29 13:55:33 UTC (rev 17877)
+++ core/trunk/annotations/pom.xml 2009-10-29 17:22:00 UTC (rev 17878)
@@ -40,11 +40,6 @@
<name>Hibernate Annotations</name>
<description>Annotations metadata for Hibernate</description>
- <issueManagement>
- <system>jira</system>
- <url>http://opensource.atlassian.com/projects/hibernate/browse/ANN</url>
- </issueManagement>
-
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
@@ -86,12 +81,12 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.CR4</version>
+ <version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <version>4.0.0.CR1</version>
+ <version>4.0.0.GA</version>
</dependency>
</dependencies>
</dependencyManagement>
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2009-10-29 13:55:33 UTC (rev 17877)
+++ core/trunk/entitymanager/pom.xml 2009-10-29 17:22:00 UTC (rev 17878)
@@ -16,12 +16,6 @@
<name>Hibernate Entitity Manager</name>
<description>Hibernate Entitity Manager</description>
- <!-- Annotations and Commons-Annotations both use the ANN JIRA key -->
- <issueManagement>
- <system>jira</system>
- <url>http://opensource.atlassian.com/projects/hibernate/browse/ANN</url>
- </issueManagement>
-
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
15 years, 1 month
Hibernate SVN: r17877 - in core/trunk/testsuite/src/test/java/org/hibernate/test: idprops and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-10-29 09:55:33 -0400 (Thu, 29 Oct 2009)
New Revision: 17877
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
Log:
HHH-1724 updated test which expected an Integer instead of Long as row count
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java 2009-10-29 08:52:03 UTC (rev 17876)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java 2009-10-29 13:55:33 UTC (rev 17877)
@@ -370,10 +370,10 @@
//s.flush();
- Integer count = (Integer) s.createCriteria(Enrolment.class)
+ Long count = (Long) s.createCriteria(Enrolment.class)
.setProjection( Projections.count("studentNumber").setDistinct() )
.uniqueResult();
- assertEquals(count, new Integer(2));
+ assertEquals(count, new Long(2));
Object object = s.createCriteria(Enrolment.class)
.setProjection( Projections.projectionList()
@@ -385,7 +385,7 @@
.uniqueResult();
Object[] result = (Object[])object;
- assertEquals(new Integer(2),result[0]);
+ assertEquals(new Long(2),result[0]);
assertEquals(new Long(667),result[1]);
assertEquals(new Long(101),result[2]);
assertEquals( 384.0, ( (Double) result[3] ).doubleValue(), 0.01 );
@@ -544,10 +544,10 @@
s.flush();
- Integer count = (Integer) s.createCriteria(Enrolment.class)
+ Long count = (Long) s.createCriteria(Enrolment.class)
.setProjection( Property.forName("studentNumber").count().setDistinct() )
.uniqueResult();
- assertEquals(count, new Integer(2));
+ assertEquals(count, new Long(2));
Object object = s.createCriteria(Enrolment.class)
.setProjection( Projections.projectionList()
@@ -559,7 +559,7 @@
.uniqueResult();
Object[] result = (Object[])object;
- assertEquals(new Integer(2),result[0]);
+ assertEquals(new Long(2),result[0]);
assertEquals(new Long(667),result[1]);
assertEquals(new Long(101),result[2]);
assertEquals(384.0, ( (Double) result[3] ).doubleValue(), 0.01);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java 2009-10-29 08:52:03 UTC (rev 17876)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idprops/IdentifierPropertyReferencesTest.java 2009-10-29 13:55:33 UTC (rev 17877)
@@ -182,6 +182,6 @@
}
private long extractCount(Criteria crit) {
- return ( ( Integer ) crit.list().get( 0 ) ).intValue();
+ return ( ( Long ) crit.list().get( 0 ) ).longValue();
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java 2009-10-29 08:52:03 UTC (rev 17876)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java 2009-10-29 13:55:33 UTC (rev 17877)
@@ -86,8 +86,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -122,8 +122,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -159,8 +159,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -203,8 +203,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -239,8 +239,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -276,8 +276,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
@@ -321,8 +321,8 @@
cv2 = (ContractVariation) it.next();
assertEquals( cv2.getText(), "more expensive" );
s.delete(c);
- assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
- assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );
+ assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
+ assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) );
t.commit();
s.close();
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java 2009-10-29 08:52:03 UTC (rev 17876)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java 2009-10-29 13:55:33 UTC (rev 17877)
@@ -603,7 +603,7 @@
s.createCriteria(NumberedNode.class)
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer(2)
+ new Long(2)
);
s.close();
@@ -646,7 +646,7 @@
s.createCriteria(NumberedNode.class)
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer(2)
+ new Long(2)
);
tx.commit();
@@ -691,7 +691,7 @@
s.createCriteria(NumberedNode.class)
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer(2)
+ new Long(2)
);
tx.commit();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-10-29 08:52:03 UTC (rev 17876)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java 2009-10-29 13:55:33 UTC (rev 17877)
@@ -242,7 +242,7 @@
s.createCriteria( NumberedNode.class )
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer( 2 )
+ new Long( 2 )
);
s.delete( root );
s.delete( child );
@@ -299,7 +299,7 @@
s.createCriteria( NumberedNode.class )
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer( 2 )
+ new Long( 2 )
);
s.delete( root );
s.delete( child );
@@ -353,7 +353,7 @@
s.createCriteria( Node.class )
.setProjection( Projections.rowCount() )
.uniqueResult(),
- new Integer( 2 )
+ new Long( 2 )
);
s.delete( root );
s.delete( child );
15 years, 1 month