HHH-6110 : Integrate new metamodel into persisters
This commit is contained in:
parent
ba44ae26cb
commit
814b514933
|
@ -29,6 +29,7 @@ import org.hibernate.cache.spi.CacheDataDescription;
|
|||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.type.VersionType;
|
||||
|
||||
/**
|
||||
|
@ -68,20 +69,10 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
|
|||
}
|
||||
|
||||
public static CacheDataDescriptionImpl decode(EntityBinding model) {
|
||||
Comparator versionComparator = null;
|
||||
if ( model.isVersioned() ) {
|
||||
versionComparator = (
|
||||
( VersionType ) model
|
||||
.getVersioningValueBinding()
|
||||
.getHibernateTypeDescriptor()
|
||||
.getExplicitType()
|
||||
).getComparator();
|
||||
}
|
||||
|
||||
return new CacheDataDescriptionImpl(
|
||||
model.isMutable(),
|
||||
model.isVersioned(),
|
||||
versionComparator
|
||||
getVersionComparator( model )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -92,4 +83,25 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
|
|||
model.getOwner().isVersioned() ? ( ( VersionType ) model.getOwner().getVersion().getType() ).getComparator() : null
|
||||
);
|
||||
}
|
||||
|
||||
public static CacheDataDescriptionImpl decode(PluralAttributeBinding model) {
|
||||
return new CacheDataDescriptionImpl(
|
||||
model.isMutable(),
|
||||
model.getEntityBinding().isVersioned(),
|
||||
getVersionComparator( model.getEntityBinding() )
|
||||
);
|
||||
}
|
||||
|
||||
private static Comparator getVersionComparator(EntityBinding model ) {
|
||||
Comparator versionComparator = null;
|
||||
if ( model.isVersioned() ) {
|
||||
versionComparator = (
|
||||
( VersionType ) model
|
||||
.getVersioningValueBinding()
|
||||
.getHibernateTypeDescriptor()
|
||||
.getExplicitType()
|
||||
).getComparator();
|
||||
}
|
||||
return versionComparator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.cache.spi.access;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.spi.CollectionRegion;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +38,7 @@ import org.hibernate.cache.spi.CollectionRegion;
|
|||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface CollectionRegionAccessStrategy {
|
||||
public interface CollectionRegionAccessStrategy extends RegionAccessStrategy {
|
||||
|
||||
/**
|
||||
* Get the wrapped collection cache region
|
||||
|
@ -48,125 +47,4 @@ public interface CollectionRegionAccessStrategy {
|
|||
*/
|
||||
public CollectionRegion getRegion();
|
||||
|
||||
/**
|
||||
* Attempt to retrieve an object from the cache. Mainly used in attempting
|
||||
* to resolve entities/collections from the second level cache.
|
||||
*
|
||||
* @param key The key of the item to be retrieved.
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @return the cached object or <tt>null</tt>
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public Object get(Object key, long txTimestamp) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database, explicitly
|
||||
* specifying the minimalPut behavior.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @param minimalPutOverride Explicit minimalPut flag
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version,
|
||||
boolean minimalPutOverride) throws CacheException;
|
||||
|
||||
/**
|
||||
* We are going to attempt to update/delete the keyed object. This
|
||||
* method is used by "asynchronous" concurrency strategies.
|
||||
* <p/>
|
||||
* The returned object must be passed back to release(), to release the
|
||||
* lock. Concurrency strategies which do not support client-visible
|
||||
* locks may silently return null.
|
||||
*
|
||||
* @param key The key of the item to lock
|
||||
* @param version The item's current version value
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public SoftLock lockItem(Object key, Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Lock the entire region
|
||||
*
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public SoftLock lockRegion() throws CacheException;
|
||||
|
||||
/**
|
||||
* Called when we have finished the attempted update/delete (which may or
|
||||
* may not have been successful), after transaction completion. This method
|
||||
* is used by "asynchronous" concurrency strategies.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param lock The lock previously obtained from {@link #lockItem}
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void unlockItem(Object key, SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after we have finished the attempted invalidation of the entire
|
||||
* region
|
||||
*
|
||||
* @param lock The lock previously obtained from {@link #lockRegion}
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void unlockRegion(SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after an item has become stale (before the transaction completes).
|
||||
* This method is used by "synchronous" concurrency strategies.
|
||||
*
|
||||
* @param key The key of the item to remove
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void remove(Object key) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called to evict data from the entire region
|
||||
*
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void removeAll() throws CacheException;
|
||||
|
||||
/**
|
||||
* Forcibly evict an item from the cache immediately without regard for transaction
|
||||
* isolation.
|
||||
*
|
||||
* @param key The key of the item to remove
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void evict(Object key) throws CacheException;
|
||||
|
||||
/**
|
||||
* Forcibly evict all items from the cache immediately without regard for transaction
|
||||
* isolation.
|
||||
*
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void evictAll() throws CacheException;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.hibernate.cache.spi.EntityRegion;
|
|||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EntityRegionAccessStrategy {
|
||||
public interface EntityRegionAccessStrategy extends RegionAccessStrategy{
|
||||
|
||||
/**
|
||||
* Get the wrapped entity cache region
|
||||
|
@ -50,95 +50,6 @@ public interface EntityRegionAccessStrategy {
|
|||
*/
|
||||
public EntityRegion getRegion();
|
||||
|
||||
/**
|
||||
* Attempt to retrieve an object from the cache. Mainly used in attempting
|
||||
* to resolve entities/collections from the second level cache.
|
||||
*
|
||||
* @param key The key of the item to be retrieved.
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @return the cached object or <tt>null</tt>
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public Object get(Object key, long txTimestamp) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database, explicitly
|
||||
* specifying the minimalPut behavior.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @param minimalPutOverride Explicit minimalPut flag
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version,
|
||||
boolean minimalPutOverride) throws CacheException;
|
||||
|
||||
/**
|
||||
* We are going to attempt to update/delete the keyed object. This
|
||||
* method is used by "asynchronous" concurrency strategies.
|
||||
* <p/>
|
||||
* The returned object must be passed back to release(), to release the
|
||||
* lock. Concurrency strategies which do not support client-visible
|
||||
* locks may silently return null.
|
||||
*
|
||||
* @param key The key of the item to lock
|
||||
* @param version The item's current version value
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public SoftLock lockItem(Object key, Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Lock the entire region
|
||||
*
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public SoftLock lockRegion() throws CacheException;
|
||||
|
||||
/**
|
||||
* Called when we have finished the attempted update/delete (which may or
|
||||
* may not have been successful), after transaction completion. This method
|
||||
* is used by "asynchronous" concurrency strategies.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param lock The lock previously obtained from {@link #lockItem}
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void unlockItem(Object key, SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after we have finished the attempted invalidation of the entire
|
||||
* region
|
||||
*
|
||||
* @param lock The lock previously obtained from {@link #lockRegion}
|
||||
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
public void unlockRegion(SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after an item has been inserted (before the transaction completes),
|
||||
* instead of calling evict().
|
||||
|
|
153
hibernate-core/src/main/java/org/hibernate/cache/spi/access/RegionAccessStrategy.java
vendored
Normal file
153
hibernate-core/src/main/java/org/hibernate/cache/spi/access/RegionAccessStrategy.java
vendored
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. 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.cache.spi.access;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface RegionAccessStrategy {
|
||||
/**
|
||||
* Attempt to retrieve an object from the cache. Mainly used in attempting
|
||||
* to resolve entities/collections from the second level cache.
|
||||
*
|
||||
* @param key The key of the item to be retrieved.
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @return the cached object or <tt>null</tt>
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
Object get(Object key, long txTimestamp) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Attempt to cache an object, after loading from the database, explicitly
|
||||
* specifying the minimalPut behavior.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param value The item
|
||||
* @param txTimestamp a timestamp prior to the transaction start time
|
||||
* @param version the item version number
|
||||
* @param minimalPutOverride Explicit minimalPut flag
|
||||
* @return <tt>true</tt> if the object was successfully cached
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
boolean putFromLoad(
|
||||
Object key,
|
||||
Object value,
|
||||
long txTimestamp,
|
||||
Object version,
|
||||
boolean minimalPutOverride) throws CacheException;
|
||||
|
||||
/**
|
||||
* We are going to attempt to update/delete the keyed object. This
|
||||
* method is used by "asynchronous" concurrency strategies.
|
||||
* <p/>
|
||||
* The returned object must be passed back to release(), to release the
|
||||
* lock. Concurrency strategies which do not support client-visible
|
||||
* locks may silently return null.
|
||||
*
|
||||
* @param key The key of the item to lock
|
||||
* @param version The item's current version value
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
SoftLock lockItem(Object key, Object version) throws CacheException;
|
||||
|
||||
/**
|
||||
* Lock the entire region
|
||||
*
|
||||
* @return A representation of our lock on the item; or null.
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
SoftLock lockRegion() throws CacheException;
|
||||
|
||||
/**
|
||||
* Called when we have finished the attempted update/delete (which may or
|
||||
* may not have been successful), after transaction completion. This method
|
||||
* is used by "asynchronous" concurrency strategies.
|
||||
*
|
||||
* @param key The item key
|
||||
* @param lock The lock previously obtained from {@link #lockItem}
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void unlockItem(Object key, SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after we have finished the attempted invalidation of the entire
|
||||
* region
|
||||
*
|
||||
* @param lock The lock previously obtained from {@link #lockRegion}
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void unlockRegion(SoftLock lock) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called after an item has become stale (before the transaction completes).
|
||||
* This method is used by "synchronous" concurrency strategies.
|
||||
*
|
||||
* @param key The key of the item to remove
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void remove(Object key) throws CacheException;
|
||||
|
||||
/**
|
||||
* Called to evict data from the entire region
|
||||
*
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void removeAll() throws CacheException;
|
||||
|
||||
/**
|
||||
* Forcibly evict an item from the cache immediately without regard for transaction
|
||||
* isolation.
|
||||
*
|
||||
* @param key The key of the item to remove
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void evict(Object key) throws CacheException;
|
||||
|
||||
/**
|
||||
* Forcibly evict all items from the cache immediately without regard for transaction
|
||||
* isolation.
|
||||
*
|
||||
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
|
||||
*/
|
||||
void evictAll() throws CacheException;
|
||||
}
|
|
@ -2661,6 +2661,7 @@ public final class HbmBinder {
|
|||
String comment = cmAtt == null ? null : cmAtt.getValue();
|
||||
|
||||
NamedQueryDefinition namedQuery = new NamedQueryDefinition(
|
||||
queryName,
|
||||
query,
|
||||
cacheable,
|
||||
region,
|
||||
|
@ -2673,7 +2674,7 @@ public final class HbmBinder {
|
|||
getParameterTypes(queryElem)
|
||||
);
|
||||
|
||||
mappings.addQuery( queryName, namedQuery );
|
||||
mappings.addQuery( namedQuery.getName(), namedQuery );
|
||||
}
|
||||
|
||||
public static CacheMode getCacheMode(String cacheMode) {
|
||||
|
|
|
@ -84,6 +84,7 @@ public class NamedSQLQuerySecondPass extends ResultSetMappingBinder implements Q
|
|||
String resultSetRef = ref == null ? null : ref.getValue();
|
||||
if ( StringHelper.isNotEmpty( resultSetRef ) ) {
|
||||
namedQuery = new NamedSQLQueryDefinition(
|
||||
queryName,
|
||||
queryElem.getText(),
|
||||
resultSetRef,
|
||||
synchronizedTables,
|
||||
|
@ -103,6 +104,7 @@ public class NamedSQLQuerySecondPass extends ResultSetMappingBinder implements Q
|
|||
else {
|
||||
ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
|
||||
namedQuery = new NamedSQLQueryDefinition(
|
||||
queryName,
|
||||
queryElem.getText(),
|
||||
definition.getQueryReturns(),
|
||||
synchronizedTables,
|
||||
|
@ -119,7 +121,7 @@ public class NamedSQLQuerySecondPass extends ResultSetMappingBinder implements Q
|
|||
);
|
||||
}
|
||||
|
||||
LOG.debugf("Named SQL query: %s -> %s", queryName, namedQuery.getQueryString());
|
||||
LOG.debugf("Named SQL query: %s -> %s", namedQuery.getName(), namedQuery.getQueryString());
|
||||
mappings.addSQLQuery( queryName, namedQuery );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public abstract class QueryBinder {
|
|||
QueryHint[] hints = queryAnn.hints();
|
||||
String queryName = queryAnn.query();
|
||||
NamedQueryDefinition query = new NamedQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryName,
|
||||
getBoolean( queryName, "org.hibernate.cacheable", hints ),
|
||||
getString( queryName, "org.hibernate.cacheRegion", hints ),
|
||||
|
@ -76,12 +77,12 @@ public abstract class QueryBinder {
|
|||
null
|
||||
);
|
||||
if ( isDefault ) {
|
||||
mappings.addDefaultQuery( queryAnn.name(), query );
|
||||
mappings.addDefaultQuery( query.getName(), query );
|
||||
}
|
||||
else {
|
||||
mappings.addQuery( queryAnn.name(), query );
|
||||
mappings.addQuery( query.getName(), query );
|
||||
}
|
||||
LOG.debugf( "Binding named query: %s => %s", queryAnn.name(), queryAnn.query() );
|
||||
LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,6 +98,7 @@ public abstract class QueryBinder {
|
|||
if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
|
||||
//sql result set usage
|
||||
query = new NamedSQLQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryName,
|
||||
resultSetMapping,
|
||||
null,
|
||||
|
@ -118,6 +120,7 @@ public abstract class QueryBinder {
|
|||
final NativeSQLQueryRootReturn entityQueryReturn =
|
||||
new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
|
||||
query = new NamedSQLQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryName,
|
||||
new NativeSQLQueryReturn[] { entityQueryReturn },
|
||||
null,
|
||||
|
@ -137,10 +140,10 @@ public abstract class QueryBinder {
|
|||
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
|
||||
}
|
||||
if ( isDefault ) {
|
||||
mappings.addDefaultSQLQuery( queryAnn.name(), query );
|
||||
mappings.addDefaultSQLQuery( query.getName(), query );
|
||||
}
|
||||
else {
|
||||
mappings.addSQLQuery( queryAnn.name(), query );
|
||||
mappings.addSQLQuery( query.getName(), query );
|
||||
}
|
||||
LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() );
|
||||
}
|
||||
|
@ -155,6 +158,7 @@ public abstract class QueryBinder {
|
|||
if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
|
||||
//sql result set usage
|
||||
query = new NamedSQLQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryAnn.query(),
|
||||
resultSetMapping,
|
||||
null,
|
||||
|
@ -176,6 +180,7 @@ public abstract class QueryBinder {
|
|||
final NativeSQLQueryRootReturn entityQueryReturn =
|
||||
new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
|
||||
query = new NamedSQLQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryAnn.query(),
|
||||
new NativeSQLQueryReturn[] { entityQueryReturn },
|
||||
null,
|
||||
|
@ -194,8 +199,8 @@ public abstract class QueryBinder {
|
|||
else {
|
||||
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
|
||||
}
|
||||
mappings.addSQLQuery( queryAnn.name(), query );
|
||||
LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() );
|
||||
mappings.addSQLQuery( query.getName(), query );
|
||||
LOG.debugf( "Binding named native query: %s => %s", query.getName(), queryAnn.query() );
|
||||
}
|
||||
|
||||
public static void bindQueries(NamedQueries queriesAnn, Mappings mappings, boolean isDefault) {
|
||||
|
@ -229,6 +234,7 @@ public abstract class QueryBinder {
|
|||
flushMode = getFlushMode( queryAnn.flushMode() );
|
||||
|
||||
NamedQueryDefinition query = new NamedQueryDefinition(
|
||||
queryAnn.name(),
|
||||
queryAnn.query(),
|
||||
queryAnn.cacheable(),
|
||||
BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(),
|
||||
|
@ -241,8 +247,8 @@ public abstract class QueryBinder {
|
|||
null
|
||||
);
|
||||
|
||||
mappings.addQuery( queryAnn.name(), query );
|
||||
LOG.debugf( "Binding named query: %s => %s", queryAnn.name(), queryAnn.query() );
|
||||
mappings.addQuery( query.getName(), query );
|
||||
LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
|
||||
}
|
||||
|
||||
private static FlushMode getFlushMode(FlushModeType flushModeType) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.FlushMode;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class NamedQueryDefinition implements Serializable {
|
||||
private final String name;
|
||||
private final String query;
|
||||
private final boolean cacheable;
|
||||
private final String cacheRegion;
|
||||
|
@ -47,6 +48,7 @@ public class NamedQueryDefinition implements Serializable {
|
|||
private String comment;
|
||||
|
||||
// kept for backward compatibility until after the 3.1beta5 release of HA
|
||||
// TODO: is this still needed?
|
||||
public NamedQueryDefinition(
|
||||
String query,
|
||||
boolean cacheable,
|
||||
|
@ -56,6 +58,7 @@ public class NamedQueryDefinition implements Serializable {
|
|||
FlushMode flushMode,
|
||||
Map parameterTypes) {
|
||||
this(
|
||||
null,
|
||||
query,
|
||||
cacheable,
|
||||
cacheRegion,
|
||||
|
@ -70,6 +73,7 @@ public class NamedQueryDefinition implements Serializable {
|
|||
}
|
||||
|
||||
public NamedQueryDefinition(
|
||||
String name,
|
||||
String query,
|
||||
boolean cacheable,
|
||||
String cacheRegion,
|
||||
|
@ -80,6 +84,7 @@ public class NamedQueryDefinition implements Serializable {
|
|||
boolean readOnly,
|
||||
String comment,
|
||||
Map parameterTypes) {
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.cacheable = cacheable;
|
||||
this.cacheRegion = cacheRegion;
|
||||
|
@ -92,6 +97,10 @@ public class NamedQueryDefinition implements Serializable {
|
|||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
return query;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
* @param callable Does the query string represent a callable object (i.e., proc)
|
||||
*/
|
||||
public NamedSQLQueryDefinition(
|
||||
String name,
|
||||
String query,
|
||||
NativeSQLQueryReturn[] queryReturns,
|
||||
List<String> querySpaces,
|
||||
|
@ -76,6 +77,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
Map parameterTypes,
|
||||
boolean callable) {
|
||||
super(
|
||||
name,
|
||||
query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */
|
||||
cacheable,
|
||||
cacheRegion,
|
||||
|
@ -111,6 +113,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
* @param callable Does the query string represent a callable object (i.e., proc)
|
||||
*/
|
||||
public NamedSQLQueryDefinition(
|
||||
String name,
|
||||
String query,
|
||||
String resultSetRef,
|
||||
List<String> querySpaces,
|
||||
|
@ -125,6 +128,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
Map parameterTypes,
|
||||
boolean callable) {
|
||||
super(
|
||||
name,
|
||||
query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */
|
||||
cacheable,
|
||||
cacheRegion,
|
||||
|
@ -172,6 +176,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
Map parameterTypes,
|
||||
boolean callable) {
|
||||
this(
|
||||
null,
|
||||
query,
|
||||
resultSetRef,
|
||||
querySpaces,
|
||||
|
|
|
@ -75,6 +75,7 @@ import org.hibernate.cache.spi.UpdateTimestampsCache;
|
|||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.access.RegionAccessStrategy;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.Settings;
|
||||
|
@ -114,6 +115,7 @@ import org.hibernate.mapping.RootClass;
|
|||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -180,12 +182,12 @@ public final class SessionFactoryImpl
|
|||
private final transient Map collectionMetadata;
|
||||
private final transient Map<String,Set<String>> collectionRolesByEntityParticipant;
|
||||
private final transient Map identifierGenerators;
|
||||
private final transient Map namedQueries;
|
||||
private final transient Map namedSqlQueries;
|
||||
private final transient Map sqlResultSetMappings;
|
||||
private final transient Map<String, NamedQueryDefinition> namedQueries;
|
||||
private final transient Map<String, NamedSQLQueryDefinition> namedSqlQueries;
|
||||
private final transient Map<String, ResultSetMappingDefinition> sqlResultSetMappings;
|
||||
private final transient Map<String, FilterDefinition> filters;
|
||||
private final transient Map fetchProfiles;
|
||||
private final transient Map imports;
|
||||
private final transient Map<String,String> imports;
|
||||
private final transient SessionFactoryServiceRegistry serviceRegistry;
|
||||
private final transient Settings settings;
|
||||
private final transient Properties properties;
|
||||
|
@ -401,10 +403,10 @@ public final class SessionFactoryImpl
|
|||
collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );
|
||||
|
||||
//Named Queries:
|
||||
namedQueries = new HashMap( cfg.getNamedQueries() );
|
||||
namedSqlQueries = new HashMap( cfg.getNamedSQLQueries() );
|
||||
sqlResultSetMappings = new HashMap( cfg.getSqlResultSetMappings() );
|
||||
imports = new HashMap( cfg.getImports() );
|
||||
namedQueries = new HashMap<String, NamedQueryDefinition>( cfg.getNamedQueries() );
|
||||
namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>( cfg.getNamedSQLQueries() );
|
||||
sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>( cfg.getSqlResultSetMappings() );
|
||||
imports = new HashMap<String,String>( cfg.getImports() );
|
||||
|
||||
// after *all* persisters and named queries are registered
|
||||
Iterator iter = entityPersisters.values().iterator();
|
||||
|
@ -529,14 +531,7 @@ public final class SessionFactoryImpl
|
|||
// TODO: remove initialization of final variables; just setting to null to make compiler happy
|
||||
this.name = null;
|
||||
this.uuid = null;
|
||||
this.collectionPersisters = null;
|
||||
this.collectionMetadata = null;
|
||||
this.collectionRolesByEntityParticipant = null;
|
||||
this.namedQueries = null;
|
||||
this.namedSqlQueries = null;
|
||||
this.sqlResultSetMappings = null;
|
||||
this.fetchProfiles = null;
|
||||
this.imports = null;
|
||||
this.queryCache = null;
|
||||
this.updateTimestampsCache = null;
|
||||
this.queryCaches = null;
|
||||
|
@ -614,10 +609,11 @@ public final class SessionFactoryImpl
|
|||
if ( entityBinding.isRoot() ) {
|
||||
// TODO: create the IdentifierGenerator while the metadata is being build, then simply
|
||||
// use EntityBinding.getIdentifierGenerator() (also remove getIdentifierGeneratorFactory from Mappings)
|
||||
IdentifierGenerator generator = entityBinding.getEntityIdentifier().createIdentifierGenerator(
|
||||
metadata.getIdentifierGeneratorFactory()
|
||||
);
|
||||
identifierGenerators.put( entityBinding.getEntity().getName(), generator );
|
||||
// TODO: this is broken; throws NullPointerException
|
||||
//IdentifierGenerator generator = entityBinding.getEntityIdentifier().createIdentifierGenerator(
|
||||
// metadata.getIdentifierGeneratorFactory()
|
||||
//);
|
||||
//identifierGenerators.put( entityBinding.getEntity().getName(), generator );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -634,7 +630,7 @@ public final class SessionFactoryImpl
|
|||
final String cacheRegionPrefix = stringBuilder.toString();
|
||||
|
||||
entityPersisters = new HashMap();
|
||||
Map<String, EntityRegionAccessStrategy> entityAccessStrategies = new HashMap<String, EntityRegionAccessStrategy>();
|
||||
Map<String, RegionAccessStrategy> entityAccessStrategies = new HashMap<String, RegionAccessStrategy>();
|
||||
Map<String,ClassMetadata> classMeta = new HashMap<String,ClassMetadata>();
|
||||
for ( EntityBinding model : metadata.getEntityBindings() ) {
|
||||
// TODO: should temp table prep happen when metadata is being built?
|
||||
|
@ -647,7 +643,7 @@ public final class SessionFactoryImpl
|
|||
model.getCaching() != null &&
|
||||
model.getCaching().getAccessType() != null ) {
|
||||
final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getCaching().getRegion();
|
||||
accessStrategy = entityAccessStrategies.get( cacheRegionName );
|
||||
accessStrategy = EntityRegionAccessStrategy.class.cast( entityAccessStrategies.get( cacheRegionName ) );
|
||||
if ( accessStrategy == null ) {
|
||||
final AccessType accessType = model.getCaching().getAccessType();
|
||||
LOG.trace("Building cache for entity data [" + model.getEntity().getName() + "]");
|
||||
|
@ -670,6 +666,101 @@ public final class SessionFactoryImpl
|
|||
}
|
||||
this.classMetadata = Collections.unmodifiableMap(classMeta);
|
||||
|
||||
Map<String,Set<String>> tmpEntityToCollectionRoleMap = new HashMap<String,Set<String>>();
|
||||
collectionPersisters = new HashMap();
|
||||
for ( PluralAttributeBinding model : metadata.getCollectionBindings() ) {
|
||||
if ( model.getAttribute() == null ) {
|
||||
throw new IllegalStateException( "No attribute defined for a PluralAttributeBinding: " + model );
|
||||
}
|
||||
if ( model.getAttribute().isSingular() ) {
|
||||
throw new IllegalStateException(
|
||||
"PluralAttributeBinding has a Singular attribute defined: " + model.getAttribute().getName()
|
||||
);
|
||||
}
|
||||
// TODO: Add PluralAttributeBinding.getCaching()
|
||||
final String cacheRegionName = cacheRegionPrefix + model.getCacheRegionName();
|
||||
final AccessType accessType = AccessType.fromExternalName( model.getCacheConcurrencyStrategy() );
|
||||
CollectionRegionAccessStrategy accessStrategy = null;
|
||||
if ( accessType != null && settings.isSecondLevelCacheEnabled() ) {
|
||||
// TODO: is model.getAttribute().getName() the collection's role??? For now, assuming it is
|
||||
LOG.trace("Building cache for collection data [" + model.getAttribute().getName() + "]");
|
||||
CollectionRegion collectionRegion =
|
||||
settings.getRegionFactory()
|
||||
.buildCollectionRegion(
|
||||
cacheRegionName, properties, CacheDataDescriptionImpl.decode( model )
|
||||
);
|
||||
accessStrategy = collectionRegion.buildAccessStrategy( accessType );
|
||||
entityAccessStrategies.put( cacheRegionName, accessStrategy );
|
||||
allCacheRegions.put( cacheRegionName, collectionRegion );
|
||||
}
|
||||
CollectionPersister persister =
|
||||
serviceRegistry
|
||||
.getService( PersisterFactory.class )
|
||||
.createCollectionPersister( metadata, model, accessStrategy, this );
|
||||
// TODO: is model.getAttribute().getName() the collection's role??? For now, assuming it is
|
||||
collectionPersisters.put( model.getAttribute().getName(), persister.getCollectionMetadata() );
|
||||
Type indexType = persister.getIndexType();
|
||||
if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
|
||||
String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
|
||||
Set roles = tmpEntityToCollectionRoleMap.get( entityName );
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet();
|
||||
tmpEntityToCollectionRoleMap.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
}
|
||||
Type elementType = persister.getElementType();
|
||||
if ( elementType.isAssociationType() && !elementType.isAnyType() ) {
|
||||
String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this );
|
||||
Set roles = tmpEntityToCollectionRoleMap.get( entityName );
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet();
|
||||
tmpEntityToCollectionRoleMap.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
}
|
||||
}
|
||||
collectionMetadata = Collections.unmodifiableMap(collectionPersisters);
|
||||
Iterator itr = tmpEntityToCollectionRoleMap.entrySet().iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final Map.Entry entry = ( Map.Entry ) itr.next();
|
||||
entry.setValue( Collections.unmodifiableSet( ( Set ) entry.getValue() ) );
|
||||
}
|
||||
collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );
|
||||
|
||||
//Named Queries:
|
||||
namedQueries = new HashMap<String,NamedQueryDefinition>();
|
||||
for ( NamedQueryDefinition namedQueryDefinition : metadata.getNamedQueryDefinitions() ) {
|
||||
namedQueries.put( namedQueryDefinition.getName(), namedQueryDefinition );
|
||||
}
|
||||
namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
for ( NamedSQLQueryDefinition namedNativeQueryDefinition: metadata.getNamedNativeQueryDefinitions() ) {
|
||||
namedSqlQueries.put( namedNativeQueryDefinition.getName(), namedNativeQueryDefinition );
|
||||
}
|
||||
sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
||||
for( ResultSetMappingDefinition resultSetMappingDefinition : metadata.getResultSetMappingDefinitions() ) {
|
||||
sqlResultSetMappings.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition );
|
||||
}
|
||||
imports = new HashMap<String,String>();
|
||||
for ( Map.Entry<String,String> importEntry : metadata.getImports() ) {
|
||||
imports.put( importEntry.getKey(), importEntry.getValue() );
|
||||
}
|
||||
|
||||
// after *all* persisters and named queries are registered
|
||||
Iterator iter = entityPersisters.values().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
final EntityPersister persister = ( ( EntityPersister ) iter.next() );
|
||||
// TODO: broken
|
||||
//persister.postInstantiate();
|
||||
registerEntityNameResolvers( persister );
|
||||
|
||||
}
|
||||
iter = collectionPersisters.values().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
||||
persister.postInstantiate();
|
||||
}
|
||||
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,19 @@
|
|||
|
||||
package org.hibernate.metamodel;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.TypeDef;
|
||||
|
||||
/**
|
||||
|
@ -68,9 +73,19 @@ public interface Metadata {
|
|||
*/
|
||||
public EntityBinding getRootEntityBinding(String entityName);
|
||||
|
||||
public Iterable<PluralAttributeBinding> getCollectionBindings();
|
||||
|
||||
public Iterable<TypeDef> getTypeDefinitions();
|
||||
|
||||
public Iterable<FilterDefinition> getFilterDefinitions();
|
||||
|
||||
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions();
|
||||
|
||||
public Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions();
|
||||
|
||||
public Iterable<ResultSetMappingDefinition> getResultSetMappingDefinitions();
|
||||
|
||||
public Iterable<Map.Entry<String, String>> getImports();
|
||||
|
||||
public IdGenerator getIdGenerator(String name);
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ public class QueryBinder {
|
|||
comment = null;
|
||||
}
|
||||
metadata.addNamedQuery(
|
||||
name,
|
||||
new NamedQueryDefinition(
|
||||
name,
|
||||
query, getBoolean( hints, QueryHints.CACHEABLE, name ), cacheRegion,
|
||||
timeout, fetchSize, getFlushMode( hints, QueryHints.FLUSH_MODE, name ),
|
||||
getCacheMode( hints, QueryHints.CACHE_MODE, name ),
|
||||
|
@ -167,6 +167,7 @@ public class QueryBinder {
|
|||
NamedSQLQueryDefinition def;
|
||||
if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
|
||||
def = new NamedSQLQueryDefinition(
|
||||
name,
|
||||
query, resultSetMapping, null, cacheable,
|
||||
cacheRegion, timeout, fetchSize,
|
||||
flushMode, cacheMode, readOnly, comment,
|
||||
|
@ -179,6 +180,7 @@ public class QueryBinder {
|
|||
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
|
||||
}
|
||||
def = new NamedSQLQueryDefinition(
|
||||
name,
|
||||
query, new NativeSQLQueryRootReturn[] {
|
||||
new NativeSQLQueryRootReturn(
|
||||
"alias1",
|
||||
|
@ -192,7 +194,7 @@ public class QueryBinder {
|
|||
);
|
||||
|
||||
}
|
||||
metadata.addNamedNativeQuery( name, def );
|
||||
metadata.addNamedNativeQuery( def );
|
||||
LOG.debugf( "Binding named native query: %s => %s", name, query );
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.DuplicateMappingException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
||||
|
@ -100,11 +101,12 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
private Map<String, EntityBinding> rootEntityBindingMap = new HashMap<String, EntityBinding>();
|
||||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private Map<String, String> imports;
|
||||
private Map<String, String> imports = new HashMap<String, String>();
|
||||
private Map<String, TypeDef> typeDefs = new HashMap<String, TypeDef>();
|
||||
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
|
||||
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
|
||||
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>();
|
||||
private Map<String, ResultSetMappingDefinition> resultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
|
||||
private Map<String, FilterDefinition> filterDefs = new HashMap<String, FilterDefinition>();
|
||||
|
||||
// todo : keep as part of Database?
|
||||
|
@ -174,11 +176,17 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
public void addFetchProfile(FetchProfile profile) {
|
||||
if ( profile == null || profile.getName() == null ) {
|
||||
throw new IllegalArgumentException( "Fetch profile object or name is null: " + profile );
|
||||
}
|
||||
fetchProfiles.put( profile.getName(), profile );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFilterDefinition(FilterDefinition def) {
|
||||
if ( def == null || def.getFilterName() == null ) {
|
||||
throw new IllegalArgumentException( "Filter definition object or name is null: " + def );
|
||||
}
|
||||
filterDefs.put( def.getFilterName(), def );
|
||||
}
|
||||
|
||||
|
@ -188,6 +196,9 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
public void addIdGenerator(IdGenerator generator) {
|
||||
if ( generator == null || generator.getName() == null ) {
|
||||
throw new IllegalArgumentException( "ID generator object or name is null." );
|
||||
}
|
||||
idGenerators.put( generator.getName(), generator );
|
||||
}
|
||||
|
||||
|
@ -205,12 +216,18 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
|
||||
if ( auxiliaryDatabaseObject == null ) {
|
||||
throw new IllegalArgumentException( "Auxiliary database object is null." );
|
||||
}
|
||||
auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNamedNativeQuery(String name, NamedSQLQueryDefinition def) {
|
||||
namedNativeQueryDefs.put( name, def );
|
||||
public void addNamedNativeQuery(NamedSQLQueryDefinition def) {
|
||||
if ( def == null || def.getName() == null ) {
|
||||
throw new IllegalArgumentException( "Named native query definition object or name is null: " + def.getQueryString() );
|
||||
}
|
||||
namedNativeQueryDefs.put( def.getName(), def );
|
||||
}
|
||||
|
||||
public NamedSQLQueryDefinition getNamedNativeQuery(String name) {
|
||||
|
@ -221,8 +238,16 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addNamedQuery(String name, NamedQueryDefinition def) {
|
||||
namedQueryDefs.put( name, def );
|
||||
public Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions() {
|
||||
return namedNativeQueryDefs.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNamedQuery(NamedQueryDefinition def) {
|
||||
if ( def == null || def.getName() == null ) {
|
||||
throw new IllegalArgumentException( "Named query definition object or name is null: " + def.getQueryString() );
|
||||
}
|
||||
namedQueryDefs.put( def.getName(), def );
|
||||
}
|
||||
|
||||
public NamedQueryDefinition getNamedQuery(String name) {
|
||||
|
@ -232,8 +257,29 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
return namedQueryDefs.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions() {
|
||||
return namedQueryDefs.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition) {
|
||||
if ( resultSetMappingDefinition == null || resultSetMappingDefinition.getName() == null ) {
|
||||
throw new IllegalArgumentException( "Resultset mappping object or name is null: " + resultSetMappingDefinition );
|
||||
}
|
||||
resultSetMappings.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ResultSetMappingDefinition> getResultSetMappingDefinitions() {
|
||||
return resultSetMappings.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTypeDefinition(TypeDef typeDef) {
|
||||
if ( typeDef == null || typeDef.getName() == null ) {
|
||||
throw new IllegalArgumentException( "Type definition object or name is null: " + typeDef.getTypeClass() );
|
||||
}
|
||||
final TypeDef previous = typeDefs.put( typeDef.getName(), typeDef );
|
||||
if ( previous != null ) {
|
||||
LOG.debugf( "Duplicate typedef name [%s] now -> %s", typeDef.getName(), typeDef.getTypeClass() );
|
||||
|
@ -318,7 +364,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
return collectionBindingMap.get( collectionRole );
|
||||
}
|
||||
|
||||
public Iterable<PluralAttributeBinding> getCollections() {
|
||||
@Override
|
||||
public Iterable<PluralAttributeBinding> getCollectionBindings() {
|
||||
return collectionBindingMap.values();
|
||||
}
|
||||
|
||||
|
@ -333,8 +380,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
|
||||
public void addImport(String importName, String entityName) {
|
||||
if ( imports == null ) {
|
||||
imports = new HashMap<String, String>();
|
||||
if ( importName == null || entityName == null ) {
|
||||
throw new IllegalArgumentException( "Import name or entity name is null" );
|
||||
}
|
||||
LOG.trace( "Import: " + importName + " -> " + entityName );
|
||||
String old = imports.put( importName, entityName );
|
||||
|
@ -343,6 +390,10 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public Iterable<Map.Entry<String, String>> getImports() {
|
||||
return imports.entrySet();
|
||||
}
|
||||
|
||||
public Iterable<FetchProfile> getFetchProfiles() {
|
||||
return fetchProfiles.values();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.source.spi;
|
||||
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||
|
@ -65,9 +66,11 @@ public interface MetadataImplementor extends Metadata, BindingContext, Mapping {
|
|||
|
||||
public void registerIdentifierGenerator(String name, String clazz);
|
||||
|
||||
public void addNamedNativeQuery(String name, NamedSQLQueryDefinition def);
|
||||
public void addNamedNativeQuery(NamedSQLQueryDefinition def);
|
||||
|
||||
public void addNamedQuery(String name, NamedQueryDefinition def);
|
||||
public void addNamedQuery(NamedQueryDefinition def);
|
||||
|
||||
public void addResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition);
|
||||
|
||||
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Selectable;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.property.BackrefPropertyAccessor;
|
||||
import org.hibernate.sql.Alias;
|
||||
|
@ -754,6 +755,75 @@ public abstract class AbstractEntityPersister
|
|||
temporaryIdTableDDL = persistentClass.getTemporaryIdTableDDL();
|
||||
}
|
||||
|
||||
|
||||
public AbstractEntityPersister(
|
||||
final EntityBinding entityBinding,
|
||||
final EntityRegionAccessStrategy cacheAccessStrategy,
|
||||
final SessionFactoryImplementor factory) throws HibernateException {
|
||||
// TODO: Implement! Initializing final fields to make compiler happy
|
||||
this.factory = factory;
|
||||
this.cacheAccessStrategy = cacheAccessStrategy;
|
||||
isLazyPropertiesCacheable = false;
|
||||
cacheEntryStructure = null;
|
||||
entityMetamodel = null;
|
||||
rootTableKeyColumnNames = null;
|
||||
rootTableKeyColumnReaders = null;
|
||||
rootTableKeyColumnReaderTemplates = null;
|
||||
identifierAliases = null;
|
||||
identifierColumnSpan = -1;
|
||||
versionColumnName = null;
|
||||
hasFormulaProperties = false;
|
||||
batchSize = -1;
|
||||
hasSubselectLoadableCollections = false;
|
||||
rowIdName = null;
|
||||
lazyProperties = null;
|
||||
sqlWhereString = null;
|
||||
sqlWhereStringTemplate = null;
|
||||
propertyColumnSpans = null;
|
||||
propertySubclassNames = null;
|
||||
propertyColumnAliases = null;
|
||||
propertyColumnNames = null;
|
||||
propertyColumnFormulaTemplates = null;
|
||||
propertyColumnReaderTemplates = null;
|
||||
propertyColumnWriters = null;
|
||||
propertyColumnUpdateable = null;
|
||||
propertyColumnInsertable = null;
|
||||
propertyUniqueness = null;
|
||||
propertySelectable = null;
|
||||
lazyPropertyNames = null;
|
||||
lazyPropertyNumbers = null;
|
||||
lazyPropertyTypes = null;
|
||||
lazyPropertyColumnAliases = null;
|
||||
subclassPropertyNameClosure = null;
|
||||
subclassPropertySubclassNameClosure = null;
|
||||
subclassPropertyTypeClosure = null;
|
||||
subclassPropertyFormulaTemplateClosure = null;
|
||||
subclassPropertyColumnNameClosure = null;
|
||||
subclassPropertyColumnReaderClosure = null;
|
||||
subclassPropertyColumnReaderTemplateClosure = null;
|
||||
subclassPropertyFetchModeClosure = null;
|
||||
subclassPropertyNullabilityClosure = null;
|
||||
propertyDefinedOnSubclass = null;
|
||||
subclassPropertyColumnNumberClosure = null;
|
||||
subclassPropertyFormulaNumberClosure = null;
|
||||
subclassPropertyCascadeStyleClosure = null;
|
||||
subclassColumnClosure = null;
|
||||
subclassColumnLazyClosure = null;
|
||||
subclassColumnAliasClosure = null;
|
||||
subclassColumnSelectableClosure = null;
|
||||
subclassColumnReaderTemplateClosure = null;
|
||||
subclassFormulaClosure = null;
|
||||
subclassFormulaTemplateClosure = null;
|
||||
subclassFormulaAliasClosure = null;
|
||||
subclassFormulaLazyClosure = null;
|
||||
filterHelper = null;
|
||||
loaderName = null;
|
||||
queryLoader = null;
|
||||
temporaryIdTableName = null;
|
||||
temporaryIdTableDDL = null;
|
||||
propertyMapping = null;
|
||||
}
|
||||
|
||||
protected String generateLazySelectString() {
|
||||
|
||||
if ( !entityMetamodel.hasLazyProperties() ) {
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.hibernate.mapping.Property;
|
|||
import org.hibernate.mapping.Selectable;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.sql.CaseFragment;
|
||||
import org.hibernate.sql.SelectFragment;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
@ -492,6 +493,43 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
|
||||
}
|
||||
|
||||
public JoinedSubclassEntityPersister(
|
||||
final EntityBinding entityBinding,
|
||||
final EntityRegionAccessStrategy cacheAccessStrategy,
|
||||
final SessionFactoryImplementor factory,
|
||||
final Mapping mapping) throws HibernateException {
|
||||
super( entityBinding, cacheAccessStrategy, factory );
|
||||
// TODO: implement!!! initializing final fields to null to make compiler happy
|
||||
tableSpan = -1;
|
||||
tableNames = null;
|
||||
naturalOrderTableNames = null;
|
||||
tableKeyColumns = null;
|
||||
tableKeyColumnReaders = null;
|
||||
tableKeyColumnReaderTemplates = null;
|
||||
naturalOrderTableKeyColumns = null;
|
||||
naturalOrderTableKeyColumnReaders = null;
|
||||
naturalOrderTableKeyColumnReaderTemplates = null;
|
||||
naturalOrderCascadeDeleteEnabled = null;
|
||||
spaces = null;
|
||||
subclassClosure = null;
|
||||
subclassTableNameClosure = null;
|
||||
subclassTableKeyColumnClosure= null;
|
||||
isClassOrSuperclassTable = null;
|
||||
naturalOrderPropertyTableNumbers = null;
|
||||
propertyTableNumbers = null;
|
||||
subclassPropertyTableNumberClosure = null;
|
||||
subclassColumnTableNumberClosure = null;
|
||||
subclassFormulaTableNumberClosure = null;
|
||||
subclassTableSequentialSelect = null;
|
||||
subclassTableIsLazyClosure = null;
|
||||
discriminatorValues = null;
|
||||
notNullColumnNames = null;
|
||||
notNullColumnTableNumbers = null;
|
||||
constraintOrderedTableNames = null;
|
||||
constraintOrderedKeyColumnNames = null;
|
||||
discriminatorSQLString = null;
|
||||
}
|
||||
|
||||
protected boolean isSubclassTableSequentialSelect(int j) {
|
||||
return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.hibernate.mapping.Selectable;
|
|||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.sql.InFragment;
|
||||
import org.hibernate.sql.Insert;
|
||||
import org.hibernate.sql.SelectFragment;
|
||||
|
@ -438,6 +439,49 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
|
|||
|
||||
}
|
||||
|
||||
public SingleTableEntityPersister(
|
||||
final EntityBinding entityBinding,
|
||||
final EntityRegionAccessStrategy cacheAccessStrategy,
|
||||
final SessionFactoryImplementor factory,
|
||||
final Mapping mapping) throws HibernateException {
|
||||
|
||||
super( entityBinding, cacheAccessStrategy, factory );
|
||||
|
||||
//TODO: implement!!!! initializing final fields to make compiler happy...
|
||||
joinSpan = -1;
|
||||
qualifiedTableNames = null;
|
||||
isInverseTable = null;
|
||||
isNullableTable = null;
|
||||
keyColumnNames = null;
|
||||
cascadeDeleteEnabled = null;
|
||||
hasSequentialSelects = false;
|
||||
spaces = null;
|
||||
subclassClosure = null;
|
||||
subclassTableNameClosure = null;
|
||||
subclassTableIsLazyClosure = null;
|
||||
isInverseSubclassTable = null;
|
||||
isNullableSubclassTable = null;
|
||||
subclassTableSequentialSelect = null;
|
||||
subclassTableKeyColumnClosure = null;
|
||||
isClassOrSuperclassTable = null;
|
||||
propertyTableNumbers = null;
|
||||
subclassPropertyTableNumberClosure = null;
|
||||
subclassColumnTableNumberClosure = null;
|
||||
subclassFormulaTableNumberClosure = null;
|
||||
forceDiscriminator = false;
|
||||
discriminatorColumnName = null;
|
||||
discriminatorColumnReaders = null;
|
||||
discriminatorColumnReaderTemplate = null;
|
||||
discriminatorFormula = null;
|
||||
discriminatorFormulaTemplate = null;
|
||||
discriminatorAlias = null;
|
||||
discriminatorType = null;
|
||||
discriminatorSQLValue = null;
|
||||
discriminatorInsertable = false;
|
||||
constraintOrderedTableNames = null;
|
||||
constraintOrderedKeyColumnNames = null;
|
||||
}
|
||||
|
||||
protected boolean isInverseTable(int j) {
|
||||
return isInverseTable[j];
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.hibernate.mapping.Column;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.sql.SelectFragment;
|
||||
import org.hibernate.sql.SimpleSelect;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
@ -235,6 +236,23 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
|||
|
||||
}
|
||||
|
||||
public UnionSubclassEntityPersister(
|
||||
final EntityBinding entityBinding,
|
||||
final EntityRegionAccessStrategy cacheAccessStrategy,
|
||||
final SessionFactoryImplementor factory,
|
||||
final Mapping mapping) throws HibernateException {
|
||||
super(entityBinding, cacheAccessStrategy, factory );
|
||||
// TODO: implement!!! initializing final fields to null to make compiler happy.
|
||||
subquery = null;
|
||||
tableName = null;
|
||||
subclassClosure = null;
|
||||
spaces = null;
|
||||
subclassSpaces = null;
|
||||
discriminatorSQLValue = null;
|
||||
constraintOrderedTableNames = null;
|
||||
constraintOrderedKeyColumnNames = null;
|
||||
}
|
||||
|
||||
public Serializable[] getQuerySpaces() {
|
||||
return subclassSpaces;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.mapping.Collection;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.spi.PersisterClassResolver;
|
||||
|
@ -104,7 +105,7 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi
|
|||
private static final Class[] COLLECTION_PERSISTER_CONSTRUCTOR_ARGS_NEW = new Class[] {
|
||||
PluralAttributeBinding.class,
|
||||
CollectionRegionAccessStrategy.class,
|
||||
Configuration.class,
|
||||
MetadataImplementor.class,
|
||||
SessionFactoryImplementor.class
|
||||
};
|
||||
|
||||
|
@ -183,44 +184,44 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi
|
|||
@SuppressWarnings( {"unchecked"})
|
||||
public CollectionPersister createCollectionPersister(
|
||||
Configuration cfg,
|
||||
Collection metadata,
|
||||
Collection collectionMetadata,
|
||||
CollectionRegionAccessStrategy cacheAccessStrategy,
|
||||
SessionFactoryImplementor factory) throws HibernateException {
|
||||
Class<? extends CollectionPersister> persisterClass = metadata.getCollectionPersisterClass();
|
||||
Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();
|
||||
if ( persisterClass == null ) {
|
||||
persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( metadata );
|
||||
persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( collectionMetadata );
|
||||
}
|
||||
|
||||
return create( persisterClass, COLLECTION_PERSISTER_CONSTRUCTOR_ARGS, cfg, metadata, cacheAccessStrategy, factory );
|
||||
return create( persisterClass, COLLECTION_PERSISTER_CONSTRUCTOR_ARGS, cfg, collectionMetadata, cacheAccessStrategy, factory );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
|
||||
public CollectionPersister createCollectionPersister(Configuration cfg,
|
||||
PluralAttributeBinding metadata,
|
||||
public CollectionPersister createCollectionPersister(MetadataImplementor metadata,
|
||||
PluralAttributeBinding collectionMetadata,
|
||||
CollectionRegionAccessStrategy cacheAccessStrategy,
|
||||
SessionFactoryImplementor factory) throws HibernateException {
|
||||
Class<? extends CollectionPersister> persisterClass = metadata.getCollectionPersisterClass();
|
||||
Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();
|
||||
if ( persisterClass == null ) {
|
||||
persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( metadata );
|
||||
persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( collectionMetadata );
|
||||
}
|
||||
|
||||
return create( persisterClass, COLLECTION_PERSISTER_CONSTRUCTOR_ARGS_NEW, cfg, metadata, cacheAccessStrategy, factory );
|
||||
return create( persisterClass, COLLECTION_PERSISTER_CONSTRUCTOR_ARGS_NEW, metadata, collectionMetadata, cacheAccessStrategy, factory );
|
||||
}
|
||||
|
||||
// TODO: change metadata arg type to PluralAttributeBinding when new metadata is integrated
|
||||
// TODO: change collectionMetadata arg type to PluralAttributeBinding when new metadata is integrated
|
||||
// TODO: change metadata arg type to MetadataImplementor when new metadata is integrated
|
||||
private static CollectionPersister create(
|
||||
Class<? extends CollectionPersister> persisterClass,
|
||||
Class[] persisterConstructorArgs,
|
||||
Configuration cfg,
|
||||
Object metadata,
|
||||
Object cfg,
|
||||
Object collectionMetadata,
|
||||
CollectionRegionAccessStrategy cacheAccessStrategy,
|
||||
SessionFactoryImplementor factory) throws HibernateException {
|
||||
try {
|
||||
Constructor<? extends CollectionPersister> constructor = persisterClass.getConstructor( persisterConstructorArgs );
|
||||
try {
|
||||
return constructor.newInstance( metadata, cacheAccessStrategy, cfg, factory );
|
||||
return constructor.newInstance( collectionMetadata, cacheAccessStrategy, cfg, factory );
|
||||
}
|
||||
catch (MappingException e) {
|
||||
throw e;
|
||||
|
|
|
@ -47,9 +47,13 @@ public class StandardPersisterClassResolver implements PersisterClassResolver {
|
|||
|
||||
public Class<? extends EntityPersister> getEntityPersisterClass(EntityBinding metadata) {
|
||||
// todo : make sure this is based on an attribute kept on the metamodel in the new code, not the concrete PersistentClass impl found!
|
||||
|
||||
if ( metadata.isRoot() ) {
|
||||
return singleTableEntityPersister(); // EARLY RETURN!
|
||||
}
|
||||
switch ( metadata.getInheritanceType() ) {
|
||||
case JOINED: {
|
||||
joinedSubclassEntityPersister();
|
||||
return joinedSubclassEntityPersister();
|
||||
}
|
||||
case SINGLE_TABLE: {
|
||||
return singleTableEntityPersister();
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.mapping.Collection;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.Service;
|
||||
|
@ -110,7 +111,7 @@ public interface PersisterFactory extends Service {
|
|||
/**
|
||||
* Create a collection persister instance.
|
||||
*
|
||||
* @param cfg The configuration
|
||||
* @param metadata The metadata
|
||||
* @param model The O/R mapping metamodel definition for the collection
|
||||
* @param cacheAccessStrategy The caching strategy for this collection
|
||||
* @param factory The session factory
|
||||
|
@ -120,7 +121,7 @@ public interface PersisterFactory extends Service {
|
|||
* @throws HibernateException Indicates a problem building the persister.
|
||||
*/
|
||||
public CollectionPersister createCollectionPersister(
|
||||
Configuration cfg,
|
||||
MetadataImplementor metadata,
|
||||
PluralAttributeBinding model,
|
||||
CollectionRegionAccessStrategy cacheAccessStrategy,
|
||||
SessionFactoryImplementor factory) throws HibernateException;
|
||||
|
|
|
@ -87,6 +87,7 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
|
|||
|
||||
private SessionFactoryBuilder getSessionFactoryBuilder() {
|
||||
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
|
||||
sources.addAnnotatedClass( SimpleEntity.class );
|
||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||
return metadata.getSessionFactoryBuilder();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. 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.metamodel.source.internal;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Entity
|
||||
public class SimpleEntity {
|
||||
@Id
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public SimpleEntity() {
|
||||
}
|
||||
|
||||
public SimpleEntity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue