HHH-6110 : Integrate new metamodel into persisters

This commit is contained in:
Gail Badner 2011-06-07 02:41:49 -07:00
parent ba44ae26cb
commit 814b514933
23 changed files with 662 additions and 286 deletions

View File

@ -29,6 +29,7 @@ import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.type.VersionType; import org.hibernate.type.VersionType;
/** /**
@ -68,20 +69,10 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
} }
public static CacheDataDescriptionImpl decode(EntityBinding model) { public static CacheDataDescriptionImpl decode(EntityBinding model) {
Comparator versionComparator = null;
if ( model.isVersioned() ) {
versionComparator = (
( VersionType ) model
.getVersioningValueBinding()
.getHibernateTypeDescriptor()
.getExplicitType()
).getComparator();
}
return new CacheDataDescriptionImpl( return new CacheDataDescriptionImpl(
model.isMutable(), model.isMutable(),
model.isVersioned(), model.isVersioned(),
versionComparator getVersionComparator( model )
); );
} }
@ -92,4 +83,25 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
model.getOwner().isVersioned() ? ( ( VersionType ) model.getOwner().getVersion().getType() ).getComparator() : null 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;
}
} }

View File

@ -23,7 +23,6 @@
*/ */
package org.hibernate.cache.spi.access; package org.hibernate.cache.spi.access;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.CollectionRegion;
/** /**
@ -39,7 +38,7 @@ import org.hibernate.cache.spi.CollectionRegion;
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface CollectionRegionAccessStrategy { public interface CollectionRegionAccessStrategy extends RegionAccessStrategy {
/** /**
* Get the wrapped collection cache region * Get the wrapped collection cache region
@ -48,125 +47,4 @@ public interface CollectionRegionAccessStrategy {
*/ */
public CollectionRegion getRegion(); 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;
} }

View File

@ -41,7 +41,7 @@ import org.hibernate.cache.spi.EntityRegion;
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface EntityRegionAccessStrategy { public interface EntityRegionAccessStrategy extends RegionAccessStrategy{
/** /**
* Get the wrapped entity cache region * Get the wrapped entity cache region
@ -50,95 +50,6 @@ public interface EntityRegionAccessStrategy {
*/ */
public EntityRegion getRegion(); 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), * Called after an item has been inserted (before the transaction completes),
* instead of calling evict(). * instead of calling evict().

View 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;
}

View File

@ -2661,6 +2661,7 @@ public final class HbmBinder {
String comment = cmAtt == null ? null : cmAtt.getValue(); String comment = cmAtt == null ? null : cmAtt.getValue();
NamedQueryDefinition namedQuery = new NamedQueryDefinition( NamedQueryDefinition namedQuery = new NamedQueryDefinition(
queryName,
query, query,
cacheable, cacheable,
region, region,
@ -2673,7 +2674,7 @@ public final class HbmBinder {
getParameterTypes(queryElem) getParameterTypes(queryElem)
); );
mappings.addQuery( queryName, namedQuery ); mappings.addQuery( namedQuery.getName(), namedQuery );
} }
public static CacheMode getCacheMode(String cacheMode) { public static CacheMode getCacheMode(String cacheMode) {

View File

@ -84,6 +84,7 @@ public class NamedSQLQuerySecondPass extends ResultSetMappingBinder implements Q
String resultSetRef = ref == null ? null : ref.getValue(); String resultSetRef = ref == null ? null : ref.getValue();
if ( StringHelper.isNotEmpty( resultSetRef ) ) { if ( StringHelper.isNotEmpty( resultSetRef ) ) {
namedQuery = new NamedSQLQueryDefinition( namedQuery = new NamedSQLQueryDefinition(
queryName,
queryElem.getText(), queryElem.getText(),
resultSetRef, resultSetRef,
synchronizedTables, synchronizedTables,
@ -103,6 +104,7 @@ public class NamedSQLQuerySecondPass extends ResultSetMappingBinder implements Q
else { else {
ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings ); ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
namedQuery = new NamedSQLQueryDefinition( namedQuery = new NamedSQLQueryDefinition(
queryName,
queryElem.getText(), queryElem.getText(),
definition.getQueryReturns(), definition.getQueryReturns(),
synchronizedTables, 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 ); mappings.addSQLQuery( queryName, namedQuery );
} }
} }

View File

@ -64,6 +64,7 @@ public abstract class QueryBinder {
QueryHint[] hints = queryAnn.hints(); QueryHint[] hints = queryAnn.hints();
String queryName = queryAnn.query(); String queryName = queryAnn.query();
NamedQueryDefinition query = new NamedQueryDefinition( NamedQueryDefinition query = new NamedQueryDefinition(
queryAnn.name(),
queryName, queryName,
getBoolean( queryName, "org.hibernate.cacheable", hints ), getBoolean( queryName, "org.hibernate.cacheable", hints ),
getString( queryName, "org.hibernate.cacheRegion", hints ), getString( queryName, "org.hibernate.cacheRegion", hints ),
@ -76,12 +77,12 @@ public abstract class QueryBinder {
null null
); );
if ( isDefault ) { if ( isDefault ) {
mappings.addDefaultQuery( queryAnn.name(), query ); mappings.addDefaultQuery( query.getName(), query );
} }
else { 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 ) ) { if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
//sql result set usage //sql result set usage
query = new NamedSQLQueryDefinition( query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryName, queryName,
resultSetMapping, resultSetMapping,
null, null,
@ -118,6 +120,7 @@ public abstract class QueryBinder {
final NativeSQLQueryRootReturn entityQueryReturn = final NativeSQLQueryRootReturn entityQueryReturn =
new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ ); new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
query = new NamedSQLQueryDefinition( query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryName, queryName,
new NativeSQLQueryReturn[] { entityQueryReturn }, new NativeSQLQueryReturn[] { entityQueryReturn },
null, null,
@ -137,10 +140,10 @@ public abstract class QueryBinder {
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" ); throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
} }
if ( isDefault ) { if ( isDefault ) {
mappings.addDefaultSQLQuery( queryAnn.name(), query ); mappings.addDefaultSQLQuery( query.getName(), query );
} }
else { else {
mappings.addSQLQuery( queryAnn.name(), query ); mappings.addSQLQuery( query.getName(), query );
} }
LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.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 ) ) { if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
//sql result set usage //sql result set usage
query = new NamedSQLQueryDefinition( query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryAnn.query(), queryAnn.query(),
resultSetMapping, resultSetMapping,
null, null,
@ -176,6 +180,7 @@ public abstract class QueryBinder {
final NativeSQLQueryRootReturn entityQueryReturn = final NativeSQLQueryRootReturn entityQueryReturn =
new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ ); new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
query = new NamedSQLQueryDefinition( query = new NamedSQLQueryDefinition(
queryAnn.name(),
queryAnn.query(), queryAnn.query(),
new NativeSQLQueryReturn[] { entityQueryReturn }, new NativeSQLQueryReturn[] { entityQueryReturn },
null, null,
@ -194,8 +199,8 @@ public abstract class QueryBinder {
else { else {
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" ); throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
} }
mappings.addSQLQuery( queryAnn.name(), query ); mappings.addSQLQuery( query.getName(), query );
LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() ); LOG.debugf( "Binding named native query: %s => %s", query.getName(), queryAnn.query() );
} }
public static void bindQueries(NamedQueries queriesAnn, Mappings mappings, boolean isDefault) { public static void bindQueries(NamedQueries queriesAnn, Mappings mappings, boolean isDefault) {
@ -229,6 +234,7 @@ public abstract class QueryBinder {
flushMode = getFlushMode( queryAnn.flushMode() ); flushMode = getFlushMode( queryAnn.flushMode() );
NamedQueryDefinition query = new NamedQueryDefinition( NamedQueryDefinition query = new NamedQueryDefinition(
queryAnn.name(),
queryAnn.query(), queryAnn.query(),
queryAnn.cacheable(), queryAnn.cacheable(),
BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(), BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(),
@ -241,8 +247,8 @@ public abstract class QueryBinder {
null null
); );
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() );
} }
private static FlushMode getFlushMode(FlushModeType flushModeType) { private static FlushMode getFlushMode(FlushModeType flushModeType) {

View File

@ -35,6 +35,7 @@ import org.hibernate.FlushMode;
* @author Gavin King * @author Gavin King
*/ */
public class NamedQueryDefinition implements Serializable { public class NamedQueryDefinition implements Serializable {
private final String name;
private final String query; private final String query;
private final boolean cacheable; private final boolean cacheable;
private final String cacheRegion; private final String cacheRegion;
@ -47,6 +48,7 @@ public class NamedQueryDefinition implements Serializable {
private String comment; private String comment;
// kept for backward compatibility until after the 3.1beta5 release of HA // kept for backward compatibility until after the 3.1beta5 release of HA
// TODO: is this still needed?
public NamedQueryDefinition( public NamedQueryDefinition(
String query, String query,
boolean cacheable, boolean cacheable,
@ -56,6 +58,7 @@ public class NamedQueryDefinition implements Serializable {
FlushMode flushMode, FlushMode flushMode,
Map parameterTypes) { Map parameterTypes) {
this( this(
null,
query, query,
cacheable, cacheable,
cacheRegion, cacheRegion,
@ -70,6 +73,7 @@ public class NamedQueryDefinition implements Serializable {
} }
public NamedQueryDefinition( public NamedQueryDefinition(
String name,
String query, String query,
boolean cacheable, boolean cacheable,
String cacheRegion, String cacheRegion,
@ -80,6 +84,7 @@ public class NamedQueryDefinition implements Serializable {
boolean readOnly, boolean readOnly,
String comment, String comment,
Map parameterTypes) { Map parameterTypes) {
this.name = name;
this.query = query; this.query = query;
this.cacheable = cacheable; this.cacheable = cacheable;
this.cacheRegion = cacheRegion; this.cacheRegion = cacheRegion;
@ -92,6 +97,10 @@ public class NamedQueryDefinition implements Serializable {
this.comment = comment; this.comment = comment;
} }
public String getName() {
return name;
}
public String getQueryString() { public String getQueryString() {
return query; return query;
} }

View File

@ -62,6 +62,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
* @param callable Does the query string represent a callable object (i.e., proc) * @param callable Does the query string represent a callable object (i.e., proc)
*/ */
public NamedSQLQueryDefinition( public NamedSQLQueryDefinition(
String name,
String query, String query,
NativeSQLQueryReturn[] queryReturns, NativeSQLQueryReturn[] queryReturns,
List<String> querySpaces, List<String> querySpaces,
@ -76,6 +77,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
Map parameterTypes, Map parameterTypes,
boolean callable) { boolean callable) {
super( super(
name,
query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */ query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */
cacheable, cacheable,
cacheRegion, cacheRegion,
@ -111,6 +113,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
* @param callable Does the query string represent a callable object (i.e., proc) * @param callable Does the query string represent a callable object (i.e., proc)
*/ */
public NamedSQLQueryDefinition( public NamedSQLQueryDefinition(
String name,
String query, String query,
String resultSetRef, String resultSetRef,
List<String> querySpaces, List<String> querySpaces,
@ -125,6 +128,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
Map parameterTypes, Map parameterTypes,
boolean callable) { boolean callable) {
super( super(
name,
query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */ query.trim(), /* trim done to workaround stupid oracle bug that cant handle whitespaces before a { in a sp */
cacheable, cacheable,
cacheRegion, cacheRegion,
@ -172,6 +176,7 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
Map parameterTypes, Map parameterTypes,
boolean callable) { boolean callable) {
this( this(
null,
query, query,
resultSetRef, resultSetRef,
querySpaces, querySpaces,

View File

@ -75,6 +75,7 @@ import org.hibernate.cache.spi.UpdateTimestampsCache;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Settings; import org.hibernate.cfg.Settings;
@ -114,6 +115,7 @@ import org.hibernate.mapping.RootClass;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.spi.MetadataImplementor; import org.hibernate.metamodel.source.spi.MetadataImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
@ -180,12 +182,12 @@ public final class SessionFactoryImpl
private final transient Map collectionMetadata; private final transient Map collectionMetadata;
private final transient Map<String,Set<String>> collectionRolesByEntityParticipant; private final transient Map<String,Set<String>> collectionRolesByEntityParticipant;
private final transient Map identifierGenerators; private final transient Map identifierGenerators;
private final transient Map namedQueries; private final transient Map<String, NamedQueryDefinition> namedQueries;
private final transient Map namedSqlQueries; private final transient Map<String, NamedSQLQueryDefinition> namedSqlQueries;
private final transient Map sqlResultSetMappings; private final transient Map<String, ResultSetMappingDefinition> sqlResultSetMappings;
private final transient Map<String, FilterDefinition> filters; private final transient Map<String, FilterDefinition> filters;
private final transient Map fetchProfiles; 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 SessionFactoryServiceRegistry serviceRegistry;
private final transient Settings settings; private final transient Settings settings;
private final transient Properties properties; private final transient Properties properties;
@ -401,10 +403,10 @@ public final class SessionFactoryImpl
collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap ); collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );
//Named Queries: //Named Queries:
namedQueries = new HashMap( cfg.getNamedQueries() ); namedQueries = new HashMap<String, NamedQueryDefinition>( cfg.getNamedQueries() );
namedSqlQueries = new HashMap( cfg.getNamedSQLQueries() ); namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>( cfg.getNamedSQLQueries() );
sqlResultSetMappings = new HashMap( cfg.getSqlResultSetMappings() ); sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>( cfg.getSqlResultSetMappings() );
imports = new HashMap( cfg.getImports() ); imports = new HashMap<String,String>( cfg.getImports() );
// after *all* persisters and named queries are registered // after *all* persisters and named queries are registered
Iterator iter = entityPersisters.values().iterator(); 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 // TODO: remove initialization of final variables; just setting to null to make compiler happy
this.name = null; this.name = null;
this.uuid = 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.fetchProfiles = null;
this.imports = null;
this.queryCache = null; this.queryCache = null;
this.updateTimestampsCache = null; this.updateTimestampsCache = null;
this.queryCaches = null; this.queryCaches = null;
@ -614,10 +609,11 @@ public final class SessionFactoryImpl
if ( entityBinding.isRoot() ) { if ( entityBinding.isRoot() ) {
// TODO: create the IdentifierGenerator while the metadata is being build, then simply // TODO: create the IdentifierGenerator while the metadata is being build, then simply
// use EntityBinding.getIdentifierGenerator() (also remove getIdentifierGeneratorFactory from Mappings) // use EntityBinding.getIdentifierGenerator() (also remove getIdentifierGeneratorFactory from Mappings)
IdentifierGenerator generator = entityBinding.getEntityIdentifier().createIdentifierGenerator( // TODO: this is broken; throws NullPointerException
metadata.getIdentifierGeneratorFactory() //IdentifierGenerator generator = entityBinding.getEntityIdentifier().createIdentifierGenerator(
); // metadata.getIdentifierGeneratorFactory()
identifierGenerators.put( entityBinding.getEntity().getName(), generator ); //);
//identifierGenerators.put( entityBinding.getEntity().getName(), generator );
} }
} }
@ -634,7 +630,7 @@ public final class SessionFactoryImpl
final String cacheRegionPrefix = stringBuilder.toString(); final String cacheRegionPrefix = stringBuilder.toString();
entityPersisters = new HashMap(); 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>(); Map<String,ClassMetadata> classMeta = new HashMap<String,ClassMetadata>();
for ( EntityBinding model : metadata.getEntityBindings() ) { for ( EntityBinding model : metadata.getEntityBindings() ) {
// TODO: should temp table prep happen when metadata is being built? // TODO: should temp table prep happen when metadata is being built?
@ -647,7 +643,7 @@ public final class SessionFactoryImpl
model.getCaching() != null && model.getCaching() != null &&
model.getCaching().getAccessType() != null ) { model.getCaching().getAccessType() != null ) {
final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getCaching().getRegion(); final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getCaching().getRegion();
accessStrategy = entityAccessStrategies.get( cacheRegionName ); accessStrategy = EntityRegionAccessStrategy.class.cast( entityAccessStrategies.get( cacheRegionName ) );
if ( accessStrategy == null ) { if ( accessStrategy == null ) {
final AccessType accessType = model.getCaching().getAccessType(); final AccessType accessType = model.getCaching().getAccessType();
LOG.trace("Building cache for entity data [" + model.getEntity().getName() + "]"); LOG.trace("Building cache for entity data [" + model.getEntity().getName() + "]");
@ -670,6 +666,101 @@ public final class SessionFactoryImpl
} }
this.classMetadata = Collections.unmodifiableMap(classMeta); 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 // TODO: implement
} }

View File

@ -24,14 +24,19 @@
package org.hibernate.metamodel; package org.hibernate.metamodel;
import java.util.Map;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.spi.FilterDefinition; 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.EntityBinding;
import org.hibernate.metamodel.binding.IdGenerator; import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.binding.TypeDef;
/** /**
@ -68,9 +73,19 @@ public interface Metadata {
*/ */
public EntityBinding getRootEntityBinding(String entityName); public EntityBinding getRootEntityBinding(String entityName);
public Iterable<PluralAttributeBinding> getCollectionBindings();
public Iterable<TypeDef> getTypeDefinitions(); public Iterable<TypeDef> getTypeDefinitions();
public Iterable<FilterDefinition> getFilterDefinitions(); 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); public IdGenerator getIdGenerator(String name);
} }

View File

@ -124,8 +124,8 @@ public class QueryBinder {
comment = null; comment = null;
} }
metadata.addNamedQuery( metadata.addNamedQuery(
name,
new NamedQueryDefinition( new NamedQueryDefinition(
name,
query, getBoolean( hints, QueryHints.CACHEABLE, name ), cacheRegion, query, getBoolean( hints, QueryHints.CACHEABLE, name ), cacheRegion,
timeout, fetchSize, getFlushMode( hints, QueryHints.FLUSH_MODE, name ), timeout, fetchSize, getFlushMode( hints, QueryHints.FLUSH_MODE, name ),
getCacheMode( hints, QueryHints.CACHE_MODE, name ), getCacheMode( hints, QueryHints.CACHE_MODE, name ),
@ -167,6 +167,7 @@ public class QueryBinder {
NamedSQLQueryDefinition def; NamedSQLQueryDefinition def;
if ( StringHelper.isNotEmpty( resultSetMapping ) ) { if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
def = new NamedSQLQueryDefinition( def = new NamedSQLQueryDefinition(
name,
query, resultSetMapping, null, cacheable, query, resultSetMapping, null, cacheable,
cacheRegion, timeout, fetchSize, cacheRegion, timeout, fetchSize,
flushMode, cacheMode, readOnly, comment, flushMode, cacheMode, readOnly, comment,
@ -179,6 +180,7 @@ public class QueryBinder {
throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" ); throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
} }
def = new NamedSQLQueryDefinition( def = new NamedSQLQueryDefinition(
name,
query, new NativeSQLQueryRootReturn[] { query, new NativeSQLQueryRootReturn[] {
new NativeSQLQueryRootReturn( new NativeSQLQueryRootReturn(
"alias1", "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 ); LOG.debugf( "Binding named native query: %s => %s", name, query );
} }

View File

@ -36,6 +36,7 @@ import org.hibernate.DuplicateMappingException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinition; 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, EntityBinding> rootEntityBindingMap = new HashMap<String, EntityBinding>();
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>(); private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>(); 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, TypeDef> typeDefs = new HashMap<String, TypeDef>();
private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>(); private Map<String, IdGenerator> idGenerators = new HashMap<String, IdGenerator>();
private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>(); private Map<String, NamedQueryDefinition> namedQueryDefs = new HashMap<String, NamedQueryDefinition>();
private Map<String, NamedSQLQueryDefinition> namedNativeQueryDefs = new HashMap<String, NamedSQLQueryDefinition>(); 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>(); private Map<String, FilterDefinition> filterDefs = new HashMap<String, FilterDefinition>();
// todo : keep as part of Database? // todo : keep as part of Database?
@ -174,11 +176,17 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
@Override @Override
public void addFetchProfile(FetchProfile profile) { 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 ); fetchProfiles.put( profile.getName(), profile );
} }
@Override @Override
public void addFilterDefinition(FilterDefinition def) { 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 ); filterDefs.put( def.getFilterName(), def );
} }
@ -188,6 +196,9 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
@Override @Override
public void addIdGenerator(IdGenerator generator) { 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 ); idGenerators.put( generator.getName(), generator );
} }
@ -205,12 +216,18 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
@Override @Override
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) { public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
if ( auxiliaryDatabaseObject == null ) {
throw new IllegalArgumentException( "Auxiliary database object is null." );
}
auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject ); auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject );
} }
@Override @Override
public void addNamedNativeQuery(String name, NamedSQLQueryDefinition def) { public void addNamedNativeQuery(NamedSQLQueryDefinition def) {
namedNativeQueryDefs.put( name, 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) { public NamedSQLQueryDefinition getNamedNativeQuery(String name) {
@ -221,8 +238,16 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
} }
@Override @Override
public void addNamedQuery(String name, NamedQueryDefinition def) { public Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions() {
namedQueryDefs.put( name, def ); 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) { public NamedQueryDefinition getNamedQuery(String name) {
@ -232,8 +257,29 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
return namedQueryDefs.get( name ); 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 @Override
public void addTypeDefinition(TypeDef typeDef) { 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 ); final TypeDef previous = typeDefs.put( typeDef.getName(), typeDef );
if ( previous != null ) { if ( previous != null ) {
LOG.debugf( "Duplicate typedef name [%s] now -> %s", typeDef.getName(), typeDef.getTypeClass() ); 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 ); return collectionBindingMap.get( collectionRole );
} }
public Iterable<PluralAttributeBinding> getCollections() { @Override
public Iterable<PluralAttributeBinding> getCollectionBindings() {
return collectionBindingMap.values(); return collectionBindingMap.values();
} }
@ -333,8 +380,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
} }
public void addImport(String importName, String entityName) { public void addImport(String importName, String entityName) {
if ( imports == null ) { if ( importName == null || entityName == null ) {
imports = new HashMap<String, String>(); throw new IllegalArgumentException( "Import name or entity name is null" );
} }
LOG.trace( "Import: " + importName + " -> " + entityName ); LOG.trace( "Import: " + importName + " -> " + entityName );
String old = imports.put( 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() { public Iterable<FetchProfile> getFetchProfiles() {
return fetchProfiles.values(); return fetchProfiles.values();
} }

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.metamodel.source.spi; package org.hibernate.metamodel.source.spi;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.NamedQueryDefinition; 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 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); public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
} }

View File

@ -92,6 +92,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.property.BackrefPropertyAccessor; import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.sql.Alias; import org.hibernate.sql.Alias;
@ -754,6 +755,75 @@ public abstract class AbstractEntityPersister
temporaryIdTableDDL = persistentClass.getTemporaryIdTableDDL(); 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() { protected String generateLazySelectString() {
if ( !entityMetamodel.hasLazyProperties() ) { if ( !entityMetamodel.hasLazyProperties() ) {

View File

@ -47,6 +47,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.sql.CaseFragment; import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.SelectFragment; import org.hibernate.sql.SelectFragment;
import org.hibernate.type.StandardBasicTypes; 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) { protected boolean isSubclassTableSequentialSelect(int j) {
return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j]; return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
} }

View File

@ -47,6 +47,7 @@ import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.sql.InFragment; import org.hibernate.sql.InFragment;
import org.hibernate.sql.Insert; import org.hibernate.sql.Insert;
import org.hibernate.sql.SelectFragment; 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) { protected boolean isInverseTable(int j) {
return isInverseTable[j]; return isInverseTable[j];
} }

View File

@ -49,6 +49,7 @@ import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.sql.SelectFragment; import org.hibernate.sql.SelectFragment;
import org.hibernate.sql.SimpleSelect; import org.hibernate.sql.SimpleSelect;
import org.hibernate.type.StandardBasicTypes; 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() { public Serializable[] getQuerySpaces() {
return subclassSpaces; return subclassSpaces;
} }

View File

@ -34,6 +34,7 @@ import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.spi.MetadataImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.spi.PersisterClassResolver; 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[] { private static final Class[] COLLECTION_PERSISTER_CONSTRUCTOR_ARGS_NEW = new Class[] {
PluralAttributeBinding.class, PluralAttributeBinding.class,
CollectionRegionAccessStrategy.class, CollectionRegionAccessStrategy.class,
Configuration.class, MetadataImplementor.class,
SessionFactoryImplementor.class SessionFactoryImplementor.class
}; };
@ -183,44 +184,44 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public CollectionPersister createCollectionPersister( public CollectionPersister createCollectionPersister(
Configuration cfg, Configuration cfg,
Collection metadata, Collection collectionMetadata,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException { SessionFactoryImplementor factory) throws HibernateException {
Class<? extends CollectionPersister> persisterClass = metadata.getCollectionPersisterClass(); Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();
if ( persisterClass == null ) { 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 @Override
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public CollectionPersister createCollectionPersister(MetadataImplementor metadata,
public CollectionPersister createCollectionPersister(Configuration cfg, PluralAttributeBinding collectionMetadata,
PluralAttributeBinding metadata,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException { SessionFactoryImplementor factory) throws HibernateException {
Class<? extends CollectionPersister> persisterClass = metadata.getCollectionPersisterClass(); Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();
if ( persisterClass == null ) { 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( private static CollectionPersister create(
Class<? extends CollectionPersister> persisterClass, Class<? extends CollectionPersister> persisterClass,
Class[] persisterConstructorArgs, Class[] persisterConstructorArgs,
Configuration cfg, Object cfg,
Object metadata, Object collectionMetadata,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException { SessionFactoryImplementor factory) throws HibernateException {
try { try {
Constructor<? extends CollectionPersister> constructor = persisterClass.getConstructor( persisterConstructorArgs ); Constructor<? extends CollectionPersister> constructor = persisterClass.getConstructor( persisterConstructorArgs );
try { try {
return constructor.newInstance( metadata, cacheAccessStrategy, cfg, factory ); return constructor.newInstance( collectionMetadata, cacheAccessStrategy, cfg, factory );
} }
catch (MappingException e) { catch (MappingException e) {
throw e; throw e;

View File

@ -47,9 +47,13 @@ public class StandardPersisterClassResolver implements PersisterClassResolver {
public Class<? extends EntityPersister> getEntityPersisterClass(EntityBinding metadata) { 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! // 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() ) { switch ( metadata.getInheritanceType() ) {
case JOINED: { case JOINED: {
joinedSubclassEntityPersister(); return joinedSubclassEntityPersister();
} }
case SINGLE_TABLE: { case SINGLE_TABLE: {
return singleTableEntityPersister(); return singleTableEntityPersister();

View File

@ -33,6 +33,7 @@ import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.spi.MetadataImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.Service; import org.hibernate.service.Service;
@ -110,7 +111,7 @@ public interface PersisterFactory extends Service {
/** /**
* Create a collection persister instance. * 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 model The O/R mapping metamodel definition for the collection
* @param cacheAccessStrategy The caching strategy for this collection * @param cacheAccessStrategy The caching strategy for this collection
* @param factory The session factory * @param factory The session factory
@ -120,7 +121,7 @@ public interface PersisterFactory extends Service {
* @throws HibernateException Indicates a problem building the persister. * @throws HibernateException Indicates a problem building the persister.
*/ */
public CollectionPersister createCollectionPersister( public CollectionPersister createCollectionPersister(
Configuration cfg, MetadataImplementor metadata,
PluralAttributeBinding model, PluralAttributeBinding model,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException; SessionFactoryImplementor factory) throws HibernateException;

View File

@ -87,6 +87,7 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
private SessionFactoryBuilder getSessionFactoryBuilder() { private SessionFactoryBuilder getSessionFactoryBuilder() {
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() ); MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
sources.addAnnotatedClass( SimpleEntity.class );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata(); MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
return metadata.getSessionFactoryBuilder(); return metadata.getSessionFactoryBuilder();
} }

View File

@ -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;
}
}