HHH-9803 - Checkstyle fix ups

This commit is contained in:
Steve Ebersole 2015-05-18 13:35:26 -05:00
parent bb3998bf34
commit 611f8a0e1c
176 changed files with 3888 additions and 3165 deletions

View File

@ -29,5 +29,5 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface SubEntityInfo extends EntityInfo { public interface SubEntityInfo extends EntityInfo {
String getExtends(); String getExtends();
} }

View File

@ -50,8 +50,8 @@
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.hql.spi.id.IdTableSupportStandardImpl; import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.AfterUseAction; import org.hibernate.hql.spi.id.local.AfterUseAction;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.procedure.internal.StandardCallableStatementSupport; import org.hibernate.procedure.internal.StandardCallableStatementSupport;
@ -78,8 +78,7 @@ public String processSql(String sql, RowSelection selection) {
final boolean hasOffset = LimitHelper.hasFirstRow( selection ); final boolean hasOffset = LimitHelper.hasFirstRow( selection );
sql = sql.trim(); sql = sql.trim();
boolean isForUpdate = false; boolean isForUpdate = false;
if (sql.toLowerCase(Locale.ROOT if (sql.toLowerCase(Locale.ROOT).endsWith( " for update" )) {
).endsWith( " for update" )) {
sql = sql.substring( 0, sql.length() - 11 ); sql = sql.substring( 0, sql.length() - 11 );
isForUpdate = true; isForUpdate = true;
} }

View File

@ -35,7 +35,6 @@
import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Queryable; import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType; import org.hibernate.sql.JoinType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
@ -61,8 +60,8 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
public static boolean useThetaStyleImplicitJoins; public static boolean useThetaStyleImplicitJoins;
public static boolean regressionStyleJoinSuppression; public static boolean regressionStyleJoinSuppression;
public static interface IllegalCollectionDereferenceExceptionBuilder { public interface IllegalCollectionDereferenceExceptionBuilder {
public QueryException buildIllegalCollectionDereferenceException( QueryException buildIllegalCollectionDereferenceException(
String collectionPropertyName, String collectionPropertyName,
FromReferenceNode lhs); FromReferenceNode lhs);
} }
@ -126,7 +125,7 @@ public static enum DereferenceType {
* *
* @param joinType The type of join to use. * @param joinType The type of join to use.
* *
* @see JoinFragment * @see org.hibernate.sql.JoinFragment
*/ */
public void setJoinType(JoinType joinType) { public void setJoinType(JoinType joinType) {
this.joinType = joinType; this.joinType = joinType;

View File

@ -90,7 +90,9 @@ public void token(String token, QueryTranslatorImpl q) throws QueryException {
} }
//ignore whitespace //ignore whitespace
if ( ParserHelper.isWhitespace( token ) ) return; if ( ParserHelper.isWhitespace( token ) ) {
return;
}
//do replacements //do replacements
String substoken = ( String ) replacements.get( token ); String substoken = ( String ) replacements.get( token );

View File

@ -25,7 +25,6 @@
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;

View File

@ -68,7 +68,6 @@
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.ScrollMode; import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.SessionBuilder; import org.hibernate.SessionBuilder;
import org.hibernate.SessionEventListener; import org.hibernate.SessionEventListener;
import org.hibernate.SessionException; import org.hibernate.SessionException;
@ -169,7 +168,7 @@
* Concrete implementation of a Session. * Concrete implementation of a Session.
* <p/> * <p/>
* Exposes two interfaces:<ul> * Exposes two interfaces:<ul>
* <li>{@link Session} to the application</li> * <li>{@link org.hibernate.Session} to the application</li>
* <li>{@link org.hibernate.engine.spi.SessionImplementor} to other Hibernate components (SPI)</li> * <li>{@link org.hibernate.engine.spi.SessionImplementor} to other Hibernate components (SPI)</li>
* </ul> * </ul>
* <p/> * <p/>

View File

@ -1504,9 +1504,7 @@ void rehash() {
// Reuse trailing consecutive sequence at same slot // Reuse trailing consecutive sequence at same slot
HashEntry<K, V> lastRun = e; HashEntry<K, V> lastRun = e;
int lastIdx = idx; int lastIdx = idx;
for ( HashEntry<K, V> last = next; for ( HashEntry<K, V> last = next; last != null; last = last.next ) {
last != null;
last = last.next ) {
int k = last.hash & sizeMask; int k = last.hash & sizeMask;
if ( k != lastIdx ) { if ( k != lastIdx ) {
lastIdx = k; lastIdx = k;

View File

@ -42,7 +42,6 @@
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.IdentityHashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -181,7 +180,7 @@ public static enum ReferenceType {
public static enum Option { public static enum Option {
/** /**
* Indicates that referential-equality (== instead of .equals()) should * Indicates that referential-equality (== instead of .equals()) should
* be used when locating keys. This offers similar behavior to {@link IdentityHashMap} * be used when locating keys. This offers similar behavior to {@link java.util.IdentityHashMap}
*/ */
IDENTITY_COMPARISONS IDENTITY_COMPARISONS
} }
@ -814,9 +813,7 @@ int rehash() {
// Reuse trailing consecutive sequence at same slot // Reuse trailing consecutive sequence at same slot
HashEntry<K, V> lastRun = e; HashEntry<K, V> lastRun = e;
int lastIdx = idx; int lastIdx = idx;
for ( HashEntry<K, V> last = next; for ( HashEntry<K, V> last = next; last != null; last = last.next ) {
last != null;
last = last.next ) {
int k = last.hash & sizeMask; int k = last.hash & sizeMask;
if ( k != lastIdx ) { if ( k != lastIdx ) {
lastIdx = k; lastIdx = k;
@ -1674,8 +1671,7 @@ public V nextElement() {
/* /*
* This class is needed for JDK5 compatibility. * This class is needed for JDK5 compatibility.
*/ */
static class SimpleEntry<K, V> implements Entry<K, V>, static class SimpleEntry<K, V> implements Entry<K, V>, java.io.Serializable {
java.io.Serializable {
private static final long serialVersionUID = -8499721149061103585L; private static final long serialVersionUID = -8499721149061103585L;
private final K key; private final K key;

View File

@ -29,16 +29,15 @@
/** /**
* @author Gavin King * @author Gavin King
*/ */
public final class SingletonIterator implements Iterator { public final class SingletonIterator<T> implements Iterator<T> {
private T value;
private Object value;
private boolean hasNext = true; private boolean hasNext = true;
public boolean hasNext() { public boolean hasNext() {
return hasNext; return hasNext;
} }
public Object next() { public T next() {
if (hasNext) { if (hasNext) {
hasNext = false; hasNext = false;
return value; return value;
@ -52,7 +51,7 @@ public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public SingletonIterator(Object value) { public SingletonIterator(T value) {
this.value = value; this.value = value;
} }

View File

@ -97,8 +97,6 @@
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.VersionType; import org.hibernate.type.VersionType;
import org.jboss.logging.Logger;
/** /**
* Abstract superclass of object loading (and querying) strategies. This class implements * Abstract superclass of object loading (and querying) strategies. This class implements
* useful common functionality that concrete loaders delegate to. It is not intended that this * useful common functionality that concrete loaders delegate to. It is not intended that this
@ -250,13 +248,13 @@ protected String preprocessSQL(
Dialect dialect, Dialect dialect,
List<AfterLoadAction> afterLoadActions) throws HibernateException { List<AfterLoadAction> afterLoadActions) throws HibernateException {
sql = applyLocks( sql, parameters, dialect, afterLoadActions ); sql = applyLocks( sql, parameters, dialect, afterLoadActions );
// Keep this here, rather than moving to Select. Some Dialects may need the hint to be appended to the very // Keep this here, rather than moving to Select. Some Dialects may need the hint to be appended to the very
// end or beginning of the finalized SQL statement, so wait until everything is processed. // end or beginning of the finalized SQL statement, so wait until everything is processed.
if ( parameters.getQueryHints() != null && parameters.getQueryHints().size() > 0 ) { if ( parameters.getQueryHints() != null && parameters.getQueryHints().size() > 0 ) {
sql = dialect.getQueryHintString( sql, parameters.getQueryHints() ); sql = dialect.getQueryHintString( sql, parameters.getQueryHints() );
} }
return getFactory().getSessionFactoryOptions().isCommentsEnabled() return getFactory().getSessionFactoryOptions().isCommentsEnabled()
? prependComment( sql, parameters ) ? prependComment( sql, parameters )
: sql; : sql;
@ -278,7 +276,10 @@ protected boolean shouldUseFollowOnLocking(
new AfterLoadAction() { new AfterLoadAction() {
@Override @Override
public void afterLoad(SessionImplementor session, Object entity, Loadable persister) { public void afterLoad(SessionImplementor session, Object entity, Loadable persister) {
( (Session) session ).buildLockRequest( lockOptions ).lock( persister.getEntityName(), entity ); ( (Session) session ).buildLockRequest( lockOptions ).lock(
persister.getEntityName(),
entity
);
} }
} }
); );
@ -370,7 +371,9 @@ public List doQueryAndInitializeNonLazyCollections(
* @param session The session from which the request originated. * @param session The session from which the request originated.
* @param queryParameters The query parameters specified by the user. * @param queryParameters The query parameters specified by the user.
* @param returnProxies Should proxies be generated * @param returnProxies Should proxies be generated
*
* @return The loaded "row". * @return The loaded "row".
*
* @throws HibernateException * @throws HibernateException
*/ */
public Object loadSingleRow( public Object loadSingleRow(
@ -394,14 +397,14 @@ public Object loadSingleRow(
hydratedObjects, hydratedObjects,
new EntityKey[entitySpan], new EntityKey[entitySpan],
returnProxies returnProxies
); );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not read next row of results", "could not read next row of results",
getSQLString() getSQLString()
); );
} }
initializeEntitiesAndCollections( initializeEntitiesAndCollections(
@ -440,12 +443,13 @@ private Object sequentialLoad(
loadedKeys, loadedKeys,
returnProxies returnProxies
); );
if ( ! keyToRead.equals( loadedKeys[0] ) ) { if ( !keyToRead.equals( loadedKeys[0] ) ) {
throw new AssertionFailure( throw new AssertionFailure(
String.format( String.format(
"Unexpected key read for row; expected [%s]; actual [%s]", "Unexpected key read for row; expected [%s]; actual [%s]",
keyToRead, keyToRead,
loadedKeys[0] ) loadedKeys[0]
)
); );
} }
if ( result == null ) { if ( result == null ) {
@ -455,12 +459,12 @@ private Object sequentialLoad(
while ( resultSet.next() && while ( resultSet.next() &&
isCurrentRowForSameEntity( keyToRead, 0, resultSet, session ) ); isCurrentRowForSameEntity( keyToRead, 0, resultSet, session ) );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not doAfterTransactionCompletion sequential read of results (forward)", "could not doAfterTransactionCompletion sequential read of results (forward)",
getSQLString() getSQLString()
); );
} }
initializeEntitiesAndCollections( initializeEntitiesAndCollections(
@ -494,7 +498,9 @@ persisterIndex, getEntityPersisters()[persisterIndex], null, resultSet, session
* @param session The session from which the request originated. * @param session The session from which the request originated.
* @param queryParameters The query parameters specified by the user. * @param queryParameters The query parameters specified by the user.
* @param returnProxies Should proxies be generated * @param returnProxies Should proxies be generated
*
* @return The loaded "row". * @return The loaded "row".
*
* @throws HibernateException * @throws HibernateException
*/ */
public Object loadSequentialRowsForward( public Object loadSequentialRowsForward(
@ -528,16 +534,16 @@ public Object loadSequentialRowsForward(
null, null,
resultSet, resultSet,
session session
); );
return sequentialLoad( resultSet, session, queryParameters, returnProxies, currentKey ); return sequentialLoad( resultSet, session, queryParameters, returnProxies, currentKey );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not perform sequential read of results (forward)", "could not perform sequential read of results (forward)",
getSQLString() getSQLString()
); );
} }
} }
@ -551,7 +557,9 @@ public Object loadSequentialRowsForward(
* @param session The session from which the request originated. * @param session The session from which the request originated.
* @param queryParameters The query parameters specified by the user. * @param queryParameters The query parameters specified by the user.
* @param returnProxies Should proxies be generated * @param returnProxies Should proxies be generated
*
* @return The loaded "row". * @return The loaded "row".
*
* @throws HibernateException * @throws HibernateException
*/ */
public Object loadSequentialRowsReverse( public Object loadSequentialRowsReverse(
@ -592,7 +600,7 @@ public Object loadSequentialRowsReverse(
null, null,
resultSet, resultSet,
session session
); );
} }
else { else {
// Since the result set cursor is always left at the first // Since the result set cursor is always left at the first
@ -612,7 +620,7 @@ public Object loadSequentialRowsReverse(
null, null,
resultSet, resultSet,
session session
); );
while ( resultSet.previous() ) { while ( resultSet.previous() ) {
EntityKey checkKey = getKeyFromResultSet( EntityKey checkKey = getKeyFromResultSet(
0, 0,
@ -620,7 +628,7 @@ public Object loadSequentialRowsReverse(
null, null,
resultSet, resultSet,
session session
); );
if ( firstPass ) { if ( firstPass ) {
firstPass = false; firstPass = false;
@ -643,7 +651,7 @@ public Object loadSequentialRowsReverse(
null, null,
resultSet, resultSet,
session session
); );
if ( !keyToRead.equals( checkKey ) ) { if ( !keyToRead.equals( checkKey ) ) {
break; break;
@ -657,12 +665,12 @@ public Object loadSequentialRowsReverse(
// and doAfterTransactionCompletion the load // and doAfterTransactionCompletion the load
return sequentialLoad( resultSet, session, queryParameters, returnProxies, keyToRead ); return sequentialLoad( resultSet, session, queryParameters, returnProxies, keyToRead );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not doAfterTransactionCompletion sequential read of results (forward)", "could not doAfterTransactionCompletion sequential read of results (forward)",
getSQLString() getSQLString()
); );
} }
} }
@ -672,7 +680,12 @@ private static EntityKey getOptionalObjectKey(QueryParameters queryParameters, S
final String optionalEntityName = queryParameters.getOptionalEntityName(); final String optionalEntityName = queryParameters.getOptionalEntityName();
if ( optionalObject != null && optionalEntityName != null ) { if ( optionalObject != null && optionalEntityName != null ) {
return session.generateEntityKey( optionalId, session.getEntityPersister( optionalEntityName, optionalObject ) ); return session.generateEntityKey(
optionalId, session.getEntityPersister(
optionalEntityName,
optionalObject
)
);
} }
else { else {
return null; return null;
@ -714,7 +727,15 @@ private Object getRowFromResultSet(
ResultTransformer forcedResultTransformer) throws SQLException, HibernateException { ResultTransformer forcedResultTransformer) throws SQLException, HibernateException {
final Loadable[] persisters = getEntityPersisters(); final Loadable[] persisters = getEntityPersisters();
final int entitySpan = persisters.length; final int entitySpan = persisters.length;
extractKeysFromResultSet( persisters, queryParameters, resultSet, session, keys, lockModesArray, hydratedObjects ); extractKeysFromResultSet(
persisters,
queryParameters,
resultSet,
session,
keys,
lockModesArray,
hydratedObjects
);
registerNonExists( keys, persisters, session ); registerNonExists( keys, persisters, session );
@ -739,7 +760,7 @@ private Object getRowFromResultSet(
Object proxy = session.getPersistenceContext().proxyFor( persisters[i], keys[i], entity ); Object proxy = session.getPersistenceContext().proxyFor( persisters[i], keys[i], entity );
if ( entity != proxy ) { if ( entity != proxy ) {
// force the proxy to resolve itself // force the proxy to resolve itself
( (HibernateProxy) proxy ).getHibernateLazyInitializer().setImplementation(entity); ( (HibernateProxy) proxy ).getHibernateLazyInitializer().setImplementation( entity );
row[i] = proxy; row[i] = proxy;
} }
} }
@ -749,8 +770,11 @@ private Object getRowFromResultSet(
return forcedResultTransformer == null return forcedResultTransformer == null
? getResultColumnOrRow( row, queryParameters.getResultTransformer(), resultSet, session ) ? getResultColumnOrRow( row, queryParameters.getResultTransformer(), resultSet, session )
: forcedResultTransformer.transformTuple( getResultRow( row, resultSet, session ), getResultRowAliases() ) : forcedResultTransformer.transformTuple(
; getResultRow( row, resultSet, session ),
getResultRowAliases()
)
;
} }
protected void extractKeysFromResultSet( protected void extractKeysFromResultSet(
@ -766,7 +790,7 @@ protected void extractKeysFromResultSet(
final int numberOfPersistersToProcess; final int numberOfPersistersToProcess;
final Serializable optionalId = queryParameters.getOptionalId(); final Serializable optionalId = queryParameters.getOptionalId();
if ( isSingleRowLoader() && optionalId != null ) { if ( isSingleRowLoader() && optionalId != null ) {
keys[ entitySpan - 1 ] = session.generateEntityKey( optionalId, persisters[ entitySpan - 1 ] ); keys[entitySpan - 1] = session.generateEntityKey( optionalId, persisters[entitySpan - 1] );
// skip the last persister below... // skip the last persister below...
numberOfPersistersToProcess = entitySpan - 1; numberOfPersistersToProcess = entitySpan - 1;
} }
@ -778,7 +802,12 @@ protected void extractKeysFromResultSet(
for ( int i = 0; i < numberOfPersistersToProcess; i++ ) { for ( int i = 0; i < numberOfPersistersToProcess; i++ ) {
final Type idType = persisters[i].getIdentifierType(); final Type idType = persisters[i].getIdentifierType();
hydratedKeyState[i] = idType.hydrate( resultSet, getEntityAliases()[i].getSuffixedKeyAliases(), session, null ); hydratedKeyState[i] = idType.hydrate(
resultSet,
getEntityAliases()[i].getSuffixedKeyAliases(),
session,
null
);
} }
for ( int i = 0; i < numberOfPersistersToProcess; i++ ) { for ( int i = 0; i < numberOfPersistersToProcess; i++ ) {
@ -854,15 +883,15 @@ private void readCollectionElements(Object[] row, ResultSet resultSet, SessionIm
final CollectionAliases[] descriptors = getCollectionAliases(); final CollectionAliases[] descriptors = getCollectionAliases();
final int[] collectionOwners = getCollectionOwners(); final int[] collectionOwners = getCollectionOwners();
for ( int i=0; i<collectionPersisters.length; i++ ) { for ( int i = 0; i < collectionPersisters.length; i++ ) {
final boolean hasCollectionOwners = collectionOwners !=null && final boolean hasCollectionOwners = collectionOwners != null &&
collectionOwners[i] > -1; collectionOwners[i] > -1;
//true if this is a query and we are loading multiple instances of the same collection role //true if this is a query and we are loading multiple instances of the same collection role
//otherwise this is a CollectionInitializer and we are loading up a single collection or batch //otherwise this is a CollectionInitializer and we are loading up a single collection or batch
final Object owner = hasCollectionOwners ? final Object owner = hasCollectionOwners ?
row[ collectionOwners[i] ] : row[collectionOwners[i]] :
null; //if null, owner will be retrieved from session null; //if null, owner will be retrieved from session
final CollectionPersister collectionPersister = collectionPersisters[i]; final CollectionPersister collectionPersister = collectionPersisters[i];
@ -883,7 +912,7 @@ private void readCollectionElements(Object[] row, ResultSet resultSet, SessionIm
descriptors[i], descriptors[i],
resultSet, resultSet,
session session
); );
} }
@ -914,7 +943,15 @@ private List doQuery(
// that I could do the control breaking at the means to know when to stop // that I could do the control breaking at the means to know when to stop
try { try {
return processResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, afterLoadActions ); return processResultSet(
rs,
queryParameters,
session,
returnProxies,
forcedResultTransformer,
maxRows,
afterLoadActions
);
} }
finally { finally {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getResourceRegistry().release( st );
@ -961,7 +998,7 @@ protected List processResultSet(
); );
results.add( result ); results.add( result );
if ( createSubselects ) { if ( createSubselects ) {
subselectResultKeys.add(keys); subselectResultKeys.add( keys );
keys = new EntityKey[entitySpan]; //can't reuse in this case keys = new EntityKey[entitySpan]; //can't reuse in this case
} }
} }
@ -995,9 +1032,9 @@ protected boolean hasSubselectLoadableCollections() {
return false; return false;
} }
private static Set[] transpose( List keys ) { private static Set[] transpose(List keys) {
Set[] result = new Set[ ( ( EntityKey[] ) keys.get(0) ).length ]; Set[] result = new Set[( (EntityKey[]) keys.get( 0 ) ).length];
for ( int j=0; j<result.length; j++ ) { for ( int j = 0; j < result.length; j++ ) {
result[j] = new HashSet( keys.size() ); result[j] = new HashSet( keys.size() );
for ( Object key : keys ) { for ( Object key : keys ) {
result[j].add( ( (EntityKey[]) key )[j] ); result[j].add( ( (EntityKey[]) key )[j] );
@ -1009,7 +1046,7 @@ private static Set[] transpose( List keys ) {
private void createSubselects(List keys, QueryParameters queryParameters, SessionImplementor session) { private void createSubselects(List keys, QueryParameters queryParameters, SessionImplementor session) {
if ( keys.size() > 1 ) { //if we only returned one entity, query by key is more efficient if ( keys.size() > 1 ) { //if we only returned one entity, query by key is more efficient
Set[] keySets = transpose(keys); Set[] keySets = transpose( keys );
Map namedParameterLocMap = buildNamedParameterLocMap( queryParameters ); Map namedParameterLocMap = buildNamedParameterLocMap( queryParameters );
@ -1042,12 +1079,12 @@ private void createSubselects(List keys, QueryParameters queryParameters, Sessio
} }
private Map buildNamedParameterLocMap(QueryParameters queryParameters) { private Map buildNamedParameterLocMap(QueryParameters queryParameters) {
if ( queryParameters.getNamedParameters()!=null ) { if ( queryParameters.getNamedParameters() != null ) {
final Map namedParameterLocMap = new HashMap(); final Map namedParameterLocMap = new HashMap();
for(String name : queryParameters.getNamedParameters().keySet()){ for ( String name : queryParameters.getNamedParameters().keySet() ) {
namedParameterLocMap.put( namedParameterLocMap.put(
name, name,
getNamedParameterLocs(name) getNamedParameterLocs( name )
); );
} }
return namedParameterLocMap; return namedParameterLocMap;
@ -1104,7 +1141,7 @@ private void initializeEntitiesAndCollections(
post = null; post = null;
} }
if ( hydratedObjects!=null ) { if ( hydratedObjects != null ) {
int hydratedObjectsSize = hydratedObjects.size(); int hydratedObjectsSize = hydratedObjects.size();
LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize ); LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize );
for ( Object hydratedObject : hydratedObjects ) { for ( Object hydratedObject : hydratedObjects ) {
@ -1123,7 +1160,7 @@ private void initializeEntitiesAndCollections(
} }
} }
} }
// Until this entire method is refactored w/ polymorphism, postLoad was // Until this entire method is refactored w/ polymorphism, postLoad was
// split off from initializeEntity. It *must* occur after // split off from initializeEntity. It *must* occur after
// endCollectionLoad to ensure the collection is in the // endCollectionLoad to ensure the collection is in the
@ -1136,7 +1173,9 @@ private void initializeEntitiesAndCollections(
final EntityEntry entityEntry = session.getPersistenceContext().getEntry( hydratedObject ); final EntityEntry entityEntry = session.getPersistenceContext().getEntry( hydratedObject );
if ( entityEntry == null ) { if ( entityEntry == null ) {
// big problem // big problem
throw new HibernateException( "Could not locate EntityEntry immediately after two-phase load" ); throw new HibernateException(
"Could not locate EntityEntry immediately after two-phase load"
);
} }
afterLoadAction.afterLoad( session, hydratedObject, (Loadable) entityEntry.getPersister() ); afterLoadAction.afterLoad( session, hydratedObject, (Loadable) entityEntry.getPersister() );
} }
@ -1152,7 +1191,7 @@ private void endCollectionLoad(
//this is a query and we are loading multiple instances of the same collection role //this is a query and we are loading multiple instances of the same collection role
session.getPersistenceContext() session.getPersistenceContext()
.getLoadContexts() .getLoadContexts()
.getCollectionLoadContext( ( ResultSet ) resultSetId ) .getCollectionLoadContext( (ResultSet) resultSetId )
.endLoadingCollections( collectionPersister ); .endLoadingCollections( collectionPersister );
} }
@ -1161,6 +1200,7 @@ private void endCollectionLoad(
* transform query results. * transform query results.
* *
* @param resultTransformer the specified result transformer * @param resultTransformer the specified result transformer
*
* @return the actual result transformer * @return the actual result transformer
*/ */
protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer) { protected ResultTransformer resolveResultTransformer(ResultTransformer resultTransformer) {
@ -1173,6 +1213,7 @@ protected List getResultList(List results, ResultTransformer resultTransformer)
/** /**
* Are rows transformed immediately after being read from the ResultSet? * Are rows transformed immediately after being read from the ResultSet?
*
* @return true, if getResultColumnOrRow() transforms the results; false, otherwise * @return true, if getResultColumnOrRow() transforms the results; false, otherwise
*/ */
protected boolean areResultSetRowsTransformedImmediately() { protected boolean areResultSetRowsTransformedImmediately() {
@ -1181,10 +1222,11 @@ protected boolean areResultSetRowsTransformedImmediately() {
/** /**
* Returns the aliases that corresponding to a result row. * Returns the aliases that corresponding to a result row.
*
* @return Returns the aliases that corresponding to a result row. * @return Returns the aliases that corresponding to a result row.
*/ */
protected String[] getResultRowAliases() { protected String[] getResultRowAliases() {
return null; return null;
} }
/** /**
@ -1252,12 +1294,14 @@ private void registerNonExists(
); );
} }
else if ( isSpecialOneToOne ) {*/ else if ( isSpecialOneToOne ) {*/
boolean isOneToOneAssociation = ownerAssociationTypes!=null && boolean isOneToOneAssociation = ownerAssociationTypes != null &&
ownerAssociationTypes[i]!=null && ownerAssociationTypes[i] != null &&
ownerAssociationTypes[i].isOneToOne(); ownerAssociationTypes[i].isOneToOne();
if ( isOneToOneAssociation ) { if ( isOneToOneAssociation ) {
persistenceContext.addNullProperty( ownerKey, persistenceContext.addNullProperty(
ownerAssociationTypes[i].getPropertyName() ); ownerKey,
ownerAssociationTypes[i].getPropertyName()
);
} }
/*} /*}
else { else {
@ -1285,7 +1329,7 @@ private void readCollectionElement(
final CollectionAliases descriptor, final CollectionAliases descriptor,
final ResultSet rs, final ResultSet rs,
final SessionImplementor session) final SessionImplementor session)
throws HibernateException, SQLException { throws HibernateException, SQLException {
final PersistenceContext persistenceContext = session.getPersistenceContext(); final PersistenceContext persistenceContext = session.getPersistenceContext();
@ -1293,14 +1337,16 @@ private void readCollectionElement(
rs, rs,
descriptor.getSuffixedKeyAliases(), descriptor.getSuffixedKeyAliases(),
session session
); );
if ( collectionRowKey != null ) { if ( collectionRowKey != null ) {
// we found a collection element in the result set // we found a collection element in the result set
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Found row of collection: %s", LOG.debugf(
MessageHelper.collectionInfoString( persister, collectionRowKey, getFactory() ) ); "Found row of collection: %s",
MessageHelper.collectionInfoString( persister, collectionRowKey, getFactory() )
);
} }
Object owner = optionalOwner; Object owner = optionalOwner;
@ -1330,8 +1376,10 @@ else if ( optionalKey != null ) {
// since what we have is an empty collection // since what we have is an empty collection
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Result set contains (possibly empty) collection: %s", LOG.debugf(
MessageHelper.collectionInfoString( persister, optionalKey, getFactory() ) ); "Result set contains (possibly empty) collection: %s",
MessageHelper.collectionInfoString( persister, optionalKey, getFactory() )
);
} }
persistenceContext.getLoadContexts() persistenceContext.getLoadContexts()
@ -1360,7 +1408,7 @@ private void handleEmptyCollections(
// for each of the passed-in keys, to account for the possibility // for each of the passed-in keys, to account for the possibility
// that the collection is empty and has no rows in the result set // that the collection is empty and has no rows in the result set
CollectionPersister[] collectionPersisters = getCollectionPersisters(); CollectionPersister[] collectionPersisters = getCollectionPersisters();
for ( CollectionPersister collectionPersister : collectionPersisters ) for ( CollectionPersister collectionPersister : collectionPersisters ) {
for ( Serializable key : keys ) { for ( Serializable key : keys ) {
//handle empty collections //handle empty collections
if ( debugEnabled ) { if ( debugEnabled ) {
@ -1375,6 +1423,7 @@ private void handleEmptyCollections(
.getCollectionLoadContext( (ResultSet) resultSetId ) .getCollectionLoadContext( (ResultSet) resultSetId )
.getLoadingCollection( collectionPersister, key ); .getLoadingCollection( collectionPersister, key );
} }
}
} }
// else this is not a collection initializer (and empty collections will // else this is not a collection initializer (and empty collections will
@ -1447,7 +1496,7 @@ private void checkVersion(
session, session,
null null
); );
if ( !versionType.isEqual(version, currentVersion) ) { if ( !versionType.isEqual( version, currentVersion ) ) {
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
session.getFactory().getStatisticsImplementor() session.getFactory().getStatisticsImplementor()
.optimisticFailure( persister.getEntityName() ); .optimisticFailure( persister.getEntityName() );
@ -1577,7 +1626,7 @@ private Object instanceNotYetLoaded(
final Object optionalObject, final Object optionalObject,
final List hydratedObjects, final List hydratedObjects,
final SessionImplementor session) final SessionImplementor session)
throws HibernateException, SQLException { throws HibernateException, SQLException {
final String instanceClass = getInstanceClass( final String instanceClass = getInstanceClass(
rs, rs,
i, i,
@ -1639,7 +1688,7 @@ private Object instanceNotYetLoaded(
private boolean isEagerPropertyFetchEnabled(int i) { private boolean isEagerPropertyFetchEnabled(int i) {
boolean[] array = getEntityEagerPropertyFetches(); boolean[] array = getEntityEagerPropertyFetches();
return array!=null && array[i]; return array != null && array[i];
} }
@ -1665,10 +1714,16 @@ private void loadFromResultSet(
final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName ); final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName );
if ( LOG.isTraceEnabled() ) { if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Initializing object from ResultSet: {0}", MessageHelper.infoString( persister, id, getFactory() ) ); LOG.tracev(
"Initializing object from ResultSet: {0}", MessageHelper.infoString(
persister,
id,
getFactory()
)
);
} }
boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i); boolean eagerPropertyFetch = isEagerPropertyFetchEnabled( i );
// add temp entry so that the next step is circular-reference // add temp entry so that the next step is circular-reference
// safe - only needed because some types don't take proper // safe - only needed because some types don't take proper
@ -1685,7 +1740,7 @@ private void loadFromResultSet(
//This is not very nice (and quite slow): //This is not very nice (and quite slow):
final String[][] cols = persister == rootPersister ? final String[][] cols = persister == rootPersister ?
getEntityAliases()[i].getSuffixedPropertyAliases() : getEntityAliases()[i].getSuffixedPropertyAliases() :
getEntityAliases()[i].getSuffixedPropertyAliases(persister); getEntityAliases()[i].getSuffixedPropertyAliases( persister );
final Object[] values = persister.hydrate( final Object[] values = persister.hydrate(
rs, rs,
@ -1697,13 +1752,13 @@ private void loadFromResultSet(
session session
); );
final Object rowId = persister.hasRowId() ? rs.getObject(rowIdAlias) : null; final Object rowId = persister.hasRowId() ? rs.getObject( rowIdAlias ) : null;
final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes(); final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) { if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName(); String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
if (ukName!=null) { if ( ukName != null ) {
final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex(ukName); final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex( ukName );
final Type type = persister.getPropertyTypes()[index]; final Type type = persister.getPropertyTypes()[index];
// polymorphism not really handled completely correctly, // polymorphism not really handled completely correctly,
@ -1740,11 +1795,11 @@ private void loadFromResultSet(
* Determine the concrete class of an instance in the <tt>ResultSet</tt> * Determine the concrete class of an instance in the <tt>ResultSet</tt>
*/ */
private String getInstanceClass( private String getInstanceClass(
final ResultSet rs, final ResultSet rs,
final int i, final int i,
final Loadable persister, final Loadable persister,
final Serializable id, final Serializable id,
final SessionImplementor session) throws HibernateException, SQLException { final SessionImplementor session) throws HibernateException, SQLException {
if ( persister.hasSubclasses() ) { if ( persister.hasSubclasses() ) {
@ -1764,7 +1819,7 @@ private String getInstanceClass(
"Discriminator: " + discriminatorValue, "Discriminator: " + discriminatorValue,
id, id,
persister.getEntityName() persister.getEntityName()
); );
} }
return result; return result;
@ -1800,6 +1855,7 @@ private void advance(final ResultSet rs, final RowSelection selection) throws SQ
* if dialect does not support LIMIT expression or processed query does not use pagination. * if dialect does not support LIMIT expression or processed query does not use pagination.
* *
* @param selection Selection criteria. * @param selection Selection criteria.
*
* @return LIMIT clause delegate. * @return LIMIT clause delegate.
*/ */
protected LimitHandler getLimitHandler(RowSelection selection) { protected LimitHandler getLimitHandler(RowSelection selection) {
@ -1807,7 +1863,11 @@ protected LimitHandler getLimitHandler(RowSelection selection) {
return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : NoopLimitHandler.INSTANCE; return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : NoopLimitHandler.INSTANCE;
} }
private ScrollMode getScrollMode(boolean scroll, boolean hasFirstRow, boolean useLimitOffSet, QueryParameters queryParameters) { private ScrollMode getScrollMode(
boolean scroll,
boolean hasFirstRow,
boolean useLimitOffSet,
QueryParameters queryParameters) {
final boolean canScroll = getFactory().getSessionFactoryOptions().isScrollableResultSetsEnabled(); final boolean canScroll = getFactory().getSessionFactoryOptions().isScrollableResultSetsEnabled();
if ( canScroll ) { if ( canScroll ) {
if ( scroll ) { if ( scroll ) {
@ -1852,7 +1912,15 @@ protected SqlStatementWrapper executeQueryStatement(
sql = preprocessSQL( sql, queryParameters, getFactory().getDialect(), afterLoadActions ); sql = preprocessSQL( sql, queryParameters, getFactory().getDialect(), afterLoadActions );
final PreparedStatement st = prepareQueryStatement( sql, queryParameters, limitHandler, scroll, session ); final PreparedStatement st = prepareQueryStatement( sql, queryParameters, limitHandler, scroll, session );
return new SqlStatementWrapper( st, getResultSet( st, queryParameters.getRowSelection(), limitHandler, queryParameters.hasAutoDiscoverScalarTypes(), session ) ); return new SqlStatementWrapper(
st, getResultSet(
st,
queryParameters.getRowSelection(),
limitHandler,
queryParameters.hasAutoDiscoverScalarTypes(),
session
)
);
} }
/** /**
@ -1861,11 +1929,11 @@ protected SqlStatementWrapper executeQueryStatement(
* limit parameters. * limit parameters.
*/ */
protected final PreparedStatement prepareQueryStatement( protected final PreparedStatement prepareQueryStatement(
String sql, String sql,
final QueryParameters queryParameters, final QueryParameters queryParameters,
final LimitHandler limitHandler, final LimitHandler limitHandler,
final boolean scroll, final boolean scroll,
final SessionImplementor session) throws SQLException, HibernateException { final SessionImplementor session) throws SQLException, HibernateException {
final Dialect dialect = getFactory().getDialect(); final Dialect dialect = getFactory().getDialect();
final RowSelection selection = queryParameters.getRowSelection(); final RowSelection selection = queryParameters.getRowSelection();
final boolean useLimit = LimitHelper.useLimit( limitHandler, selection ); final boolean useLimit = LimitHelper.useLimit( limitHandler, selection );
@ -1873,7 +1941,7 @@ protected final PreparedStatement prepareQueryStatement(
final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset(); final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
final boolean callable = queryParameters.isCallable(); final boolean callable = queryParameters.isCallable();
final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimitOffset, queryParameters ); final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimitOffset, queryParameters );
PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareQueryStatement( PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareQueryStatement(
sql, sql,
callable, callable,
@ -1886,8 +1954,8 @@ protected final PreparedStatement prepareQueryStatement(
//TODO: can we limit stored procedures ?! //TODO: can we limit stored procedures ?!
col += limitHandler.bindLimitParametersAtStartOfQuery( selection, st, col ); col += limitHandler.bindLimitParametersAtStartOfQuery( selection, st, col );
if (callable) { if ( callable ) {
col = dialect.registerResultSetOutParameter( (CallableStatement)st, col ); col = dialect.registerResultSetOutParameter( (CallableStatement) st, col );
} }
col += bindParameterValues( st, queryParameters, col, session ); col += bindParameterValues( st, queryParameters, col, session );
@ -1923,15 +1991,16 @@ else if ( dialect.isLockTimeoutParameterized() ) {
} }
} }
if ( LOG.isTraceEnabled() ) if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Bound [{0}] parameters total", col ); LOG.tracev( "Bound [{0}] parameters total", col );
}
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw sqle; throw sqle;
} }
catch ( HibernateException he ) { catch (HibernateException he) {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw he; throw he;
@ -1948,7 +2017,9 @@ else if ( dialect.isLockTimeoutParameterized() ) {
* @param queryParameters The encapsulation of the parameter values to be bound. * @param queryParameters The encapsulation of the parameter values to be bound.
* @param startIndex The position from which to start binding parameter values. * @param startIndex The position from which to start binding parameter values.
* @param session The originating session. * @param session The originating session.
*
* @return The number of JDBC bind positions actually bound during this method execution. * @return The number of JDBC bind positions actually bound during this method execution.
*
* @throws SQLException Indicates problems performing the binding. * @throws SQLException Indicates problems performing the binding.
*/ */
protected int bindParameterValues( protected int bindParameterValues(
@ -1973,7 +2044,9 @@ protected int bindParameterValues(
* @param queryParameters The encapsulation of the parameter values to be bound. * @param queryParameters The encapsulation of the parameter values to be bound.
* @param startIndex The position from which to start binding parameter values. * @param startIndex The position from which to start binding parameter values.
* @param session The originating session. * @param session The originating session.
*
* @return The number of JDBC bind positions actually bound during this method execution. * @return The number of JDBC bind positions actually bound during this method execution.
*
* @throws SQLException Indicates problems performing the binding. * @throws SQLException Indicates problems performing the binding.
* @throws org.hibernate.HibernateException Indicates problems delegating binding to the types. * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/ */
@ -2006,7 +2079,9 @@ protected int bindPositionalParameters(
* @param namedParams A map of parameter names to values * @param namedParams A map of parameter names to values
* @param startIndex The position from which to start binding parameter values. * @param startIndex The position from which to start binding parameter values.
* @param session The originating session. * @param session The originating session.
*
* @return The number of JDBC bind positions actually bound during this method execution. * @return The number of JDBC bind positions actually bound during this method execution.
*
* @throws SQLException Indicates problems performing the binding. * @throws SQLException Indicates problems performing the binding.
* @throws org.hibernate.HibernateException Indicates problems delegating binding to the types. * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/ */
@ -2042,7 +2117,7 @@ protected int bindNamedParameters(
} }
public int[] getNamedParameterLocs(String name) { public int[] getNamedParameterLocs(String name) {
throw new AssertionFailure("no named parameters"); throw new AssertionFailure( "no named parameters" );
} }
/** /**
@ -2056,7 +2131,7 @@ protected final ResultSet getResultSet(
final SessionImplementor session) throws SQLException, HibernateException { final SessionImplementor session) throws SQLException, HibernateException {
try { try {
ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st ); ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st );
rs = wrapResultSetIfEnabled( rs , session ); rs = wrapResultSetIfEnabled( rs, session );
if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) { if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
advance( rs, selection ); advance( rs, selection );
@ -2067,7 +2142,7 @@ protected final ResultSet getResultSet(
} }
return rs; return rs;
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().getResourceRegistry().release( st );
session.getJdbcCoordinator().afterStatementExecution(); session.getJdbcCoordinator().afterStatementExecution();
throw sqle; throw sqle;
@ -2075,7 +2150,7 @@ protected final ResultSet getResultSet(
} }
protected void autoDiscoverTypes(ResultSet rs) { protected void autoDiscoverTypes(ResultSet rs) {
throw new AssertionFailure("Auto discover types not supported in this loader"); throw new AssertionFailure( "Auto discover types not supported in this loader" );
} }
@ -2088,7 +2163,7 @@ private ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplem
.getService( JdbcServices.class ) .getService( JdbcServices.class )
.getResultSetWrapper().wrap( rs, retreiveColumnNameToIndexCache( rs ) ); .getResultSetWrapper().wrap( rs, retreiveColumnNameToIndexCache( rs ) );
} }
catch(SQLException e) { catch (SQLException e) {
LOG.unableToWrapResultSet( e ); LOG.unableToWrapResultSet( e );
return rs; return rs;
} }
@ -2131,21 +2206,26 @@ protected final List loadEntity(
List result; List result;
try { try {
QueryParameters qp = new QueryParameters(); QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes( new Type[] { identifierType } ); qp.setPositionalParameterTypes( new Type[] {identifierType} );
qp.setPositionalParameterValues( new Object[] { id } ); qp.setPositionalParameterValues( new Object[] {id} );
qp.setOptionalObject( optionalObject ); qp.setOptionalObject( optionalObject );
qp.setOptionalEntityName( optionalEntityName ); qp.setOptionalEntityName( optionalEntityName );
qp.setOptionalId( optionalIdentifier ); qp.setOptionalId( optionalIdentifier );
qp.setLockOptions( lockOptions ); qp.setLockOptions( lockOptions );
result = doQueryAndInitializeNonLazyCollections( session, qp, false ); result = doQueryAndInitializeNonLazyCollections( session, qp, false );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
final Loadable[] persisters = getEntityPersisters(); final Loadable[] persisters = getEntityPersisters();
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not load an entity: " + "could not load an entity: " +
MessageHelper.infoString( persisters[persisters.length-1], id, identifierType, getFactory() ), MessageHelper.infoString(
getSQLString() persisters[persisters.length - 1],
id,
identifierType,
getFactory()
),
getSQLString()
); );
} }
@ -2157,15 +2237,16 @@ protected final List loadEntity(
/** /**
* Called by subclasses that load entities * Called by subclasses that load entities
*
* @param persister only needed for logging * @param persister only needed for logging
*/ */
protected final List loadEntity( protected final List loadEntity(
final SessionImplementor session, final SessionImplementor session,
final Object key, final Object key,
final Object index, final Object index,
final Type keyType, final Type keyType,
final Type indexType, final Type indexType,
final EntityPersister persister) throws HibernateException { final EntityPersister persister) throws HibernateException {
LOG.debug( "Loading collection element by index" ); LOG.debug( "Loading collection element by index" );
List result; List result;
@ -2173,17 +2254,17 @@ protected final List loadEntity(
result = doQueryAndInitializeNonLazyCollections( result = doQueryAndInitializeNonLazyCollections(
session, session,
new QueryParameters( new QueryParameters(
new Type[] { keyType, indexType }, new Type[] {keyType, indexType},
new Object[] { key, index } new Object[] {key, index}
), ),
false false
); );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not load collection element by index", "could not load collection element by index",
getSQLString() getSQLString()
); );
} }
@ -2205,8 +2286,9 @@ public final List loadEntityBatch(
final Serializable optionalId, final Serializable optionalId,
final EntityPersister persister, final EntityPersister persister,
LockOptions lockOptions) throws HibernateException { LockOptions lockOptions) throws HibernateException {
if ( LOG.isDebugEnabled() ) if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister, ids, getFactory() ) ); LOG.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister, ids, getFactory() ) );
}
Type[] types = new Type[ids.length]; Type[] types = new Type[ids.length];
Arrays.fill( types, idType ); Arrays.fill( types, idType );
@ -2221,12 +2303,12 @@ public final List loadEntityBatch(
qp.setLockOptions( lockOptions ); qp.setLockOptions( lockOptions );
result = doQueryAndInitializeNonLazyCollections( session, qp, false ); result = doQueryAndInitializeNonLazyCollections( session, qp, false );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not load an entity batch: " + "could not load an entity batch: " +
MessageHelper.infoString( getEntityPersisters()[0], ids, getFactory() ), MessageHelper.infoString( getEntityPersisters()[0], ids, getFactory() ),
getSQLString() getSQLString()
); );
} }
@ -2240,9 +2322,9 @@ public final List loadEntityBatch(
* Called by subclasses that initialize collections * Called by subclasses that initialize collections
*/ */
public final void loadCollection( public final void loadCollection(
final SessionImplementor session, final SessionImplementor session,
final Serializable id, final Serializable id,
final Type type) throws HibernateException { final Type type) throws HibernateException {
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( LOG.debugf(
"Loading collection: %s", "Loading collection: %s",
@ -2250,19 +2332,19 @@ public final void loadCollection(
); );
} }
Serializable[] ids = new Serializable[]{id}; Serializable[] ids = new Serializable[] {id};
try { try {
doQueryAndInitializeNonLazyCollections( doQueryAndInitializeNonLazyCollections(
session, session,
new QueryParameters( new Type[]{type}, ids, ids ), new QueryParameters( new Type[] {type}, ids, ids ),
true true
); );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not initialize a collection: " + "could not initialize a collection: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], id, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], id, getFactory() ),
getSQLString() getSQLString()
); );
} }
@ -2293,11 +2375,11 @@ public final void loadCollectionBatch(
true true
); );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not initialize a collection batch: " + "could not initialize a collection batch: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
getSQLString() getSQLString()
); );
} }
@ -2318,16 +2400,17 @@ protected final void loadCollectionSubselect(
final Type[] idTypes = new Type[ids.length]; final Type[] idTypes = new Type[ids.length];
Arrays.fill( idTypes, type ); Arrays.fill( idTypes, type );
try { try {
doQueryAndInitializeNonLazyCollections( session, doQueryAndInitializeNonLazyCollections(
session,
new QueryParameters( parameterTypes, parameterValues, namedParameters, ids ), new QueryParameters( parameterTypes, parameterValues, namedParameters, ids ),
true true
); );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not load collection by subselect: " + "could not load collection by subselect: " +
MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ), MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
getSQLString() getSQLString()
); );
} }
@ -2343,7 +2426,7 @@ protected List list(
final Set<Serializable> querySpaces, final Set<Serializable> querySpaces,
final Type[] resultTypes) throws HibernateException { final Type[] resultTypes) throws HibernateException {
final boolean cacheable = factory.getSessionFactoryOptions().isQueryCacheEnabled() && final boolean cacheable = factory.getSessionFactoryOptions().isQueryCacheEnabled() &&
queryParameters.isCacheable(); queryParameters.isCacheable();
if ( cacheable ) { if ( cacheable ) {
return listUsingQueryCache( session, queryParameters, querySpaces, resultTypes ); return listUsingQueryCache( session, queryParameters, querySpaces, resultTypes );
@ -2525,12 +2608,13 @@ protected void putResultInQueryCache(
protected List doList(final SessionImplementor session, final QueryParameters queryParameters) protected List doList(final SessionImplementor session, final QueryParameters queryParameters)
throws HibernateException { throws HibernateException {
return doList( session, queryParameters, null); return doList( session, queryParameters, null );
} }
private List doList(final SessionImplementor session, private List doList(
final QueryParameters queryParameters, final SessionImplementor session,
final ResultTransformer forcedResultTransformer) final QueryParameters queryParameters,
final ResultTransformer forcedResultTransformer)
throws HibernateException { throws HibernateException {
final boolean stats = getFactory().getStatistics().isStatisticsEnabled(); final boolean stats = getFactory().getStatistics().isStatisticsEnabled();
@ -2543,7 +2627,7 @@ private List doList(final SessionImplementor session,
try { try {
result = doQueryAndInitializeNonLazyCollections( session, queryParameters, true, forcedResultTransformer ); result = doQueryAndInitializeNonLazyCollections( session, queryParameters, true, forcedResultTransformer );
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not execute query", "could not execute query",
@ -2594,7 +2678,9 @@ protected boolean needsFetchingScroll() {
* @param holderInstantiator If the return values are expected to be wrapped * @param holderInstantiator If the return values are expected to be wrapped
* in a holder, this is the thing that knows how to wrap them. * in a holder, this is the thing that knows how to wrap them.
* @param session The session from which the scroll request originated. * @param session The session from which the scroll request originated.
*
* @return The ScrollableResults instance. * @return The ScrollableResults instance.
*
* @throws HibernateException Indicates an error executing the query, or constructing * @throws HibernateException Indicates an error executing the query, or constructing
* the ScrollableResults. * the ScrollableResults.
*/ */
@ -2615,7 +2701,12 @@ protected ScrollableResults scroll(
try { try {
// Don't use Collections#emptyList() here -- follow on locking potentially adds AfterLoadActions, // Don't use Collections#emptyList() here -- follow on locking potentially adds AfterLoadActions,
// so the list cannot be immutable. // so the list cannot be immutable.
final SqlStatementWrapper wrapper = executeQueryStatement( queryParameters, true, new ArrayList<AfterLoadAction>(), session ); final SqlStatementWrapper wrapper = executeQueryStatement(
queryParameters,
true,
new ArrayList<AfterLoadAction>(),
session
);
final ResultSet rs = wrapper.getResultSet(); final ResultSet rs = wrapper.getResultSet();
final PreparedStatement st = (PreparedStatement) wrapper.getStatement(); final PreparedStatement st = (PreparedStatement) wrapper.getStatement();
@ -2653,7 +2744,7 @@ protected ScrollableResults scroll(
} }
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw factory.getSQLExceptionHelper().convert( throw factory.getSQLExceptionHelper().convert(
sqle, sqle,
"could not execute query using scroll", "could not execute query using scroll",
@ -2667,7 +2758,8 @@ protected ScrollableResults scroll(
* Calculate and cache select-clause suffixes. Must be * Calculate and cache select-clause suffixes. Must be
* called by subclasses after instantiation. * called by subclasses after instantiation.
*/ */
protected void postInstantiate() {} protected void postInstantiate() {
}
/** /**
* Get the result set descriptor * Get the result set descriptor

View File

@ -25,7 +25,6 @@
import org.hibernate.loader.plan.spi.CollectionQuerySpace; import org.hibernate.loader.plan.spi.CollectionQuerySpace;
import org.hibernate.loader.plan.spi.Join; import org.hibernate.loader.plan.spi.Join;
import org.hibernate.persister.collection.CollectionPropertyNames;
/** /**
* Describes a collection query space that allows adding joins with other * Describes a collection query space that allows adding joins with other
@ -38,18 +37,18 @@
public interface ExpandingCollectionQuerySpace extends CollectionQuerySpace, ExpandingQuerySpace { public interface ExpandingCollectionQuerySpace extends CollectionQuerySpace, ExpandingQuerySpace {
/** /**
* Adds a join with another query space for either a collection element or index. If {@code join} * Adds a join with another query space for either a collection element or index.
* is an instance of {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata}, then the only valid *
* If {@code join} is an instance of {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata}, then the only valid
* values returned by {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata#getJoinedPropertyName} * values returned by {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata#getJoinedPropertyName}
* are {@link CollectionPropertyNames#COLLECTION_ELEMENTS} and {@link CollectionPropertyNames#COLLECTION_INDICES}, * are {@code "elements"} and {@code "indices"} for the collection element or index, respectively.
* for the collection element or index, respectively.
* *
* @param join The element or index join to add. * @param join The element or index join to add.
* *
* @throws java.lang.IllegalArgumentException if {@code join} is an instance of * @throws java.lang.IllegalArgumentException if {@code join} is an instance of
* {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata} and {@code join.getJoinedPropertyName() * {@link org.hibernate.loader.plan.spi.JoinDefinedByMetadata} and {@code join.getJoinedPropertyName()
* is neither {@link CollectionPropertyNames#COLLECTION_ELEMENTS} nor {@link CollectionPropertyNames#COLLECTION_INDICES}}. * is neither {@code "elements"} and {@code "indices"}.
* @throws java.lang.IllegalStateException if there is already an existing join with the same joined property name. * @throws java.lang.IllegalStateException if there is already an existing join with the same joined property name.
*/ */
public void addJoin(Join join); void addJoin(Join join);
} }

View File

@ -47,14 +47,10 @@
import org.hibernate.persister.entity.Loadable; import org.hibernate.persister.entity.Loadable;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.jboss.logging.Logger;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class ResultSetProcessingContextImpl implements ResultSetProcessingContext { public class ResultSetProcessingContextImpl implements ResultSetProcessingContext {
private static final Logger LOG = Logger.getLogger( ResultSetProcessingContextImpl.class );
private final ResultSet resultSet; private final ResultSet resultSet;
private final SessionImplementor session; private final SessionImplementor session;
private final LoadPlan loadPlan; private final LoadPlan loadPlan;
@ -74,18 +70,9 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex
/** /**
* Builds a ResultSetProcessingContextImpl * Builds a ResultSetProcessingContextImpl
* *
* @param resultSet
* @param session
* @param loadPlan
* @param readOnly
* @param shouldUseOptionalEntityInformation There are times when the "optional entity information" on * @param shouldUseOptionalEntityInformation There are times when the "optional entity information" on
* QueryParameters should be used and times when they should not. Collection initializers, batch loaders, etc * QueryParameters should be used and times when they should not. Collection initializers, batch loaders, etc
* are times when it should NOT be used. * are times when it should NOT be used.
* @param forceFetchLazyAttributes
* @param shouldReturnProxies
* @param queryParameters
* @param namedParameterContext
* @param hadSubselectFetches
*/ */
public ResultSetProcessingContextImpl( public ResultSetProcessingContextImpl(
final ResultSet resultSet, final ResultSet resultSet,
@ -305,8 +292,9 @@ void finishUpRow() {
subselectLoadableEntityKeyMap = new HashMap<EntityPersister, Set<EntityKey>>(); subselectLoadableEntityKeyMap = new HashMap<EntityPersister, Set<EntityKey>>();
} }
for ( HydratedEntityRegistration registration : currentRowHydratedEntityRegistrationList ) { for ( HydratedEntityRegistration registration : currentRowHydratedEntityRegistrationList ) {
Set<EntityKey> entityKeys = subselectLoadableEntityKeyMap.get( registration.getEntityReference() Set<EntityKey> entityKeys = subselectLoadableEntityKeyMap.get(
.getEntityPersister() ); registration.getEntityReference().getEntityPersister()
);
if ( entityKeys == null ) { if ( entityKeys == null ) {
entityKeys = new HashSet<EntityKey>(); entityKeys = new HashSet<EntityKey>();
subselectLoadableEntityKeyMap.put( registration.getEntityReference().getEntityPersister(), entityKeys ); subselectLoadableEntityKeyMap.put( registration.getEntityReference().getEntityPersister(), entityKeys );

View File

@ -42,31 +42,31 @@ public Array(MetadataImplementor metadata, PersistentClass owner) {
} }
public Class getElementClass() throws MappingException { public Class getElementClass() throws MappingException {
if (elementClassName==null) { if ( elementClassName == null ) {
org.hibernate.type.Type elementType = getElement().getType(); org.hibernate.type.Type elementType = getElement().getType();
return isPrimitiveArray() ? return isPrimitiveArray()
( (PrimitiveType) elementType ).getPrimitiveClass() : ? ( (PrimitiveType) elementType ).getPrimitiveClass()
elementType.getReturnedClass(); : elementType.getReturnedClass();
} }
else { else {
try { try {
return ReflectHelper.classForName(elementClassName); return ReflectHelper.classForName( elementClassName );
} }
catch (ClassNotFoundException cnfe) { catch (ClassNotFoundException cnfe) {
throw new MappingException(cnfe); throw new MappingException( cnfe );
} }
} }
} }
@Override @Override
public CollectionType getDefaultCollectionType() throws MappingException { public CollectionType getDefaultCollectionType() throws MappingException {
return getMetadata().getTypeResolver() return getMetadata().getTypeResolver()
.getTypeFactory() .getTypeFactory()
.array( getRole(), getReferencedPropertyName(), getElementClass() ); .array( getRole(), getReferencedPropertyName(), getElementClass() );
} }
@Override @Override
public boolean isArray() { public boolean isArray() {
return true; return true;
} }
@ -76,6 +76,7 @@ public boolean isArray() {
public String getElementClassName() { public String getElementClassName() {
return elementClassName; return elementClassName;
} }
/** /**
* @param elementClassName The elementClassName to set. * @param elementClassName The elementClassName to set.
*/ */
@ -84,7 +85,7 @@ public void setElementClassName(String elementClassName) {
} }
@Override @Override
public Object accept(ValueVisitor visitor) { public Object accept(ValueVisitor visitor) {
return visitor.accept(this); return visitor.accept( this );
} }
} }

View File

@ -43,7 +43,7 @@
/** /**
* Mapping for a collection. Subclasses specialize to particular collection styles. * Mapping for a collection. Subclasses specialize to particular collection styles.
* *
* @author Gavin King * @author Gavin King
*/ */
public abstract class Collection implements Fetchable, Value, Filterable { public abstract class Collection implements Fetchable, Value, Filterable {
@ -145,10 +145,10 @@ public Comparator getComparator() {
try { try {
setComparator( (Comparator) ReflectHelper.classForName( comparatorClassName ).newInstance() ); setComparator( (Comparator) ReflectHelper.classForName( comparatorClassName ).newInstance() );
} }
catch ( Exception e ) { catch (Exception e) {
throw new MappingException( throw new MappingException(
"Could not instantiate comparator class [" + comparatorClassName "Could not instantiate comparator class [" + comparatorClassName
+ "] for collection " + getRole() + "] for collection " + getRole()
); );
} }
} }
@ -230,12 +230,12 @@ public PersistentClass getOwner() {
} }
/** /**
* @deprecated Inject the owner into constructor.
*
* @param owner The owner * @param owner The owner
*
* @deprecated Inject the owner into constructor.
*/ */
@Deprecated @Deprecated
public void setOwner(PersistentClass owner) { public void setOwner(PersistentClass owner) {
this.owner = owner; this.owner = owner;
} }
@ -305,34 +305,37 @@ public void validate(Mapping mapping) throws MappingException {
if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) { if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) {
throw new MappingException( throw new MappingException(
"only inverse one-to-many associations may use on-delete=\"cascade\": " "only inverse one-to-many associations may use on-delete=\"cascade\": "
+ getRole() ); + getRole()
);
} }
if ( !getKey().isValid( mapping ) ) { if ( !getKey().isValid( mapping ) ) {
throw new MappingException( throw new MappingException(
"collection foreign key mapping has wrong number of columns: " "collection foreign key mapping has wrong number of columns: "
+ getRole() + getRole()
+ " type: " + " type: "
+ getKey().getType().getName() ); + getKey().getType().getName()
);
} }
if ( !getElement().isValid( mapping ) ) { if ( !getElement().isValid( mapping ) ) {
throw new MappingException( throw new MappingException(
"collection element mapping has wrong number of columns: " "collection element mapping has wrong number of columns: "
+ getRole() + getRole()
+ " type: " + " type: "
+ getElement().getType().getName() ); + getElement().getType().getName()
);
} }
checkColumnDuplication(); checkColumnDuplication();
if ( elementNodeName!=null && elementNodeName.startsWith("@") ) { if ( elementNodeName != null && elementNodeName.startsWith( "@" ) ) {
throw new MappingException("element node must not be an attribute: " + elementNodeName ); throw new MappingException( "element node must not be an attribute: " + elementNodeName );
} }
if ( elementNodeName!=null && elementNodeName.equals(".") ) { if ( elementNodeName != null && elementNodeName.equals( "." ) ) {
throw new MappingException("element node must not be the parent: " + elementNodeName ); throw new MappingException( "element node must not be the parent: " + elementNodeName );
} }
if ( nodeName!=null && nodeName.indexOf('@')>-1 ) { if ( nodeName != null && nodeName.indexOf( '@' ) > -1 ) {
throw new MappingException("collection node must not be an attribute: " + elementNodeName ); throw new MappingException( "collection node must not be an attribute: " + elementNodeName );
} }
} }
@ -343,10 +346,12 @@ private void checkColumnDuplication(java.util.Set distinctColumns, Iterator colu
if ( !s.isFormula() ) { if ( !s.isFormula() ) {
Column col = (Column) s; Column col = (Column) s;
if ( !distinctColumns.add( col.getName() ) ) { if ( !distinctColumns.add( col.getName() ) ) {
throw new MappingException( "Repeated column in mapping for collection: " throw new MappingException(
+ getRole() "Repeated column in mapping for collection: "
+ " column: " + getRole()
+ col.getName() ); + " column: "
+ col.getName()
);
} }
} }
} }
@ -356,14 +361,18 @@ private void checkColumnDuplication() throws MappingException {
HashSet cols = new HashSet(); HashSet cols = new HashSet();
checkColumnDuplication( cols, getKey().getColumnIterator() ); checkColumnDuplication( cols, getKey().getColumnIterator() );
if ( isIndexed() ) { if ( isIndexed() ) {
checkColumnDuplication( cols, ( (IndexedCollection) this ) checkColumnDuplication(
.getIndex() cols, ( (IndexedCollection) this )
.getColumnIterator() ); .getIndex()
.getColumnIterator()
);
} }
if ( isIdentified() ) { if ( isIdentified() ) {
checkColumnDuplication( cols, ( (IdentifierCollection) this ) checkColumnDuplication(
.getIdentifier() cols, ( (IdentifierCollection) this )
.getColumnIterator() ); .getIdentifier()
.getColumnIterator()
);
} }
if ( !isOneToMany() ) { if ( !isOneToMany() ) {
checkColumnDuplication( cols, getElement().getColumnIterator() ); checkColumnDuplication( cols, getElement().getColumnIterator() );
@ -454,7 +463,6 @@ public void setCacheRegionName(String cacheRegionName) {
} }
public void setCustomSQLInsert(String customSQLInsert, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) { public void setCustomSQLInsert(String customSQLInsert, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
this.customSQLInsert = customSQLInsert; this.customSQLInsert = customSQLInsert;
this.customInsertCallable = callable; this.customInsertCallable = callable;
@ -509,7 +517,10 @@ public ExecuteUpdateResultCheckStyle getCustomSQLDeleteCheckStyle() {
return deleteCheckStyle; return deleteCheckStyle;
} }
public void setCustomSQLDeleteAll(String customSQLDeleteAll, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) { public void setCustomSQLDeleteAll(
String customSQLDeleteAll,
boolean callable,
ExecuteUpdateResultCheckStyle checkStyle) {
this.customSQLDeleteAll = customSQLDeleteAll; this.customSQLDeleteAll = customSQLDeleteAll;
this.customDeleteAllCallable = callable; this.customDeleteAllCallable = callable;
this.deleteAllCheckStyle = checkStyle; this.deleteAllCheckStyle = checkStyle;
@ -527,15 +538,44 @@ public ExecuteUpdateResultCheckStyle getCustomSQLDeleteAllCheckStyle() {
return deleteAllCheckStyle; return deleteAllCheckStyle;
} }
public void addFilter(String name, String condition, boolean autoAliasInjection, java.util.Map<String,String> aliasTableMap, java.util.Map<String,String> aliasEntityMap) { public void addFilter(
filters.add(new FilterConfiguration(name, condition, autoAliasInjection, aliasTableMap, aliasEntityMap, null)); String name,
String condition,
boolean autoAliasInjection,
java.util.Map<String, String> aliasTableMap,
java.util.Map<String, String> aliasEntityMap) {
filters.add(
new FilterConfiguration(
name,
condition,
autoAliasInjection,
aliasTableMap,
aliasEntityMap,
null
)
);
} }
public java.util.List getFilters() { public java.util.List getFilters() {
return filters; return filters;
} }
public void addManyToManyFilter(String name, String condition, boolean autoAliasInjection, java.util.Map<String,String> aliasTableMap, java.util.Map<String,String> aliasEntityMap) { public void addManyToManyFilter(
manyToManyFilters.add(new FilterConfiguration(name, condition, autoAliasInjection, aliasTableMap, aliasEntityMap, null)); String name,
String condition,
boolean autoAliasInjection,
java.util.Map<String, String> aliasTableMap,
java.util.Map<String, String> aliasEntityMap) {
manyToManyFilters.add(
new FilterConfiguration(
name,
condition,
autoAliasInjection,
aliasTableMap,
aliasEntityMap,
null
)
);
} }
public java.util.List getManyToManyFilters() { public java.util.List getManyToManyFilters() {
@ -543,7 +583,7 @@ public java.util.List getManyToManyFilters() {
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getName() + '(' + getRole() + ')'; return getClass().getName() + '(' + getRole() + ')';
} }
@ -650,7 +690,7 @@ public void setEmbedded(boolean embedded) {
public boolean isSubselectLoadable() { public boolean isSubselectLoadable() {
return subselectLoadable; return subselectLoadable;
} }
public void setSubselectLoadable(boolean subqueryLoadable) { public void setSubselectLoadable(boolean subqueryLoadable) {
this.subselectLoadable = subqueryLoadable; this.subselectLoadable = subqueryLoadable;
@ -671,15 +711,15 @@ public boolean isExtraLazy() {
public void setExtraLazy(boolean extraLazy) { public void setExtraLazy(boolean extraLazy) {
this.extraLazy = extraLazy; this.extraLazy = extraLazy;
} }
public boolean hasOrder() { public boolean hasOrder() {
return orderBy!=null || manyToManyOrderBy!=null; return orderBy != null || manyToManyOrderBy != null;
} }
public void setComparatorClassName(String comparatorClassName) { public void setComparatorClassName(String comparatorClassName) {
this.comparatorClassName = comparatorClassName; this.comparatorClassName = comparatorClassName;
} }
public String getComparatorClassName() { public String getComparatorClassName() {
return comparatorClassName; return comparatorClassName;
} }

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.mapping; package org.hibernate.mapping;
import java.io.Serializable; import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
@ -35,6 +36,7 @@
/** /**
* A column of a relational database table * A column of a relational database table
*
* @author Gavin King * @author Gavin King
*/ */
public class Column implements Selectable, Serializable, Cloneable { public class Column implements Selectable, Serializable, Cloneable {
@ -43,13 +45,13 @@ public class Column implements Selectable, Serializable, Cloneable {
public static final int DEFAULT_PRECISION = 19; public static final int DEFAULT_PRECISION = 19;
public static final int DEFAULT_SCALE = 2; public static final int DEFAULT_SCALE = 2;
private int length=DEFAULT_LENGTH; private int length = DEFAULT_LENGTH;
private int precision=DEFAULT_PRECISION; private int precision = DEFAULT_PRECISION;
private int scale=DEFAULT_SCALE; private int scale = DEFAULT_SCALE;
private Value value; private Value value;
private int typeIndex; private int typeIndex;
private String name; private String name;
private boolean nullable=true; private boolean nullable = true;
private boolean unique; private boolean unique;
private String sqlType; private String sqlType;
private Integer sqlTypeCode; private Integer sqlTypeCode;
@ -65,38 +67,45 @@ public Column() {
} }
public Column(String columnName) { public Column(String columnName) {
setName(columnName); setName( columnName );
} }
public int getLength() { public int getLength() {
return length; return length;
} }
public void setLength(int length) { public void setLength(int length) {
this.length = length; this.length = length;
} }
public Value getValue() { public Value getValue() {
return value; return value;
} }
public void setValue(Value value) { public void setValue(Value value) {
this.value= value; this.value = value;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
if ( if (
StringHelper.isNotEmpty( name ) && StringHelper.isNotEmpty( name ) &&
Dialect.QUOTE.indexOf( name.charAt(0) ) > -1 //TODO: deprecated, remove eventually Dialect.QUOTE.indexOf( name.charAt( 0 ) ) > -1 //TODO: deprecated, remove eventually
) { ) {
quoted=true; quoted = true;
this.name=name.substring( 1, name.length()-1 ); this.name = name.substring( 1, name.length() - 1 );
} }
else { else {
this.name = name; this.name = name;
} }
} }
/** returns quoted name as it would be in the mapping file. */ /**
* returns quoted name as it would be in the mapping file.
*/
public String getQuotedName() { public String getQuotedName() {
return quoted ? return quoted ?
"`" + name + "`" : "`" + name + "`" :
@ -105,14 +114,14 @@ public String getQuotedName() {
public String getQuotedName(Dialect d) { public String getQuotedName(Dialect d) {
return quoted ? return quoted ?
d.openQuote() + name + d.closeQuote() : d.openQuote() + name + d.closeQuote() :
name; name;
} }
@Override @Override
public String getAlias(Dialect dialect) { public String getAlias(Dialect dialect) {
final int lastLetter = StringHelper.lastIndexOfLetter( name ); final int lastLetter = StringHelper.lastIndexOfLetter( name );
final String suffix = Integer.toString(uniqueInteger) + '_'; final String suffix = Integer.toString( uniqueInteger ) + '_';
String alias = name; String alias = name;
if ( lastLetter == -1 ) { if ( lastLetter == -1 ) {
@ -123,12 +132,15 @@ else if ( name.length() > lastLetter + 1 ) {
} }
boolean useRawName = name.length() + suffix.length() <= dialect.getMaxAliasLength() boolean useRawName = name.length() + suffix.length() <= dialect.getMaxAliasLength()
&& !quoted && !name.toLowerCase(Locale.ROOT).equals( "rowid" ); && !quoted && !name.toLowerCase( Locale.ROOT ).equals( "rowid" );
if ( !useRawName ) { if ( !useRawName ) {
if ( suffix.length() >= dialect.getMaxAliasLength() ) { if ( suffix.length() >= dialect.getMaxAliasLength() ) {
throw new MappingException( String.format( throw new MappingException(
"Unique suffix [%s] length must be less than maximum [%d]", String.format(
suffix, dialect.getMaxAliasLength() ) ); "Unique suffix [%s] length must be less than maximum [%d]",
suffix, dialect.getMaxAliasLength()
)
);
} }
if ( alias.length() + suffix.length() > dialect.getMaxAliasLength() ) { if ( alias.length() + suffix.length() > dialect.getMaxAliasLength() ) {
alias = alias.substring( 0, dialect.getMaxAliasLength() - suffix.length() ); alias = alias.substring( 0, dialect.getMaxAliasLength() - suffix.length() );
@ -136,13 +148,13 @@ else if ( name.length() > lastLetter + 1 ) {
} }
return alias + suffix; return alias + suffix;
} }
/** /**
* Generate a column alias that is unique across multiple tables * Generate a column alias that is unique across multiple tables
*/ */
@Override @Override
public String getAlias(Dialect dialect, Table table) { public String getAlias(Dialect dialect, Table table) {
return getAlias(dialect) + table.getUniqueInteger() + '_'; return getAlias( dialect ) + table.getUniqueInteger() + '_';
} }
public boolean isNullable() { public boolean isNullable() {
@ -150,12 +162,13 @@ public boolean isNullable() {
} }
public void setNullable(boolean nullable) { public void setNullable(boolean nullable) {
this.nullable=nullable; this.nullable = nullable;
} }
public int getTypeIndex() { public int getTypeIndex() {
return typeIndex; return typeIndex;
} }
public void setTypeIndex(int typeIndex) { public void setTypeIndex(int typeIndex) {
this.typeIndex = typeIndex; this.typeIndex = typeIndex;
} }
@ -168,8 +181,8 @@ public boolean isUnique() {
public int hashCode() { public int hashCode() {
//used also for generation of FK names! //used also for generation of FK names!
return isQuoted() ? return isQuoted() ?
name.hashCode() : name.hashCode() :
name.toLowerCase(Locale.ROOT).hashCode(); name.toLowerCase( Locale.ROOT ).hashCode();
} }
@Override @Override
@ -179,63 +192,63 @@ public boolean equals(Object object) {
@SuppressWarnings("SimplifiableIfStatement") @SuppressWarnings("SimplifiableIfStatement")
public boolean equals(Column column) { public boolean equals(Column column) {
if (null == column) { if ( null == column ) {
return false; return false;
} }
if (this == column) { if ( this == column ) {
return true; return true;
} }
return isQuoted() ? return isQuoted() ?
name.equals(column.name) : name.equals( column.name ) :
name.equalsIgnoreCase(column.name); name.equalsIgnoreCase( column.name );
} }
public int getSqlTypeCode(Mapping mapping) throws MappingException { public int getSqlTypeCode(Mapping mapping) throws MappingException {
org.hibernate.type.Type type = getValue().getType(); org.hibernate.type.Type type = getValue().getType();
try { try {
int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()]; int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()];
if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) { if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() ); throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
} }
return sqlTypeCode; return sqlTypeCode;
} }
catch ( Exception e ) { catch (Exception e) {
throw new MappingException( throw new MappingException(
"Could not determine type for column " + "Could not determine type for column " +
name + name +
" of type " + " of type " +
type.getClass().getName() + type.getClass().getName() +
": " + ": " +
e.getClass().getName(), e.getClass().getName(),
e e
); );
} }
} }
/** /**
* Returns the underlying columns sqltypecode. * Returns the underlying columns sqltypecode.
* If null, it is because the sqltype code is unknown. * If null, it is because the sqltype code is unknown.
* * <p/>
* Use #getSqlTypeCode(Mapping) to retreive the sqltypecode used * Use #getSqlTypeCode(Mapping) to retreive the sqltypecode used
* for the columns associated Value/Type. * for the columns associated Value/Type.
* *
* @return sqlTypeCode if it is set, otherwise null. * @return sqlTypeCode if it is set, otherwise null.
*/ */
public Integer getSqlTypeCode() { public Integer getSqlTypeCode() {
return sqlTypeCode; return sqlTypeCode;
} }
public void setSqlTypeCode(Integer typeCode) { public void setSqlTypeCode(Integer typeCode) {
sqlTypeCode=typeCode; sqlTypeCode = typeCode;
} }
public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException { public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
if ( sqlType == null ) { if ( sqlType == null ) {
sqlType = dialect.getTypeName( getSqlTypeCode( mapping ), getLength(), getPrecision(), getScale() ); sqlType = dialect.getTypeName( getSqlTypeCode( mapping ), getLength(), getPrecision(), getScale() );
} }
return sqlType; return sqlType;
} }
public String getSqlType() { public String getSqlType() {
return sqlType; return sqlType;
@ -267,7 +280,7 @@ public void setCheckConstraint(String checkConstraint) {
} }
public boolean hasCheckConstraint() { public boolean hasCheckConstraint() {
return checkConstraint!=null; return checkConstraint != null;
} }
@Override @Override
@ -284,7 +297,7 @@ public boolean hasCustomRead() {
public String getReadExpr(Dialect dialect) { public String getReadExpr(Dialect dialect) {
return hasCustomRead() ? customRead : getQuotedName( dialect ); return hasCustomRead() ? customRead : getQuotedName( dialect );
} }
public String getWriteExpr() { public String getWriteExpr() {
return ( customWrite != null && customWrite.length() > 0 ) ? customWrite : "?"; return ( customWrite != null && customWrite.length() > 0 ) ? customWrite : "?";
} }
@ -296,17 +309,18 @@ public boolean isFormula() {
@Override @Override
public String getText(Dialect d) { public String getText(Dialect d) {
return getQuotedName(d); return getQuotedName( d );
} }
@Override @Override
public String getText() { public String getText() {
return getName(); return getName();
} }
public int getPrecision() { public int getPrecision() {
return precision; return precision;
} }
public void setPrecision(int scale) { public void setPrecision(int scale) {
this.precision = scale; this.precision = scale;
} }
@ -314,6 +328,7 @@ public void setPrecision(int scale) {
public int getScale() { public int getScale() {
return scale; return scale;
} }
public void setScale(int scale) { public void setScale(int scale) {
this.scale = scale; this.scale = scale;
} }
@ -351,7 +366,7 @@ public void setCustomRead(String customRead) {
} }
public String getCanonicalName() { public String getCanonicalName() {
return quoted ? name : name.toLowerCase(Locale.ROOT); return quoted ? name : name.toLowerCase( Locale.ROOT );
} }
/** /**

View File

@ -36,9 +36,9 @@
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class DenormalizedTable extends Table { public class DenormalizedTable extends Table {
private final Table includedTable; private final Table includedTable;
public DenormalizedTable(Table includedTable) { public DenormalizedTable(Table includedTable) {
this.includedTable = includedTable; this.includedTable = includedTable;
includedTable.setHasDenormalizedTables(); includedTable.setHasDenormalizedTables();
@ -50,7 +50,12 @@ public DenormalizedTable(Schema schema, Identifier physicalTableName, boolean is
includedTable.setHasDenormalizedTables(); includedTable.setHasDenormalizedTables();
} }
public DenormalizedTable(Schema schema, Identifier physicalTableName, String subselectFragment, boolean isAbstract, Table includedTable) { public DenormalizedTable(
Schema schema,
Identifier physicalTableName,
String subselectFragment,
boolean isAbstract,
Table includedTable) {
super( schema, physicalTableName, subselectFragment, isAbstract ); super( schema, physicalTableName, subselectFragment, isAbstract );
this.includedTable = includedTable; this.includedTable = includedTable;
includedTable.setHasDenormalizedTables(); includedTable.setHasDenormalizedTables();
@ -63,28 +68,28 @@ public DenormalizedTable(Schema schema, String subselect, boolean isAbstract, Ta
} }
@Override @Override
public void createForeignKeys() { public void createForeignKeys() {
includedTable.createForeignKeys(); includedTable.createForeignKeys();
Iterator iter = includedTable.getForeignKeyIterator(); Iterator iter = includedTable.getForeignKeyIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
ForeignKey fk = (ForeignKey) iter.next(); ForeignKey fk = (ForeignKey) iter.next();
createForeignKey( createForeignKey(
Constraint.generateName( Constraint.generateName(
fk.generatedConstraintNamePrefix(), fk.generatedConstraintNamePrefix(),
this, this,
fk.getColumns() fk.getColumns()
), ),
fk.getColumns(), fk.getColumns(),
fk.getReferencedEntityName(), fk.getReferencedEntityName(),
fk.getReferencedColumns() fk.getReferencedColumns()
); );
} }
} }
@Override @Override
public Column getColumn(Column column) { public Column getColumn(Column column) {
Column superColumn = super.getColumn( column ); Column superColumn = super.getColumn( column );
if (superColumn != null) { if ( superColumn != null ) {
return superColumn; return superColumn;
} }
else { else {
@ -103,25 +108,25 @@ public Column getColumn(Identifier name) {
} }
@Override @Override
public Iterator getColumnIterator() { public Iterator getColumnIterator() {
return new JoinedIterator( return new JoinedIterator(
includedTable.getColumnIterator(), includedTable.getColumnIterator(),
super.getColumnIterator() super.getColumnIterator()
); );
} }
@Override @Override
public boolean containsColumn(Column column) { public boolean containsColumn(Column column) {
return super.containsColumn(column) || includedTable.containsColumn(column); return super.containsColumn( column ) || includedTable.containsColumn( column );
} }
@Override @Override
public PrimaryKey getPrimaryKey() { public PrimaryKey getPrimaryKey() {
return includedTable.getPrimaryKey(); return includedTable.getPrimaryKey();
} }
@Override @Override
public Iterator getUniqueKeyIterator() { public Iterator getUniqueKeyIterator() {
Iterator iter = includedTable.getUniqueKeyIterator(); Iterator iter = includedTable.getUniqueKeyIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
UniqueKey uk = (UniqueKey) iter.next(); UniqueKey uk = (UniqueKey) iter.next();
@ -131,21 +136,21 @@ public Iterator getUniqueKeyIterator() {
} }
@Override @Override
public Iterator getIndexIterator() { public Iterator getIndexIterator() {
List indexes = new ArrayList(); List indexes = new ArrayList();
Iterator iter = includedTable.getIndexIterator(); Iterator iter = includedTable.getIndexIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Index parentIndex = (Index) iter.next(); Index parentIndex = (Index) iter.next();
Index index = new Index(); Index index = new Index();
index.setName( getName() + parentIndex.getName() ); index.setName( getName() + parentIndex.getName() );
index.setTable(this); index.setTable( this );
index.addColumns( parentIndex.getColumnIterator() ); index.addColumns( parentIndex.getColumnIterator() );
indexes.add( index ); indexes.add( index );
} }
return new JoinedIterator( return new JoinedIterator(
indexes.iterator(), indexes.iterator(),
super.getIndexIterator() super.getIndexIterator()
); );
} }
public Table getIncludedTable() { public Table getIncludedTable() {

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -32,6 +33,7 @@
/** /**
* A foreign key constraint * A foreign key constraint
*
* @author Gavin King * @author Gavin King
*/ */
public class ForeignKey extends Constraint { public class ForeignKey extends Constraint {
@ -68,32 +70,36 @@ public void setName(String name) {
} }
} }
public String sqlConstraintString(Dialect dialect, String constraintName, String defaultCatalog, String defaultSchema) { public String sqlConstraintString(
String[] columnNames = new String[ getColumnSpan() ]; Dialect dialect,
String[] referencedColumnNames = new String[ getColumnSpan() ]; String constraintName,
String defaultCatalog,
String defaultSchema) {
String[] columnNames = new String[getColumnSpan()];
String[] referencedColumnNames = new String[getColumnSpan()];
final Iterator<Column> referencedColumnItr; final Iterator<Column> referencedColumnItr;
if ( isReferenceToPrimaryKey() ) { if ( isReferenceToPrimaryKey() ) {
referencedColumnItr = referencedTable.getPrimaryKey().getColumnIterator(); referencedColumnItr = referencedTable.getPrimaryKey().getColumnIterator();
} }
else { else {
referencedColumnItr = referencedColumns.iterator(); referencedColumnItr = referencedColumns.iterator();
} }
Iterator columnItr = getColumnIterator(); Iterator columnItr = getColumnIterator();
int i=0; int i = 0;
while ( columnItr.hasNext() ) { while ( columnItr.hasNext() ) {
columnNames[i] = ( (Column) columnItr.next() ).getQuotedName(dialect); columnNames[i] = ( (Column) columnItr.next() ).getQuotedName( dialect );
referencedColumnNames[i] = referencedColumnItr.next().getQuotedName(dialect); referencedColumnNames[i] = referencedColumnItr.next().getQuotedName( dialect );
i++; i++;
} }
final String result = dialect.getAddForeignKeyConstraintString( final String result = dialect.getAddForeignKeyConstraintString(
constraintName, constraintName,
columnNames, columnNames,
referencedTable.getQualifiedName(dialect, defaultCatalog, defaultSchema), referencedTable.getQualifiedName( dialect, defaultCatalog, defaultSchema ),
referencedColumnNames, referencedColumnNames,
isReferenceToPrimaryKey() isReferenceToPrimaryKey()
); );
return cascadeDeleteEnabled && dialect.supportsCascadeDelete() return cascadeDeleteEnabled && dialect.supportsCascadeDelete()
? result + " on delete cascade" ? result + " on delete cascade"
@ -105,32 +111,32 @@ public Table getReferencedTable() {
} }
private void appendColumns(StringBuilder buf, Iterator columns) { private void appendColumns(StringBuilder buf, Iterator columns) {
while( columns.hasNext() ) { while ( columns.hasNext() ) {
Column column = (Column) columns.next(); Column column = (Column) columns.next();
buf.append( column.getName() ); buf.append( column.getName() );
if ( columns.hasNext() ) { if ( columns.hasNext() ) {
buf.append(","); buf.append( "," );
} }
} }
} }
public void setReferencedTable(Table referencedTable) throws MappingException { public void setReferencedTable(Table referencedTable) throws MappingException {
//if( isReferenceToPrimaryKey() ) alignColumns(referencedTable); // TODO: possibly remove to allow more piecemal building of a foreignkey. //if( isReferenceToPrimaryKey() ) alignColumns(referencedTable); // TODO: possibly remove to allow more piecemal building of a foreignkey.
this.referencedTable = referencedTable; this.referencedTable = referencedTable;
} }
/** /**
* Validates that columnspan of the foreignkey and the primarykey is the same. * Validates that columnspan of the foreignkey and the primarykey is the same.
* * <p/>
* Furthermore it aligns the length of the underlying tables columns. * Furthermore it aligns the length of the underlying tables columns.
*/ */
public void alignColumns() { public void alignColumns() {
if ( isReferenceToPrimaryKey() ) { if ( isReferenceToPrimaryKey() ) {
alignColumns(referencedTable); alignColumns( referencedTable );
} }
} }
private void alignColumns(Table referencedTable) { private void alignColumns(Table referencedTable) {
final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan(); final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan();
if ( referencedPkColumnSpan != getColumnSpan() ) { if ( referencedPkColumnSpan != getColumnSpan() ) {
@ -139,15 +145,15 @@ private void alignColumns(Table referencedTable) {
.append( getTable().getName() ) .append( getTable().getName() )
.append( " [" ); .append( " [" );
appendColumns( sb, getColumnIterator() ); appendColumns( sb, getColumnIterator() );
sb.append("])") sb.append( "])" )
.append( ") must have same number of columns as the referenced primary key (" ) .append( ") must have same number of columns as the referenced primary key (" )
.append( referencedTable.getName() ) .append( referencedTable.getName() )
.append( " [" ); .append( " [" );
appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() );
sb.append("])"); sb.append( "])" );
throw new MappingException( sb.toString() ); throw new MappingException( sb.toString() );
} }
Iterator fkCols = getColumnIterator(); Iterator fkCols = getColumnIterator();
Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator();
while ( pkCols.hasNext() ) { while ( pkCols.hasNext() ) {
@ -166,7 +172,7 @@ public void setReferencedEntityName(String referencedEntityName) {
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
final StringBuilder buf = new StringBuilder( "alter table " ); final StringBuilder buf = new StringBuilder( "alter table " );
buf.append( getTable().getQualifiedName(dialect, defaultCatalog, defaultSchema) ); buf.append( getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ) );
buf.append( dialect.getDropForeignKeyString() ); buf.append( dialect.getDropForeignKeyString() );
if ( dialect.supportsIfExistsBeforeConstraintName() ) { if ( dialect.supportsIfExistsBeforeConstraintName() ) {
buf.append( "if exists " ); buf.append( "if exists " );
@ -185,19 +191,23 @@ public boolean isCascadeDeleteEnabled() {
public void setCascadeDeleteEnabled(boolean cascadeDeleteEnabled) { public void setCascadeDeleteEnabled(boolean cascadeDeleteEnabled) {
this.cascadeDeleteEnabled = cascadeDeleteEnabled; this.cascadeDeleteEnabled = cascadeDeleteEnabled;
} }
public boolean isPhysicalConstraint() { public boolean isPhysicalConstraint() {
return referencedTable.isPhysicalTable() return referencedTable.isPhysicalTable()
&& getTable().isPhysicalTable() && getTable().isPhysicalTable()
&& !referencedTable.hasDenormalizedTables(); && !referencedTable.hasDenormalizedTables();
} }
/** Returns the referenced columns if the foreignkey does not refer to the primary key */ /**
* Returns the referenced columns if the foreignkey does not refer to the primary key
*/
public List getReferencedColumns() { public List getReferencedColumns() {
return referencedColumns; return referencedColumns;
} }
/** Does this foreignkey reference the primary key of the reference table */ /**
* Does this foreignkey reference the primary key of the reference table
*/
public boolean isReferenceToPrimaryKey() { public boolean isReferenceToPrimaryKey() {
return referencedColumns.isEmpty(); return referencedColumns.isEmpty();
} }
@ -205,28 +215,30 @@ public boolean isReferenceToPrimaryKey() {
public void addReferencedColumns(Iterator referencedColumnsIterator) { public void addReferencedColumns(Iterator referencedColumnsIterator) {
while ( referencedColumnsIterator.hasNext() ) { while ( referencedColumnsIterator.hasNext() ) {
Selectable col = (Selectable) referencedColumnsIterator.next(); Selectable col = (Selectable) referencedColumnsIterator.next();
if ( !col.isFormula() ) addReferencedColumn( (Column) col ); if ( !col.isFormula() ) {
addReferencedColumn( (Column) col );
}
} }
} }
private void addReferencedColumn(Column column) { private void addReferencedColumn(Column column) {
if ( !referencedColumns.contains(column) ) { if ( !referencedColumns.contains( column ) ) {
referencedColumns.add( column ); referencedColumns.add( column );
} }
} }
public String toString() { public String toString() {
if(!isReferenceToPrimaryKey() ) { if ( !isReferenceToPrimaryKey() ) {
return getClass().getName() return getClass().getName()
+ '(' + getTable().getName() + getColumns() + '(' + getTable().getName() + getColumns()
+ " ref-columns:" + '(' + getReferencedColumns() + ") as " + getName() + ")"; + " ref-columns:" + '(' + getReferencedColumns() + ") as " + getName() + ")";
} }
else { else {
return super.toString(); return super.toString();
} }
} }
public String generatedConstraintNamePrefix() { public String generatedConstraintNamePrefix() {
return "FK_"; return "FK_";
} }

View File

@ -176,11 +176,14 @@ public String sqlConstraintString(Dialect dialect) {
Iterator iter = getColumnIterator(); Iterator iter = getColumnIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) ); buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) );
if ( iter.hasNext() ) buf.append( ", " ); if ( iter.hasNext() ) {
buf.append( ", " );
}
} }
return buf.append( ')' ).toString(); return buf.append( ')' ).toString();
} }
@Override
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
return "drop index " + return "drop index " +
StringHelper.qualify( StringHelper.qualify(
@ -219,13 +222,11 @@ public void addColumn(Column column, String order) {
} }
public void addColumns(Iterator extraColumns) { public void addColumns(Iterator extraColumns) {
while ( extraColumns.hasNext() ) addColumn( (Column) extraColumns.next() ); while ( extraColumns.hasNext() ) {
addColumn( (Column) extraColumns.next() );
}
} }
/**
* @param column
* @return true if this constraint already contains a column with same name.
*/
public boolean containsColumn(Column column) { public boolean containsColumn(Column column) {
return columns.contains( column ); return columns.contains( column );
} }
@ -238,6 +239,7 @@ public void setName(String name) {
this.name = name; this.name = name;
} }
@Override
public String toString() { public String toString() {
return getClass().getName() + "(" + getName() + ")"; return getClass().getName() + "(" + getName() + ")";
} }

View File

@ -34,6 +34,7 @@
/** /**
* A mapping for a one-to-many association * A mapping for a one-to-many association
*
* @author Gavin King * @author Gavin King
*/ */
public class OneToMany implements Value { public class OneToMany implements Value {
@ -47,28 +48,28 @@ public class OneToMany implements Value {
public OneToMany(MetadataImplementor metadata, PersistentClass owner) throws MappingException { public OneToMany(MetadataImplementor metadata, PersistentClass owner) throws MappingException {
this.metadata = metadata; this.metadata = metadata;
this.referencingTable = (owner==null) ? null : owner.getTable(); this.referencingTable = ( owner == null ) ? null : owner.getTable();
} }
private EntityType getEntityType() { private EntityType getEntityType() {
return metadata.getTypeResolver().getTypeFactory().manyToOne( return metadata.getTypeResolver().getTypeFactory().manyToOne(
getReferencedEntityName(), getReferencedEntityName(),
true, true,
null, null,
false, false,
false, false,
isIgnoreNotFound(), isIgnoreNotFound(),
false false
); );
} }
public PersistentClass getAssociatedClass() { public PersistentClass getAssociatedClass() {
return associatedClass; return associatedClass;
} }
/** /**
* Associated entity on the many side * Associated entity on the many side
*/ */
public void setAssociatedClass(PersistentClass associatedClass) { public void setAssociatedClass(PersistentClass associatedClass) {
this.associatedClass = associatedClass; this.associatedClass = associatedClass;
} }
@ -89,9 +90,9 @@ public FetchMode getFetchMode() {
return FetchMode.JOIN; return FetchMode.JOIN;
} }
/** /**
* Table of the owner entity (the "one" side) * Table of the owner entity (the "one" side)
*/ */
public Table getTable() { public Table getTable() {
return referencingTable; return referencingTable;
} }
@ -115,37 +116,38 @@ public boolean isAlternateUniqueKey() {
public boolean hasFormula() { public boolean hasFormula() {
return false; return false;
} }
public boolean isValid(Mapping mapping) throws MappingException { public boolean isValid(Mapping mapping) throws MappingException {
if (referencedEntityName==null) { if ( referencedEntityName == null ) {
throw new MappingException("one to many association must specify the referenced entity"); throw new MappingException( "one to many association must specify the referenced entity" );
} }
return true; return true;
} }
public String getReferencedEntityName() { public String getReferencedEntityName() {
return referencedEntityName; return referencedEntityName;
} }
/** /**
* Associated entity on the "many" side * Associated entity on the "many" side
*/ */
public void setReferencedEntityName(String referencedEntityName) { public void setReferencedEntityName(String referencedEntityName) {
this.referencedEntityName = referencedEntityName==null ? null : referencedEntityName.intern(); this.referencedEntityName = referencedEntityName == null ? null : referencedEntityName.intern();
} }
public void setTypeUsingReflection(String className, String propertyName) {} public void setTypeUsingReflection(String className, String propertyName) {
public Object accept(ValueVisitor visitor) {
return visitor.accept(this);
} }
public Object accept(ValueVisitor visitor) {
return visitor.accept( this );
}
public boolean[] getColumnInsertability() { public boolean[] getColumnInsertability() {
//TODO: we could just return all false... //TODO: we could just return all false...
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public boolean[] getColumnUpdateability() { public boolean[] getColumnUpdateability() {
//TODO: we could just return all false... //TODO: we could just return all false...
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@ -176,5 +178,5 @@ public boolean isIgnoreNotFound() {
public void setIgnoreNotFound(boolean ignoreNotFound) { public void setIgnoreNotFound(boolean ignoreNotFound) {
this.ignoreNotFound = ignoreNotFound; this.ignoreNotFound = ignoreNotFound;
} }
} }

View File

@ -33,7 +33,6 @@
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
@ -52,7 +51,7 @@
*/ */
public abstract class PersistentClass implements AttributeContainer, Serializable, Filterable, MetaAttributable { public abstract class PersistentClass implements AttributeContainer, Serializable, Filterable, MetaAttributable {
private static final Alias PK_ALIAS = new Alias(15, "PK"); private static final Alias PK_ALIAS = new Alias( 15, "PK" );
public static final String NULL_DISCRIMINATOR_MAPPING = "null"; public static final String NULL_DISCRIMINATOR_MAPPING = "null";
public static final String NOT_NULL_DISCRIMINATOR_MAPPING = "not null"; public static final String NOT_NULL_DISCRIMINATOR_MAPPING = "not null";
@ -61,10 +60,10 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
private String className; private String className;
private transient Class mappedClass; private transient Class mappedClass;
private String proxyInterfaceName; private String proxyInterfaceName;
private transient Class proxyInterface; private transient Class proxyInterface;
private String nodeName; private String nodeName;
private String jpaEntityName; private String jpaEntityName;
@ -77,7 +76,7 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
private final ArrayList subclassTables = new ArrayList(); private final ArrayList subclassTables = new ArrayList();
private boolean dynamicInsert; private boolean dynamicInsert;
private boolean dynamicUpdate; private boolean dynamicUpdate;
private int batchSize=-1; private int batchSize = -1;
private boolean selectBeforeUpdate; private boolean selectBeforeUpdate;
private java.util.Map metaAttributes; private java.util.Map metaAttributes;
private ArrayList<Join> joins = new ArrayList<Join>(); private ArrayList<Join> joins = new ArrayList<Join>();
@ -111,7 +110,7 @@ public String getClassName() {
} }
public void setClassName(String className) { public void setClassName(String className) {
this.className = className==null ? null : className.intern(); this.className = className == null ? null : className.intern();
this.mappedClass = null; this.mappedClass = null;
} }
@ -125,32 +124,32 @@ public void setProxyInterfaceName(String proxyInterfaceName) {
} }
public Class getMappedClass() throws MappingException { public Class getMappedClass() throws MappingException {
if (className==null) { if ( className == null ) {
return null; return null;
} }
try { try {
if (mappedClass == null) { if ( mappedClass == null ) {
mappedClass = ReflectHelper.classForName(className); mappedClass = ReflectHelper.classForName( className );
} }
return mappedClass; return mappedClass;
} }
catch (ClassNotFoundException cnfe) { catch (ClassNotFoundException cnfe) {
throw new MappingException("entity class not found: " + className, cnfe); throw new MappingException( "entity class not found: " + className, cnfe );
} }
} }
public Class getProxyInterface() { public Class getProxyInterface() {
if (proxyInterfaceName==null) { if ( proxyInterfaceName == null ) {
return null; return null;
} }
try { try {
if (proxyInterface == null) { if ( proxyInterface == null ) {
proxyInterface = ReflectHelper.classForName( proxyInterfaceName ); proxyInterface = ReflectHelper.classForName( proxyInterfaceName );
} }
return proxyInterface; return proxyInterface;
} }
catch (ClassNotFoundException cnfe) { catch (ClassNotFoundException cnfe) {
throw new MappingException("proxy class not found: " + proxyInterfaceName, cnfe); throw new MappingException( "proxy class not found: " + proxyInterfaceName, cnfe );
} }
} }
@ -159,8 +158,9 @@ public boolean useDynamicInsert() {
} }
abstract int nextSubclassId(); abstract int nextSubclassId();
public abstract int getSubclassId(); public abstract int getSubclassId();
public boolean useDynamicUpdate() { public boolean useDynamicUpdate() {
return dynamicUpdate; return dynamicUpdate;
} }
@ -181,18 +181,18 @@ public String getDiscriminatorValue() {
public void addSubclass(Subclass subclass) throws MappingException { public void addSubclass(Subclass subclass) throws MappingException {
// inheritance cycle detection (paranoid check) // inheritance cycle detection (paranoid check)
PersistentClass superclass = getSuperclass(); PersistentClass superclass = getSuperclass();
while (superclass!=null) { while ( superclass != null ) {
if ( subclass.getEntityName().equals( superclass.getEntityName() ) ) { if ( subclass.getEntityName().equals( superclass.getEntityName() ) ) {
throw new MappingException( throw new MappingException(
"Circular inheritance mapping detected: " + "Circular inheritance mapping detected: " +
subclass.getEntityName() + subclass.getEntityName() +
" will have it self as superclass when extending " + " will have it self as superclass when extending " +
getEntityName() getEntityName()
); );
} }
superclass = superclass.getSuperclass(); superclass = superclass.getSuperclass();
} }
subclasses.add(subclass); subclasses.add( subclass );
} }
public boolean hasSubclasses() { public boolean hasSubclasses() {
@ -201,51 +201,51 @@ public boolean hasSubclasses() {
public int getSubclassSpan() { public int getSubclassSpan() {
int n = subclasses.size(); int n = subclasses.size();
Iterator iter = subclasses.iterator(); for ( Subclass subclass : subclasses ) {
while ( iter.hasNext() ) { n += subclass.getSubclassSpan();
n += ( (Subclass) iter.next() ).getSubclassSpan();
} }
return n; return n;
} }
/** /**
* Iterate over subclasses in a special 'order', most derived subclasses * Iterate over subclasses in a special 'order', most derived subclasses
* first. * first.
*/ */
public Iterator getSubclassIterator() { public Iterator<Subclass> getSubclassIterator() {
Iterator[] iters = new Iterator[ subclasses.size() + 1 ]; Iterator[] iters = new Iterator[subclasses.size() + 1];
Iterator iter = subclasses.iterator(); Iterator iter = subclasses.iterator();
int i=0; int i = 0;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
iters[i++] = ( (Subclass) iter.next() ).getSubclassIterator(); iters[i++] = ( (Subclass) iter.next() ).getSubclassIterator();
} }
iters[i] = subclasses.iterator(); iters[i] = subclasses.iterator();
return new JoinedIterator(iters); return new JoinedIterator( iters );
} }
public Iterator getSubclassClosureIterator() { public Iterator getSubclassClosureIterator() {
ArrayList iters = new ArrayList(); ArrayList iters = new ArrayList();
iters.add( new SingletonIterator(this) ); iters.add( new SingletonIterator( this ) );
Iterator iter = getSubclassIterator(); Iterator iter = getSubclassIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
PersistentClass clazz = (PersistentClass) iter.next(); PersistentClass clazz = (PersistentClass) iter.next();
iters.add( clazz.getSubclassClosureIterator() ); iters.add( clazz.getSubclassClosureIterator() );
} }
return new JoinedIterator(iters); return new JoinedIterator( iters );
} }
public Table getIdentityTable() { public Table getIdentityTable() {
return getRootTable(); return getRootTable();
} }
public Iterator getDirectSubclasses() { public Iterator getDirectSubclasses() {
return subclasses.iterator(); return subclasses.iterator();
} }
@Override @Override
public void addProperty(Property p) { public void addProperty(Property p) {
properties.add(p); properties.add( p );
declaredProperties.add(p); declaredProperties.add( p );
p.setPersistentClass(this); p.setPersistentClass( this );
} }
public abstract Table getTable(); public abstract Table getTable();
@ -255,58 +255,80 @@ public String getEntityName() {
} }
public abstract boolean isMutable(); public abstract boolean isMutable();
public abstract boolean hasIdentifierProperty(); public abstract boolean hasIdentifierProperty();
public abstract Property getIdentifierProperty(); public abstract Property getIdentifierProperty();
public abstract Property getDeclaredIdentifierProperty(); public abstract Property getDeclaredIdentifierProperty();
public abstract KeyValue getIdentifier(); public abstract KeyValue getIdentifier();
public abstract Property getVersion(); public abstract Property getVersion();
public abstract Property getDeclaredVersion(); public abstract Property getDeclaredVersion();
public abstract Value getDiscriminator(); public abstract Value getDiscriminator();
public abstract boolean isInherited(); public abstract boolean isInherited();
public abstract boolean isPolymorphic(); public abstract boolean isPolymorphic();
public abstract boolean isVersioned(); public abstract boolean isVersioned();
public abstract String getNaturalIdCacheRegionName(); public abstract String getNaturalIdCacheRegionName();
public abstract String getCacheConcurrencyStrategy(); public abstract String getCacheConcurrencyStrategy();
public abstract PersistentClass getSuperclass(); public abstract PersistentClass getSuperclass();
public abstract boolean isExplicitPolymorphism(); public abstract boolean isExplicitPolymorphism();
public abstract boolean isDiscriminatorInsertable(); public abstract boolean isDiscriminatorInsertable();
public abstract Iterator getPropertyClosureIterator(); public abstract Iterator getPropertyClosureIterator();
public abstract Iterator getTableClosureIterator(); public abstract Iterator getTableClosureIterator();
public abstract Iterator getKeyClosureIterator(); public abstract Iterator getKeyClosureIterator();
protected void addSubclassProperty(Property prop) { protected void addSubclassProperty(Property prop) {
subclassProperties.add(prop); subclassProperties.add( prop );
} }
protected void addSubclassJoin(Join join) { protected void addSubclassJoin(Join join) {
subclassJoins.add(join); subclassJoins.add( join );
} }
protected void addSubclassTable(Table subclassTable) { protected void addSubclassTable(Table subclassTable) {
subclassTables.add(subclassTable); subclassTables.add( subclassTable );
} }
public Iterator getSubclassPropertyClosureIterator() { public Iterator getSubclassPropertyClosureIterator() {
ArrayList iters = new ArrayList(); ArrayList iters = new ArrayList();
iters.add( getPropertyClosureIterator() ); iters.add( getPropertyClosureIterator() );
iters.add( subclassProperties.iterator() ); iters.add( subclassProperties.iterator() );
for ( int i=0; i<subclassJoins.size(); i++ ) { for ( int i = 0; i < subclassJoins.size(); i++ ) {
Join join = (Join) subclassJoins.get(i); Join join = (Join) subclassJoins.get( i );
iters.add( join.getPropertyIterator() ); iters.add( join.getPropertyIterator() );
} }
return new JoinedIterator(iters); return new JoinedIterator( iters );
} }
public Iterator getSubclassJoinClosureIterator() { public Iterator getSubclassJoinClosureIterator() {
return new JoinedIterator( getJoinClosureIterator(), subclassJoins.iterator() ); return new JoinedIterator( getJoinClosureIterator(), subclassJoins.iterator() );
} }
public Iterator getSubclassTableClosureIterator() { public Iterator getSubclassTableClosureIterator() {
return new JoinedIterator( getTableClosureIterator(), subclassTables.iterator() ); return new JoinedIterator( getTableClosureIterator(), subclassTables.iterator() );
} }
public boolean isClassOrSuperclassJoin(Join join) { public boolean isClassOrSuperclassJoin(Join join) {
return joins.contains(join); return joins.contains( join );
} }
public boolean isClassOrSuperclassTable(Table closureTable) { public boolean isClassOrSuperclassTable(Table closureTable) {
return getTable()==closureTable; return getTable() == closureTable;
} }
public boolean isLazy() { public boolean isLazy() {
@ -318,10 +340,15 @@ public void setLazy(boolean lazy) {
} }
public abstract boolean hasEmbeddedIdentifier(); public abstract boolean hasEmbeddedIdentifier();
public abstract Class getEntityPersisterClass(); public abstract Class getEntityPersisterClass();
public abstract void setEntityPersisterClass(Class classPersisterClass); public abstract void setEntityPersisterClass(Class classPersisterClass);
public abstract Table getRootTable(); public abstract Table getRootTable();
public abstract RootClass getRootClass(); public abstract RootClass getRootClass();
public abstract KeyValue getKey(); public abstract KeyValue getKey();
public void setDiscriminatorValue(String discriminatorValue) { public void setDiscriminatorValue(String discriminatorValue) {
@ -329,16 +356,16 @@ public void setDiscriminatorValue(String discriminatorValue) {
} }
public void setEntityName(String entityName) { public void setEntityName(String entityName) {
this.entityName = entityName==null ? null : entityName.intern(); this.entityName = entityName == null ? null : entityName.intern();
} }
public void createPrimaryKey() { public void createPrimaryKey() {
//Primary key constraint //Primary key constraint
PrimaryKey pk = new PrimaryKey(); PrimaryKey pk = new PrimaryKey();
Table table = getTable(); Table table = getTable();
pk.setTable(table); pk.setTable( table );
pk.setName( PK_ALIAS.toAliasString( table.getName() ) ); pk.setName( PK_ALIAS.toAliasString( table.getName() ) );
table.setPrimaryKey(pk); table.setPrimaryKey( pk );
pk.addColumns( getKey().getColumnIterator() ); pk.addColumns( getKey().getColumnIterator() );
} }
@ -364,8 +391,9 @@ public void setSelectBeforeUpdate(boolean selectBeforeUpdate) {
/** /**
* Build an iterator of properties which are "referenceable". * Build an iterator of properties which are "referenceable".
* *
* @see #getReferencedProperty for a discussion of "referenceable"
* @return The property iterator. * @return The property iterator.
*
* @see #getReferencedProperty for a discussion of "referenceable"
*/ */
public Iterator getReferenceablePropertyIterator() { public Iterator getReferenceablePropertyIterator() {
return getPropertyClosureIterator(); return getPropertyClosureIterator();
@ -378,14 +406,16 @@ public Iterator getReferenceablePropertyIterator() {
* mapping (an identifier or explcitly named in a property-ref). * mapping (an identifier or explcitly named in a property-ref).
* *
* @param propertyPath The property path to resolve into a property reference. * @param propertyPath The property path to resolve into a property reference.
*
* @return The property reference (never null). * @return The property reference (never null).
*
* @throws MappingException If the property could not be found. * @throws MappingException If the property could not be found.
*/ */
public Property getReferencedProperty(String propertyPath) throws MappingException { public Property getReferencedProperty(String propertyPath) throws MappingException {
try { try {
return getRecursiveProperty( propertyPath, getReferenceablePropertyIterator() ); return getRecursiveProperty( propertyPath, getReferenceablePropertyIterator() );
} }
catch ( MappingException e ) { catch (MappingException e) {
throw new MappingException( throw new MappingException(
"property-ref [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e "property-ref [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
); );
@ -396,7 +426,7 @@ public Property getRecursiveProperty(String propertyPath) throws MappingExceptio
try { try {
return getRecursiveProperty( propertyPath, getPropertyIterator() ); return getRecursiveProperty( propertyPath, getPropertyIterator() );
} }
catch ( MappingException e ) { catch (MappingException e) {
throw new MappingException( throw new MappingException(
"property [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]", e
); );
@ -408,7 +438,7 @@ private Property getRecursiveProperty(String propertyPath, Iterator iter) throws
StringTokenizer st = new StringTokenizer( propertyPath, ".", false ); StringTokenizer st = new StringTokenizer( propertyPath, ".", false );
try { try {
while ( st.hasMoreElements() ) { while ( st.hasMoreElements() ) {
final String element = ( String ) st.nextElement(); final String element = (String) st.nextElement();
if ( property == null ) { if ( property == null ) {
Property identifierProperty = getIdentifierProperty(); Property identifierProperty = getIdentifierProperty();
if ( identifierProperty != null && identifierProperty.getName().equals( element ) ) { if ( identifierProperty != null && identifierProperty.getName().equals( element ) ) {
@ -427,7 +457,7 @@ else if ( identifierProperty == null && getIdentifierMapper() != null ) {
property = identifierProperty; property = identifierProperty;
} }
} }
catch( MappingException ignore ) { catch (MappingException ignore) {
// ignore it... // ignore it...
} }
} }
@ -438,11 +468,11 @@ else if ( identifierProperty == null && getIdentifierMapper() != null ) {
} }
else { else {
//flat recursive algorithm //flat recursive algorithm
property = ( ( Component ) property.getValue() ).getProperty( element ); property = ( (Component) property.getValue() ).getProperty( element );
} }
} }
} }
catch ( MappingException e ) { catch (MappingException e) {
throw new MappingException( "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]" ); throw new MappingException( "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]" );
} }
@ -450,8 +480,8 @@ else if ( identifierProperty == null && getIdentifierMapper() != null ) {
} }
private Property getProperty(String propertyName, Iterator iterator) throws MappingException { private Property getProperty(String propertyName, Iterator iterator) throws MappingException {
if(iterator.hasNext()) { if ( iterator.hasNext() ) {
String root = StringHelper.root(propertyName); String root = StringHelper.root( propertyName );
while ( iterator.hasNext() ) { while ( iterator.hasNext() ) {
Property prop = (Property) iterator.next(); Property prop = (Property) iterator.next();
if ( prop.getName().equals( root ) ) { if ( prop.getName().equals( root ) ) {
@ -466,7 +496,7 @@ public Property getProperty(String propertyName) throws MappingException {
Iterator iter = getPropertyClosureIterator(); Iterator iter = getPropertyClosureIterator();
Property identifierProperty = getIdentifierProperty(); Property identifierProperty = getIdentifierProperty();
if ( identifierProperty != null if ( identifierProperty != null
&& identifierProperty.getName().equals( StringHelper.root(propertyName) ) ) { && identifierProperty.getName().equals( StringHelper.root( propertyName ) ) ) {
return identifierProperty; return identifierProperty;
} }
else { else {
@ -502,26 +532,26 @@ public void validate(Mapping mapping) throws MappingException {
Iterator iter = getPropertyIterator(); Iterator iter = getPropertyIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Property prop = (Property) iter.next(); Property prop = (Property) iter.next();
if ( !prop.isValid(mapping) ) { if ( !prop.isValid( mapping ) ) {
throw new MappingException( throw new MappingException(
"property mapping has wrong number of columns: " + "property mapping has wrong number of columns: " +
StringHelper.qualify( getEntityName(), prop.getName() ) + StringHelper.qualify( getEntityName(), prop.getName() ) +
" type: " + " type: " +
prop.getType().getName() prop.getType().getName()
); );
} }
} }
checkPropertyDuplication(); checkPropertyDuplication();
checkColumnDuplication(); checkColumnDuplication();
} }
private void checkPropertyDuplication() throws MappingException { private void checkPropertyDuplication() throws MappingException {
HashSet<String> names = new HashSet<String>(); HashSet<String> names = new HashSet<String>();
Iterator iter = getPropertyIterator(); Iterator iter = getPropertyIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Property prop = (Property) iter.next(); Property prop = (Property) iter.next();
if ( !names.add( prop.getName() ) ) { if ( !names.add( prop.getName() ) ) {
throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName()); throw new MappingException( "Duplicate property mapping of " + prop.getName() + " found in " + getEntityName() );
} }
} }
} }
@ -529,6 +559,7 @@ private void checkPropertyDuplication() throws MappingException {
public boolean isDiscriminatorValueNotNull() { public boolean isDiscriminatorValueNotNull() {
return NOT_NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() ); return NOT_NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
} }
public boolean isDiscriminatorValueNull() { public boolean isDiscriminatorValueNull() {
return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() ); return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
} }
@ -548,10 +579,10 @@ public MetaAttribute getMetaAttribute(String name) {
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getName() + '(' + getEntityName() + ')'; return getClass().getName() + '(' + getEntityName() + ')';
} }
public Iterator getJoinIterator() { public Iterator getJoinIterator() {
return joins.iterator(); return joins.iterator();
} }
@ -561,8 +592,8 @@ public Iterator getJoinClosureIterator() {
} }
public void addJoin(Join join) { public void addJoin(Join join) {
joins.add(join); joins.add( join );
join.setPersistentClass(this); join.setPersistentClass( this );
} }
public int getJoinClosureSpan() { public int getJoinClosureSpan() {
@ -578,11 +609,11 @@ public int getPropertyClosureSpan() {
} }
public int getJoinNumber(Property prop) { public int getJoinNumber(Property prop) {
int result=1; int result = 1;
Iterator iter = getSubclassJoinClosureIterator(); Iterator iter = getSubclassJoinClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Join join = (Join) iter.next(); Join join = (Join) iter.next();
if ( join.containsProperty(prop) ) { if ( join.containsProperty( prop ) ) {
return result; return result;
} }
result++; result++;
@ -604,7 +635,7 @@ public Iterator getPropertyIterator() {
ArrayList iterators = new ArrayList(); ArrayList iterators = new ArrayList();
iterators.add( properties.iterator() ); iterators.add( properties.iterator() );
for ( int i = 0; i < joins.size(); i++ ) { for ( int i = 0; i < joins.size(); i++ ) {
Join join = ( Join ) joins.get( i ); Join join = (Join) joins.get( i );
iterators.add( join.getPropertyIterator() ); iterators.add( join.getPropertyIterator() );
} }
return new JoinedIterator( iterators ); return new JoinedIterator( iterators );
@ -675,8 +706,22 @@ public ExecuteUpdateResultCheckStyle getCustomSQLDeleteCheckStyle() {
return deleteCheckStyle; return deleteCheckStyle;
} }
public void addFilter(String name, String condition, boolean autoAliasInjection, java.util.Map<String,String> aliasTableMap, java.util.Map<String,String> aliasEntityMap) { public void addFilter(
filters.add(new FilterConfiguration(name, condition, autoAliasInjection, aliasTableMap, aliasEntityMap, this)); String name,
String condition,
boolean autoAliasInjection,
java.util.Map<String, String> aliasTableMap,
java.util.Map<String, String> aliasEntityMap) {
filters.add(
new FilterConfiguration(
name,
condition,
autoAliasInjection,
aliasTableMap,
aliasEntityMap,
this
)
);
} }
public java.util.List getFilters() { public java.util.List getFilters() {
@ -694,13 +739,13 @@ public String getLoaderName() {
} }
public void setLoaderName(String loaderName) { public void setLoaderName(String loaderName) {
this.loaderName = loaderName==null ? null : loaderName.intern(); this.loaderName = loaderName == null ? null : loaderName.intern();
} }
public abstract java.util.Set getSynchronizedTables(); public abstract java.util.Set getSynchronizedTables();
public void addSynchronizedTable(String table) { public void addSynchronizedTable(String table) {
synchronizedTables.add(table); synchronizedTables.add( table );
} }
public Boolean isAbstract() { public Boolean isAbstract() {
@ -711,27 +756,27 @@ public void setAbstract(Boolean isAbstract) {
this.isAbstract = isAbstract; this.isAbstract = isAbstract;
} }
protected void checkColumnDuplication(Set distinctColumns, Iterator columns) protected void checkColumnDuplication(Set distinctColumns, Iterator columns)
throws MappingException { throws MappingException {
while ( columns.hasNext() ) { while ( columns.hasNext() ) {
Selectable columnOrFormula = (Selectable) columns.next(); Selectable columnOrFormula = (Selectable) columns.next();
if ( !columnOrFormula.isFormula() ) { if ( !columnOrFormula.isFormula() ) {
Column col = (Column) columnOrFormula; Column col = (Column) columnOrFormula;
if ( !distinctColumns.add( col.getName() ) ) { if ( !distinctColumns.add( col.getName() ) ) {
throw new MappingException( throw new MappingException(
"Repeated column in mapping for entity: " + "Repeated column in mapping for entity: " +
getEntityName() + getEntityName() +
" column: " + " column: " +
col.getName() + col.getName() +
" (should be mapped with insert=\"false\" update=\"false\")" " (should be mapped with insert=\"false\" update=\"false\")"
); );
} }
} }
} }
} }
protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties) protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties)
throws MappingException { throws MappingException {
while ( properties.hasNext() ) { while ( properties.hasNext() ) {
Property prop = (Property) properties.next(); Property prop = (Property) properties.next();
if ( prop.getValue() instanceof Component ) { //TODO: remove use of instanceof! if ( prop.getValue() instanceof Component ) { //TODO: remove use of instanceof!
@ -745,18 +790,18 @@ protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator prop
} }
} }
} }
protected Iterator getNonDuplicatedPropertyIterator() { protected Iterator getNonDuplicatedPropertyIterator() {
return getUnjoinedPropertyIterator(); return getUnjoinedPropertyIterator();
} }
protected Iterator getDiscriminatorColumnIterator() { protected Iterator getDiscriminatorColumnIterator() {
return EmptyIterator.INSTANCE; return EmptyIterator.INSTANCE;
} }
protected void checkColumnDuplication() { protected void checkColumnDuplication() {
HashSet cols = new HashSet(); HashSet cols = new HashSet();
if (getIdentifierMapper() == null ) { if ( getIdentifierMapper() == null ) {
//an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator() //an identifier mapper => getKey will be included in the getNonDuplicatedPropertyIterator()
//and checked later, so it needs to be excluded //and checked later, so it needs to be excluded
checkColumnDuplication( cols, getKey().getColumnIterator() ); checkColumnDuplication( cols, getKey().getColumnIterator() );
@ -771,13 +816,13 @@ protected void checkColumnDuplication() {
checkPropertyColumnDuplication( cols, join.getPropertyIterator() ); checkPropertyColumnDuplication( cols, join.getPropertyIterator() );
} }
} }
public abstract Object accept(PersistentClassVisitor mv); public abstract Object accept(PersistentClassVisitor mv);
public String getNodeName() { public String getNodeName() {
return nodeName; return nodeName;
} }
public void setNodeName(String nodeName) { public void setNodeName(String nodeName) {
this.nodeName = nodeName; this.nodeName = nodeName;
} }
@ -785,23 +830,23 @@ public void setNodeName(String nodeName) {
public String getJpaEntityName() { public String getJpaEntityName() {
return jpaEntityName; return jpaEntityName;
} }
public void setJpaEntityName(String jpaEntityName) { public void setJpaEntityName(String jpaEntityName) {
this.jpaEntityName = jpaEntityName; this.jpaEntityName = jpaEntityName;
} }
public boolean hasPojoRepresentation() { public boolean hasPojoRepresentation() {
return getClassName()!=null; return getClassName() != null;
} }
public boolean hasDom4jRepresentation() { public boolean hasDom4jRepresentation() {
return getNodeName()!=null; return getNodeName() != null;
} }
public boolean hasSubselectLoadableCollections() { public boolean hasSubselectLoadableCollections() {
return hasSubselectLoadableCollections; return hasSubselectLoadableCollections;
} }
public void setSubselectLoadableCollections(boolean hasSubselectCollections) { public void setSubselectLoadableCollections(boolean hasSubselectCollections) {
this.hasSubselectLoadableCollections = hasSubselectCollections; this.hasSubselectLoadableCollections = hasSubselectCollections;
} }
@ -834,8 +879,10 @@ public void addTuplizer(EntityMode entityMode, String implClassName) {
} }
public String getTuplizerImplClassName(EntityMode mode) { public String getTuplizerImplClassName(EntityMode mode) {
if ( tuplizerImpls == null ) return null; if ( tuplizerImpls == null ) {
return ( String ) tuplizerImpls.get( mode ); return null;
}
return (String) tuplizerImpls.get( mode );
} }
public java.util.Map getTuplizerMap() { public java.util.Map getTuplizerMap() {
@ -862,15 +909,15 @@ public Iterator getDeclaredPropertyIterator() {
ArrayList iterators = new ArrayList(); ArrayList iterators = new ArrayList();
iterators.add( declaredProperties.iterator() ); iterators.add( declaredProperties.iterator() );
for ( int i = 0; i < joins.size(); i++ ) { for ( int i = 0; i < joins.size(); i++ ) {
Join join = ( Join ) joins.get( i ); Join join = (Join) joins.get( i );
iterators.add( join.getDeclaredPropertyIterator() ); iterators.add( join.getDeclaredPropertyIterator() );
} }
return new JoinedIterator( iterators ); return new JoinedIterator( iterators );
} }
public void addMappedsuperclassProperty(Property p) { public void addMappedsuperclassProperty(Property p) {
properties.add(p); properties.add( p );
p.setPersistentClass(this); p.setPersistentClass( this );
} }
public MappedSuperclass getSuperMappedSuperclass() { public MappedSuperclass getSuperMappedSuperclass() {

View File

@ -198,7 +198,7 @@ public void setValueGenerationStrategy(ValueGeneration valueGenerationStrategy)
this.valueGenerationStrategy = valueGenerationStrategy; this.valueGenerationStrategy = valueGenerationStrategy;
} }
public void setUpdateable(boolean mutable) { public void setUpdateable(boolean mutable) {
this.updateable = mutable; this.updateable = mutable;
} }

View File

@ -30,19 +30,18 @@
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.SingletonIterator; import org.hibernate.internal.util.collections.SingletonIterator;
import org.jboss.logging.Logger;
/** /**
* The root class of an inheritance hierarchy * The root class of an inheritance hierarchy
*
* @author Gavin King * @author Gavin King
*/ */
public class RootClass extends PersistentClass implements TableOwner { public class RootClass extends PersistentClass implements TableOwner {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( RootClass.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, RootClass.class.getName());
public static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id"; public static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
public static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class"; public static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
@ -70,30 +69,31 @@ public class RootClass extends PersistentClass implements TableOwner {
private boolean cachingExplicitlyRequested; private boolean cachingExplicitlyRequested;
@Override @Override
int nextSubclassId() { int nextSubclassId() {
return ++nextSubclassId; return ++nextSubclassId;
} }
@Override @Override
public int getSubclassId() { public int getSubclassId() {
return 0; return 0;
} }
public void setTable(Table table) { public void setTable(Table table) {
this.table=table; this.table = table;
} }
@Override @Override
public Table getTable() { public Table getTable() {
return table; return table;
} }
@Override @Override
public Property getIdentifierProperty() { public Property getIdentifierProperty() {
return identifierProperty; return identifierProperty;
} }
@Override @Override
public Property getDeclaredIdentifierProperty() { public Property getDeclaredIdentifierProperty() {
return declaredIdentifierProperty; return declaredIdentifierProperty;
} }
@ -102,25 +102,27 @@ public void setDeclaredIdentifierProperty(Property declaredIdentifierProperty) {
} }
@Override @Override
public KeyValue getIdentifier() { public KeyValue getIdentifier() {
return identifier; return identifier;
} }
@Override
public boolean hasIdentifierProperty() {
return identifierProperty!=null;
}
@Override @Override
public Value getDiscriminator() { public boolean hasIdentifierProperty() {
return identifierProperty != null;
}
@Override
public Value getDiscriminator() {
return discriminator; return discriminator;
} }
@Override @Override
public boolean isInherited() { public boolean isInherited() {
return false; return false;
} }
@Override @Override
public boolean isPolymorphic() { public boolean isPolymorphic() {
return polymorphic; return polymorphic;
} }
@ -129,41 +131,43 @@ public void setPolymorphic(boolean polymorphic) {
} }
@Override @Override
public RootClass getRootClass() { public RootClass getRootClass() {
return this; return this;
} }
@Override @Override
public Iterator getPropertyClosureIterator() { public Iterator getPropertyClosureIterator() {
return getPropertyIterator(); return getPropertyIterator();
} }
@Override @Override
public Iterator getTableClosureIterator() { public Iterator getTableClosureIterator() {
return new SingletonIterator( getTable() ); return new SingletonIterator( getTable() );
} }
@Override @Override
public Iterator getKeyClosureIterator() { public Iterator getKeyClosureIterator() {
return new SingletonIterator( getKey() ); return new SingletonIterator( getKey() );
} }
@Override @Override
public void addSubclass(Subclass subclass) throws MappingException { public void addSubclass(Subclass subclass) throws MappingException {
super.addSubclass(subclass); super.addSubclass( subclass );
setPolymorphic(true); setPolymorphic( true );
} }
@Override @Override
public boolean isExplicitPolymorphism() { public boolean isExplicitPolymorphism() {
return explicitPolymorphism; return explicitPolymorphism;
} }
@Override @Override
public Property getVersion() { public Property getVersion() {
return version; return version;
} }
@Override @Override
public Property getDeclaredVersion() { public Property getDeclaredVersion() {
return declaredVersion; return declaredVersion;
} }
@ -174,42 +178,44 @@ public void setDeclaredVersion(Property declaredVersion) {
public void setVersion(Property version) { public void setVersion(Property version) {
this.version = version; this.version = version;
} }
@Override @Override
public boolean isVersioned() { public boolean isVersioned() {
return version!=null; return version != null;
} }
@Override @Override
public boolean isMutable() { public boolean isMutable() {
return mutable; return mutable;
} }
@Override @Override
public boolean hasEmbeddedIdentifier() { public boolean hasEmbeddedIdentifier() {
return embeddedIdentifier; return embeddedIdentifier;
} }
@Override @Override
public Class getEntityPersisterClass() { public Class getEntityPersisterClass() {
return entityPersisterClass; return entityPersisterClass;
} }
@Override @Override
public Table getRootTable() { public Table getRootTable() {
return getTable(); return getTable();
} }
@Override @Override
public void setEntityPersisterClass(Class persister) { public void setEntityPersisterClass(Class persister) {
this.entityPersisterClass = persister; this.entityPersisterClass = persister;
} }
@Override @Override
public PersistentClass getSuperclass() { public PersistentClass getSuperclass() {
return null; return null;
} }
@Override @Override
public KeyValue getKey() { public KeyValue getKey() {
return getIdentifier(); return getIdentifier();
} }
@ -231,7 +237,7 @@ public void setIdentifier(KeyValue identifier) {
public void setIdentifierProperty(Property identifierProperty) { public void setIdentifierProperty(Property identifierProperty) {
this.identifierProperty = identifierProperty; this.identifierProperty = identifierProperty;
identifierProperty.setPersistentClass(this); identifierProperty.setPersistentClass( this );
} }
@ -240,7 +246,7 @@ public void setMutable(boolean mutable) {
} }
@Override @Override
public boolean isDiscriminatorInsertable() { public boolean isDiscriminatorInsertable() {
return discriminatorInsertable; return discriminatorInsertable;
} }
@ -249,7 +255,7 @@ public void setDiscriminatorInsertable(boolean insertable) {
} }
@Override @Override
public boolean isForceDiscriminator() { public boolean isForceDiscriminator() {
return forceDiscriminator; return forceDiscriminator;
} }
@ -258,7 +264,7 @@ public void setForceDiscriminator(boolean forceDiscriminator) {
} }
@Override @Override
public String getWhere() { public String getWhere() {
return where; return where;
} }
@ -267,14 +273,14 @@ public void setWhere(String string) {
} }
@Override @Override
public void validate(Mapping mapping) throws MappingException { public void validate(Mapping mapping) throws MappingException {
super.validate(mapping); super.validate( mapping );
if ( !getIdentifier().isValid(mapping) ) { if ( !getIdentifier().isValid( mapping ) ) {
throw new MappingException( throw new MappingException(
"identifier mapping has wrong number of columns: " + "identifier mapping has wrong number of columns: " +
getEntityName() + getEntityName() +
" type: " + " type: " +
getIdentifier().getType().getName() getIdentifier().getType().getName()
); );
} }
checkCompositeIdentifier(); checkCompositeIdentifier();
@ -304,7 +310,7 @@ private void checkCompositeIdentifier() {
} }
@Override @Override
public String getCacheConcurrencyStrategy() { public String getCacheConcurrencyStrategy() {
return cacheConcurrencyStrategy; return cacheConcurrencyStrategy;
} }
@ -313,22 +319,24 @@ public void setCacheConcurrencyStrategy(String cacheConcurrencyStrategy) {
} }
public String getCacheRegionName() { public String getCacheRegionName() {
return cacheRegionName==null ? getEntityName() : cacheRegionName; return cacheRegionName == null ? getEntityName() : cacheRegionName;
} }
public void setCacheRegionName(String cacheRegionName) { public void setCacheRegionName(String cacheRegionName) {
this.cacheRegionName = cacheRegionName; this.cacheRegionName = cacheRegionName;
} }
@Override @Override
public String getNaturalIdCacheRegionName() { public String getNaturalIdCacheRegionName() {
return naturalIdCacheRegionName; return naturalIdCacheRegionName;
} }
public void setNaturalIdCacheRegionName(String naturalIdCacheRegionName) { public void setNaturalIdCacheRegionName(String naturalIdCacheRegionName) {
this.naturalIdCacheRegionName = naturalIdCacheRegionName; this.naturalIdCacheRegionName = naturalIdCacheRegionName;
} }
@Override @Override
public boolean isLazyPropertiesCacheable() { public boolean isLazyPropertiesCacheable() {
return lazyPropertiesCacheable; return lazyPropertiesCacheable;
} }
@ -337,12 +345,12 @@ public void setLazyPropertiesCacheable(boolean lazyPropertiesCacheable) {
} }
@Override @Override
public boolean isJoinedSubclass() { public boolean isJoinedSubclass() {
return false; return false;
} }
@Override @Override
public java.util.Set getSynchronizedTables() { public java.util.Set getSynchronizedTables() {
return synchronizedTables; return synchronizedTables;
} }
@ -360,8 +368,8 @@ public Set<Table> getIdentityTables() {
} }
@Override @Override
public Object accept(PersistentClassVisitor mv) { public Object accept(PersistentClassVisitor mv) {
return mv.accept(this); return mv.accept( this );
} }
public void setCachingExplicitlyRequested(boolean explicitlyRequested) { public void setCachingExplicitlyRequested(boolean explicitlyRequested) {

View File

@ -236,7 +236,9 @@ public IdentifierGenerator createIdentifierGenerator(
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Table table= (Table) iter.next(); Table table= (Table) iter.next();
tables.append( table.getQuotedName(dialect) ); tables.append( table.getQuotedName(dialect) );
if ( iter.hasNext() ) tables.append(", "); if ( iter.hasNext() ) {
tables.append(", ");
}
} }
params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() ); params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
} }
@ -526,7 +528,7 @@ public Properties getTypeParameters() {
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getName() + '(' + columns.toString() + ')'; return getClass().getName() + '(' + columns.toString() + ')';
} }

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.mapping; package org.hibernate.mapping;
import java.util.Iterator; import java.util.Iterator;
import org.hibernate.MappingException; import org.hibernate.MappingException;
@ -32,18 +33,19 @@
* @author Gavin King * @author Gavin King
*/ */
public class SingleTableSubclass extends Subclass { public class SingleTableSubclass extends Subclass {
public SingleTableSubclass(PersistentClass superclass) { public SingleTableSubclass(PersistentClass superclass) {
super(superclass); super( superclass );
} }
@SuppressWarnings("unchecked")
protected Iterator getNonDuplicatedPropertyIterator() { protected Iterator getNonDuplicatedPropertyIterator() {
return new JoinedIterator( return new JoinedIterator(
getSuperclass().getUnjoinedPropertyIterator(), getSuperclass().getUnjoinedPropertyIterator(),
getUnjoinedPropertyIterator() getUnjoinedPropertyIterator()
); );
} }
protected Iterator getDiscriminatorColumnIterator() { protected Iterator getDiscriminatorColumnIterator() {
if ( isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ) { if ( isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ) {
return getDiscriminator().getColumnIterator(); return getDiscriminator().getColumnIterator();
@ -54,13 +56,17 @@ protected Iterator getDiscriminatorColumnIterator() {
} }
public Object accept(PersistentClassVisitor mv) { public Object accept(PersistentClassVisitor mv) {
return mv.accept(this); return mv.accept( this );
}
public void validate(Mapping mapping) throws MappingException {
if ( getDiscriminator() == null ) {
throw new MappingException(
"No discriminator found for " + getEntityName()
+ ". Discriminator is needed when 'single-table-per-hierarchy' "
+ "is used and a class has subclasses"
);
}
super.validate( mapping );
} }
public void validate(Mapping mapping) throws MappingException {
if(getDiscriminator()==null) {
throw new MappingException("No discriminator found for " + getEntityName() + ". Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses");
}
super.validate(mapping);
}
} }

View File

@ -36,10 +36,10 @@
* @author Brett Meyer * @author Brett Meyer
*/ */
public class UniqueKey extends Constraint { public class UniqueKey extends Constraint {
private java.util.Map<Column, String> columnOrderMap = new HashMap<Column, String>( ); private java.util.Map<Column, String> columnOrderMap = new HashMap<Column, String>();
@Override @Override
public String sqlConstraintString( public String sqlConstraintString(
Dialect dialect, Dialect dialect,
String constraintName, String constraintName,
String defaultCatalog, String defaultCatalog,
@ -50,8 +50,11 @@ public String sqlConstraintString(
} }
@Override @Override
public String sqlCreateString(Dialect dialect, Mapping p, public String sqlCreateString(
String defaultCatalog, String defaultSchema) { Dialect dialect,
Mapping p,
String defaultCatalog,
String defaultSchema) {
return null; return null;
// return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand( // return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
// this, defaultCatalog, defaultSchema // this, defaultCatalog, defaultSchema
@ -59,8 +62,10 @@ public String sqlCreateString(Dialect dialect, Mapping p,
} }
@Override @Override
public String sqlDropString(Dialect dialect, String defaultCatalog, public String sqlDropString(
String defaultSchema) { Dialect dialect,
String defaultCatalog,
String defaultSchema) {
return null; return null;
// return dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand( // return dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
// this, defaultCatalog, defaultSchema // this, defaultCatalog, defaultSchema
@ -77,7 +82,7 @@ public void addColumn(Column column, String order) {
public Map<Column, String> getColumnOrderMap() { public Map<Column, String> getColumnOrderMap() {
return columnOrderMap; return columnOrderMap;
} }
public String generatedConstraintNamePrefix() { public String generatedConstraintNamePrefix() {
return "UK_"; return "UK_";
} }

View File

@ -61,8 +61,11 @@ public NamedParameterSpecification(int sourceLine, int sourceColumn, String name
* @return The number of sql bind positions "eaten" by this bind operation. * @return The number of sql bind positions "eaten" by this bind operation.
*/ */
@Override @Override
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) public int bind(
throws SQLException { PreparedStatement statement,
QueryParameters qp,
SessionImplementor session,
int position) throws SQLException {
TypedValue typedValue = qp.getNamedParameters().get( name ); TypedValue typedValue = qp.getNamedParameters().get( name );
typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session ); typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
return typedValue.getType().getColumnSpan( session.getFactory() ); return typedValue.getType().getColumnSpan( session.getFactory() );

View File

@ -49,8 +49,11 @@ public VersionTypeSeedParameterSpecification(VersionType type) {
} }
@Override @Override
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) public int bind(
throws SQLException { PreparedStatement statement,
QueryParameters qp,
SessionImplementor session,
int position) throws SQLException {
type.nullSafeSet( statement, type.seed( session ), position, session ); type.nullSafeSet( statement, type.seed( session ), position, session );
return 1; return 1;
} }

View File

@ -864,7 +864,7 @@ public Object readIndex(ResultSet rs, String[] aliases, SessionImplementor sessi
protected Object decrementIndexByBase(Object index) { protected Object decrementIndexByBase(Object index) {
if ( baseIndex != 0 ) { if ( baseIndex != 0 ) {
index = (Integer)index - baseIndex; index = (Integer)index - baseIndex;
} }
return index; return index;
} }
@ -919,7 +919,7 @@ protected int writeIndex(PreparedStatement st, Object index, int i, SessionImple
protected Object incrementIndexByBase(Object index) { protected Object incrementIndexByBase(Object index) {
if ( baseIndex != 0 ) { if ( baseIndex != 0 ) {
index = (Integer)index + baseIndex; index = (Integer)index + baseIndex;
} }
return index; return index;
} }

View File

@ -79,19 +79,19 @@ public BasicCollectionPersister(
* Generate the SQL DELETE that deletes all rows * Generate the SQL DELETE that deletes all rows
*/ */
@Override @Override
protected String generateDeleteString() { protected String generateDeleteString() {
final Delete delete = new Delete() final Delete delete = new Delete()
.setTableName( qualifiedTableName ) .setTableName( qualifiedTableName )
.addPrimaryKeyColumns( keyColumnNames ); .addPrimaryKeyColumns( keyColumnNames );
if ( hasWhere ) { if ( hasWhere ) {
delete.setWhere( sqlWhereString ); delete.setWhere( sqlWhereString );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
delete.setComment( "delete collection " + getRole() ); delete.setComment( "delete collection " + getRole() );
} }
return delete.toStatementString(); return delete.toStatementString();
} }
@ -99,27 +99,27 @@ protected String generateDeleteString() {
* Generate the SQL INSERT that creates a new row * Generate the SQL INSERT that creates a new row
*/ */
@Override @Override
protected String generateInsertRowString() { protected String generateInsertRowString() {
final Insert insert = new Insert( getDialect() ) final Insert insert = new Insert( getDialect() )
.setTableName( qualifiedTableName ) .setTableName( qualifiedTableName )
.addColumns( keyColumnNames ); .addColumns( keyColumnNames );
if ( hasIdentifier) { if ( hasIdentifier ) {
insert.addColumn( identifierColumnName ); insert.addColumn( identifierColumnName );
} }
if ( hasIndex /*&& !indexIsFormula*/ ) { if ( hasIndex /*&& !indexIsFormula*/ ) {
insert.addColumns( indexColumnNames, indexColumnIsSettable ); insert.addColumns( indexColumnNames, indexColumnIsSettable );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
insert.setComment( "insert collection row " + getRole() ); insert.setComment( "insert collection row " + getRole() );
} }
//if ( !elementIsFormula ) { //if ( !elementIsFormula ) {
insert.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); insert.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters );
//} //}
return insert.toStatementString(); return insert.toStatementString();
} }
@ -127,16 +127,16 @@ protected String generateInsertRowString() {
* Generate the SQL UPDATE that updates a row * Generate the SQL UPDATE that updates a row
*/ */
@Override @Override
protected String generateUpdateRowString() { protected String generateUpdateRowString() {
final Update update = new Update( getDialect() ) final Update update = new Update( getDialect() )
.setTableName( qualifiedTableName ); .setTableName( qualifiedTableName );
//if ( !elementIsFormula ) { //if ( !elementIsFormula ) {
update.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); update.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters );
//} //}
if ( hasIdentifier ) { if ( hasIdentifier ) {
update.addPrimaryKeyColumns( new String[]{ identifierColumnName } ); update.addPrimaryKeyColumns( new String[] {identifierColumnName} );
} }
else if ( hasIndex && !indexContainsFormula ) { else if ( hasIndex && !indexContainsFormula ) {
update.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); update.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) );
@ -145,14 +145,14 @@ else if ( hasIndex && !indexContainsFormula ) {
update.addPrimaryKeyColumns( keyColumnNames ); update.addPrimaryKeyColumns( keyColumnNames );
update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
update.setComment( "update collection row " + getRole() ); update.setComment( "update collection row " + getRole() );
} }
return update.toStatementString(); return update.toStatementString();
} }
@Override @Override
protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session) protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException { throws HibernateException {
@ -163,11 +163,11 @@ protected void doProcessQueuedOps(PersistentCollection collection, Serializable
* Generate the SQL DELETE that deletes a particular row * Generate the SQL DELETE that deletes a particular row
*/ */
@Override @Override
protected String generateDeleteRowString() { protected String generateDeleteRowString() {
final Delete delete = new Delete().setTableName( qualifiedTableName ); final Delete delete = new Delete().setTableName( qualifiedTableName );
if ( hasIdentifier ) { if ( hasIdentifier ) {
delete.addPrimaryKeyColumns( new String[]{ identifierColumnName } ); delete.addPrimaryKeyColumns( new String[] {identifierColumnName} );
} }
else if ( hasIndex && !indexContainsFormula ) { else if ( hasIndex && !indexContainsFormula ) {
delete.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); delete.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) );
@ -176,11 +176,11 @@ else if ( hasIndex && !indexContainsFormula ) {
delete.addPrimaryKeyColumns( keyColumnNames ); delete.addPrimaryKeyColumns( keyColumnNames );
delete.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); delete.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
delete.setComment( "delete collection row " + getRole() ); delete.setComment( "delete collection row " + getRole() );
} }
return delete.toStatementString(); return delete.toStatementString();
} }
@ -198,15 +198,16 @@ public boolean isOneToMany() {
} }
@Override @Override
public boolean isManyToMany() { public boolean isManyToMany() {
return elementType.isEntityType(); //instanceof AssociationType; return elementType.isEntityType(); //instanceof AssociationType;
} }
private BasicBatchKey updateBatchKey; private BasicBatchKey updateBatchKey;
@Override @Override
protected int doUpdateRows(Serializable id, PersistentCollection collection, SessionImplementor session) throws HibernateException { protected int doUpdateRows(Serializable id, PersistentCollection collection, SessionImplementor session)
if ( ArrayHelper.isAllFalse(elementColumnIsSettable) ) { throws HibernateException {
if ( ArrayHelper.isAllFalse( elementColumnIsSettable ) ) {
return 0; return 0;
} }
@ -244,7 +245,7 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
} }
try { try {
offset+= expectation.prepare( st ); offset += expectation.prepare( st );
int loc = writeElement( st, collection.getElement( entry ), offset, session ); int loc = writeElement( st, collection.getElement( entry ), offset, session );
if ( hasIdentifier ) { if ( hasIdentifier ) {
writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session ); writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session );
@ -265,10 +266,14 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
.addToBatch(); .addToBatch();
} }
else { else {
expectation.verifyOutcome( session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 ); expectation.verifyOutcome(
session.getJdbcCoordinator().getResultSetReturn().executeUpdate(
st
), st, -1
);
} }
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
if ( useBatch ) { if ( useBatch ) {
session.getJdbcCoordinator().abortBatch(); session.getJdbcCoordinator().abortBatch();
} }
@ -286,26 +291,31 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
} }
return count; return count;
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw getSQLExceptionHelper().convert( throw getSQLExceptionHelper().convert(
sqle, sqle,
"could not update collection rows: " + MessageHelper.collectionInfoString( this, collection, id, session ), "could not update collection rows: " + MessageHelper.collectionInfoString(
this,
collection,
id,
session
),
getSQLUpdateRowString() getSQLUpdateRowString()
); );
} }
} }
public String selectFragment( public String selectFragment(
Joinable rhs, Joinable rhs,
String rhsAlias, String rhsAlias,
String lhsAlias, String lhsAlias,
String entitySuffix, String entitySuffix,
String collectionSuffix, String collectionSuffix,
boolean includeCollectionColumns) { boolean includeCollectionColumns) {
// we need to determine the best way to know that two joinables // we need to determine the best way to know that two joinables
// represent a single many-to-many... // represent a single many-to-many...
if ( rhs != null && isManyToMany() && !rhs.isCollection() ) { if ( rhs != null && isManyToMany() && !rhs.isCollection() ) {
AssociationType elementType = ( ( AssociationType ) getElementType() ); AssociationType elementType = ( (AssociationType) getElementType() );
if ( rhs.equals( elementType.getAssociatedJoinable( getFactory() ) ) ) { if ( rhs.equals( elementType.getAssociatedJoinable( getFactory() ) ) ) {
return manyToManySelectFragment( rhs, rhsAlias, lhsAlias, collectionSuffix ); return manyToManySelectFragment( rhs, rhsAlias, lhsAlias, collectionSuffix );
} }
@ -314,10 +324,10 @@ public String selectFragment(
} }
private String manyToManySelectFragment( private String manyToManySelectFragment(
Joinable rhs, Joinable rhs,
String rhsAlias, String rhsAlias,
String lhsAlias, String lhsAlias,
String collectionSuffix) { String collectionSuffix) {
SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix );
String[] elementColumnNames = rhs.getKeyColumnNames(); String[] elementColumnNames = rhs.getKeyColumnNames();
@ -335,7 +345,7 @@ private String manyToManySelectFragment(
* @see org.hibernate.loader.collection.BasicCollectionLoader * @see org.hibernate.loader.collection.BasicCollectionLoader
*/ */
@Override @Override
protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers) protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers)
throws MappingException { throws MappingException {
return BatchingCollectionInitializerBuilder.getBuilder( getFactory() ) return BatchingCollectionInitializerBuilder.getBuilder( getFactory() )
.createBatchingCollectionInitializer( this, batchSize, getFactory(), loadQueryInfluencers ); .createBatchingCollectionInitializer( this, batchSize, getFactory(), loadQueryInfluencers );
@ -347,7 +357,11 @@ public String fromJoinFragment(String alias, boolean innerJoin, boolean includeS
} }
@Override @Override
public String fromJoinFragment(String alias, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { public String fromJoinFragment(
String alias,
boolean innerJoin,
boolean includeSubclasses,
Set<String> treatAsDeclarations) {
return ""; return "";
} }
@ -357,26 +371,30 @@ public String whereJoinFragment(String alias, boolean innerJoin, boolean include
} }
@Override @Override
public String whereJoinFragment(String alias, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { public String whereJoinFragment(
String alias,
boolean innerJoin,
boolean includeSubclasses,
Set<String> treatAsDeclarations) {
return ""; return "";
} }
@Override @Override
protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) { protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) {
return new SubselectCollectionLoader( return new SubselectCollectionLoader(
this, this,
subselect.toSubselectString( getCollectionType().getLHSPropertyName() ), subselect.toSubselectString( getCollectionType().getLHSPropertyName() ),
subselect.getResult(), subselect.getResult(),
subselect.getQueryParameters(), subselect.getQueryParameters(),
subselect.getNamedParameterLocMap(), subselect.getNamedParameterLocMap(),
session.getFactory(), session.getFactory(),
session.getLoadQueryInfluencers() session.getLoadQueryInfluencers()
); );
} }
@Override @Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) { public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return new StaticFilterAliasGenerator(rootAlias); return new StaticFilterAliasGenerator( rootAlias );
} }
} }

View File

@ -43,7 +43,9 @@ public Type toType(String propertyName) throws QueryException {
return memberPersister.getElementType(); return memberPersister.getElementType();
} }
else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_INDICES) ) { else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_INDICES) ) {
if ( !memberPersister.hasIndex() ) throw new QueryException("unindexed collection before indices()"); if ( !memberPersister.hasIndex() ) {
throw new QueryException("unindexed collection before indices()");
}
return memberPersister.getIndexType(); return memberPersister.getIndexType();
} }
else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_SIZE) ) { else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_SIZE) ) {

View File

@ -30,21 +30,19 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.AbstractQueryImpl; import org.hibernate.internal.AbstractQueryImpl;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.loader.collection.CollectionInitializer; import org.hibernate.loader.collection.CollectionInitializer;
import org.jboss.logging.Logger;
/** /**
* A wrapper around a named query. * A wrapper around a named query.
*
* @author Gavin King * @author Gavin King
*/ */
public final class NamedQueryCollectionInitializer implements CollectionInitializer { public final class NamedQueryCollectionInitializer implements CollectionInitializer {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( NamedQueryCollectionInitializer.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, private final String queryName;
NamedQueryCollectionInitializer.class.getName());
private final String queryName;
private final CollectionPersister persister; private final CollectionPersister persister;
public NamedQueryCollectionInitializer(String queryName, CollectionPersister persister) { public NamedQueryCollectionInitializer(String queryName, CollectionPersister persister) {
@ -53,26 +51,22 @@ public NamedQueryCollectionInitializer(String queryName, CollectionPersister per
this.persister = persister; this.persister = persister;
} }
public void initialize(Serializable key, SessionImplementor session) public void initialize(Serializable key, SessionImplementor session) throws HibernateException {
throws HibernateException { LOG.debugf( "Initializing collection: %s using named query: %s", persister.getRole(), queryName );
LOG.debugf("Initializing collection: %s using named query: %s", persister.getRole(), queryName);
//TODO: is there a more elegant way than downcasting? //TODO: is there a more elegant way than downcasting?
AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery(queryName); AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery( queryName );
if ( query.getNamedParameters().length>0 ) { if ( query.getNamedParameters().length > 0 ) {
query.setParameter( query.setParameter(
query.getNamedParameters()[0], query.getNamedParameters()[0],
key, key,
persister.getKeyType() persister.getKeyType()
); );
} }
else { else {
query.setParameter( 0, key, persister.getKeyType() ); query.setParameter( 0, key, persister.getKeyType() );
} }
query.setCollectionKey( key )
.setFlushMode( FlushMode.MANUAL )
.list();
query.setCollectionKey( key ).setFlushMode( FlushMode.MANUAL ).list();
} }
} }

View File

@ -67,12 +67,12 @@ public class OneToManyPersister extends AbstractCollectionPersister {
private final boolean keyIsUpdateable; private final boolean keyIsUpdateable;
@Override @Override
protected boolean isRowDeleteEnabled() { protected boolean isRowDeleteEnabled() {
return keyIsUpdateable && keyIsNullable; return keyIsUpdateable && keyIsNullable;
} }
@Override @Override
protected boolean isRowInsertEnabled() { protected boolean isRowInsertEnabled() {
return keyIsUpdateable; return keyIsUpdateable;
} }
@ -95,24 +95,24 @@ public OneToManyPersister(
* Generate the SQL UPDATE that updates all the foreign keys to null * Generate the SQL UPDATE that updates all the foreign keys to null
*/ */
@Override @Override
protected String generateDeleteString() { protected String generateDeleteString() {
final Update update = new Update( getDialect() ) final Update update = new Update( getDialect() )
.setTableName( qualifiedTableName ) .setTableName( qualifiedTableName )
.addColumns( keyColumnNames, "null" ) .addColumns( keyColumnNames, "null" )
.addPrimaryKeyColumns( keyColumnNames ); .addPrimaryKeyColumns( keyColumnNames );
if ( hasIndex && !indexContainsFormula ) { if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames, "null" ); update.addColumns( indexColumnNames, "null" );
} }
if ( hasWhere ) { if ( hasWhere ) {
update.setWhere( sqlWhereString ); update.setWhere( sqlWhereString );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
update.setComment( "delete one-to-many " + getRole() ); update.setComment( "delete one-to-many " + getRole() );
} }
return update.toStatementString(); return update.toStatementString();
} }
@ -120,21 +120,21 @@ protected String generateDeleteString() {
* Generate the SQL UPDATE that updates a foreign key to a value * Generate the SQL UPDATE that updates a foreign key to a value
*/ */
@Override @Override
protected String generateInsertRowString() { protected String generateInsertRowString() {
final Update update = new Update( getDialect() ) final Update update = new Update( getDialect() )
.setTableName( qualifiedTableName ) .setTableName( qualifiedTableName )
.addColumns( keyColumnNames ); .addColumns( keyColumnNames );
if ( hasIndex && !indexContainsFormula ) { if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames ); update.addColumns( indexColumnNames );
} }
//identifier collections not supported for 1-to-many //identifier collections not supported for 1-to-many
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
update.setComment( "create one-to-many row " + getRole() ); update.setComment( "create one-to-many row " + getRole() );
} }
return update.addPrimaryKeyColumns( elementColumnNames, elementColumnWriters ) return update.addPrimaryKeyColumns( elementColumnNames, elementColumnWriters )
.toStatementString(); .toStatementString();
} }
@ -143,16 +143,16 @@ protected String generateInsertRowString() {
* Generate the SQL UPDATE that inserts a collection index * Generate the SQL UPDATE that inserts a collection index
*/ */
@Override @Override
protected String generateUpdateRowString() { protected String generateUpdateRowString() {
final Update update = new Update( getDialect() ).setTableName( qualifiedTableName ); final Update update = new Update( getDialect() ).setTableName( qualifiedTableName );
update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters );
if ( hasIdentifier ) { if ( hasIdentifier ) {
update.addPrimaryKeyColumns( new String[]{ identifierColumnName } ); update.addPrimaryKeyColumns( new String[] {identifierColumnName} );
} }
if ( hasIndex && !indexContainsFormula ) { if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames ); update.addColumns( indexColumnNames );
} }
return update.toStatementString(); return update.toStatementString();
} }
@ -161,19 +161,19 @@ protected String generateUpdateRowString() {
* key to null * key to null
*/ */
@Override @Override
protected String generateDeleteRowString() { protected String generateDeleteRowString() {
final Update update = new Update( getDialect() ) final Update update = new Update( getDialect() )
.setTableName( qualifiedTableName ) .setTableName( qualifiedTableName )
.addColumns( keyColumnNames, "null" ); .addColumns( keyColumnNames, "null" );
if ( hasIndex && !indexContainsFormula ) { if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames, "null" ); update.addColumns( indexColumnNames, "null" );
} }
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) { if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
update.setComment( "delete one-to-many row " + getRole() ); update.setComment( "delete one-to-many row " + getRole() );
} }
//use a combination of foreign key columns and pk columns, since //use a combination of foreign key columns and pk columns, since
//the ordering of removal and addition is not guaranteed when //the ordering of removal and addition is not guaranteed when
//a child moves from one parent to another //a child moves from one parent to another
@ -181,21 +181,21 @@ protected String generateDeleteRowString() {
return update.addPrimaryKeyColumns( rowSelectColumnNames ) return update.addPrimaryKeyColumns( rowSelectColumnNames )
.toStatementString(); .toStatementString();
} }
@Override @Override
public void recreate(PersistentCollection collection, Serializable id, SessionImplementor session) public void recreate(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException { throws HibernateException {
super.recreate( collection, id, session ); super.recreate( collection, id, session );
writeIndex( collection, collection.entries( this ), id, true, session ); writeIndex( collection, collection.entries( this ), id, true, session );
} }
@Override @Override
public void insertRows(PersistentCollection collection, Serializable id, SessionImplementor session) public void insertRows(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException { throws HibernateException {
super.insertRows( collection, id, session ); super.insertRows( collection, id, session );
writeIndex( collection, collection.entries( this ), id, true, session ); writeIndex( collection, collection.entries( this ), id, true, session );
} }
@Override @Override
protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session) protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException { throws HibernateException {
@ -229,7 +229,7 @@ private void writeIndex(
recreateBatchKey = new BasicBatchKey( recreateBatchKey = new BasicBatchKey(
getRole() + "#RECREATE", getRole() + "#RECREATE",
expectation expectation
); );
} }
st = session st = session
.getJdbcCoordinator() .getJdbcCoordinator()
@ -246,9 +246,19 @@ private void writeIndex(
try { try {
offset += expectation.prepare( st ); offset += expectation.prepare( st );
if ( hasIdentifier ) { if ( hasIdentifier ) {
offset = writeIdentifier( st, collection.getIdentifier( entry, nextIndex ), offset, session ); offset = writeIdentifier(
st,
collection.getIdentifier( entry, nextIndex ),
offset,
session
);
} }
offset = writeIndex( st, collection.getIndex( entry, nextIndex, this ), offset, session ); offset = writeIndex(
st,
collection.getIndex( entry, nextIndex, this ),
offset,
session
);
offset = writeElement( st, collection.getElement( entry ), offset, session ); offset = writeElement( st, collection.getElement( entry ), offset, session );
if ( useBatch ) { if ( useBatch ) {
@ -257,10 +267,14 @@ private void writeIndex(
.addToBatch(); .addToBatch();
} }
else { else {
expectation.verifyOutcome( session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 ); expectation.verifyOutcome(
session.getJdbcCoordinator()
.getResultSetReturn()
.executeUpdate( st ), st, -1
);
} }
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
if ( useBatch ) { if ( useBatch ) {
session.getJdbcCoordinator().abortBatch(); session.getJdbcCoordinator().abortBatch();
} }
@ -278,7 +292,7 @@ private void writeIndex(
} }
} }
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw sqlExceptionHelper.convert( throw sqlExceptionHelper.convert(
sqle, sqle,
"could not update collection: " + "could not update collection: " +
@ -292,6 +306,7 @@ private void writeIndex(
public boolean consumesEntityAlias() { public boolean consumesEntityAlias() {
return true; return true;
} }
public boolean consumesCollectionAlias() { public boolean consumesCollectionAlias() {
return true; return true;
} }
@ -301,7 +316,7 @@ public boolean isOneToMany() {
} }
@Override @Override
public boolean isManyToMany() { public boolean isManyToMany() {
return false; return false;
} }
@ -309,11 +324,11 @@ public boolean isManyToMany() {
private BasicBatchKey insertRowBatchKey; private BasicBatchKey insertRowBatchKey;
@Override @Override
protected int doUpdateRows(Serializable id, PersistentCollection collection, SessionImplementor session) { protected int doUpdateRows(Serializable id, PersistentCollection collection, SessionImplementor session) {
// we finish all the "removes" first to take care of possible unique // we finish all the "removes" first to take care of possible unique
// constraints and so that we can take better advantage of batching // constraints and so that we can take better advantage of batching
try { try {
int count = 0; int count = 0;
if ( isRowDeleteEnabled() ) { if ( isRowDeleteEnabled() ) {
@ -335,7 +350,11 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
int offset = 1; int offset = 1;
while ( entries.hasNext() ) { while ( entries.hasNext() ) {
Object entry = entries.next(); Object entry = entries.next();
if ( collection.needsUpdating( entry, i, elementType ) ) { // will still be issued when it used to be null if ( collection.needsUpdating(
entry,
i,
elementType
) ) { // will still be issued when it used to be null
if ( useBatch ) { if ( useBatch ) {
st = session st = session
.getJdbcCoordinator() .getJdbcCoordinator()
@ -349,7 +368,7 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
.prepareStatement( sql, isDeleteCallable() ); .prepareStatement( sql, isDeleteCallable() );
} }
int loc = writeKey( st, id, offset, session ); int loc = writeKey( st, id, offset, session );
writeElementToWhere( st, collection.getSnapshotElement(entry, i), loc, session ); writeElementToWhere( st, collection.getSnapshotElement( entry, i ), loc, session );
if ( useBatch ) { if ( useBatch ) {
session session
.getJdbcCoordinator() .getJdbcCoordinator()
@ -357,14 +376,18 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
.addToBatch(); .addToBatch();
} }
else { else {
deleteExpectation.verifyOutcome( session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 ); deleteExpectation.verifyOutcome(
session.getJdbcCoordinator()
.getResultSetReturn()
.executeUpdate( st ), st, -1
);
} }
count++; count++;
} }
i++; i++;
} }
} }
catch ( SQLException e ) { catch (SQLException e) {
if ( useBatch ) { if ( useBatch ) {
session.getJdbcCoordinator().abortBatch(); session.getJdbcCoordinator().abortBatch();
} }
@ -377,7 +400,7 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
} }
} }
} }
if ( isRowInsertEnabled() ) { if ( isRowInsertEnabled() ) {
final Expectation insertExpectation = Expectations.appropriateExpectation( getInsertCheckStyle() ); final Expectation insertExpectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
boolean useBatch = insertExpectation.canBeBatched(); boolean useBatch = insertExpectation.canBeBatched();
@ -425,14 +448,18 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
session.getJdbcCoordinator().getBatch( insertRowBatchKey ).addToBatch(); session.getJdbcCoordinator().getBatch( insertRowBatchKey ).addToBatch();
} }
else { else {
insertExpectation.verifyOutcome( session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 ); insertExpectation.verifyOutcome(
session.getJdbcCoordinator()
.getResultSetReturn()
.executeUpdate( st ), st, -1
);
} }
count++; count++;
} }
i++; i++;
} }
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
if ( useBatch ) { if ( useBatch ) {
session.getJdbcCoordinator().abortBatch(); session.getJdbcCoordinator().abortBatch();
} }
@ -448,30 +475,30 @@ protected int doUpdateRows(Serializable id, PersistentCollection collection, Ses
return count; return count;
} }
catch ( SQLException sqle ) { catch (SQLException sqle) {
throw getFactory().getSQLExceptionHelper().convert( throw getFactory().getSQLExceptionHelper().convert(
sqle, sqle,
"could not update collection rows: " + "could not update collection rows: " +
MessageHelper.collectionInfoString( this, collection, id, session ), MessageHelper.collectionInfoString( this, collection, id, session ),
getSQLInsertRowString() getSQLInsertRowString()
); );
} }
} }
public String selectFragment( public String selectFragment(
Joinable rhs, Joinable rhs,
String rhsAlias, String rhsAlias,
String lhsAlias, String lhsAlias,
String entitySuffix, String entitySuffix,
String collectionSuffix, String collectionSuffix,
boolean includeCollectionColumns) { boolean includeCollectionColumns) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
if ( includeCollectionColumns ) { if ( includeCollectionColumns ) {
// buf.append( selectFragment( lhsAlias, "" ) )//ignore suffix for collection columns! // buf.append( selectFragment( lhsAlias, "" ) )//ignore suffix for collection columns!
buf.append( selectFragment( lhsAlias, collectionSuffix ) ) buf.append( selectFragment( lhsAlias, collectionSuffix ) )
.append( ", " ); .append( ", " );
} }
OuterJoinLoadable ojl = ( OuterJoinLoadable ) getElementPersister(); OuterJoinLoadable ojl = (OuterJoinLoadable) getElementPersister();
return buf.append( ojl.selectFragment( lhsAlias, entitySuffix ) )//use suffix for the entity columns return buf.append( ojl.selectFragment( lhsAlias, entitySuffix ) )//use suffix for the entity columns
.toString(); .toString();
} }
@ -482,7 +509,7 @@ public String selectFragment(
* @see org.hibernate.loader.collection.OneToManyLoader * @see org.hibernate.loader.collection.OneToManyLoader
*/ */
@Override @Override
protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers) protected CollectionInitializer createCollectionInitializer(LoadQueryInfluencers loadQueryInfluencers)
throws MappingException { throws MappingException {
return BatchingCollectionInitializerBuilder.getBuilder( getFactory() ) return BatchingCollectionInitializerBuilder.getBuilder( getFactory() )
.createBatchingOneToManyInitializer( this, batchSize, getFactory(), loadQueryInfluencers ); .createBatchingOneToManyInitializer( this, batchSize, getFactory(), loadQueryInfluencers );
@ -499,7 +526,12 @@ public String fromJoinFragment(
boolean innerJoin, boolean innerJoin,
boolean includeSubclasses, boolean includeSubclasses,
Set<String> treatAsDeclarations) { Set<String> treatAsDeclarations) {
return ( (Joinable) getElementPersister() ).fromJoinFragment( alias, innerJoin, includeSubclasses, treatAsDeclarations ); return ( (Joinable) getElementPersister() ).fromJoinFragment(
alias,
innerJoin,
includeSubclasses,
treatAsDeclarations
);
} }
@Override @Override
@ -513,19 +545,24 @@ public String whereJoinFragment(
boolean innerJoin, boolean innerJoin,
boolean includeSubclasses, boolean includeSubclasses,
Set<String> treatAsDeclarations) { Set<String> treatAsDeclarations) {
return ( (Joinable) getElementPersister() ).whereJoinFragment( alias, innerJoin, includeSubclasses, treatAsDeclarations ); return ( (Joinable) getElementPersister() ).whereJoinFragment(
alias,
innerJoin,
includeSubclasses,
treatAsDeclarations
);
} }
@Override @Override
public String getTableName() { public String getTableName() {
return ( (Joinable) getElementPersister() ).getTableName(); return ( (Joinable) getElementPersister() ).getTableName();
} }
@Override @Override
public String filterFragment(String alias) throws MappingException { public String filterFragment(String alias) throws MappingException {
String result = super.filterFragment( alias ); String result = super.filterFragment( alias );
if ( getElementPersister() instanceof Joinable ) { if ( getElementPersister() instanceof Joinable ) {
result += ( ( Joinable ) getElementPersister() ).oneToManyFilterFragment( alias ); result += ( (Joinable) getElementPersister() ).oneToManyFilterFragment( alias );
} }
return result; return result;
@ -535,14 +572,14 @@ public String filterFragment(String alias) throws MappingException {
protected String filterFragment(String alias, Set<String> treatAsDeclarations) throws MappingException { protected String filterFragment(String alias, Set<String> treatAsDeclarations) throws MappingException {
String result = super.filterFragment( alias ); String result = super.filterFragment( alias );
if ( getElementPersister() instanceof Joinable ) { if ( getElementPersister() instanceof Joinable ) {
result += ( ( Joinable ) getElementPersister() ).oneToManyFilterFragment( alias, treatAsDeclarations ); result += ( (Joinable) getElementPersister() ).oneToManyFilterFragment( alias, treatAsDeclarations );
} }
return result; return result;
} }
@Override @Override
protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) { protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) {
return new SubselectOneToManyLoader( return new SubselectOneToManyLoader(
this, this,
subselect.toSubselectString( getCollectionType().getLHSPropertyName() ), subselect.toSubselectString( getCollectionType().getLHSPropertyName() ),
subselect.getResult(), subselect.getResult(),
@ -550,18 +587,18 @@ protected CollectionInitializer createSubselectInitializer(SubselectFetch subsel
subselect.getNamedParameterLocMap(), subselect.getNamedParameterLocMap(),
session.getFactory(), session.getFactory(),
session.getLoadQueryInfluencers() session.getLoadQueryInfluencers()
); );
} }
@Override @Override
public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner) { public Object getElementByIndex(Serializable key, Object index, SessionImplementor session, Object owner) {
return new CollectionElementLoader( this, getFactory(), session.getLoadQueryInfluencers() ) return new CollectionElementLoader( this, getFactory(), session.getLoadQueryInfluencers() )
.loadElement( session, key, incrementIndexByBase(index) ); .loadElement( session, key, incrementIndexByBase( index ) );
} }
@Override @Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) { public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return getElementPersister().getFilterAliasGenerator(rootAlias); return getElementPersister().getFilterAliasGenerator( rootAlias );
} }
} }

View File

@ -40,38 +40,36 @@
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/** /**
* Basic implementation of the {@link PropertyMapping} contract. * Basic implementation of the {@link PropertyMapping} contract.
* *
* @author Gavin King * @author Gavin King
*/ */
public abstract class AbstractPropertyMapping implements PropertyMapping { public abstract class AbstractPropertyMapping implements PropertyMapping {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPropertyMapping.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPropertyMapping.class );
private final Map typesByPropertyPath = new HashMap(); private final Map<String, Type> typesByPropertyPath = new HashMap<String, Type>();
private final Map columnsByPropertyPath = new HashMap(); private final Map<String, String[]> columnsByPropertyPath = new HashMap<String, String[]>();
private final Map columnReadersByPropertyPath = new HashMap(); private final Map<String, String[]> columnReadersByPropertyPath = new HashMap<String, String[]>();
private final Map columnReaderTemplatesByPropertyPath = new HashMap(); private final Map<String, String[]> columnReaderTemplatesByPropertyPath = new HashMap<String, String[]>();
private final Map formulaTemplatesByPropertyPath = new HashMap(); private final Map<String, String[]> formulaTemplatesByPropertyPath = new HashMap<String, String[]>();
public String[] getIdentifierColumnNames() { public String[] getIdentifierColumnNames() {
throw new UnsupportedOperationException("one-to-one is not supported here"); throw new UnsupportedOperationException( "one-to-one is not supported here" );
} }
public String[] getIdentifierColumnReaderTemplates() { public String[] getIdentifierColumnReaderTemplates() {
throw new UnsupportedOperationException("one-to-one is not supported here"); throw new UnsupportedOperationException( "one-to-one is not supported here" );
} }
public String[] getIdentifierColumnReaders() { public String[] getIdentifierColumnReaders() {
throw new UnsupportedOperationException("one-to-one is not supported here"); throw new UnsupportedOperationException( "one-to-one is not supported here" );
} }
protected abstract String getEntityName(); protected abstract String getEntityName();
public Type toType(String propertyName) throws QueryException { public Type toType(String propertyName) throws QueryException {
Type type = (Type) typesByPropertyPath.get(propertyName); Type type = typesByPropertyPath.get( propertyName );
if ( type == null ) { if ( type == null ) {
throw propertyException( propertyName ); throw propertyException( propertyName );
} }
@ -83,24 +81,24 @@ protected final QueryException propertyException(String propertyName) throws Que
} }
public String[] getColumnNames(String propertyName) { public String[] getColumnNames(String propertyName) {
String[] cols = (String[]) columnsByPropertyPath.get(propertyName); String[] cols = columnsByPropertyPath.get( propertyName );
if (cols==null) { if ( cols == null ) {
throw new MappingException("unknown property: " + propertyName); throw new MappingException( "unknown property: " + propertyName );
} }
return cols; return cols;
} }
public String[] toColumns(String alias, String propertyName) throws QueryException { public String[] toColumns(String alias, String propertyName) throws QueryException {
//TODO: *two* hashmap lookups here is one too many... //TODO: *two* hashmap lookups here is one too many...
String[] columns = (String[]) columnsByPropertyPath.get(propertyName); String[] columns = columnsByPropertyPath.get( propertyName );
if ( columns == null ) { if ( columns == null ) {
throw propertyException( propertyName ); throw propertyException( propertyName );
} }
String[] formulaTemplates = (String[]) formulaTemplatesByPropertyPath.get(propertyName); String[] formulaTemplates = formulaTemplatesByPropertyPath.get( propertyName );
String[] columnReaderTemplates = (String[]) columnReaderTemplatesByPropertyPath.get(propertyName); String[] columnReaderTemplates = columnReaderTemplatesByPropertyPath.get( propertyName );
String[] result = new String[columns.length]; String[] result = new String[columns.length];
for ( int i=0; i<columns.length; i++ ) { for ( int i = 0; i < columns.length; i++ ) {
if ( columnReaderTemplates[i]==null ) { if ( columnReaderTemplates[i] == null ) {
result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, alias ); result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, alias );
} }
else { else {
@ -111,15 +109,15 @@ public String[] toColumns(String alias, String propertyName) throws QueryExcepti
} }
public String[] toColumns(String propertyName) throws QueryException { public String[] toColumns(String propertyName) throws QueryException {
String[] columns = (String[]) columnsByPropertyPath.get(propertyName); String[] columns = columnsByPropertyPath.get( propertyName );
if ( columns == null ) { if ( columns == null ) {
throw propertyException( propertyName ); throw propertyException( propertyName );
} }
String[] formulaTemplates = (String[]) formulaTemplatesByPropertyPath.get(propertyName); String[] formulaTemplates = formulaTemplatesByPropertyPath.get( propertyName );
String[] columnReaders = (String[]) columnReadersByPropertyPath.get(propertyName); String[] columnReaders = columnReadersByPropertyPath.get( propertyName );
String[] result = new String[columns.length]; String[] result = new String[columns.length];
for ( int i=0; i<columns.length; i++ ) { for ( int i = 0; i < columns.length; i++ ) {
if ( columnReaders[i]==null ) { if ( columnReaders[i] == null ) {
result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, "" ); result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, "" );
} }
else { else {
@ -139,16 +137,21 @@ protected void addPropertyPath(
// TODO : not quite sure yet of the difference, but this is only needed from annotations for @Id @ManyToOne support // TODO : not quite sure yet of the difference, but this is only needed from annotations for @Id @ManyToOne support
if ( typesByPropertyPath.containsKey( path ) ) { if ( typesByPropertyPath.containsKey( path ) ) {
if ( LOG.isTraceEnabled() ) { if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Skipping duplicate registration of path [{0}], existing type = [{1}], incoming type = [{2}]", path, typesByPropertyPath.get( path ), type ); LOG.tracev(
"Skipping duplicate registration of path [{0}], existing type = [{1}], incoming type = [{2}]",
path,
typesByPropertyPath.get( path ),
type
);
} }
return; return;
} }
typesByPropertyPath.put(path, type); typesByPropertyPath.put( path, type );
columnsByPropertyPath.put(path, columns); columnsByPropertyPath.put( path, columns );
columnReadersByPropertyPath.put(path, columnReaders); columnReadersByPropertyPath.put( path, columnReaders );
columnReaderTemplatesByPropertyPath.put(path, columnReaderTemplates); columnReaderTemplatesByPropertyPath.put( path, columnReaderTemplates );
if (formulaTemplates!=null) { if ( formulaTemplates != null ) {
formulaTemplatesByPropertyPath.put(path, formulaTemplates); formulaTemplatesByPropertyPath.put( path, formulaTemplates );
} }
} }
@ -174,11 +177,11 @@ protected void initPropertyPaths(
assert columns != null : "Incoming columns should not be null : " + path; assert columns != null : "Incoming columns should not be null : " + path;
assert type != null : "Incoming type should not be null : " + path; assert type != null : "Incoming type should not be null : " + path;
if ( columns.length!=type.getColumnSpan(factory) ) { if ( columns.length != type.getColumnSpan( factory ) ) {
throw new MappingException( throw new MappingException(
"broken column mapping for: " + path + "broken column mapping for: " + path +
" of: " + getEntityName() " of: " + getEntityName()
); );
} }
if ( type.isAssociationType() ) { if ( type.isAssociationType() ) {
@ -190,38 +193,55 @@ protected void initPropertyPaths(
} }
else { else {
String foreignKeyProperty = actype.getLHSPropertyName(); String foreignKeyProperty = actype.getLHSPropertyName();
if ( foreignKeyProperty!=null && !path.equals(foreignKeyProperty) ) { if ( foreignKeyProperty != null && !path.equals( foreignKeyProperty ) ) {
//TODO: this requires that the collection is defined after the //TODO: this requires that the collection is defined after the
// referenced property in the mapping file (ok?) // referenced property in the mapping file (ok?)
columns = (String[]) columnsByPropertyPath.get(foreignKeyProperty); columns = columnsByPropertyPath.get( foreignKeyProperty );
if (columns==null) return; //get em on the second pass! if ( columns == null ) {
columnReaders = (String[]) columnReadersByPropertyPath.get(foreignKeyProperty); return; //get em on the second pass!
columnReaderTemplates = (String[]) columnReaderTemplatesByPropertyPath.get(foreignKeyProperty); }
columnReaders = columnReadersByPropertyPath.get( foreignKeyProperty );
columnReaderTemplates = columnReaderTemplatesByPropertyPath.get( foreignKeyProperty );
} }
} }
} }
if (path!=null) { if ( path != null ) {
addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates); addPropertyPath( path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates );
} }
if ( type.isComponentType() ) { if ( type.isComponentType() ) {
CompositeType actype = (CompositeType) type; CompositeType actype = (CompositeType) type;
initComponentPropertyPaths( path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory ); initComponentPropertyPaths(
path,
actype,
columns,
columnReaders,
columnReaderTemplates,
formulaTemplates,
factory
);
if ( actype.isEmbedded() ) { if ( actype.isEmbedded() ) {
initComponentPropertyPaths( initComponentPropertyPaths(
path==null ? null : StringHelper.qualifier(path), path == null ? null : StringHelper.qualifier( path ),
actype, actype,
columns, columns,
columnReaders, columnReaders,
columnReaderTemplates, columnReaderTemplates,
formulaTemplates, formulaTemplates,
factory factory
); );
} }
} }
else if ( type.isEntityType() ) { else if ( type.isEntityType() ) {
initIdentifierPropertyPaths( path, (EntityType) type, columns, columnReaders, columnReaderTemplates, factory ); initIdentifierPropertyPaths(
path,
(EntityType) type,
columns,
columnReaders,
columnReaderTemplates,
factory
);
} }
} }
@ -234,21 +254,21 @@ protected void initIdentifierPropertyPaths(
final Mapping factory) throws MappingException { final Mapping factory) throws MappingException {
Type idtype = etype.getIdentifierOrUniqueKeyType( factory ); Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory); String idPropName = etype.getIdentifierOrUniqueKeyPropertyName( factory );
boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory ); boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory );
if ( etype.isReferenceToPrimaryKey() ) { if ( etype.isReferenceToPrimaryKey() ) {
if ( !hasNonIdentifierPropertyNamedId ) { if ( !hasNonIdentifierPropertyNamedId ) {
String idpath1 = extendPath(path, EntityPersister.ENTITY_ID); String idpath1 = extendPath( path, EntityPersister.ENTITY_ID );
addPropertyPath(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null); addPropertyPath( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null );
initPropertyPaths(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory); initPropertyPaths( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
} }
} }
if (idPropName!=null) { if ( idPropName != null ) {
String idpath2 = extendPath(path, idPropName); String idpath2 = extendPath( path, idPropName );
addPropertyPath(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null); addPropertyPath( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null );
initPropertyPaths(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory); initPropertyPaths( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
} }
} }
@ -257,9 +277,12 @@ private boolean hasNonIdentifierPropertyNamedId(final EntityType entityType, fin
// I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so // I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so
// if it returns for a property named 'id', then we should have a non-id field named id // if it returns for a property named 'id', then we should have a non-id field named id
try { try {
return factory.getReferencedPropertyType( entityType.getAssociatedEntityName(), EntityPersister.ENTITY_ID ) != null; return factory.getReferencedPropertyType(
entityType.getAssociatedEntityName(),
EntityPersister.ENTITY_ID
) != null;
} }
catch( MappingException e ) { catch (MappingException e) {
return false; return false;
} }
} }
@ -274,21 +297,29 @@ protected void initComponentPropertyPaths(
Type[] types = type.getSubtypes(); Type[] types = type.getSubtypes();
String[] properties = type.getPropertyNames(); String[] properties = type.getPropertyNames();
int begin=0; int begin = 0;
for ( int i=0; i<properties.length; i++ ) { for ( int i = 0; i < properties.length; i++ ) {
String subpath = extendPath( path, properties[i] ); String subpath = extendPath( path, properties[i] );
try { try {
int length = types[i].getColumnSpan(factory); int length = types[i].getColumnSpan( factory );
String[] columnSlice = ArrayHelper.slice(columns, begin, length); String[] columnSlice = ArrayHelper.slice( columns, begin, length );
String[] columnReaderSlice = ArrayHelper.slice(columnReaders, begin, length); String[] columnReaderSlice = ArrayHelper.slice( columnReaders, begin, length );
String[] columnReaderTemplateSlice = ArrayHelper.slice( columnReaderTemplates, begin, length ); String[] columnReaderTemplateSlice = ArrayHelper.slice( columnReaderTemplates, begin, length );
String[] formulaSlice = formulaTemplates==null ? String[] formulaSlice = formulaTemplates == null ?
null : ArrayHelper.slice(formulaTemplates, begin, length); null : ArrayHelper.slice( formulaTemplates, begin, length );
initPropertyPaths(subpath, types[i], columnSlice, columnReaderSlice, columnReaderTemplateSlice, formulaSlice, factory); initPropertyPaths(
begin+=length; subpath,
types[i],
columnSlice,
columnReaderSlice,
columnReaderTemplateSlice,
formulaSlice,
factory
);
begin += length;
} }
catch (Exception e) { catch (Exception e) {
throw new MappingException("bug in initComponentPropertyPaths", e); throw new MappingException( "bug in initComponentPropertyPaths", e );
} }
} }
} }

View File

@ -31,12 +31,12 @@
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.internal.util.compare.EqualsHelper;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.type.AbstractType; import org.hibernate.type.AbstractType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -87,7 +87,7 @@ public Object nullSafeGet(
throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" ); throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" );
} }
final EntityPersister entityPersister = session.getEntityPersister( entityName, null ); final EntityPersister entityPersister = session.getEntityPersister( entityName, null );
return ( EntityMode.POJO == entityPersister.getEntityMode() ) ? entityPersister.getMappedClass() : entityName; return ( EntityMode.POJO == entityPersister.getEntityMode() ) ? entityPersister.getMappedClass() : entityName;
} }
public void nullSafeSet( public void nullSafeSet(

View File

@ -79,7 +79,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String[][] keyColumnNames; private final String[][] keyColumnNames;
private final boolean[] cascadeDeleteEnabled; private final boolean[] cascadeDeleteEnabled;
private final boolean hasSequentialSelects; private final boolean hasSequentialSelects;
private final String[] spaces; private final String[] spaces;
private final String[] subclassClosure; private final String[] subclassClosure;
@ -103,7 +103,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final int[] subclassFormulaTableNumberClosure; private final int[] subclassFormulaTableNumberClosure;
// discriminator column // discriminator column
private final Map subclassesByDiscriminatorValue = new HashMap(); private final Map<Object, String> subclassesByDiscriminatorValue = new HashMap<Object, String>();
private final boolean forceDiscriminator; private final boolean forceDiscriminator;
private final String discriminatorColumnName; private final String discriminatorColumnName;
private final String discriminatorColumnReaders; private final String discriminatorColumnReaders;
@ -120,19 +120,19 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String[][] constraintOrderedKeyColumnNames; private final String[][] constraintOrderedKeyColumnNames;
//private final Map propertyTableNumbersByName = new HashMap(); //private final Map propertyTableNumbersByName = new HashMap();
private final Map propertyTableNumbersByNameAndSubclass = new HashMap(); private final Map<String, Integer> propertyTableNumbersByNameAndSubclass = new HashMap<String, Integer>();
private final Map sequentialSelectStringsByEntityName = new HashMap();
private static final Object NULL_DISCRIMINATOR = new MarkerObject("<null discriminator>"); private final Map<String, String> sequentialSelectStringsByEntityName = new HashMap<String, String>();
private static final Object NOT_NULL_DISCRIMINATOR = new MarkerObject("<not null discriminator>");
private static final Object NULL_DISCRIMINATOR = new MarkerObject( "<null discriminator>" );
private static final Object NOT_NULL_DISCRIMINATOR = new MarkerObject( "<not null discriminator>" );
private static final String NULL_STRING = "null"; private static final String NULL_STRING = "null";
private static final String NOT_NULL_STRING = "not null"; private static final String NOT_NULL_STRING = "not null";
//INITIALIZATION: //INITIALIZATION:
public SingleTableEntityPersister( public SingleTableEntityPersister(
final PersistentClass persistentClass, final PersistentClass persistentClass,
final EntityRegionAccessStrategy cacheAccessStrategy, final EntityRegionAccessStrategy cacheAccessStrategy,
final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy,
final PersisterCreationContext creationContext) throws HibernateException { final PersisterCreationContext creationContext) throws HibernateException {
@ -143,16 +143,16 @@ public SingleTableEntityPersister(
// CLASS + TABLE // CLASS + TABLE
joinSpan = persistentClass.getJoinClosureSpan()+1; joinSpan = persistentClass.getJoinClosureSpan() + 1;
qualifiedTableNames = new String[joinSpan]; qualifiedTableNames = new String[joinSpan];
isInverseTable = new boolean[joinSpan]; isInverseTable = new boolean[joinSpan];
isNullableTable = new boolean[joinSpan]; isNullableTable = new boolean[joinSpan];
keyColumnNames = new String[joinSpan][]; keyColumnNames = new String[joinSpan][];
final Table table = persistentClass.getRootTable(); final Table table = persistentClass.getRootTable();
qualifiedTableNames[0] = table.getQualifiedName( qualifiedTableNames[0] = table.getQualifiedName(
factory.getDialect(), factory.getDialect(),
factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultSchemaName()
); );
isInverseTable[0] = false; isInverseTable[0] = false;
isNullableTable[0] = false; isNullableTable[0] = false;
@ -173,18 +173,18 @@ public SingleTableEntityPersister(
customSQLInsert[0] = persistentClass.getCustomSQLInsert(); customSQLInsert[0] = persistentClass.getCustomSQLInsert();
insertCallable[0] = customSQLInsert[0] != null && persistentClass.isCustomInsertCallable(); insertCallable[0] = customSQLInsert[0] != null && persistentClass.isCustomInsertCallable();
insertResultCheckStyles[0] = persistentClass.getCustomSQLInsertCheckStyle() == null insertResultCheckStyles[0] = persistentClass.getCustomSQLInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[0], insertCallable[0] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[0], insertCallable[0] )
: persistentClass.getCustomSQLInsertCheckStyle(); : persistentClass.getCustomSQLInsertCheckStyle();
customSQLUpdate[0] = persistentClass.getCustomSQLUpdate(); customSQLUpdate[0] = persistentClass.getCustomSQLUpdate();
updateCallable[0] = customSQLUpdate[0] != null && persistentClass.isCustomUpdateCallable(); updateCallable[0] = customSQLUpdate[0] != null && persistentClass.isCustomUpdateCallable();
updateResultCheckStyles[0] = persistentClass.getCustomSQLUpdateCheckStyle() == null updateResultCheckStyles[0] = persistentClass.getCustomSQLUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[0], updateCallable[0] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[0], updateCallable[0] )
: persistentClass.getCustomSQLUpdateCheckStyle(); : persistentClass.getCustomSQLUpdateCheckStyle();
customSQLDelete[0] = persistentClass.getCustomSQLDelete(); customSQLDelete[0] = persistentClass.getCustomSQLDelete();
deleteCallable[0] = customSQLDelete[0] != null && persistentClass.isCustomDeleteCallable(); deleteCallable[0] = customSQLDelete[0] != null && persistentClass.isCustomDeleteCallable();
deleteResultCheckStyles[0] = persistentClass.getCustomSQLDeleteCheckStyle() == null deleteResultCheckStyles[0] = persistentClass.getCustomSQLDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[0], deleteCallable[0] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[0], deleteCallable[0] )
: persistentClass.getCustomSQLDeleteCheckStyle(); : persistentClass.getCustomSQLDeleteCheckStyle();
// JOINS // JOINS
@ -192,34 +192,34 @@ public SingleTableEntityPersister(
int j = 1; int j = 1;
while ( joinIter.hasNext() ) { while ( joinIter.hasNext() ) {
Join join = (Join) joinIter.next(); Join join = (Join) joinIter.next();
qualifiedTableNames[j] = join.getTable().getQualifiedName( qualifiedTableNames[j] = join.getTable().getQualifiedName(
factory.getDialect(), factory.getDialect(),
factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultSchemaName()
); );
isInverseTable[j] = join.isInverse(); isInverseTable[j] = join.isInverse();
isNullableTable[j] = join.isOptional(); isNullableTable[j] = join.isOptional();
cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() && cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() &&
factory.getDialect().supportsCascadeDelete(); factory.getDialect().supportsCascadeDelete();
customSQLInsert[j] = join.getCustomSQLInsert(); customSQLInsert[j] = join.getCustomSQLInsert();
insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable(); insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
insertResultCheckStyles[j] = join.getCustomSQLInsertCheckStyle() == null insertResultCheckStyles[j] = join.getCustomSQLInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] )
: join.getCustomSQLInsertCheckStyle(); : join.getCustomSQLInsertCheckStyle();
customSQLUpdate[j] = join.getCustomSQLUpdate(); customSQLUpdate[j] = join.getCustomSQLUpdate();
updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable(); updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable();
updateResultCheckStyles[j] = join.getCustomSQLUpdateCheckStyle() == null updateResultCheckStyles[j] = join.getCustomSQLUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] )
: join.getCustomSQLUpdateCheckStyle(); : join.getCustomSQLUpdateCheckStyle();
customSQLDelete[j] = join.getCustomSQLDelete(); customSQLDelete[j] = join.getCustomSQLDelete();
deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable(); deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable();
deleteResultCheckStyles[j] = join.getCustomSQLDeleteCheckStyle() == null deleteResultCheckStyles[j] = join.getCustomSQLDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] ) ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] )
: join.getCustomSQLDeleteCheckStyle(); : join.getCustomSQLDeleteCheckStyle();
Iterator iter = join.getKey().getColumnIterator(); Iterator iter = join.getKey().getColumnIterator();
keyColumnNames[j] = new String[ join.getKey().getColumnSpan() ]; keyColumnNames[j] = new String[join.getKey().getColumnSpan()];
int i = 0; int i = 0;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Column col = (Column) iter.next(); Column col = (Column) iter.next();
@ -237,15 +237,15 @@ public SingleTableEntityPersister(
} }
spaces = ArrayHelper.join( spaces = ArrayHelper.join(
qualifiedTableNames, qualifiedTableNames,
ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() ) ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
); );
final boolean lazyAvailable = isInstrumented(); final boolean lazyAvailable = isInstrumented();
boolean hasDeferred = false; boolean hasDeferred = false;
ArrayList subclassTables = new ArrayList(); ArrayList<String> subclassTables = new ArrayList<String>();
ArrayList joinKeyColumns = new ArrayList(); ArrayList<String[]> joinKeyColumns = new ArrayList<String[]>();
ArrayList<Boolean> isConcretes = new ArrayList<Boolean>(); ArrayList<Boolean> isConcretes = new ArrayList<Boolean>();
ArrayList<Boolean> isDeferreds = new ArrayList<Boolean>(); ArrayList<Boolean> isDeferreds = new ArrayList<Boolean>();
ArrayList<Boolean> isInverses = new ArrayList<Boolean>(); ArrayList<Boolean> isInverses = new ArrayList<Boolean>();
@ -253,59 +253,64 @@ public SingleTableEntityPersister(
ArrayList<Boolean> isLazies = new ArrayList<Boolean>(); ArrayList<Boolean> isLazies = new ArrayList<Boolean>();
subclassTables.add( qualifiedTableNames[0] ); subclassTables.add( qualifiedTableNames[0] );
joinKeyColumns.add( getIdentifierColumnNames() ); joinKeyColumns.add( getIdentifierColumnNames() );
isConcretes.add(Boolean.TRUE); isConcretes.add( Boolean.TRUE );
isDeferreds.add(Boolean.FALSE); isDeferreds.add( Boolean.FALSE );
isInverses.add(Boolean.FALSE); isInverses.add( Boolean.FALSE );
isNullables.add(Boolean.FALSE); isNullables.add( Boolean.FALSE );
isLazies.add(Boolean.FALSE); isLazies.add( Boolean.FALSE );
joinIter = persistentClass.getSubclassJoinClosureIterator(); joinIter = persistentClass.getSubclassJoinClosureIterator();
while ( joinIter.hasNext() ) { while ( joinIter.hasNext() ) {
Join join = (Join) joinIter.next(); Join join = (Join) joinIter.next();
isConcretes.add( persistentClass.isClassOrSuperclassJoin(join) ); isConcretes.add( persistentClass.isClassOrSuperclassJoin( join ) );
isDeferreds.add( join.isSequentialSelect() ); isDeferreds.add( join.isSequentialSelect() );
isInverses.add( join.isInverse() ); isInverses.add( join.isInverse() );
isNullables.add( join.isOptional() ); isNullables.add( join.isOptional() );
isLazies.add( lazyAvailable && join.isLazy() ); isLazies.add( lazyAvailable && join.isLazy() );
if ( join.isSequentialSelect() && !persistentClass.isClassOrSuperclassJoin(join) ) { if ( join.isSequentialSelect() && !persistentClass.isClassOrSuperclassJoin( join ) ) {
hasDeferred = true; hasDeferred = true;
} }
subclassTables.add( join.getTable().getQualifiedName( subclassTables.add(
factory.getDialect(), join.getTable().getQualifiedName(
factory.getSettings().getDefaultCatalogName(), factory.getDialect(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultCatalogName(),
) ); factory.getSettings().getDefaultSchemaName()
)
);
Iterator iter = join.getKey().getColumnIterator(); Iterator iter = join.getKey().getColumnIterator();
String[] keyCols = new String[ join.getKey().getColumnSpan() ]; String[] keyCols = new String[join.getKey().getColumnSpan()];
int i = 0; int i = 0;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Column col = (Column) iter.next(); Column col = (Column) iter.next();
keyCols[i++] = col.getQuotedName( factory.getDialect() ); keyCols[i++] = col.getQuotedName( factory.getDialect() );
} }
joinKeyColumns.add(keyCols); joinKeyColumns.add( keyCols );
} }
subclassTableSequentialSelect = ArrayHelper.toBooleanArray(isDeferreds); subclassTableSequentialSelect = ArrayHelper.toBooleanArray( isDeferreds );
subclassTableNameClosure = ArrayHelper.toStringArray(subclassTables); subclassTableNameClosure = ArrayHelper.toStringArray( subclassTables );
subclassTableIsLazyClosure = ArrayHelper.toBooleanArray(isLazies); subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( joinKeyColumns ); subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( joinKeyColumns );
isClassOrSuperclassTable = ArrayHelper.toBooleanArray(isConcretes); isClassOrSuperclassTable = ArrayHelper.toBooleanArray( isConcretes );
isInverseSubclassTable = ArrayHelper.toBooleanArray(isInverses); isInverseSubclassTable = ArrayHelper.toBooleanArray( isInverses );
isNullableSubclassTable = ArrayHelper.toBooleanArray(isNullables); isNullableSubclassTable = ArrayHelper.toBooleanArray( isNullables );
hasSequentialSelects = hasDeferred; hasSequentialSelects = hasDeferred;
// DISCRIMINATOR // DISCRIMINATOR
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
Value discrimValue = persistentClass.getDiscriminator(); Value discrimValue = persistentClass.getDiscriminator();
if (discrimValue==null) { if ( discrimValue == null ) {
throw new MappingException("discriminator mapping required for single table polymorphic persistence"); throw new MappingException( "discriminator mapping required for single table polymorphic persistence" );
} }
forceDiscriminator = persistentClass.isForceDiscriminator(); forceDiscriminator = persistentClass.isForceDiscriminator();
Selectable selectable = (Selectable) discrimValue.getColumnIterator().next(); Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
if ( discrimValue.hasFormula() ) { if ( discrimValue.hasFormula() ) {
Formula formula = (Formula) selectable; Formula formula = (Formula) selectable;
discriminatorFormula = formula.getFormula(); discriminatorFormula = formula.getFormula();
discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); discriminatorFormulaTemplate = formula.getTemplate(
factory.getDialect(),
factory.getSqlFunctionRegistry()
);
discriminatorColumnName = null; discriminatorColumnName = null;
discriminatorColumnReaders = null; discriminatorColumnReaders = null;
discriminatorColumnReaderTemplate = null; discriminatorColumnReaderTemplate = null;
@ -315,7 +320,10 @@ public SingleTableEntityPersister(
Column column = (Column) selectable; Column column = (Column) selectable;
discriminatorColumnName = column.getQuotedName( factory.getDialect() ); discriminatorColumnName = column.getQuotedName( factory.getDialect() );
discriminatorColumnReaders = column.getReadExpr( factory.getDialect() ); discriminatorColumnReaders = column.getReadExpr( factory.getDialect() );
discriminatorColumnReaderTemplate = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); discriminatorColumnReaderTemplate = column.getTemplate(
factory.getDialect(),
factory.getSqlFunctionRegistry()
);
discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() ); discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
discriminatorFormula = null; discriminatorFormula = null;
discriminatorFormulaTemplate = null; discriminatorFormulaTemplate = null;
@ -339,10 +347,10 @@ else if ( persistentClass.isDiscriminatorValueNotNull() ) {
discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() ); discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() );
} }
catch (ClassCastException cce) { catch (ClassCastException cce) {
throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() ); throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() );
} }
catch (Exception e) { catch (Exception e) {
throw new MappingException("Could not format discriminator value to SQL string", e); throw new MappingException( "Could not format discriminator value to SQL string", e );
} }
} }
} }
@ -362,47 +370,47 @@ else if ( persistentClass.isDiscriminatorValueNotNull() ) {
// PROPERTIES // PROPERTIES
propertyTableNumbers = new int[ getPropertySpan() ]; propertyTableNumbers = new int[getPropertySpan()];
Iterator iter = persistentClass.getPropertyClosureIterator(); Iterator iter = persistentClass.getPropertyClosureIterator();
int i=0; int i = 0;
while( iter.hasNext() ) { while ( iter.hasNext() ) {
Property prop = (Property) iter.next(); Property prop = (Property) iter.next();
propertyTableNumbers[i++] = persistentClass.getJoinNumber(prop); propertyTableNumbers[i++] = persistentClass.getJoinNumber( prop );
} }
//TODO: code duplication with JoinedSubclassEntityPersister //TODO: code duplication with JoinedSubclassEntityPersister
ArrayList columnJoinNumbers = new ArrayList(); ArrayList<Integer> columnJoinNumbers = new ArrayList<Integer>();
ArrayList formulaJoinedNumbers = new ArrayList(); ArrayList<Integer> formulaJoinedNumbers = new ArrayList<Integer>();
ArrayList propertyJoinNumbers = new ArrayList(); ArrayList<Integer> propertyJoinNumbers = new ArrayList<Integer>();
iter = persistentClass.getSubclassPropertyClosureIterator(); iter = persistentClass.getSubclassPropertyClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Property prop = (Property) iter.next(); Property prop = (Property) iter.next();
Integer join = persistentClass.getJoinNumber(prop); Integer join = persistentClass.getJoinNumber( prop );
propertyJoinNumbers.add(join); propertyJoinNumbers.add( join );
//propertyTableNumbersByName.put( prop.getName(), join ); //propertyTableNumbersByName.put( prop.getName(), join );
propertyTableNumbersByNameAndSubclass.put( propertyTableNumbersByNameAndSubclass.put(
prop.getPersistentClass().getEntityName() + '.' + prop.getName(), prop.getPersistentClass().getEntityName() + '.' + prop.getName(),
join join
); );
Iterator citer = prop.getColumnIterator(); Iterator citer = prop.getColumnIterator();
while ( citer.hasNext() ) { while ( citer.hasNext() ) {
Selectable thing = (Selectable) citer.next(); Selectable thing = (Selectable) citer.next();
if ( thing.isFormula() ) { if ( thing.isFormula() ) {
formulaJoinedNumbers.add(join); formulaJoinedNumbers.add( join );
} }
else { else {
columnJoinNumbers.add(join); columnJoinNumbers.add( join );
} }
} }
} }
subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnJoinNumbers); subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnJoinNumbers );
subclassFormulaTableNumberClosure = ArrayHelper.toIntArray(formulaJoinedNumbers); subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaJoinedNumbers );
subclassPropertyTableNumberClosure = ArrayHelper.toIntArray(propertyJoinNumbers); subclassPropertyTableNumberClosure = ArrayHelper.toIntArray( propertyJoinNumbers );
int subclassSpan = persistentClass.getSubclassSpan() + 1; int subclassSpan = persistentClass.getSubclassSpan() + 1;
subclassClosure = new String[subclassSpan]; subclassClosure = new String[subclassSpan];
@ -414,7 +422,7 @@ else if ( persistentClass.isDiscriminatorValueNotNull() ) {
// SUBCLASSES // SUBCLASSES
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
iter = persistentClass.getSubclassIterator(); iter = persistentClass.getSubclassIterator();
int k=1; int k = 1;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Subclass sc = (Subclass) iter.next(); Subclass sc = (Subclass) iter.next();
subclassClosure[k++] = sc.getEntityName(); subclassClosure[k++] = sc.getEntityName();
@ -428,15 +436,15 @@ else if ( sc.isDiscriminatorValueNotNull() ) {
try { try {
DiscriminatorType dtype = (DiscriminatorType) discriminatorType; DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
addSubclassByDiscriminatorValue( addSubclassByDiscriminatorValue(
dtype.stringToObject( sc.getDiscriminatorValue() ), dtype.stringToObject( sc.getDiscriminatorValue() ),
sc.getEntityName() sc.getEntityName()
); );
} }
catch (ClassCastException cce) { catch (ClassCastException cce) {
throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() ); throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() );
} }
catch (Exception e) { catch (Exception e) {
throw new MappingException("Error parsing discriminator value", e); throw new MappingException( "Error parsing discriminator value", e );
} }
} }
} }
@ -445,13 +453,13 @@ else if ( sc.isDiscriminatorValueNotNull() ) {
initLockers(); initLockers();
initSubclassPropertyAliasesMap( persistentClass ); initSubclassPropertyAliasesMap( persistentClass );
postConstruct( creationContext.getMetadata() ); postConstruct( creationContext.getMetadata() );
} }
private void addSubclassByDiscriminatorValue(Object discriminatorValue, String entityName) { private void addSubclassByDiscriminatorValue(Object discriminatorValue, String entityName) {
String mappedEntityName = (String) subclassesByDiscriminatorValue.put( discriminatorValue, entityName ); String mappedEntityName = subclassesByDiscriminatorValue.put( discriminatorValue, entityName );
if ( mappedEntityName != null ) { if ( mappedEntityName != null ) {
throw new MappingException( throw new MappingException(
"Entities [" + entityName + "] and [" + mappedEntityName "Entities [" + entityName + "] and [" + mappedEntityName
@ -474,12 +482,12 @@ public String getDiscriminatorColumnName() {
public String getDiscriminatorColumnReaders() { public String getDiscriminatorColumnReaders() {
return discriminatorColumnReaders; return discriminatorColumnReaders;
} }
public String getDiscriminatorColumnReaderTemplate() { public String getDiscriminatorColumnReaderTemplate() {
return discriminatorColumnReaderTemplate; return discriminatorColumnReaderTemplate;
} }
protected String getDiscriminatorAlias() { protected String getDiscriminatorAlias() {
return discriminatorAlias; return discriminatorAlias;
} }
@ -509,13 +517,13 @@ public String[] getSubclassClosure() {
} }
public String getSubclassForDiscriminatorValue(Object value) { public String getSubclassForDiscriminatorValue(Object value) {
if (value==null) { if ( value == null ) {
return (String) subclassesByDiscriminatorValue.get(NULL_DISCRIMINATOR); return subclassesByDiscriminatorValue.get( NULL_DISCRIMINATOR );
} }
else { else {
String result = (String) subclassesByDiscriminatorValue.get(value); String result = subclassesByDiscriminatorValue.get( value );
if (result==null) { if ( result == null ) {
result = (String) subclassesByDiscriminatorValue.get(NOT_NULL_DISCRIMINATOR); result = subclassesByDiscriminatorValue.get( NOT_NULL_DISCRIMINATOR );
} }
return result; return result;
} }
@ -528,7 +536,7 @@ public Serializable[] getPropertySpaces() {
//Access cached SQL //Access cached SQL
protected boolean isDiscriminatorFormula() { protected boolean isDiscriminatorFormula() {
return discriminatorColumnName==null; return discriminatorColumnName == null;
} }
protected String getDiscriminatorFormula() { protected String getDiscriminatorFormula() {
@ -538,23 +546,23 @@ protected String getDiscriminatorFormula() {
protected String getTableName(int j) { protected String getTableName(int j) {
return qualifiedTableNames[j]; return qualifiedTableNames[j];
} }
protected String[] getKeyColumns(int j) { protected String[] getKeyColumns(int j) {
return keyColumnNames[j]; return keyColumnNames[j];
} }
protected boolean isTableCascadeDeleteEnabled(int j) { protected boolean isTableCascadeDeleteEnabled(int j) {
return cascadeDeleteEnabled[j]; return cascadeDeleteEnabled[j];
} }
protected boolean isPropertyOfTable(int property, int j) { protected boolean isPropertyOfTable(int property, int j) {
return propertyTableNumbers[property]==j; return propertyTableNumbers[property] == j;
} }
protected boolean isSubclassTableSequentialSelect(int j) { protected boolean isSubclassTableSequentialSelect(int j) {
return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j]; return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
} }
// Execute the SQL: // Execute the SQL:
public String fromTableFragment(String name) { public String fromTableFragment(String name) {
@ -563,9 +571,9 @@ public String fromTableFragment(String name) {
@Override @Override
public String filterFragment(String alias) throws MappingException { public String filterFragment(String alias) throws MappingException {
String result = discriminatorFilterFragment(alias); String result = discriminatorFilterFragment( alias );
if ( hasWhere() ) { if ( hasWhere() ) {
result += " and " + getSQLWhereString(alias); result += " and " + getSQLWhereString( alias );
} }
return result; return result;
} }
@ -573,7 +581,7 @@ public String filterFragment(String alias) throws MappingException {
private String discriminatorFilterFragment(String alias) throws MappingException { private String discriminatorFilterFragment(String alias) throws MappingException {
return discriminatorFilterFragment( alias, null ); return discriminatorFilterFragment( alias, null );
} }
public String oneToManyFilterFragment(String alias) throws MappingException { public String oneToManyFilterFragment(String alias) throws MappingException {
return forceDiscriminator return forceDiscriminator
? discriminatorFilterFragment( alias, null ) ? discriminatorFilterFragment( alias, null )
@ -596,10 +604,10 @@ public String filterFragment(String alias, Set<String> treatAsDeclarations) {
return result; return result;
} }
private String discriminatorFilterFragment(String alias, Set<String> treatAsDeclarations) { private String discriminatorFilterFragment(String alias, Set<String> treatAsDeclarations) {
final boolean hasTreatAs = treatAsDeclarations != null && !treatAsDeclarations.isEmpty(); final boolean hasTreatAs = treatAsDeclarations != null && !treatAsDeclarations.isEmpty();
if ( !needsDiscriminator() && !hasTreatAs) { if ( !needsDiscriminator() && !hasTreatAs ) {
return ""; return "";
} }
@ -633,7 +641,7 @@ private String[] decodeTreatAsRequests(Set<String> treatAsDeclarations) {
values.add( queryable.getDiscriminatorSQLValue() ); values.add( queryable.getDiscriminatorSQLValue() );
} }
} }
return values.toArray( new String[ values.size() ] ); return values.toArray( new String[values.size()] );
} }
private String[] fullDiscriminatorValues; private String[] fullDiscriminatorValues;
@ -648,14 +656,14 @@ private String[] fullDiscriminatorValues() {
values.add( queryable.getDiscriminatorSQLValue() ); values.add( queryable.getDiscriminatorSQLValue() );
} }
} }
fullDiscriminatorValues = values.toArray( new String[values.size() ] ); fullDiscriminatorValues = values.toArray( new String[values.size()] );
} }
return fullDiscriminatorValues; return fullDiscriminatorValues;
} }
public String getSubclassPropertyTableName(int i) { public String getSubclassPropertyTableName(int i) {
return subclassTableNameClosure[ subclassPropertyTableNumberClosure[i] ]; return subclassTableNameClosure[subclassPropertyTableNumberClosure[i]];
} }
protected void addDiscriminatorToSelect(SelectFragment select, String name, String suffix) { protected void addDiscriminatorToSelect(SelectFragment select, String name, String suffix) {
@ -663,10 +671,10 @@ protected void addDiscriminatorToSelect(SelectFragment select, String name, Stri
select.addFormula( name, getDiscriminatorFormulaTemplate(), getDiscriminatorAlias() ); select.addFormula( name, getDiscriminatorFormulaTemplate(), getDiscriminatorAlias() );
} }
else { else {
select.addColumn( name, getDiscriminatorColumnName(), getDiscriminatorAlias() ); select.addColumn( name, getDiscriminatorColumnName(), getDiscriminatorAlias() );
} }
} }
protected int[] getPropertyTableNumbersInSelect() { protected int[] getPropertyTableNumbersInSelect() {
return propertyTableNumbers; return propertyTableNumbers;
} }
@ -681,7 +689,7 @@ public int getTableSpan() {
protected void addDiscriminatorToInsert(Insert insert) { protected void addDiscriminatorToInsert(Insert insert) {
if (discriminatorInsertable) { if ( discriminatorInsertable ) {
insert.addColumn( getDiscriminatorColumnName(), discriminatorSQLValue ); insert.addColumn( getDiscriminatorColumnName(), discriminatorSQLValue );
} }
@ -698,27 +706,27 @@ protected int[] getSubclassFormulaTableNumberClosure() {
protected int[] getPropertyTableNumbers() { protected int[] getPropertyTableNumbers() {
return propertyTableNumbers; return propertyTableNumbers;
} }
protected boolean isSubclassPropertyDeferred(String propertyName, String entityName) { protected boolean isSubclassPropertyDeferred(String propertyName, String entityName) {
return hasSequentialSelects && return hasSequentialSelects &&
isSubclassTableSequentialSelect( getSubclassPropertyTableNumber(propertyName, entityName) ); isSubclassTableSequentialSelect( getSubclassPropertyTableNumber( propertyName, entityName ) );
} }
public boolean hasSequentialSelect() { public boolean hasSequentialSelect() {
return hasSequentialSelects; return hasSequentialSelects;
} }
private int getSubclassPropertyTableNumber(String propertyName, String entityName) { private int getSubclassPropertyTableNumber(String propertyName, String entityName) {
Type type = propertyMapping.toType(propertyName); Type type = propertyMapping.toType( propertyName );
if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) { if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) {
return 0; return 0;
} }
final Integer tabnum = (Integer) propertyTableNumbersByNameAndSubclass.get(entityName + '.' + propertyName); final Integer tabnum = propertyTableNumbersByNameAndSubclass.get( entityName + '.' + propertyName );
return tabnum==null ? 0 : tabnum; return tabnum == null ? 0 : tabnum;
} }
protected String getSequentialSelect(String entityName) { protected String getSequentialSelect(String entityName) {
return (String) sequentialSelectStringsByEntityName.get(entityName); return sequentialSelectStringsByEntityName.get( entityName );
} }
private String generateSequentialSelect(Loadable persister) { private String generateSequentialSelect(Loadable persister) {
@ -726,49 +734,49 @@ private String generateSequentialSelect(Loadable persister) {
//note that this method could easily be moved up to BasicEntityPersister, //note that this method could easily be moved up to BasicEntityPersister,
//if we ever needed to reuse it from other subclasses //if we ever needed to reuse it from other subclasses
//figure out which tables need to be fetched //figure out which tables need to be fetched
AbstractEntityPersister subclassPersister = (AbstractEntityPersister) persister; AbstractEntityPersister subclassPersister = (AbstractEntityPersister) persister;
HashSet tableNumbers = new HashSet(); HashSet<Integer> tableNumbers = new HashSet<Integer>();
String[] props = subclassPersister.getPropertyNames(); String[] props = subclassPersister.getPropertyNames();
String[] classes = subclassPersister.getPropertySubclassNames(); String[] classes = subclassPersister.getPropertySubclassNames();
for ( int i=0; i<props.length; i++ ) { for ( int i = 0; i < props.length; i++ ) {
int propTableNumber = getSubclassPropertyTableNumber( props[i], classes[i] ); int propTableNumber = getSubclassPropertyTableNumber( props[i], classes[i] );
if ( isSubclassTableSequentialSelect(propTableNumber) && !isSubclassTableLazy(propTableNumber) ) { if ( isSubclassTableSequentialSelect( propTableNumber ) && !isSubclassTableLazy( propTableNumber ) ) {
tableNumbers.add( propTableNumber); tableNumbers.add( propTableNumber );
} }
} }
if ( tableNumbers.isEmpty() ) { if ( tableNumbers.isEmpty() ) {
return null; return null;
} }
//figure out which columns are needed //figure out which columns are needed
ArrayList columnNumbers = new ArrayList(); ArrayList<Integer> columnNumbers = new ArrayList<Integer>();
final int[] columnTableNumbers = getSubclassColumnTableNumberClosure(); final int[] columnTableNumbers = getSubclassColumnTableNumberClosure();
for ( int i=0; i<getSubclassColumnClosure().length; i++ ) { for ( int i = 0; i < getSubclassColumnClosure().length; i++ ) {
if ( tableNumbers.contains( columnTableNumbers[i] ) ) { if ( tableNumbers.contains( columnTableNumbers[i] ) ) {
columnNumbers.add( i ); columnNumbers.add( i );
} }
} }
//figure out which formulas are needed //figure out which formulas are needed
ArrayList formulaNumbers = new ArrayList(); ArrayList<Integer> formulaNumbers = new ArrayList<Integer>();
final int[] formulaTableNumbers = getSubclassColumnTableNumberClosure(); final int[] formulaTableNumbers = getSubclassColumnTableNumberClosure();
for ( int i=0; i<getSubclassFormulaTemplateClosure().length; i++ ) { for ( int i = 0; i < getSubclassFormulaTemplateClosure().length; i++ ) {
if ( tableNumbers.contains( formulaTableNumbers[i] ) ) { if ( tableNumbers.contains( formulaTableNumbers[i] ) ) {
formulaNumbers.add( i ); formulaNumbers.add( i );
} }
} }
//render the SQL //render the SQL
return renderSelect( return renderSelect(
ArrayHelper.toIntArray(tableNumbers), ArrayHelper.toIntArray( tableNumbers ),
ArrayHelper.toIntArray(columnNumbers), ArrayHelper.toIntArray( columnNumbers ),
ArrayHelper.toIntArray(formulaNumbers) ArrayHelper.toIntArray( formulaNumbers )
); );
} }
protected String[] getSubclassTableKeyColumns(int j) { protected String[] getSubclassTableKeyColumns(int j) {
return subclassTableKeyColumnClosure[j]; return subclassTableKeyColumnClosure[j];
} }
@ -788,30 +796,30 @@ protected boolean isClassOrSuperclassTable(int j) {
protected boolean isSubclassTableLazy(int j) { protected boolean isSubclassTableLazy(int j) {
return subclassTableIsLazyClosure[j]; return subclassTableIsLazyClosure[j];
} }
protected boolean isNullableTable(int j) { protected boolean isNullableTable(int j) {
return isNullableTable[j]; return isNullableTable[j];
} }
protected boolean isNullableSubclassTable(int j) { protected boolean isNullableSubclassTable(int j) {
return isNullableSubclassTable[j]; return isNullableSubclassTable[j];
} }
public String getPropertyTableName(String propertyName) { public String getPropertyTableName(String propertyName) {
Integer index = getEntityMetamodel().getPropertyIndexOrNull(propertyName); Integer index = getEntityMetamodel().getPropertyIndexOrNull( propertyName );
if (index==null) { if ( index == null ) {
return null; return null;
} }
return qualifiedTableNames[ propertyTableNumbers[index] ]; return qualifiedTableNames[propertyTableNumbers[index]];
} }
protected void doPostInstantiate() { protected void doPostInstantiate() {
if (hasSequentialSelects) { if ( hasSequentialSelects ) {
String[] entityNames = getSubclassClosure(); String[] entityNames = getSubclassClosure();
for ( int i=1; i<entityNames.length; i++ ) { for ( int i = 1; i < entityNames.length; i++ ) {
Loadable loadable = (Loadable) getFactory().getEntityPersister( entityNames[i] ); Loadable loadable = (Loadable) getFactory().getEntityPersister( entityNames[i] );
if ( !loadable.isAbstract() ) { //perhaps not really necessary... if ( !loadable.isAbstract() ) { //perhaps not really necessary...
String sequentialSelect = generateSequentialSelect(loadable); String sequentialSelect = generateSequentialSelect( loadable );
sequentialSelectStringsByEntityName.put( entityNames[i], sequentialSelect ); sequentialSelectStringsByEntityName.put( entityNames[i], sequentialSelect );
} }
} }
@ -832,6 +840,6 @@ public String[][] getContraintOrderedTableKeyColumnClosure() {
@Override @Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) { public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return new DynamicFilterAliasGenerator(qualifiedTableNames, rootAlias); return new DynamicFilterAliasGenerator( qualifiedTableNames, rootAlias );
} }
} }

View File

@ -60,7 +60,7 @@
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
* Implementation of the "table-per-concrete-class" or "roll-down" mapping * Implementation of the "table-per-concrete-class" or "roll-down" mapping
* strategy for an entity and its inheritence hierarchy. * strategy for an entity and its inheritence hierarchy.
* *
* @author Gavin King * @author Gavin King
@ -84,7 +84,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
//INITIALIZATION: //INITIALIZATION:
public UnionSubclassEntityPersister( public UnionSubclassEntityPersister(
final PersistentClass persistentClass, final PersistentClass persistentClass,
final EntityRegionAccessStrategy cacheAccessStrategy, final EntityRegionAccessStrategy cacheAccessStrategy,
final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy, final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy,
final PersisterCreationContext creationContext) throws HibernateException { final PersisterCreationContext creationContext) throws HibernateException {
@ -95,17 +95,17 @@ public UnionSubclassEntityPersister(
if ( getIdentifierGenerator() instanceof IdentityGenerator ) { if ( getIdentifierGenerator() instanceof IdentityGenerator ) {
throw new MappingException( throw new MappingException(
"Cannot use identity column key generation with <union-subclass> mapping for: " + "Cannot use identity column key generation with <union-subclass> mapping for: " +
getEntityName() getEntityName()
); );
} }
// TABLE // TABLE
tableName = persistentClass.getTable().getQualifiedName( tableName = persistentClass.getTable().getQualifiedName(
factory.getDialect(), factory.getDialect(),
factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultSchemaName()
); );
/*rootTableName = persistentClass.getRootTable().getQualifiedName( /*rootTableName = persistentClass.getRootTable().getQualifiedName(
factory.getDialect(), factory.getDialect(),
@ -122,34 +122,34 @@ public UnionSubclassEntityPersister(
callable = sql != null && persistentClass.isCustomInsertCallable(); callable = sql != null && persistentClass.isCustomInsertCallable();
checkStyle = sql == null checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT ? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLInsertCheckStyle() == null : persistentClass.getCustomSQLInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable ) ? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLInsertCheckStyle(); : persistentClass.getCustomSQLInsertCheckStyle();
customSQLInsert = new String[] { sql }; customSQLInsert = new String[] {sql};
insertCallable = new boolean[] { callable }; insertCallable = new boolean[] {callable};
insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle }; insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[] {checkStyle};
sql = persistentClass.getCustomSQLUpdate(); sql = persistentClass.getCustomSQLUpdate();
callable = sql != null && persistentClass.isCustomUpdateCallable(); callable = sql != null && persistentClass.isCustomUpdateCallable();
checkStyle = sql == null checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT ? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLUpdateCheckStyle() == null : persistentClass.getCustomSQLUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable ) ? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLUpdateCheckStyle(); : persistentClass.getCustomSQLUpdateCheckStyle();
customSQLUpdate = new String[] { sql }; customSQLUpdate = new String[] {sql};
updateCallable = new boolean[] { callable }; updateCallable = new boolean[] {callable};
updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle }; updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[] {checkStyle};
sql = persistentClass.getCustomSQLDelete(); sql = persistentClass.getCustomSQLDelete();
callable = sql != null && persistentClass.isCustomDeleteCallable(); callable = sql != null && persistentClass.isCustomDeleteCallable();
checkStyle = sql == null checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT ? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLDeleteCheckStyle() == null : persistentClass.getCustomSQLDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable ) ? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLDeleteCheckStyle(); : persistentClass.getCustomSQLDeleteCheckStyle();
customSQLDelete = new String[] { sql }; customSQLDelete = new String[] {sql};
deleteCallable = new boolean[] { callable }; deleteCallable = new boolean[] {callable};
deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle }; deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] {checkStyle};
discriminatorValue = persistentClass.getSubclassId(); discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
@ -161,43 +161,45 @@ public UnionSubclassEntityPersister(
subclassClosure[0] = getEntityName(); subclassClosure[0] = getEntityName();
// SUBCLASSES // SUBCLASSES
subclassByDiscriminatorValue.put( subclassByDiscriminatorValue.put(
persistentClass.getSubclassId(), persistentClass.getSubclassId(),
persistentClass.getEntityName() persistentClass.getEntityName()
); );
if ( persistentClass.isPolymorphic() ) { if ( persistentClass.isPolymorphic() ) {
Iterator iter = persistentClass.getSubclassIterator(); Iterator iter = persistentClass.getSubclassIterator();
int k=1; int k = 1;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Subclass sc = (Subclass) iter.next(); Subclass sc = (Subclass) iter.next();
subclassClosure[k++] = sc.getEntityName(); subclassClosure[k++] = sc.getEntityName();
subclassByDiscriminatorValue.put( sc.getSubclassId(), sc.getEntityName() ); subclassByDiscriminatorValue.put( sc.getSubclassId(), sc.getEntityName() );
} }
} }
//SPACES //SPACES
//TODO: i'm not sure, but perhaps we should exclude //TODO: i'm not sure, but perhaps we should exclude
// abstract denormalized tables? // abstract denormalized tables?
int spacesSize = 1 + persistentClass.getSynchronizedTables().size(); int spacesSize = 1 + persistentClass.getSynchronizedTables().size();
spaces = new String[spacesSize]; spaces = new String[spacesSize];
spaces[0] = tableName; spaces[0] = tableName;
Iterator iter = persistentClass.getSynchronizedTables().iterator(); Iterator iter = persistentClass.getSynchronizedTables().iterator();
for ( int i=1; i<spacesSize; i++ ) { for ( int i = 1; i < spacesSize; i++ ) {
spaces[i] = (String) iter.next(); spaces[i] = (String) iter.next();
} }
HashSet subclassTables = new HashSet(); HashSet subclassTables = new HashSet();
iter = persistentClass.getSubclassTableClosureIterator(); iter = persistentClass.getSubclassTableClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Table table = (Table) iter.next(); Table table = (Table) iter.next();
subclassTables.add( table.getQualifiedName( subclassTables.add(
factory.getDialect(), table.getQualifiedName(
factory.getSettings().getDefaultCatalogName(), factory.getDialect(),
factory.getSettings().getDefaultSchemaName() factory.getSettings().getDefaultCatalogName(),
) ); factory.getSettings().getDefaultSchemaName()
)
);
} }
subclassSpaces = ArrayHelper.toStringArray(subclassTables); subclassSpaces = ArrayHelper.toStringArray( subclassTables );
subquery = generateSubquery( persistentClass, creationContext.getMetadata() ); subquery = generateSubquery( persistentClass, creationContext.getMetadata() );
@ -211,7 +213,7 @@ public UnionSubclassEntityPersister(
} }
iter = persistentClass.getSubclassTableClosureIterator(); iter = persistentClass.getSubclassTableClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
Table tab = ( Table ) iter.next(); Table tab = (Table) iter.next();
if ( !tab.isAbstractUnionTable() ) { if ( !tab.isAbstractUnionTable() ) {
String tableName = tab.getQualifiedName( String tableName = tab.getQualifiedName(
factory.getDialect(), factory.getDialect(),
@ -221,8 +223,8 @@ public UnionSubclassEntityPersister(
tableNames.add( tableName ); tableNames.add( tableName );
String[] key = new String[idColumnSpan]; String[] key = new String[idColumnSpan];
Iterator citer = tab.getPrimaryKey().getColumnIterator(); Iterator citer = tab.getPrimaryKey().getColumnIterator();
for ( int k=0; k<idColumnSpan; k++ ) { for ( int k = 0; k < idColumnSpan; k++ ) {
key[k] = ( ( Column ) citer.next() ).getQuotedName( factory.getDialect() ); key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
} }
keyColumns.add( key ); keyColumns.add( key );
} }
@ -232,14 +234,14 @@ public UnionSubclassEntityPersister(
constraintOrderedKeyColumnNames = ArrayHelper.to2DStringArray( keyColumns ); constraintOrderedKeyColumnNames = ArrayHelper.to2DStringArray( keyColumns );
} }
else { else {
constraintOrderedTableNames = new String[] { tableName }; constraintOrderedTableNames = new String[] {tableName};
constraintOrderedKeyColumnNames = new String[][] { getIdentifierColumnNames() }; constraintOrderedKeyColumnNames = new String[][] {getIdentifierColumnNames()};
} }
initLockers(); initLockers();
initSubclassPropertyAliasesMap( persistentClass ); initSubclassPropertyAliasesMap( persistentClass );
postConstruct( creationContext.getMetadata() ); postConstruct( creationContext.getMetadata() );
} }
@ -247,7 +249,7 @@ public UnionSubclassEntityPersister(
public Serializable[] getQuerySpaces() { public Serializable[] getQuerySpaces() {
return subclassSpaces; return subclassSpaces;
} }
public String getTableName() { public String getTableName() {
return subquery; return subquery;
} }
@ -269,7 +271,7 @@ public String[] getSubclassClosure() {
} }
public String getSubclassForDiscriminatorValue(Object value) { public String getSubclassForDiscriminatorValue(Object value) {
return (String) subclassByDiscriminatorValue.get(value); return (String) subclassByDiscriminatorValue.get( value );
} }
public Serializable[] getPropertySpaces() { public Serializable[] getPropertySpaces() {
@ -285,19 +287,19 @@ protected boolean isDiscriminatorFormula() {
*/ */
protected String generateSelectString(LockMode lockMode) { protected String generateSelectString(LockMode lockMode) {
SimpleSelect select = new SimpleSelect( getFactory().getDialect() ) SimpleSelect select = new SimpleSelect( getFactory().getDialect() )
.setLockMode(lockMode) .setLockMode( lockMode )
.setTableName( getTableName() ) .setTableName( getTableName() )
.addColumns( getIdentifierColumnNames() ) .addColumns( getIdentifierColumnNames() )
.addColumns( .addColumns(
getSubclassColumnClosure(), getSubclassColumnClosure(),
getSubclassColumnAliasClosure(), getSubclassColumnAliasClosure(),
getSubclassColumnLazyiness() getSubclassColumnLazyiness()
) )
.addColumns( .addColumns(
getSubclassFormulaClosure(), getSubclassFormulaClosure(),
getSubclassFormulaAliasClosure(), getSubclassFormulaAliasClosure(),
getSubclassFormulaLazyiness() getSubclassFormulaLazyiness()
); );
//TODO: include the rowids!!!! //TODO: include the rowids!!!!
if ( hasSubclasses() ) { if ( hasSubclasses() ) {
if ( isDiscriminatorFormula() ) { if ( isDiscriminatorFormula() ) {
@ -324,11 +326,11 @@ protected String getTableName(int j) {
protected String[] getKeyColumns(int j) { protected String[] getKeyColumns(int j) {
return getIdentifierColumnNames(); return getIdentifierColumnNames();
} }
protected boolean isTableCascadeDeleteEnabled(int j) { protected boolean isTableCascadeDeleteEnabled(int j) {
return false; return false;
} }
protected boolean isPropertyOfTable(int property, int j) { protected boolean isPropertyOfTable(int property, int j) {
return true; return true;
} }
@ -336,7 +338,7 @@ protected boolean isPropertyOfTable(int property, int j) {
// Execute the SQL: // Execute the SQL:
public String fromTableFragment(String name) { public String fromTableFragment(String name) {
return getTableName() + ' ' + name; return getTableName() + ' ' + name;
} }
@Override @Override
@ -356,11 +358,11 @@ public String getSubclassPropertyTableName(int i) {
} }
protected void addDiscriminatorToSelect(SelectFragment select, String name, String suffix) { protected void addDiscriminatorToSelect(SelectFragment select, String name, String suffix) {
select.addColumn( name, getDiscriminatorColumnName(), getDiscriminatorAlias() ); select.addColumn( name, getDiscriminatorColumnName(), getDiscriminatorAlias() );
} }
protected int[] getPropertyTableNumbersInSelect() { protected int[] getPropertyTableNumbersInSelect() {
return new int[ getPropertySpan() ]; return new int[getPropertySpan()];
} }
protected int getSubclassPropertyTableNumber(int i) { protected int getSubclassPropertyTableNumber(int i) {
@ -381,32 +383,32 @@ public int getTableSpan() {
} }
protected int[] getSubclassColumnTableNumberClosure() { protected int[] getSubclassColumnTableNumberClosure() {
return new int[ getSubclassColumnClosure().length ]; return new int[getSubclassColumnClosure().length];
} }
protected int[] getSubclassFormulaTableNumberClosure() { protected int[] getSubclassFormulaTableNumberClosure() {
return new int[ getSubclassFormulaClosure().length ]; return new int[getSubclassFormulaClosure().length];
} }
protected boolean[] getTableHasColumns() { protected boolean[] getTableHasColumns() {
return new boolean[] { true }; return new boolean[] {true};
} }
protected int[] getPropertyTableNumbers() { protected int[] getPropertyTableNumbers() {
return new int[ getPropertySpan() ]; return new int[getPropertySpan()];
} }
protected String generateSubquery(PersistentClass model, Mapping mapping) { protected String generateSubquery(PersistentClass model, Mapping mapping) {
Dialect dialect = getFactory().getDialect(); Dialect dialect = getFactory().getDialect();
Settings settings = getFactory().getSettings(); Settings settings = getFactory().getSettings();
if ( !model.hasSubclasses() ) { if ( !model.hasSubclasses() ) {
return model.getTable().getQualifiedName( return model.getTable().getQualifiedName(
dialect, dialect,
settings.getDefaultCatalogName(), settings.getDefaultCatalogName(),
settings.getDefaultSchemaName() settings.getDefaultSchemaName()
); );
} }
HashSet columns = new LinkedHashSet(); HashSet columns = new LinkedHashSet();
@ -422,11 +424,11 @@ protected String generateSubquery(PersistentClass model, Mapping mapping) {
} }
StringBuilder buf = new StringBuilder() StringBuilder buf = new StringBuilder()
.append("( "); .append( "( " );
Iterator siter = new JoinedIterator( Iterator siter = new JoinedIterator(
new SingletonIterator(model), new SingletonIterator( model ),
model.getSubclassIterator() model.getSubclassIterator()
); );
while ( siter.hasNext() ) { while ( siter.hasNext() ) {
@ -434,51 +436,53 @@ protected String generateSubquery(PersistentClass model, Mapping mapping) {
Table table = clazz.getTable(); Table table = clazz.getTable();
if ( !table.isAbstractUnionTable() ) { if ( !table.isAbstractUnionTable() ) {
//TODO: move to .sql package!! //TODO: move to .sql package!!
buf.append("select "); buf.append( "select " );
Iterator citer = columns.iterator(); Iterator citer = columns.iterator();
while ( citer.hasNext() ) { while ( citer.hasNext() ) {
Column col = (Column) citer.next(); Column col = (Column) citer.next();
if ( !table.containsColumn(col) ) { if ( !table.containsColumn( col ) ) {
int sqlType = col.getSqlTypeCode(mapping); int sqlType = col.getSqlTypeCode( mapping );
buf.append( dialect.getSelectClauseNullString(sqlType) ) buf.append( dialect.getSelectClauseNullString( sqlType ) )
.append(" as "); .append( " as " );
} }
buf.append( col.getQuotedName(dialect) ); buf.append( col.getQuotedName( dialect ) );
buf.append(", "); buf.append( ", " );
} }
buf.append( clazz.getSubclassId() ) buf.append( clazz.getSubclassId() )
.append(" as clazz_"); .append( " as clazz_" );
buf.append(" from ") buf.append( " from " )
.append( table.getQualifiedName( .append(
dialect, table.getQualifiedName(
settings.getDefaultCatalogName(), dialect,
settings.getDefaultSchemaName() settings.getDefaultCatalogName(),
) ); settings.getDefaultSchemaName()
buf.append(" union "); )
);
buf.append( " union " );
if ( dialect.supportsUnionAll() ) { if ( dialect.supportsUnionAll() ) {
buf.append("all "); buf.append( "all " );
} }
} }
} }
if ( buf.length() > 2 ) { if ( buf.length() > 2 ) {
//chop the last union (all) //chop the last union (all)
buf.setLength( buf.length() - ( dialect.supportsUnionAll() ? 11 : 7 ) ); buf.setLength( buf.length() - ( dialect.supportsUnionAll() ? 11 : 7 ) );
} }
return buf.append(" )").toString(); return buf.append( " )" ).toString();
} }
protected String[] getSubclassTableKeyColumns(int j) { protected String[] getSubclassTableKeyColumns(int j) {
if (j!=0) { if ( j != 0 ) {
throw new AssertionFailure("only one table"); throw new AssertionFailure( "only one table" );
} }
return getIdentifierColumnNames(); return getIdentifierColumnNames();
} }
public String getSubclassTableName(int j) { public String getSubclassTableName(int j) {
if (j!=0) { if ( j != 0 ) {
throw new AssertionFailure("only one table"); throw new AssertionFailure( "only one table" );
} }
return tableName; return tableName;
} }
@ -488,8 +492,8 @@ public int getSubclassTableSpan() {
} }
protected boolean isClassOrSuperclassTable(int j) { protected boolean isClassOrSuperclassTable(int j) {
if (j!=0) { if ( j != 0 ) {
throw new AssertionFailure("only one table"); throw new AssertionFailure( "only one table" );
} }
return true; return true;
} }
@ -509,6 +513,6 @@ public String[][] getContraintOrderedTableKeyColumnClosure() {
@Override @Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) { public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return new StaticFilterAliasGenerator(rootAlias); return new StaticFilterAliasGenerator( rootAlias );
} }
} }

View File

@ -48,13 +48,13 @@ public class StandardPersisterClassResolver implements PersisterClassResolver {
public Class<? extends EntityPersister> getEntityPersisterClass(PersistentClass metadata) { public Class<? extends EntityPersister> getEntityPersisterClass(PersistentClass 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 ( RootClass.class.isInstance( metadata ) ) { if ( RootClass.class.isInstance( metadata ) ) {
if ( metadata.hasSubclasses() ) { if ( metadata.hasSubclasses() ) {
//If the class has children, we need to find of which kind //If the class has children, we need to find of which kind
metadata = (PersistentClass) metadata.getDirectSubclasses().next(); metadata = (PersistentClass) metadata.getDirectSubclasses().next();
} }
else { else {
return singleTableEntityPersister(); return singleTableEntityPersister();
} }
} }
if ( JoinedSubclass.class.isInstance( metadata ) ) { if ( JoinedSubclass.class.isInstance( metadata ) ) {
return joinedSubclassEntityPersister(); return joinedSubclassEntityPersister();
@ -62,7 +62,7 @@ public Class<? extends EntityPersister> getEntityPersisterClass(PersistentClass
else if ( UnionSubclass.class.isInstance( metadata ) ) { else if ( UnionSubclass.class.isInstance( metadata ) ) {
return unionSubclassEntityPersister(); return unionSubclassEntityPersister();
} }
else if ( SingleTableSubclass.class.isInstance( metadata ) ) { else if ( SingleTableSubclass.class.isInstance( metadata ) ) {
return singleTableEntityPersister(); return singleTableEntityPersister();
} }
else { else {
@ -72,7 +72,7 @@ else if ( SingleTableSubclass.class.isInstance( metadata ) ) {
} }
} }
public Class<? extends EntityPersister> singleTableEntityPersister() { public Class<? extends EntityPersister> singleTableEntityPersister() {
return SingleTableEntityPersister.class; return SingleTableEntityPersister.class;
} }

View File

@ -276,7 +276,8 @@ public static String collectionInfoString(
if ( collectionKey.getClass().isAssignableFrom( if ( collectionKey.getClass().isAssignableFrom(
ownerIdentifierType.getReturnedClass() ) ) { ownerIdentifierType.getReturnedClass() ) ) {
ownerKey = collectionKey; ownerKey = collectionKey;
} else { }
else {
ownerKey = session.getPersistenceContext() ownerKey = session.getPersistenceContext()
.getEntry( collection.getOwner() ).getId(); .getEntry( collection.getOwner() ).getId();
} }
@ -372,7 +373,8 @@ private static void addIdToCollectionInfoString(
if ( id.getClass().isAssignableFrom( if ( id.getClass().isAssignableFrom(
ownerIdentifierType.getReturnedClass() ) ) { ownerIdentifierType.getReturnedClass() ) ) {
s.append( ownerIdentifierType.toLoggableString( id, factory ) ); s.append( ownerIdentifierType.toLoggableString( id, factory ) );
} else { }
else {
// TODO: This is a crappy backup if a property-ref is used. // TODO: This is a crappy backup if a property-ref is used.
// If the reference is an object w/o toString(), this isn't going to work. // If the reference is an object w/o toString(), this isn't going to work.
s.append( id.toString() ); s.append( id.toString() );

View File

@ -37,9 +37,6 @@
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.jboss.logging.Logger;
/** /**
* Accesses property values via a get/set pair, which may be nonpublic. * Accesses property values via a get/set pair, which may be nonpublic.
@ -56,19 +53,19 @@ public static final class BasicSetter implements Setter {
private final String propertyName; private final String propertyName;
private BasicSetter(Class clazz, Method method, String propertyName) { private BasicSetter(Class clazz, Method method, String propertyName) {
this.clazz=clazz; this.clazz = clazz;
this.method=method; this.method = method;
this.propertyName=propertyName; this.propertyName = propertyName;
} }
@Override @Override
public void set(Object target, Object value, SessionFactoryImplementor factory) public void set(Object target, Object value, SessionFactoryImplementor factory)
throws HibernateException { throws HibernateException {
try { try {
method.invoke( target, value ); method.invoke( target, value );
} }
catch (NullPointerException npe) { catch (NullPointerException npe) {
if ( value==null && method.getParameterTypes()[0].isPrimitive() ) { if ( value == null && method.getParameterTypes()[0].isPrimitive() ) {
throw new PropertyAccessException( throw new PropertyAccessException(
npe, npe,
"Null value was assigned to a property of primitive type", "Null value was assigned to a property of primitive type",
@ -107,7 +104,7 @@ public void set(Object target, Object value, SessionFactoryImplementor factory)
//cannot occur //cannot occur
} }
catch (IllegalArgumentException iae) { catch (IllegalArgumentException iae) {
if ( value==null && method.getParameterTypes()[0].isPrimitive() ) { if ( value == null && method.getParameterTypes()[0].isPrimitive() ) {
throw new PropertyAccessException( throw new PropertyAccessException(
iae, iae,
"Null value was assigned to a property of primitive type", "Null value was assigned to a property of primitive type",
@ -143,11 +140,11 @@ public String getMethodName() {
} }
Object readResolve() { Object readResolve() {
return createSetter(clazz, propertyName); return createSetter( clazz, propertyName );
} }
@Override @Override
public String toString() { public String toString() {
return "BasicSetter(" + clazz.getName() + '.' + propertyName + ')'; return "BasicSetter(" + clazz.getName() + '.' + propertyName + ')';
} }
} }
@ -158,9 +155,9 @@ public static final class BasicGetter implements Getter {
private final String propertyName; private final String propertyName;
private BasicGetter(Class clazz, Method method, String propertyName) { private BasicGetter(Class clazz, Method method, String propertyName) {
this.clazz=clazz; this.clazz = clazz;
this.method=method; this.method = method;
this.propertyName=propertyName; this.propertyName = propertyName;
} }
@Override @Override
@ -188,7 +185,7 @@ public Object get(Object target) throws HibernateException {
//cannot occur //cannot occur
} }
catch (IllegalArgumentException iae) { catch (IllegalArgumentException iae) {
LOG.illegalPropertyGetterArgument(clazz.getName(), propertyName); LOG.illegalPropertyGetterArgument( clazz.getName(), propertyName );
throw new PropertyAccessException( throw new PropertyAccessException(
iae, iae,
"IllegalArgumentException occurred calling", "IllegalArgumentException occurred calling",
@ -225,51 +222,51 @@ public String getMethodName() {
} }
@Override @Override
public String toString() { public String toString() {
return "BasicGetter(" + clazz.getName() + '.' + propertyName + ')'; return "BasicGetter(" + clazz.getName() + '.' + propertyName + ')';
} }
Object readResolve() { Object readResolve() {
return createGetter(clazz, propertyName); return createGetter( clazz, propertyName );
} }
} }
@Override @Override
public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException {
return createSetter(theClass, propertyName); return createSetter( theClass, propertyName );
} }
private static Setter createSetter(Class theClass, String propertyName) throws PropertyNotFoundException { private static Setter createSetter(Class theClass, String propertyName) throws PropertyNotFoundException {
BasicSetter result = getSetterOrNull(theClass, propertyName); BasicSetter result = getSetterOrNull( theClass, propertyName );
if (result==null) { if ( result == null ) {
throw new PropertyNotFoundException( throw new PropertyNotFoundException(
"Could not find a setter for property " + "Could not find a setter for property " +
propertyName + propertyName +
" in class " + " in class " +
theClass.getName() theClass.getName()
); );
} }
return result; return result;
} }
private static BasicSetter getSetterOrNull(Class theClass, String propertyName) { private static BasicSetter getSetterOrNull(Class theClass, String propertyName) {
if (theClass==Object.class || theClass==null) { if ( theClass == Object.class || theClass == null ) {
return null; return null;
} }
Method method = setterMethod(theClass, propertyName); Method method = setterMethod( theClass, propertyName );
if (method!=null) { if ( method != null ) {
method.setAccessible(true); method.setAccessible( true );
return new BasicSetter(theClass, method, propertyName); return new BasicSetter( theClass, method, propertyName );
} }
else { else {
BasicSetter setter = getSetterOrNull( theClass.getSuperclass(), propertyName ); BasicSetter setter = getSetterOrNull( theClass.getSuperclass(), propertyName );
if (setter==null) { if ( setter == null ) {
Class[] interfaces = theClass.getInterfaces(); Class[] interfaces = theClass.getInterfaces();
for ( int i=0; setter==null && i<interfaces.length; i++ ) { for ( int i = 0; setter == null && i < interfaces.length; i++ ) {
setter=getSetterOrNull( interfaces[i], propertyName ); setter = getSetterOrNull( interfaces[i], propertyName );
} }
} }
return setter; return setter;
@ -278,8 +275,8 @@ private static BasicSetter getSetterOrNull(Class theClass, String propertyName)
} }
private static Method setterMethod(Class theClass, String propertyName) { private static Method setterMethod(Class theClass, String propertyName) {
BasicGetter getter = getGetterOrNull(theClass, propertyName); BasicGetter getter = getGetterOrNull( theClass, propertyName );
Class returnType = (getter==null) ? null : getter.getReturnType(); Class returnType = ( getter == null ) ? null : getter.getReturnType();
Method[] methods = theClass.getDeclaredMethods(); Method[] methods = theClass.getDeclaredMethods();
Method potentialSetter = null; Method potentialSetter = null;
@ -301,39 +298,39 @@ private static Method setterMethod(Class theClass, String propertyName) {
@Override @Override
public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
return createGetter(theClass, propertyName); return createGetter( theClass, propertyName );
} }
public static Getter createGetter(Class theClass, String propertyName) throws PropertyNotFoundException { public static Getter createGetter(Class theClass, String propertyName) throws PropertyNotFoundException {
BasicGetter result = getGetterOrNull(theClass, propertyName); BasicGetter result = getGetterOrNull( theClass, propertyName );
if (result==null) { if ( result == null ) {
throw new PropertyNotFoundException( throw new PropertyNotFoundException(
"Could not find a getter for " + "Could not find a getter for " +
propertyName + propertyName +
" in class " + " in class " +
theClass.getName() theClass.getName()
); );
} }
return result; return result;
} }
private static BasicGetter getGetterOrNull(Class theClass, String propertyName) { private static BasicGetter getGetterOrNull(Class theClass, String propertyName) {
if (theClass==Object.class || theClass==null) { if ( theClass == Object.class || theClass == null ) {
return null; return null;
} }
Method method = getterMethod(theClass, propertyName); Method method = getterMethod( theClass, propertyName );
if (method!=null) { if ( method != null ) {
method.setAccessible(true); method.setAccessible( true );
return new BasicGetter(theClass, method, propertyName); return new BasicGetter( theClass, method, propertyName );
} }
else { else {
BasicGetter getter = getGetterOrNull( theClass.getSuperclass(), propertyName ); BasicGetter getter = getGetterOrNull( theClass.getSuperclass(), propertyName );
if (getter==null) { if ( getter == null ) {
Class[] interfaces = theClass.getInterfaces(); Class[] interfaces = theClass.getInterfaces();
for ( int i=0; getter==null && i<interfaces.length; i++ ) { for ( int i = 0; getter == null && i < interfaces.length; i++ ) {
getter=getGetterOrNull( interfaces[i], propertyName ); getter = getGetterOrNull( interfaces[i], propertyName );
} }
} }
return getter; return getter;

View File

@ -22,48 +22,48 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.property; package org.hibernate.property;
import org.hibernate.PropertyNotFoundException; import org.hibernate.PropertyNotFoundException;
/** /**
* @author max * @author max
*
*/ */
public class ChainedPropertyAccessor implements PropertyAccessor { public class ChainedPropertyAccessor implements PropertyAccessor {
final PropertyAccessor[] chain; final PropertyAccessor[] chain;
public ChainedPropertyAccessor(PropertyAccessor[] chain) { public ChainedPropertyAccessor(PropertyAccessor[] chain) {
this.chain = chain; this.chain = chain;
} }
public Getter getGetter(Class theClass, String propertyName) public Getter getGetter(Class theClass, String propertyName)
throws PropertyNotFoundException { throws PropertyNotFoundException {
Getter result = null; Getter result = null;
for (int i = 0; i < chain.length; i++) { for ( PropertyAccessor candidate : chain ) {
PropertyAccessor candidate = chain[i];
try { try {
result = candidate.getGetter(theClass, propertyName); result = candidate.getGetter( theClass, propertyName );
return result; return result;
} catch (PropertyNotFoundException pnfe) { }
catch (PropertyNotFoundException pnfe) {
// ignore // ignore
} }
} }
throw new PropertyNotFoundException("Could not find getter for " + propertyName + " on " + theClass); throw new PropertyNotFoundException( "Could not find getter for " + propertyName + " on " + theClass );
} }
public Setter getSetter(Class theClass, String propertyName) public Setter getSetter(Class theClass, String propertyName)
throws PropertyNotFoundException { throws PropertyNotFoundException {
Setter result = null; Setter result = null;
for (int i = 0; i < chain.length; i++) { for ( PropertyAccessor candidate : chain ) {
PropertyAccessor candidate = chain[i];
try { try {
result = candidate.getSetter(theClass, propertyName); result = candidate.getSetter( theClass, propertyName );
return result; return result;
} catch (PropertyNotFoundException pnfe) { }
// catch (PropertyNotFoundException pnfe) {
// ignore
} }
} }
throw new PropertyNotFoundException("Could not find setter for " + propertyName + " on " + theClass); throw new PropertyNotFoundException( "Could not find setter for " + propertyName + " on " + theClass );
} }
} }

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.property; package org.hibernate.property;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -32,7 +33,6 @@
import org.hibernate.PropertyNotFoundException; import org.hibernate.PropertyNotFoundException;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.ReflectHelper;
/** /**
* Accesses fields directly. * Accesses fields directly.
@ -130,7 +130,8 @@ public void set(Object target, Object value, SessionFactoryImplementor factory)
clazz, clazz,
name name
); );
} else { }
else {
throw new PropertyAccessException(e, "could not set a field value by reflection", true, clazz, name); throw new PropertyAccessException(e, "could not set a field value by reflection", true, clazz, name);
} }
} }

View File

@ -57,26 +57,28 @@ public final class PropertyAccessorFactory {
// 3) Code can then simply call PropertyAccess.getGetter() with no parameters; likewise with // 3) Code can then simply call PropertyAccess.getGetter() with no parameters; likewise with
// PropertyAccessor.getSetter() // PropertyAccessor.getSetter()
/** /**
* Retrieves a PropertyAccessor instance based on the given property definition and * Retrieves a PropertyAccessor instance based on the given property definition and
* entity mode. * entity mode.
* *
* @param property The property for which to retrieve an accessor. * @param property The property for which to retrieve an accessor.
* @param mode The mode for the resulting entity. * @param mode The mode for the resulting entity.
* @return An appropriate accessor. *
* @throws MappingException * @return An appropriate accessor.
*/ *
* @throws MappingException
*/
public static PropertyAccessor getPropertyAccessor(Property property, EntityMode mode) throws MappingException { public static PropertyAccessor getPropertyAccessor(Property property, EntityMode mode) throws MappingException {
//TODO: this is temporary in that the end result will probably not take a Property reference per-se. //TODO: this is temporary in that the end result will probably not take a Property reference per-se.
if ( null == mode || EntityMode.POJO.equals( mode ) ) { if ( null == mode || EntityMode.POJO.equals( mode ) ) {
return getPojoPropertyAccessor( property.getPropertyAccessorName() ); return getPojoPropertyAccessor( property.getPropertyAccessorName() );
} }
else if ( EntityMode.MAP.equals( mode ) ) { else if ( EntityMode.MAP.equals( mode ) ) {
return getDynamicMapPropertyAccessor(); return getDynamicMapPropertyAccessor();
} }
else { else {
throw new MappingException( "Unknown entity mode [" + mode + "]" ); throw new MappingException( "Unknown entity mode [" + mode + "]" );
} }
} }
@ -84,6 +86,7 @@ else if ( EntityMode.MAP.equals( mode ) ) {
* Retreives a PropertyAccessor specific for a PojoRepresentation with the given access strategy. * Retreives a PropertyAccessor specific for a PojoRepresentation with the given access strategy.
* *
* @param pojoAccessorStrategy The access strategy. * @param pojoAccessorStrategy The access strategy.
*
* @return An appropriate accessor. * @return An appropriate accessor.
*/ */
private static PropertyAccessor getPojoPropertyAccessor(String pojoAccessorStrategy) { private static PropertyAccessor getPojoPropertyAccessor(String pojoAccessorStrategy) {
@ -96,7 +99,7 @@ else if ( "field".equals( pojoAccessorStrategy ) ) {
else if ( "embedded".equals( pojoAccessorStrategy ) ) { else if ( "embedded".equals( pojoAccessorStrategy ) ) {
return EMBEDDED_PROPERTY_ACCESSOR; return EMBEDDED_PROPERTY_ACCESSOR;
} }
else if ( "noop".equals(pojoAccessorStrategy) ) { else if ( "noop".equals( pojoAccessorStrategy ) ) {
return NOOP_ACCESSOR; return NOOP_ACCESSOR;
} }
else { else {
@ -114,44 +117,45 @@ private static PropertyAccessor resolveCustomAccessor(String accessorName) {
accessorClass = ReflectHelper.classForName( accessorName ); accessorClass = ReflectHelper.classForName( accessorName );
} }
catch (ClassNotFoundException cnfe) { catch (ClassNotFoundException cnfe) {
throw new MappingException("could not find PropertyAccessor class: " + accessorName, cnfe); throw new MappingException( "could not find PropertyAccessor class: " + accessorName, cnfe );
} }
try { try {
return (PropertyAccessor) accessorClass.newInstance(); return (PropertyAccessor) accessorClass.newInstance();
} }
catch (Exception e) { catch (Exception e) {
throw new MappingException("could not instantiate PropertyAccessor class: " + accessorName, e); throw new MappingException( "could not instantiate PropertyAccessor class: " + accessorName, e );
} }
} }
private PropertyAccessorFactory() {} private PropertyAccessorFactory() {
}
// todo : this eventually needs to be removed // todo : this eventually needs to be removed
public static PropertyAccessor getPropertyAccessor(Class optionalClass, String type) throws MappingException { public static PropertyAccessor getPropertyAccessor(Class optionalClass, String type) throws MappingException {
if ( type==null ) { if ( type == null ) {
type = optionalClass==null || optionalClass==Map.class ? "map" : "property"; type = optionalClass == null || optionalClass == Map.class ? "map" : "property";
} }
return getPropertyAccessor(type); return getPropertyAccessor( type );
} }
// todo : this eventually needs to be removed // todo : this eventually needs to be removed
public static PropertyAccessor getPropertyAccessor(String type) throws MappingException { public static PropertyAccessor getPropertyAccessor(String type) throws MappingException {
if ( type==null || "property".equals(type) ) { if ( type == null || "property".equals( type ) ) {
return BASIC_PROPERTY_ACCESSOR; return BASIC_PROPERTY_ACCESSOR;
} }
if ( "field".equals(type) ) { if ( "field".equals( type ) ) {
return DIRECT_PROPERTY_ACCESSOR; return DIRECT_PROPERTY_ACCESSOR;
} }
if ( "map".equals(type) ) { if ( "map".equals( type ) ) {
return MAP_ACCESSOR; return MAP_ACCESSOR;
} }
if ( "embedded".equals(type) ) { if ( "embedded".equals( type ) ) {
return EMBEDDED_PROPERTY_ACCESSOR; return EMBEDDED_PROPERTY_ACCESSOR;
} }
if ( "noop".equals(type)) { if ( "noop".equals( type ) ) {
return NOOP_ACCESSOR; return NOOP_ACCESSOR;
} }
return resolveCustomAccessor(type); return resolveCustomAccessor( type );
} }
} }

View File

@ -39,7 +39,7 @@
*/ */
public abstract class BasicLazyInitializer extends AbstractLazyInitializer { public abstract class BasicLazyInitializer extends AbstractLazyInitializer {
protected static final Object INVOKE_IMPLEMENTATION = new MarkerObject("INVOKE_IMPLEMENTATION"); protected static final Object INVOKE_IMPLEMENTATION = new MarkerObject( "INVOKE_IMPLEMENTATION" );
protected final Class persistentClass; protected final Class persistentClass;
protected final Method getIdentifierMethod; protected final Method getIdentifierMethod;
@ -51,14 +51,14 @@ public abstract class BasicLazyInitializer extends AbstractLazyInitializer {
protected BasicLazyInitializer( protected BasicLazyInitializer(
String entityName, String entityName,
Class persistentClass, Class persistentClass,
Serializable id, Serializable id,
Method getIdentifierMethod, Method getIdentifierMethod,
Method setIdentifierMethod, Method setIdentifierMethod,
CompositeType componentIdType, CompositeType componentIdType,
SessionImplementor session, SessionImplementor session,
boolean overridesEquals) { boolean overridesEquals) {
super(entityName, id, session); super( entityName, id, session );
this.persistentClass = persistentClass; this.persistentClass = persistentClass;
this.getIdentifierMethod = getIdentifierMethod; this.getIdentifierMethod = getIdentifierMethod;
this.setIdentifierMethod = setIdentifierMethod; this.setIdentifierMethod = setIdentifierMethod;
@ -72,25 +72,25 @@ protected final Object invoke(Method method, Object[] args, Object proxy) throws
String methodName = method.getName(); String methodName = method.getName();
int params = args.length; int params = args.length;
if ( params==0 ) { if ( params == 0 ) {
if ( "writeReplace".equals(methodName) ) { if ( "writeReplace".equals( methodName ) ) {
return getReplacement(); return getReplacement();
} }
else if ( !overridesEquals && "hashCode".equals(methodName) ) { else if ( !overridesEquals && "hashCode".equals( methodName ) ) {
return System.identityHashCode(proxy); return System.identityHashCode( proxy );
} }
else if ( isUninitialized() && method.equals(getIdentifierMethod) ) { else if ( isUninitialized() && method.equals( getIdentifierMethod ) ) {
return getIdentifier(); return getIdentifier();
} }
else if ( "getHibernateLazyInitializer".equals(methodName) ) { else if ( "getHibernateLazyInitializer".equals( methodName ) ) {
return this; return this;
} }
} }
else if ( params==1 ) { else if ( params == 1 ) {
if ( !overridesEquals && "equals".equals(methodName) ) { if ( !overridesEquals && "equals".equals( methodName ) ) {
return args[0]==proxy; return args[0] == proxy;
} }
else if ( method.equals(setIdentifierMethod) ) { else if ( method.equals( setIdentifierMethod ) ) {
initialize(); initialize();
setIdentifier( (Serializable) args[0] ); setIdentifier( (Serializable) args[0] );
return INVOKE_IMPLEMENTATION; return INVOKE_IMPLEMENTATION;
@ -98,7 +98,7 @@ else if ( method.equals(setIdentifierMethod) ) {
} }
//if it is a property of an embedded component, invoke on the "identifier" //if it is a property of an embedded component, invoke on the "identifier"
if ( componentIdType!=null && componentIdType.isMethodOf(method) ) { if ( componentIdType != null && componentIdType.isMethodOf( method ) ) {
return method.invoke( getIdentifier(), args ); return method.invoke( getIdentifier(), args );
} }
@ -109,19 +109,19 @@ else if ( method.equals(setIdentifierMethod) ) {
private Object getReplacement() { private Object getReplacement() {
final SessionImplementor session = getSession(); final SessionImplementor session = getSession();
if ( isUninitialized() && session != null && session.isOpen()) { if ( isUninitialized() && session != null && session.isOpen() ) {
final EntityKey key = session.generateEntityKey( final EntityKey key = session.generateEntityKey(
getIdentifier(), getIdentifier(),
session.getFactory().getEntityPersister( getEntityName() ) session.getFactory().getEntityPersister( getEntityName() )
); );
final Object entity = session.getPersistenceContext().getEntity(key); final Object entity = session.getPersistenceContext().getEntity( key );
if (entity!=null) { if ( entity != null ) {
setImplementation( entity ); setImplementation( entity );
} }
} }
if ( isUninitialized() ) { if ( isUninitialized() ) {
if (replacement==null) { if ( replacement == null ) {
replacement = serializableProxy(); replacement = serializableProxy();
} }
return replacement; return replacement;

View File

@ -28,10 +28,8 @@
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.Connection; import java.sql.Connection;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.resource.jdbc.LogicalConnection; import org.hibernate.resource.jdbc.LogicalConnection;
import org.hibernate.resource.jdbc.ResourceRegistry; import org.hibernate.resource.jdbc.ResourceRegistry;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor; import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;

View File

@ -27,27 +27,34 @@
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.Connection; import java.sql.Connection;
import org.hibernate.engine.jdbc.spi.ConnectionObserver;
import org.hibernate.resource.jdbc.LogicalConnection; import org.hibernate.resource.jdbc.LogicalConnection;
/** /**
* SPI contract for LogicalConnection
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface LogicalConnectionImplementor extends LogicalConnection { public interface LogicalConnectionImplementor extends LogicalConnection {
// todo : expose the Connection as below? or accept(WorkInConnection) where WorkInConnection is given access to Connection? /**
public Connection getPhysicalConnection(); * Exposes access to the "real" Connection.
*
* @todo : expose Connection as here? or accept(WorkInConnection) where WorkInConnection is given access to Connection?
*
* @return The connection
*/
Connection getPhysicalConnection();
/** /**
* Notification indicating a JDBC statement has been executed to trigger * Notification indicating a JDBC statement has been executed to trigger
* {@link org.hibernate.ConnectionReleaseMode#AFTER_STATEMENT} releasing if needed * {@link org.hibernate.ConnectionReleaseMode#AFTER_STATEMENT} releasing if needed
*/ */
public void afterStatement(); void afterStatement();
/** /**
* Notification indicating a transaction has completed to trigger * Notification indicating a transaction has completed to trigger
* {@link org.hibernate.ConnectionReleaseMode#AFTER_TRANSACTION} releasing if needed * {@link org.hibernate.ConnectionReleaseMode#AFTER_TRANSACTION} releasing if needed
*/ */
public void afterTransaction(); void afterTransaction();
/** /**
* Manually disconnect the underlying JDBC Connection. The assumption here * Manually disconnect the underlying JDBC Connection. The assumption here
@ -56,7 +63,7 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
* @return The connection maintained here at time of disconnect. {@code null} if * @return The connection maintained here at time of disconnect. {@code null} if
* there was no connection cached internally. * there was no connection cached internally.
*/ */
public Connection manualDisconnect(); Connection manualDisconnect();
/** /**
* Manually reconnect the underlying JDBC Connection. Should be called at some point after manualDisconnect(). * Manually reconnect the underlying JDBC Connection. Should be called at some point after manualDisconnect().
@ -64,16 +71,16 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
* @param suppliedConnection For user supplied connection strategy the user needs to hand us the connection * @param suppliedConnection For user supplied connection strategy the user needs to hand us the connection
* with which to reconnect. It is an error to pass a connection in the other strategies. * with which to reconnect. It is an error to pass a connection in the other strategies.
*/ */
public void manualReconnect(Connection suppliedConnection); void manualReconnect(Connection suppliedConnection);
/** /**
* Creates a shareable copy of itself for use in "shared sessions" * Creates a shareable copy of itself for use in "shared sessions"
* *
* @return The shareable copy. * @return The shareable copy.
*/ */
public LogicalConnectionImplementor makeShareableCopy(); LogicalConnectionImplementor makeShareableCopy();
public PhysicalJdbcTransaction getPhysicalJdbcTransaction(); PhysicalJdbcTransaction getPhysicalJdbcTransaction();
/** /**
* Serialization hook * Serialization hook
@ -82,5 +89,5 @@ public interface LogicalConnectionImplementor extends LogicalConnection {
* *
* @throws java.io.IOException Problem accessing stream * @throws java.io.IOException Problem accessing stream
*/ */
public void serialize(ObjectOutputStream oos) throws IOException; void serialize(ObjectOutputStream oos) throws IOException;
} }

View File

@ -23,10 +23,9 @@
*/ */
package org.hibernate.resource.transaction.backend.jdbc.internal; package org.hibernate.resource.transaction.backend.jdbc.internal;
import javax.transaction.Status;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.transaction.Status;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.transaction.spi.IsolationDelegate; import org.hibernate.engine.transaction.spi.IsolationDelegate;
@ -38,7 +37,6 @@
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess; import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper;
import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl; import org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.resource.transaction.spi.TransactionStatus;

View File

@ -23,11 +23,8 @@
*/ */
package org.hibernate.resource.transaction.backend.jta.internal.synchronization; package org.hibernate.resource.transaction.backend.jta.internal.synchronization;
import javax.persistence.spi.PersistenceUnitTransactionType;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.engine.spi.SessionImplementor;
/** /**
* A pluggable strategy for defining any actions to be performed during * A pluggable strategy for defining any actions to be performed during
* {@link javax.transaction.Synchronization#afterCompletion} processing from the the * {@link javax.transaction.Synchronization#afterCompletion} processing from the the
@ -36,5 +33,5 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface AfterCompletionAction extends Serializable { public interface AfterCompletionAction extends Serializable {
public void doAction(boolean successful); void doAction(boolean successful);
} }

View File

@ -63,5 +63,5 @@ public enum TransactionStatus {
* Status code indicating a transaction that is in the process of * Status code indicating a transaction that is in the process of
* rolling back. * rolling back.
*/ */
ROLLING_BACK ROLLING_BACK
} }

View File

@ -285,7 +285,7 @@ private <R extends Service> void applyInjections(R service) {
} }
} }
catch (NullPointerException e) { catch (NullPointerException e) {
log.error( "NPE injecting service deps : " + service.getClass().getName() ); log.error( "NPE injecting service deps : " + service.getClass().getName() );
} }
} }
@ -344,7 +344,7 @@ public boolean isActive() {
} }
@Override @Override
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public void destroy() { public void destroy() {
if ( !active ) { if ( !active ) {
return; return;

View File

@ -29,7 +29,7 @@
/** /**
* Since Service lookup is a very hot operation and essentially it's a read only * Since Service lookup is a very hot operation and essentially it's a read only
* data structure, to achieve threadsafety we can use immutability. * data structure, to achieve thread-safety we can use immutability.
* For our use case we just need reference equality, and the expectation is that a limited * For our use case we just need reference equality, and the expectation is that a limited
* number of elements will be contained in this custom collection (<32). * number of elements will be contained in this custom collection (<32).
* So the following structure is functionally equivalent to an Identity based ConcurrentMap, * So the following structure is functionally equivalent to an Identity based ConcurrentMap,
@ -123,6 +123,12 @@ public int compareTo(Entry o) {
} }
@Override @Override
public int hashCode() {
return hash;
}
@Override
@SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"})
public boolean equals(Object obj) { public boolean equals(Object obj) {
//A ClassCastException is really not expected here, //A ClassCastException is really not expected here,
//as it's an internal private class, //as it's an internal private class,

View File

@ -25,13 +25,12 @@
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.service.Service;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory; import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
/** /**
* Acts as a {@link Service} in the {@link org.hibernate.boot.registry.internal.StandardServiceRegistryImpl} whose function is as a factory for * Acts as a service in the {@link org.hibernate.boot.registry.internal.StandardServiceRegistryImpl} whose
* {@link SessionFactoryServiceRegistryImpl} implementations. * function is to act as a factory for {@link SessionFactoryServiceRegistryImpl} implementations.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -23,6 +23,7 @@
* *
*/ */
package org.hibernate.sql; package org.hibernate.sql;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -30,6 +31,7 @@
/** /**
* A translated HQL query * A translated HQL query
*
* @author Gavin King * @author Gavin King
*/ */
public class QuerySelect { public class QuerySelect {
@ -44,37 +46,38 @@ public class QuerySelect {
private boolean distinct; private boolean distinct;
private static final HashSet<String> DONT_SPACE_TOKENS = new HashSet<String>(); private static final HashSet<String> DONT_SPACE_TOKENS = new HashSet<String>();
static { static {
//dontSpace.add("'"); //dontSpace.add("'");
DONT_SPACE_TOKENS.add("."); DONT_SPACE_TOKENS.add( "." );
DONT_SPACE_TOKENS.add("+"); DONT_SPACE_TOKENS.add( "+" );
DONT_SPACE_TOKENS.add("-"); DONT_SPACE_TOKENS.add( "-" );
DONT_SPACE_TOKENS.add("/"); DONT_SPACE_TOKENS.add( "/" );
DONT_SPACE_TOKENS.add("*"); DONT_SPACE_TOKENS.add( "*" );
DONT_SPACE_TOKENS.add("<"); DONT_SPACE_TOKENS.add( "<" );
DONT_SPACE_TOKENS.add(">"); DONT_SPACE_TOKENS.add( ">" );
DONT_SPACE_TOKENS.add("="); DONT_SPACE_TOKENS.add( "=" );
DONT_SPACE_TOKENS.add("#"); DONT_SPACE_TOKENS.add( "#" );
DONT_SPACE_TOKENS.add("~"); DONT_SPACE_TOKENS.add( "~" );
DONT_SPACE_TOKENS.add("|"); DONT_SPACE_TOKENS.add( "|" );
DONT_SPACE_TOKENS.add("&"); DONT_SPACE_TOKENS.add( "&" );
DONT_SPACE_TOKENS.add("<="); DONT_SPACE_TOKENS.add( "<=" );
DONT_SPACE_TOKENS.add(">="); DONT_SPACE_TOKENS.add( ">=" );
DONT_SPACE_TOKENS.add("=>"); DONT_SPACE_TOKENS.add( "=>" );
DONT_SPACE_TOKENS.add("=<"); DONT_SPACE_TOKENS.add( "=<" );
DONT_SPACE_TOKENS.add("!="); DONT_SPACE_TOKENS.add( "!=" );
DONT_SPACE_TOKENS.add("<>"); DONT_SPACE_TOKENS.add( "<>" );
DONT_SPACE_TOKENS.add("!#"); DONT_SPACE_TOKENS.add( "!#" );
DONT_SPACE_TOKENS.add("!~"); DONT_SPACE_TOKENS.add( "!~" );
DONT_SPACE_TOKENS.add("!<"); DONT_SPACE_TOKENS.add( "!<" );
DONT_SPACE_TOKENS.add("!>"); DONT_SPACE_TOKENS.add( "!>" );
DONT_SPACE_TOKENS.add("("); //for MySQL DONT_SPACE_TOKENS.add( "(" ); //for MySQL
DONT_SPACE_TOKENS.add(")"); DONT_SPACE_TOKENS.add( ")" );
} }
public QuerySelect(Dialect dialect) { public QuerySelect(Dialect dialect) {
this.dialect = dialect; this.dialect = dialect;
joins = new QueryJoinFragment(dialect, false); joins = new QueryJoinFragment( dialect, false );
} }
public JoinFragment getJoinFragment() { public JoinFragment getJoinFragment() {
@ -82,20 +85,20 @@ public JoinFragment getJoinFragment() {
} }
public void addSelectFragmentString(String fragment) { public void addSelectFragmentString(String fragment) {
if ( fragment.length()>0 && fragment.charAt(0)==',' ) { if ( fragment.length() > 0 && fragment.charAt( 0 ) == ',' ) {
fragment = fragment.substring(1); fragment = fragment.substring( 1 );
} }
fragment = fragment.trim(); fragment = fragment.trim();
if ( fragment.length()>0 ) { if ( fragment.length() > 0 ) {
if ( select.length()>0 ) { if ( select.length() > 0 ) {
select.append(", "); select.append( ", " );
} }
select.append(fragment); select.append( fragment );
} }
} }
public void addSelectColumn(String columnName, String alias) { public void addSelectColumn(String columnName, String alias) {
addSelectFragmentString(columnName + ' ' + alias); addSelectFragmentString( columnName + ' ' + alias );
} }
public void setDistinct(boolean distinct) { public void setDistinct(boolean distinct) {
@ -104,107 +107,109 @@ public void setDistinct(boolean distinct) {
public void setWhereTokens(Iterator tokens) { public void setWhereTokens(Iterator tokens) {
//if ( conjunctiveWhere.length()>0 ) conjunctiveWhere.append(" and "); //if ( conjunctiveWhere.length()>0 ) conjunctiveWhere.append(" and ");
appendTokens(where, tokens); appendTokens( where, tokens );
} }
public void prependWhereConditions(String conditions) { public void prependWhereConditions(String conditions) {
if (where.length() > 0) { if ( where.length() > 0 ) {
where.insert(0, conditions + " and "); where.insert( 0, conditions + " and " );
} }
else { else {
where.append(conditions); where.append( conditions );
} }
} }
public void setGroupByTokens(Iterator tokens) { public void setGroupByTokens(Iterator tokens) {
//if ( groupBy.length()>0 ) groupBy.append(" and "); //if ( groupBy.length()>0 ) groupBy.append(" and ");
appendTokens(groupBy, tokens); appendTokens( groupBy, tokens );
} }
public void setOrderByTokens(Iterator tokens) { public void setOrderByTokens(Iterator tokens) {
//if ( orderBy.length()>0 ) orderBy.append(" and "); //if ( orderBy.length()>0 ) orderBy.append(" and ");
appendTokens(orderBy, tokens); appendTokens( orderBy, tokens );
} }
public void setHavingTokens(Iterator tokens) { public void setHavingTokens(Iterator tokens) {
//if ( having.length()>0 ) having.append(" and "); //if ( having.length()>0 ) having.append(" and ");
appendTokens(having, tokens); appendTokens( having, tokens );
} }
public void addOrderBy(String orderByString) { public void addOrderBy(String orderByString) {
if ( orderBy.length() > 0 ) { if ( orderBy.length() > 0 ) {
orderBy.append(", "); orderBy.append( ", " );
} }
orderBy.append(orderByString); orderBy.append( orderByString );
} }
public String toQueryString() { public String toQueryString() {
StringBuilder buf = new StringBuilder(50); StringBuilder buf = new StringBuilder( 50 );
if (comment!=null) { if ( comment != null ) {
buf.append("/* ").append(comment).append(" */ "); buf.append( "/* " ).append( comment ).append( " */ " );
} }
buf.append("select "); buf.append( "select " );
if (distinct) { if ( distinct ) {
buf.append("distinct "); buf.append( "distinct " );
} }
String from = joins.toFromFragmentString(); String from = joins.toFromFragmentString();
if ( from.startsWith(",") ) { if ( from.startsWith( "," ) ) {
from = from.substring(1); from = from.substring( 1 );
} }
else if ( from.startsWith(" inner join") ){ else if ( from.startsWith( " inner join" ) ) {
from = from.substring(11); from = from.substring( 11 );
} }
buf.append( select.toString() ) buf.append( select.toString() )
.append(" from") .append( " from" )
.append(from); .append( from );
String outerJoinsAfterWhere = joins.toWhereFragmentString().trim(); String outerJoinsAfterWhere = joins.toWhereFragmentString().trim();
String whereConditions = where.toString().trim(); String whereConditions = where.toString().trim();
boolean hasOuterJoinsAfterWhere = outerJoinsAfterWhere.length() > 0; boolean hasOuterJoinsAfterWhere = outerJoinsAfterWhere.length() > 0;
boolean hasWhereConditions = whereConditions.length() > 0; boolean hasWhereConditions = whereConditions.length() > 0;
if (hasOuterJoinsAfterWhere || hasWhereConditions) { if ( hasOuterJoinsAfterWhere || hasWhereConditions ) {
buf.append(" where "); buf.append( " where " );
if (hasOuterJoinsAfterWhere) { if ( hasOuterJoinsAfterWhere ) {
buf.append( outerJoinsAfterWhere.substring(4) ); buf.append( outerJoinsAfterWhere.substring( 4 ) );
} }
if (hasWhereConditions) { if ( hasWhereConditions ) {
if (hasOuterJoinsAfterWhere) { if ( hasOuterJoinsAfterWhere ) {
buf.append(" and ("); buf.append( " and (" );
} }
buf.append(whereConditions); buf.append( whereConditions );
if (hasOuterJoinsAfterWhere) { if ( hasOuterJoinsAfterWhere ) {
buf.append(")"); buf.append( ")" );
} }
} }
} }
if ( groupBy.length() > 0 ) { if ( groupBy.length() > 0 ) {
buf.append(" group by ").append( groupBy.toString() ); buf.append( " group by " ).append( groupBy.toString() );
} }
if ( having.length() > 0 ) { if ( having.length() > 0 ) {
buf.append(" having ").append( having.toString() ); buf.append( " having " ).append( having.toString() );
} }
if ( orderBy.length() > 0 ) { if ( orderBy.length() > 0 ) {
buf.append(" order by ").append( orderBy.toString() ); buf.append( " order by " ).append( orderBy.toString() );
} }
return dialect.transformSelectString( buf.toString() ); return dialect.transformSelectString( buf.toString() );
} }
private static void appendTokens(StringBuilder buf, Iterator iter) { private static void appendTokens(StringBuilder buf, Iterator iter) {
boolean lastSpaceable=true; boolean lastSpaceable = true;
boolean lastQuoted=false; boolean lastQuoted = false;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
String token = (String) iter.next(); String token = (String) iter.next();
boolean spaceable = !DONT_SPACE_TOKENS.contains(token); boolean spaceable = !DONT_SPACE_TOKENS.contains( token );
boolean quoted = token.startsWith("'"); boolean quoted = token.startsWith( "'" );
if (spaceable && lastSpaceable) { if ( spaceable && lastSpaceable ) {
if ( !quoted || !lastQuoted ) buf.append(' '); if ( !quoted || !lastQuoted ) {
buf.append( ' ' );
}
} }
lastSpaceable = spaceable; lastSpaceable = spaceable;
buf.append(token); buf.append( token );
lastQuoted = token.endsWith("'"); lastQuoted = token.endsWith( "'" );
} }
} }
@ -213,7 +218,7 @@ public void setComment(String comment) {
} }
public QuerySelect copy() { public QuerySelect copy() {
QuerySelect copy = new QuerySelect(dialect); QuerySelect copy = new QuerySelect( dialect );
copy.joins = this.joins.copy(); copy.joins = this.joins.copy();
copy.select.append( this.select.toString() ); copy.select.append( this.select.toString() );
copy.where.append( this.where.toString() ); copy.where.append( this.where.toString() );

View File

@ -39,15 +39,15 @@
*/ */
public class SelectFragment { public class SelectFragment {
private String suffix; private String suffix;
private List columns = new ArrayList(); private List<String> columns = new ArrayList<String>();
//private List aliases = new ArrayList(); //private List aliases = new ArrayList();
private List columnAliases = new ArrayList(); private List<String> columnAliases = new ArrayList<String>();
private String extraSelectList; private String extraSelectList;
private String[] usedAliases; private String[] usedAliases;
public SelectFragment() {} public SelectFragment() {}
public List getColumns() { public List<String> getColumns() {
return columns; return columns;
} }
@ -117,7 +117,9 @@ public SelectFragment addColumns(String tableAlias, String[] columnNames, String
public SelectFragment addFormulas(String tableAlias, String[] formulas, String[] formulaAliases) { public SelectFragment addFormulas(String tableAlias, String[] formulas, String[] formulaAliases) {
for ( int i=0; i<formulas.length; i++ ) { for ( int i=0; i<formulas.length; i++ ) {
if ( formulas[i]!=null ) addFormula( tableAlias, formulas[i], formulaAliases[i] ); if ( formulas[i]!=null ) {
addFormula( tableAlias, formulas[i], formulaAliases[i] );
}
} }
return this; return this;
} }
@ -140,16 +142,16 @@ public SelectFragment addColumnTemplates(String tableAlias, String[] columnTempl
public String toFragmentString() { public String toFragmentString() {
StringBuilder buf = new StringBuilder( columns.size() * 10 ); StringBuilder buf = new StringBuilder( columns.size() * 10 );
Iterator iter = columns.iterator(); Iterator<String> iter = columns.iterator();
Iterator columnAliasIter = columnAliases.iterator(); Iterator<String> columnAliasIter = columnAliases.iterator();
//HashMap columnsUnique = new HashMap(); //HashMap columnsUnique = new HashMap();
HashSet columnsUnique = new HashSet(); HashSet<String> columnsUnique = new HashSet<String>();
if (usedAliases!=null) { if (usedAliases!=null) {
columnsUnique.addAll( Arrays.asList(usedAliases) ); columnsUnique.addAll( Arrays.asList(usedAliases) );
} }
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
String column = (String) iter.next(); String column = iter.next();
String columnAlias = (String) columnAliasIter.next(); String columnAlias = columnAliasIter.next();
//TODO: eventually put this back in, once we think all is fixed //TODO: eventually put this back in, once we think all is fixed
//Object otherAlias = columnsUnique.put(qualifiedColumn, columnAlias); //Object otherAlias = columnsUnique.put(qualifiedColumn, columnAlias);
/*if ( otherAlias!=null && !columnAlias.equals(otherAlias) ) { /*if ( otherAlias!=null && !columnAlias.equals(otherAlias) ) {

View File

@ -23,9 +23,6 @@
* *
*/ */
package org.hibernate.sql; package org.hibernate.sql;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -35,6 +32,10 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.Dialect;
/** /**
* An SQL <tt>SELECT</tt> statement with no table joins * An SQL <tt>SELECT</tt> statement with no table joins
* *
@ -51,16 +52,16 @@ public SimpleSelect(Dialect dialect) {
private String tableName; private String tableName;
private String orderBy; private String orderBy;
private Dialect dialect; private Dialect dialect;
private LockOptions lockOptions = new LockOptions( LockMode.READ); private LockOptions lockOptions = new LockOptions( LockMode.READ );
private String comment; private String comment;
private List columns = new ArrayList(); private List<String> columns = new ArrayList<String>();
private Map aliases = new HashMap(); private Map<String, String> aliases = new HashMap<String, String>();
private List whereTokens = new ArrayList(); private List<String> whereTokens = new ArrayList<String>();
public SimpleSelect addColumns(String[] columnNames, String[] columnAliases) { public SimpleSelect addColumns(String[] columnNames, String[] columnAliases) {
for ( int i=0; i<columnNames.length; i++ ) { for ( int i = 0; i < columnNames.length; i++ ) {
if ( columnNames[i]!=null ) { if ( columnNames[i] != null ) {
addColumn( columnNames[i], columnAliases[i] ); addColumn( columnNames[i], columnAliases[i] );
} }
} }
@ -68,8 +69,8 @@ public SimpleSelect addColumns(String[] columnNames, String[] columnAliases) {
} }
public SimpleSelect addColumns(String[] columns, String[] aliases, boolean[] ignore) { public SimpleSelect addColumns(String[] columns, String[] aliases, boolean[] ignore) {
for ( int i=0; i<ignore.length; i++ ) { for ( int i = 0; i < ignore.length; i++ ) {
if ( !ignore[i] && columns[i]!=null ) { if ( !ignore[i] && columns[i] != null ) {
addColumn( columns[i], aliases[i] ); addColumn( columns[i], aliases[i] );
} }
} }
@ -84,15 +85,16 @@ public SimpleSelect addColumns(String[] columnNames) {
} }
return this; return this;
} }
public SimpleSelect addColumn(String columnName) { public SimpleSelect addColumn(String columnName) {
columns.add(columnName); columns.add( columnName );
//aliases.put( columnName, DEFAULT_ALIAS.toAliasString(columnName) ); //aliases.put( columnName, DEFAULT_ALIAS.toAliasString(columnName) );
return this; return this;
} }
public SimpleSelect addColumn(String columnName, String alias) { public SimpleSelect addColumn(String columnName, String alias) {
columns.add(columnName); columns.add( columnName );
aliases.put(columnName, alias); aliases.put( columnName, alias );
return this; return this;
} }
@ -101,8 +103,8 @@ public SimpleSelect setTableName(String tableName) {
return this; return this;
} }
public SimpleSelect setLockOptions( LockOptions lockOptions ) { public SimpleSelect setLockOptions(LockOptions lockOptions) {
LockOptions.copy(lockOptions, this.lockOptions); LockOptions.copy( lockOptions, this.lockOptions );
return this; return this;
} }
@ -112,13 +114,13 @@ public SimpleSelect setLockMode(LockMode lockMode) {
} }
public SimpleSelect addWhereToken(String token) { public SimpleSelect addWhereToken(String token) {
whereTokens.add(token); whereTokens.add( token );
return this; return this;
} }
private void and() { private void and() {
if ( whereTokens.size()>0 ) { if ( whereTokens.size() > 0 ) {
whereTokens.add("and"); whereTokens.add( "and" );
} }
} }
@ -135,7 +137,7 @@ public SimpleSelect addCondition(String lhs, String condition) {
} }
public SimpleSelect addCondition(String[] lhs, String op, String[] rhs) { public SimpleSelect addCondition(String[] lhs, String op, String[] rhs) {
for ( int i=0; i<lhs.length; i++ ) { for ( int i = 0; i < lhs.length; i++ ) {
addCondition( lhs[i], op, rhs[i] ); addCondition( lhs[i], op, rhs[i] );
} }
return this; return this;
@ -151,49 +153,51 @@ public SimpleSelect addCondition(String[] lhs, String condition) {
} }
public String toStatementString() { public String toStatementString() {
StringBuilder buf = new StringBuilder( StringBuilder buf = new StringBuilder(
columns.size()*10 + columns.size() * 10 +
tableName.length() + tableName.length() +
whereTokens.size() * 10 + whereTokens.size() * 10 +
10 10
); );
if ( comment!=null ) { if ( comment != null ) {
buf.append("/* ").append(comment).append(" */ "); buf.append( "/* " ).append( comment ).append( " */ " );
} }
buf.append("select "); buf.append( "select " );
Set uniqueColumns = new HashSet(); Set<String> uniqueColumns = new HashSet<String>();
Iterator iter = columns.iterator(); Iterator<String> iter = columns.iterator();
boolean appendComma = false; boolean appendComma = false;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
String col = (String) iter.next(); String col = iter.next();
String alias = (String) aliases.get(col); String alias = aliases.get( col );
if ( uniqueColumns.add(alias==null ? col : alias) ) { if ( uniqueColumns.add( alias == null ? col : alias ) ) {
if (appendComma) buf.append(", "); if ( appendComma ) {
buf.append(col); buf.append( ", " );
if ( alias!=null && !alias.equals(col) ) { }
buf.append(" as ") buf.append( col );
.append(alias); if ( alias != null && !alias.equals( col ) ) {
buf.append( " as " )
.append( alias );
} }
appendComma = true; appendComma = true;
} }
} }
buf.append(" from ") buf.append( " from " )
.append( dialect.appendLockHint(lockOptions, tableName) ); .append( dialect.appendLockHint( lockOptions, tableName ) );
if ( whereTokens.size() > 0 ) { if ( whereTokens.size() > 0 ) {
buf.append(" where ") buf.append( " where " )
.append( toWhereClause() ); .append( toWhereClause() );
} }
if (orderBy!=null) { if ( orderBy != null ) {
buf.append(orderBy); buf.append( orderBy );
} }
if (lockOptions!=null) { if ( lockOptions != null ) {
buf.append( dialect.getForUpdateString(lockOptions) ); buf.append( dialect.getForUpdateString( lockOptions ) );
} }
return dialect.transformSelectString( buf.toString() ); return dialect.transformSelectString( buf.toString() );
@ -201,11 +205,11 @@ public String toStatementString() {
public String toWhereClause() { public String toWhereClause() {
StringBuilder buf = new StringBuilder( whereTokens.size() * 5 ); StringBuilder buf = new StringBuilder( whereTokens.size() * 5 );
Iterator iter = whereTokens.iterator(); Iterator<String> iter = whereTokens.iterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
buf.append( iter.next() ); buf.append( iter.next() );
if ( iter.hasNext() ) { if ( iter.hasNext() ) {
buf.append(' '); buf.append( ' ' );
} }
} }
return buf.toString(); return buf.toString();

View File

@ -119,7 +119,7 @@ public static String renderWhereStringTemplate(String sqlWhereString, Dialect di
* @deprecated Only intended for annotations usage; use {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)} instead * @deprecated Only intended for annotations usage; use {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)} instead
*/ */
@Deprecated @Deprecated
@SuppressWarnings({ "JavaDoc" }) @SuppressWarnings({ "JavaDoc" })
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) { public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) {
return renderWhereStringTemplate( return renderWhereStringTemplate(
sqlWhereString, sqlWhereString,
@ -654,7 +654,7 @@ public SqlValueReference[] map(String reference) {
* @deprecated Use {@link #translateOrderBy} instead * @deprecated Use {@link #translateOrderBy} instead
*/ */
@Deprecated @Deprecated
public static String renderOrderByStringTemplate( public static String renderOrderByStringTemplate(
String orderByFragment, String orderByFragment,
Dialect dialect, Dialect dialect,
SQLFunctionRegistry functionRegistry) { SQLFunctionRegistry functionRegistry) {

View File

@ -46,7 +46,7 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class OrderByFragmentParser extends GeneratedOrderByFragmentParser { public class OrderByFragmentParser extends GeneratedOrderByFragmentParser {
private static final Logger LOG = Logger.getLogger(OrderByFragmentParser.class.getName()); private static final Logger LOG = Logger.getLogger( OrderByFragmentParser.class.getName() );
private final TranslationContext context; private final TranslationContext context;
@ -63,7 +63,7 @@ public Set<String> getColumnReferences() {
} }
@Override @Override
protected AST quotedIdentifier(AST ident) { protected AST quotedIdentifier(AST ident) {
/* /*
* Semantic action used during recognition of quoted identifiers (quoted column names) * Semantic action used during recognition of quoted identifiers (quoted column names)
*/ */
@ -74,7 +74,7 @@ protected AST quotedIdentifier(AST ident) {
} }
@Override @Override
protected AST quotedString(AST ident) { protected AST quotedString(AST ident) {
/* /*
* Semantic action used during recognition of quoted strings (string literals) * Semantic action used during recognition of quoted strings (string literals)
*/ */
@ -103,19 +103,19 @@ protected boolean isFunctionName(AST ast) {
} }
else { else {
// if function.hasParenthesesIfNoArguments() is true, then assume the node is not a function // if function.hasParenthesesIfNoArguments() is true, then assume the node is not a function
return ! function.hasParenthesesIfNoArguments(); return !function.hasParenthesesIfNoArguments();
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected AST resolveFunction(AST ast) { protected AST resolveFunction(AST ast) {
/* /*
* Semantic action used during recognition of a *known* function * Semantic action used during recognition of a *known* function
*/ */
AST child = ast.getFirstChild(); AST child = ast.getFirstChild();
if ( child != null ) { if ( child != null ) {
assert "{param list}".equals( child.getText() ); assert "{param list}".equals( child.getText() );
child = child.getFirstChild(); child = child.getFirstChild();
} }
@ -173,7 +173,7 @@ else if ( nodeText.startsWith( "{" ) && nodeText.endsWith( "}" ) ) {
} }
@Override @Override
protected AST resolveIdent(AST ident) { protected AST resolveIdent(AST ident) {
/* /*
* Semantic action used during recognition of an identifier. This identifier might be a column name, it might * Semantic action used during recognition of an identifier. This identifier might be a column name, it might
* be a property name. * be a property name.
@ -183,7 +183,7 @@ protected AST resolveIdent(AST ident) {
try { try {
sqlValueReferences = context.getColumnMapper().map( text ); sqlValueReferences = context.getColumnMapper().map( text );
} }
catch( Throwable t ) { catch (Throwable t) {
sqlValueReferences = null; sqlValueReferences = null;
} }
@ -261,9 +261,9 @@ private static boolean isValidIdentifierCharacter(char c) {
} }
@Override @Override
protected AST postProcessSortSpecification(AST sortSpec) { protected AST postProcessSortSpecification(AST sortSpec) {
assert SORT_SPEC == sortSpec.getType(); assert SORT_SPEC == sortSpec.getType();
SortSpecification sortSpecification = ( SortSpecification ) sortSpec; SortSpecification sortSpecification = (SortSpecification) sortSpec;
AST sortKey = sortSpecification.getSortKey(); AST sortKey = sortSpecification.getSortKey();
if ( IDENT_LIST == sortKey.getFirstChild().getType() ) { if ( IDENT_LIST == sortKey.getFirstChild().getType() ) {
AST identList = sortKey.getFirstChild(); AST identList = sortKey.getFirstChild();
@ -299,11 +299,10 @@ private SortSpecification createSortSpecification(
if ( orderingSpecification != null ) { if ( orderingSpecification != null ) {
sortSpecification.addChild( orderingSpecification ); sortSpecification.addChild( orderingSpecification );
} }
return ( SortSpecification ) sortSpecification; return (SortSpecification) sortSpecification;
} }
// trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private int traceDepth = 0; private int traceDepth = 0;
@ -314,8 +313,8 @@ public void traceIn(String ruleName) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> "; String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> ";
LOG.trace(prefix + ruleName); LOG.trace( prefix + ruleName );
} }
@Override @Override
@ -323,8 +322,8 @@ public void traceOut(String ruleName) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " "; String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " ";
LOG.trace(prefix + ruleName); LOG.trace( prefix + ruleName );
} }
@Override @Override

View File

@ -51,22 +51,22 @@ public OrderByFragmentRenderer(SessionFactoryImplementor sessionFactory) {
} }
@Override @Override
protected void out(AST ast) { protected void out(AST ast) {
out( ( ( Node ) ast ).getRenderableText() ); out( ( (Node) ast ).getRenderableText() );
} }
// handle trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // handle trace logging ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private int traceDepth = 0; private int traceDepth = 0;
@Override @Override
public void traceIn(String ruleName, AST tree) { public void traceIn(String ruleName, AST tree) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> "; String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> ";
String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")"; String traceText = ruleName + " (" + buildTraceNodeName( tree ) + ")";
LOG.trace( prefix + traceText ); LOG.trace( prefix + traceText );
} }
@ -77,17 +77,20 @@ private String buildTraceNodeName(AST tree) {
} }
@Override @Override
public void traceOut(String ruleName, AST tree) { public void traceOut(String ruleName, AST tree) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " "; String prefix = "<-" + StringHelper.repeat( '-', ( --traceDepth * 2 ) ) + " ";
LOG.trace( prefix + ruleName ); LOG.trace( prefix + ruleName );
} }
@Override @Override
protected String renderOrderByElement(String expression, String collation, String order, String nulls) { protected String renderOrderByElement(String expression, String collation, String order, String nulls) {
final NullPrecedence nullPrecedence = NullPrecedence.parse( nulls, sessionFactory.getSettings().getDefaultNullPrecedence() ); final NullPrecedence nullPrecedence = NullPrecedence.parse(
nulls,
sessionFactory.getSessionFactoryOptions().getDefaultNullPrecedence()
);
return sessionFactory.getDialect().renderOrderByElement( expression, collation, order, nullPrecedence ); return sessionFactory.getDialect().renderOrderByElement( expression, collation, order, nullPrecedence );
} }
} }

View File

@ -24,7 +24,6 @@
package org.hibernate.stat.internal; package org.hibernate.stat.internal;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
@ -140,11 +139,11 @@ public long getSizeInMemory() {
} }
@Override @Override
@SuppressWarnings("unchecked")
public Map getEntries() { public Map getEntries() {
final Map map = new HashMap(); final Map map = new HashMap();
final Iterator iter = this.region.toMap().entrySet().iterator(); for ( Object o : this.region.toMap().entrySet() ) {
while ( iter.hasNext() ) { final Map.Entry me = (Map.Entry) o;
final Map.Entry me = (Map.Entry) iter.next();
map.put( ( (NaturalIdCacheKey) me.getKey() ).getNaturalIdValues(), me.getValue() ); map.put( ( (NaturalIdCacheKey) me.getKey() ).getNaturalIdValues(), me.getValue() );
} }
return map; return map;
@ -189,8 +188,12 @@ void queryExecuted(long time) {
this.readLock.lock(); this.readLock.lock();
try { try {
// Less chances for a context switch // Less chances for a context switch
for ( long old = this.executionMinTime.get(); time < old && !this.executionMinTime.compareAndSet( old, time ); old = this.executionMinTime.get() ) {;} //noinspection StatementWithEmptyBody
for ( long old = this.executionMaxTime.get(); time > old && !this.executionMaxTime.compareAndSet( old, time ); old = this.executionMaxTime.get() ) {;} for ( long old = this.executionMinTime.get(); time < old && !this.executionMinTime.compareAndSet( old, time ); old = this.executionMinTime.get() ) {
}
//noinspection StatementWithEmptyBody
for ( long old = this.executionMaxTime.get(); time > old && !this.executionMaxTime.compareAndSet( old, time ); old = this.executionMaxTime.get() ) {
}
this.executionCount.getAndIncrement(); this.executionCount.getAndIncrement();
this.totalExecutionTime.addAndGet( time ); this.totalExecutionTime.addAndGet( time );
} }

View File

@ -39,7 +39,7 @@
import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics;
import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.stat.spi.StatisticsImplementor;
import org.jboss.logging.Logger; import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
* Implementation of {@link org.hibernate.stat.Statistics} based on the {@link java.util.concurrent} package. * Implementation of {@link org.hibernate.stat.Statistics} based on the {@link java.util.concurrent} package.
@ -48,8 +48,7 @@
*/ */
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service { public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service {
private static final CoreMessageLogger LOG = messageLogger( ConcurrentStatisticsImpl.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ConcurrentStatisticsImpl.class.getName());
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
@ -393,7 +392,8 @@ public void naturalIdCacheMiss(String regionName) {
@Override @Override
public void naturalIdQueryExecuted(String regionName, long time) { public void naturalIdQueryExecuted(String regionName, long time) {
naturalIdQueryExecutionCount.getAndIncrement(); naturalIdQueryExecutionCount.getAndIncrement();
boolean isLongestQuery = false; boolean isLongestQuery;
//noinspection StatementWithEmptyBody
for ( long old = naturalIdQueryExecutionMaxTime.get(); for ( long old = naturalIdQueryExecutionMaxTime.get();
( isLongestQuery = time > old ) && ( !naturalIdQueryExecutionMaxTime.compareAndSet( old, time ) ); ( isLongestQuery = time > old ) && ( !naturalIdQueryExecutionMaxTime.compareAndSet( old, time ) );
old = naturalIdQueryExecutionMaxTime.get() ) { old = naturalIdQueryExecutionMaxTime.get() ) {
@ -411,7 +411,8 @@ public void naturalIdQueryExecuted(String regionName, long time) {
public void queryExecuted(String hql, int rows, long time) { public void queryExecuted(String hql, int rows, long time) {
LOG.hql(hql, time, (long) rows ); LOG.hql(hql, time, (long) rows );
queryExecutionCount.getAndIncrement(); queryExecutionCount.getAndIncrement();
boolean isLongestQuery = false; boolean isLongestQuery;
//noinspection StatementWithEmptyBody
for ( long old = queryExecutionMaxTime.get(); for ( long old = queryExecutionMaxTime.get();
( isLongestQuery = time > old ) && ( !queryExecutionMaxTime.compareAndSet( old, time ) ); ( isLongestQuery = time > old ) && ( !queryExecutionMaxTime.compareAndSet( old, time ) );
old = queryExecutionMaxTime.get() ) { old = queryExecutionMaxTime.get() ) {

View File

@ -29,12 +29,13 @@ public ImportSqlCommandExtractor initiateService(Map configurationValues, Servic
return instantiateExplicitCommandExtractor( extractorClassName, classLoaderService ); return instantiateExplicitCommandExtractor( extractorClassName, classLoaderService );
} }
private ImportSqlCommandExtractor instantiateExplicitCommandExtractor(String extractorClassName, private ImportSqlCommandExtractor instantiateExplicitCommandExtractor(
ClassLoaderService classLoaderService) { String extractorClassName,
ClassLoaderService classLoaderService) {
try { try {
return (ImportSqlCommandExtractor) classLoaderService.classForName( extractorClassName ).newInstance(); return (ImportSqlCommandExtractor) classLoaderService.classForName( extractorClassName ).newInstance();
} }
catch ( Exception e ) { catch (Exception e) {
throw new HibernateException( throw new HibernateException(
"Could not instantiate import sql command extractor [" + extractorClassName + "]", e "Could not instantiate import sql command extractor [" + extractorClassName + "]", e
); );

View File

@ -73,7 +73,7 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SchemaExport { public class SchemaExport {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SchemaExport.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SchemaExport.class );
private static final String DEFAULT_IMPORT_FILE = "/import.sql"; private static final String DEFAULT_IMPORT_FILE = "/import.sql";
@ -236,6 +236,7 @@ public SchemaExport(
* *
* @param metadata The metadata object holding the mapping info to be exported * @param metadata The metadata object holding the mapping info to be exported
* @param connection The JDBC connection to use. * @param connection The JDBC connection to use.
*
* @throws HibernateException Indicates problem preparing for schema export. * @throws HibernateException Indicates problem preparing for schema export.
*/ */
public SchemaExport(MetadataImplementor metadata, Connection connection) throws HibernateException { public SchemaExport(MetadataImplementor metadata, Connection connection) throws HibernateException {
@ -295,6 +296,7 @@ public SchemaExport(
* For generating a export script file, this is the file which will be written. * For generating a export script file, this is the file which will be written.
* *
* @param filename The name of the file to which to write the export script. * @param filename The name of the file to which to write the export script.
*
* @return this * @return this
*/ */
public SchemaExport setOutputFile(String filename) { public SchemaExport setOutputFile(String filename) {
@ -306,6 +308,7 @@ public SchemaExport setOutputFile(String filename) {
* Set the end of statement delimiter * Set the end of statement delimiter
* *
* @param delimiter The delimiter * @param delimiter The delimiter
*
* @return this * @return this
*/ */
public SchemaExport setDelimiter(String delimiter) { public SchemaExport setDelimiter(String delimiter) {
@ -317,6 +320,7 @@ public SchemaExport setDelimiter(String delimiter) {
* Should we format the sql strings? * Should we format the sql strings?
* *
* @param format Should we format SQL strings * @param format Should we format SQL strings
*
* @return this * @return this
*/ */
public SchemaExport setFormat(boolean format) { public SchemaExport setFormat(boolean format) {
@ -328,6 +332,7 @@ public SchemaExport setFormat(boolean format) {
* Set <i>import.sql</i> command extractor. By default {@link SingleLineSqlCommandExtractor} is used. * Set <i>import.sql</i> command extractor. By default {@link SingleLineSqlCommandExtractor} is used.
* *
* @param importSqlCommandExtractor <i>import.sql</i> command extractor. * @param importSqlCommandExtractor <i>import.sql</i> command extractor.
*
* @return this * @return this
*/ */
public SchemaExport setImportSqlCommandExtractor(ImportSqlCommandExtractor importSqlCommandExtractor) { public SchemaExport setImportSqlCommandExtractor(ImportSqlCommandExtractor importSqlCommandExtractor) {
@ -339,6 +344,7 @@ public SchemaExport setImportSqlCommandExtractor(ImportSqlCommandExtractor impor
* Should we stop once an error occurs? * Should we stop once an error occurs?
* *
* @param haltOnError True if export should stop after error. * @param haltOnError True if export should stop after error.
*
* @return this * @return this
*/ */
public SchemaExport setHaltOnError(boolean haltOnError) { public SchemaExport setHaltOnError(boolean haltOnError) {
@ -399,7 +405,7 @@ else if ( justCreate ) {
} }
public void execute(Target output, Type type) { public void execute(Target output, Type type) {
if ( (outputFile == null && output == Target.NONE) || type == SchemaExport.Type.NONE ) { if ( ( outputFile == null && output == Target.NONE ) || type == SchemaExport.Type.NONE ) {
return; return;
} }
exceptions.clear(); exceptions.clear();
@ -407,14 +413,14 @@ public void execute(Target output, Type type) {
LOG.runningHbm2ddlSchemaExport(); LOG.runningHbm2ddlSchemaExport();
final List<NamedReader> importFileReaders = new ArrayList<NamedReader>(); final List<NamedReader> importFileReaders = new ArrayList<NamedReader>();
for ( String currentFile : importFiles.split(",") ) { for ( String currentFile : importFiles.split( "," ) ) {
try { try {
final String resourceName = currentFile.trim(); final String resourceName = currentFile.trim();
InputStream stream = ConfigHelper.getResourceAsStream( resourceName ); InputStream stream = ConfigHelper.getResourceAsStream( resourceName );
importFileReaders.add( new NamedReader( resourceName, stream ) ); importFileReaders.add( new NamedReader( resourceName, stream ) );
} }
catch ( HibernateException e ) { catch (HibernateException e) {
LOG.debugf("Import file not found: %s", currentFile); LOG.debugf( "Import file not found: %s", currentFile );
} }
} }
@ -437,7 +443,7 @@ public void execute(Target output, Type type) {
} }
if ( type.doCreate() ) { if ( type.doCreate() ) {
perform( createSQL, exporters ); perform( createSQL, exporters );
if ( ! importFileReaders.isEmpty() ) { if ( !importFileReaders.isEmpty() ) {
for ( NamedReader namedReader : importFileReaders ) { for ( NamedReader namedReader : importFileReaders ) {
importScript( namedReader, exporters ); importScript( namedReader, exporters );
} }
@ -466,14 +472,14 @@ public void execute(Target output, Type type) {
catch (Exception ignore) { catch (Exception ignore) {
} }
} }
LOG.schemaExportComplete(); LOG.schemaExportComplete();
} }
} }
private void perform(String[] sqlCommands, List<Exporter> exporters) { private void perform(String[] sqlCommands, List<Exporter> exporters) {
for ( String sqlCommand : sqlCommands ) { for ( String sqlCommand : sqlCommands ) {
String formatted = formatter.format( sqlCommand ); String formatted = formatter.format( sqlCommand );
if ( delimiter != null ) { if ( delimiter != null ) {
formatted += delimiter; formatted += delimiter;
} }
sqlStatementLogger.logStatement( sqlCommand, formatter ); sqlStatementLogger.logStatement( sqlCommand, formatter );
@ -496,11 +502,11 @@ private void perform(String[] sqlCommands, List<Exporter> exporters) {
private void importScript(NamedReader namedReader, List<Exporter> exporters) throws Exception { private void importScript(NamedReader namedReader, List<Exporter> exporters) throws Exception {
BufferedReader reader = new BufferedReader( namedReader.getReader() ); BufferedReader reader = new BufferedReader( namedReader.getReader() );
String[] statements = importSqlCommandExtractor.extractCommands( reader ); String[] statements = importSqlCommandExtractor.extractCommands( reader );
if (statements != null) { if ( statements != null ) {
for ( String statement : statements ) { for ( String statement : statements ) {
if ( statement != null ) { if ( statement != null ) {
String trimmedSql = statement.trim(); String trimmedSql = statement.trim();
if ( trimmedSql.endsWith( ";" )) { if ( trimmedSql.endsWith( ";" ) ) {
trimmedSql = trimmedSql.substring( 0, statement.length() - 1 ); trimmedSql = trimmedSql.substring( 0, statement.length() - 1 );
} }
if ( !StringHelper.isEmpty( trimmedSql ) ) { if ( !StringHelper.isEmpty( trimmedSql ) ) {
@ -511,14 +517,16 @@ private void importScript(NamedReader namedReader, List<Exporter> exporters) thr
} }
} }
} }
catch ( Exception e ) { catch (Exception e) {
if (haltOnError) { if ( haltOnError ) {
throw new ImportScriptException( "Error during statement execution (file: '" throw new ImportScriptException(
+ namedReader.getName() + "'): " + trimmedSql, e ); "Error during statement execution (file: '"
+ namedReader.getName() + "'): " + trimmedSql, e
);
} }
exceptions.add(e); exceptions.add( e );
LOG.unsuccessful(trimmedSql); LOG.unsuccessful( trimmedSql );
LOG.error(e.getMessage()); LOG.error( e.getMessage() );
} }
} }
} }
@ -557,14 +565,19 @@ public static void main(String[] args) {
.setDelimiter( commandLineArgs.delimiter ) .setDelimiter( commandLineArgs.delimiter )
.setImportSqlCommandExtractor( serviceRegistry.getService( ImportSqlCommandExtractor.class ) ) .setImportSqlCommandExtractor( serviceRegistry.getService( ImportSqlCommandExtractor.class ) )
.setFormat( commandLineArgs.format ); .setFormat( commandLineArgs.format );
schemaExport.execute( commandLineArgs.script, commandLineArgs.export, commandLineArgs.drop, commandLineArgs.create ); schemaExport.execute(
commandLineArgs.script,
commandLineArgs.export,
commandLineArgs.drop,
commandLineArgs.create
);
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( serviceRegistry ); StandardServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
catch ( Exception e ) { catch (Exception e) {
LOG.unableToCreateSchema( e ); LOG.unableToCreateSchema( e );
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -197,7 +197,7 @@ public void setHaltonerror(boolean haltOnError) {
* Execute the task * Execute the task
*/ */
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
try { try {
buildSchemaExport().execute( !quiet, !text, drop, create ); buildSchemaExport().execute( !quiet, !text, drop, create );
} }

View File

@ -64,7 +64,7 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class SchemaUpdate { public class SchemaUpdate {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SchemaUpdate.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SchemaUpdate.class );
private final MetadataImplementor metadata; private final MetadataImplementor metadata;
private final ServiceRegistry serviceRegistry; private final ServiceRegistry serviceRegistry;
@ -113,9 +113,9 @@ public SchemaUpdate(ServiceRegistry serviceRegistry, MetadataImplementor metadat
public void execute(boolean script, boolean doUpdate) { public void execute(boolean script, boolean doUpdate) {
execute( Target.interpret( script, doUpdate ) ); execute( Target.interpret( script, doUpdate ) );
} }
public void execute(Target target) { public void execute(Target target) {
LOG.runningHbm2ddlSchemaUpdate(); LOG.runningHbm2ddlSchemaUpdate();
exceptions.clear(); exceptions.clear();
@ -203,8 +203,8 @@ public static void main(String[] args) {
StandardServiceRegistryBuilder.destroy( serviceRegistry ); StandardServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
catch ( Exception e ) { catch (Exception e) {
LOG.unableToRunSchemaUpdate(e); LOG.unableToRunSchemaUpdate( e );
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -51,7 +51,7 @@
/** /**
* An Ant task for <tt>SchemaUpdate</tt>. * An Ant task for <tt>SchemaUpdate</tt>.
* * <p/>
* <pre> * <pre>
* &lt;taskdef name="schemaupdate" * &lt;taskdef name="schemaupdate"
* classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask" * classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"
@ -66,8 +66,8 @@
* &lt;/schemaupdate&gt; * &lt;/schemaupdate&gt;
* </pre> * </pre>
* *
* @see SchemaUpdate
* @author Rong C Ou, Gavin King * @author Rong C Ou, Gavin King
* @see SchemaUpdate
*/ */
public class SchemaUpdateTask extends MatchingTask { public class SchemaUpdateTask extends MatchingTask {
private List<FileSet> fileSets = new LinkedList<FileSet>(); private List<FileSet> fileSets = new LinkedList<FileSet>();
@ -81,7 +81,7 @@ public class SchemaUpdateTask extends MatchingTask {
private String implicitNamingStrategy = null; private String implicitNamingStrategy = null;
private String physicalNamingStrategy = null; private String physicalNamingStrategy = null;
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
public void addFileset(FileSet fileSet) { public void addFileset(FileSet fileSet) {
fileSets.add( fileSet ); fileSets.add( fileSet );
@ -95,10 +95,10 @@ public void addFileset(FileSet fileSet) {
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
public void setProperties(File propertiesFile) { public void setProperties(File propertiesFile) {
if ( !propertiesFile.exists() ) { if ( !propertiesFile.exists() ) {
throw new BuildException("Properties file: " + propertiesFile + " does not exist."); throw new BuildException( "Properties file: " + propertiesFile + " does not exist." );
} }
log("Using properties file " + propertiesFile, Project.MSG_DEBUG); log( "Using properties file " + propertiesFile, Project.MSG_DEBUG );
this.propertiesFile = propertiesFile; this.propertiesFile = propertiesFile;
} }
@ -113,14 +113,14 @@ public void setConfig(File configurationFile) {
} }
/** /**
* Enable "text-only" mode. The schema will not be updated in the database. * Enable "text-only" mode. The schema will not be updated in the database.
* *
* @param text true to enable text-only mode * @param text true to enable text-only mode
*/ */
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
public void setText(boolean text) { public void setText(boolean text) {
this.text = text; this.text = text;
} }
/** /**
* Enable "quiet" mode. The schema will not be written to standard out. * Enable "quiet" mode. The schema will not be written to standard out.
@ -181,9 +181,9 @@ public void setDelimiter(String delimiter) {
* Execute the task * Execute the task
*/ */
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
log("Running Hibernate Core SchemaUpdate."); log( "Running Hibernate Core SchemaUpdate." );
log("This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org."); log( "This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org." );
try { try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(); final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
@ -204,19 +204,19 @@ public void execute() throws BuildException {
su.execute( !quiet, !text ); su.execute( !quiet, !text );
} }
catch (HibernateException e) { catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e); throw new BuildException( "Schema text failed: " + e.getMessage(), e );
} }
catch (FileNotFoundException e) { catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e); throw new BuildException( "File not found: " + e.getMessage(), e );
} }
catch (IOException e) { catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e); throw new BuildException( "IOException : " + e.getMessage(), e );
} }
catch (BuildException e) { catch (BuildException e) {
throw e; throw e;
} }
catch (Exception e) { catch (Exception e) {
throw new BuildException(e); throw new BuildException( e );
} }
} }
@ -238,7 +238,7 @@ private void configure(StandardServiceRegistryBuilder registryBuilder) throws IO
private void configure(MetadataSources metadataSources) { private void configure(MetadataSources metadataSources) {
for ( String filename : collectFiles() ) { for ( String filename : collectFiles() ) {
if ( filename.endsWith(".jar") ) { if ( filename.endsWith( ".jar" ) ) {
metadataSources.addJar( new File( filename ) ); metadataSources.addJar( new File( filename ) );
} }
else { else {
@ -273,7 +273,10 @@ private void configure(MetadataBuilder metadataBuilder) {
); );
} }
catch (Exception e) { catch (Exception e) {
throw new BuildException( "Unable to instantiate specified ImplicitNamingStrategy [" + implicitNamingStrategy + "]", e ); throw new BuildException(
"Unable to instantiate specified ImplicitNamingStrategy [" + implicitNamingStrategy + "]",
e
);
} }
} }
@ -284,7 +287,10 @@ private void configure(MetadataBuilder metadataBuilder) {
); );
} }
catch (Exception e) { catch (Exception e) {
throw new BuildException( "Unable to instantiate specified PhysicalNamingStrategy [" + physicalNamingStrategy + "]", e ); throw new BuildException(
"Unable to instantiate specified PhysicalNamingStrategy [" + physicalNamingStrategy + "]",
e
);
} }
} }
} }

View File

@ -239,4 +239,4 @@ public static MetadataImplementor buildMetadataFromMainArgs(String[] args) throw
StandardServiceRegistryBuilder.destroy( serviceRegistry ); StandardServiceRegistryBuilder.destroy( serviceRegistry );
} }
} }
} }

View File

@ -130,7 +130,7 @@ public void setPhysicalNamingStrategy(String physicalNamingStrategy) {
* Execute the task * Execute the task
*/ */
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
try { try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(); final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure( ssrBuilder ); configure( ssrBuilder );

View File

@ -23,18 +23,18 @@
*/ */
package org.hibernate.tool.hbm2ddl; package org.hibernate.tool.hbm2ddl;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.ForeignKey;
import org.jboss.logging.Logger;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.ForeignKey;
import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
* JDBC table metadata * JDBC table metadata
* *
@ -42,32 +42,31 @@
* @author Max Rydahl Andersen * @author Max Rydahl Andersen
*/ */
public class TableMetadata { public class TableMetadata {
private static final CoreMessageLogger LOG = messageLogger( TableMetadata.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, TableMetadata.class.getName());
private final String catalog; private final String catalog;
private final String schema; private final String schema;
private final String name; private final String name;
private final Map columns = new HashMap(); private final Map<String, ColumnMetadata> columns = new HashMap<String, ColumnMetadata>();
private final Map foreignKeys = new HashMap(); private final Map<String,ForeignKeyMetadata> foreignKeys = new HashMap<String,ForeignKeyMetadata>();
private final Map indexes = new HashMap(); private final Map<String, IndexMetadata> indexes = new HashMap<String, IndexMetadata>();
TableMetadata(ResultSet rs, DatabaseMetaData meta, boolean extras) throws SQLException { TableMetadata(ResultSet rs, DatabaseMetaData meta, boolean extras) throws SQLException {
catalog = rs.getString("TABLE_CAT"); catalog = rs.getString( "TABLE_CAT" );
schema = rs.getString("TABLE_SCHEM"); schema = rs.getString( "TABLE_SCHEM" );
name = rs.getString("TABLE_NAME"); name = rs.getString( "TABLE_NAME" );
initColumns(meta); initColumns( meta );
if (extras) { if ( extras ) {
initForeignKeys(meta); initForeignKeys( meta );
initIndexes(meta); initIndexes( meta );
} }
String cat = catalog==null ? "" : catalog + '.'; String cat = catalog == null ? "" : catalog + '.';
String schem = schema==null ? "" : schema + '.'; String schem = schema == null ? "" : schema + '.';
LOG.tableFound( cat + schem + name ); LOG.tableFound( cat + schem + name );
LOG.columns( columns.keySet() ); LOG.columns( columns.keySet() );
if (extras) { if ( extras ) {
LOG.foreignKeys( foreignKeys.keySet() ); LOG.foreignKeys( foreignKeys.keySet() );
LOG.indexes( indexes.keySet() ); LOG.indexes( indexes.keySet() );
} }
} }
@ -84,22 +83,20 @@ public String getSchema() {
} }
@Override @Override
public String toString() { public String toString() {
return "TableMetadata(" + name + ')'; return "TableMetadata(" + name + ')';
} }
public ColumnMetadata getColumnMetadata(String columnName) { public ColumnMetadata getColumnMetadata(String columnName) {
return (ColumnMetadata) columns.get( columnName.toLowerCase(Locale.ROOT) ); return columns.get( columnName.toLowerCase( Locale.ROOT ) );
} }
public ForeignKeyMetadata getForeignKeyMetadata(String keyName) { public ForeignKeyMetadata getForeignKeyMetadata(String keyName) {
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase(Locale.ROOT) ); return foreignKeys.get( keyName.toLowerCase( Locale.ROOT ) );
} }
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) { public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
Iterator it = foreignKeys.values().iterator(); for ( ForeignKeyMetadata existingFk : foreignKeys.values() ) {
while ( it.hasNext() ) {
ForeignKeyMetadata existingFk = ( ForeignKeyMetadata ) it.next();
if ( existingFk.matches( fk ) ) { if ( existingFk.matches( fk ) ) {
return existingFk; return existingFk;
} }
@ -108,51 +105,51 @@ public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
} }
public IndexMetadata getIndexMetadata(String indexName) { public IndexMetadata getIndexMetadata(String indexName) {
return (IndexMetadata) indexes.get( indexName.toLowerCase(Locale.ROOT) ); return indexes.get( indexName.toLowerCase( Locale.ROOT ) );
} }
private void addForeignKey(ResultSet rs) throws SQLException { private void addForeignKey(ResultSet rs) throws SQLException {
String fk = rs.getString("FK_NAME"); String fk = rs.getString( "FK_NAME" );
if (fk == null) { if ( fk == null ) {
return; return;
} }
ForeignKeyMetadata info = getForeignKeyMetadata(fk); ForeignKeyMetadata info = getForeignKeyMetadata( fk );
if (info == null) { if ( info == null ) {
info = new ForeignKeyMetadata(rs); info = new ForeignKeyMetadata( rs );
foreignKeys.put( info.getName().toLowerCase(Locale.ROOT), info ); foreignKeys.put( info.getName().toLowerCase( Locale.ROOT ), info );
} }
info.addReference( rs ); info.addReference( rs );
} }
private void addIndex(ResultSet rs) throws SQLException { private void addIndex(ResultSet rs) throws SQLException {
String index = rs.getString("INDEX_NAME"); String index = rs.getString( "INDEX_NAME" );
if (index == null) { if ( index == null ) {
return; return;
} }
IndexMetadata info = getIndexMetadata(index); IndexMetadata info = getIndexMetadata( index );
if (info == null) { if ( info == null ) {
info = new IndexMetadata(rs); info = new IndexMetadata( rs );
indexes.put( info.getName().toLowerCase(Locale.ROOT), info ); indexes.put( info.getName().toLowerCase( Locale.ROOT ), info );
} }
info.addColumn( getColumnMetadata( rs.getString("COLUMN_NAME") ) ); info.addColumn( getColumnMetadata( rs.getString( "COLUMN_NAME" ) ) );
} }
public void addColumn(ResultSet rs) throws SQLException { public void addColumn(ResultSet rs) throws SQLException {
String column = rs.getString("COLUMN_NAME"); String column = rs.getString( "COLUMN_NAME" );
if (column==null) { if ( column == null ) {
return; return;
} }
if ( getColumnMetadata(column) == null ) { if ( getColumnMetadata( column ) == null ) {
ColumnMetadata info = new ColumnMetadata(rs); ColumnMetadata info = new ColumnMetadata( rs );
columns.put( info.getName().toLowerCase(Locale.ROOT), info ); columns.put( info.getName().toLowerCase( Locale.ROOT ), info );
} }
} }
@ -160,13 +157,13 @@ private void initForeignKeys(DatabaseMetaData meta) throws SQLException {
ResultSet rs = null; ResultSet rs = null;
try { try {
rs = meta.getImportedKeys(catalog, schema, name); rs = meta.getImportedKeys( catalog, schema, name );
while ( rs.next() ) { while ( rs.next() ) {
addForeignKey(rs); addForeignKey( rs );
} }
} }
finally { finally {
if (rs != null) { if ( rs != null ) {
rs.close(); rs.close();
} }
} }
@ -176,17 +173,17 @@ private void initIndexes(DatabaseMetaData meta) throws SQLException {
ResultSet rs = null; ResultSet rs = null;
try { try {
rs = meta.getIndexInfo(catalog, schema, name, false, true); rs = meta.getIndexInfo( catalog, schema, name, false, true );
while ( rs.next() ) { while ( rs.next() ) {
if ( rs.getShort("TYPE") == DatabaseMetaData.tableIndexStatistic ) { if ( rs.getShort( "TYPE" ) == DatabaseMetaData.tableIndexStatistic ) {
continue; continue;
} }
addIndex(rs); addIndex( rs );
} }
} }
finally { finally {
if (rs != null) { if ( rs != null ) {
rs.close(); rs.close();
} }
} }
@ -196,13 +193,13 @@ private void initColumns(DatabaseMetaData meta) throws SQLException {
ResultSet rs = null; ResultSet rs = null;
try { try {
rs = meta.getColumns(catalog, schema, name, "%"); rs = meta.getColumns( catalog, schema, name, "%" );
while ( rs.next() ) { while ( rs.next() ) {
addColumn(rs); addColumn( rs );
} }
} }
finally { finally {
if (rs != null) { if ( rs != null ) {
rs.close(); rs.close();
} }
} }

View File

@ -86,7 +86,7 @@ public final boolean performExtendedInstrumentation() {
protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options); protected abstract Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options);
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
try { try {
buildInstrumenter( logger, this ) buildInstrumenter( logger, this )
.execute( collectSpecifiedFiles() ); .execute( collectSpecifiedFiles() );

View File

@ -65,7 +65,7 @@
*/ */
public class InstrumentTask extends BasicInstrumentationTask { public class InstrumentTask extends BasicInstrumentationTask {
@Override @Override
protected Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options) { protected Instrumenter buildInstrumenter(Logger logger, Instrumenter.Options options) {
return new JavassistInstrumenter( logger, options ); return new JavassistInstrumenter( logger, options );
} }
} }

View File

@ -31,7 +31,7 @@
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.jboss.logging.Logger; import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
* Distinctions the result tuples in the final result based on the defined * Distinctions the result tuples in the final result based on the defined
@ -43,11 +43,9 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class DistinctResultTransformer extends BasicTransformerAdapter { public class DistinctResultTransformer extends BasicTransformerAdapter {
public static final DistinctResultTransformer INSTANCE = new DistinctResultTransformer(); public static final DistinctResultTransformer INSTANCE = new DistinctResultTransformer();
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, private static final CoreMessageLogger LOG = messageLogger( DistinctResultTransformer.class );
DistinctResultTransformer.class.getName());
/** /**
* Helper class to handle distincting * Helper class to handle distincting
@ -59,20 +57,14 @@ private Identity(Object entity) {
this.entity = entity; this.entity = entity;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return Identity.class.isInstance( other ) return Identity.class.isInstance( other )
&& this.entity == ( ( Identity ) other ).entity; && this.entity == ( (Identity) other ).entity;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public int hashCode() { public int hashCode() {
return System.identityHashCode( entity ); return System.identityHashCode( entity );
} }
} }
@ -87,11 +79,10 @@ private DistinctResultTransformer() {
* Uniquely distinct each tuple row here. * Uniquely distinct each tuple row here.
*/ */
@Override @Override
public List transformList(List list) { public List transformList(List list) {
List result = new ArrayList( list.size() ); List<Object> result = new ArrayList<Object>( list.size() );
Set distinct = new HashSet(); Set<Identity> distinct = new HashSet<Identity>();
for ( int i = 0; i < list.size(); i++ ) { for ( Object entity : list ) {
Object entity = list.get( i );
if ( distinct.add( new Identity( entity ) ) ) { if ( distinct.add( new Identity( entity ) ) ) {
result.add( entity ); result.add( entity );
} }

View File

@ -50,7 +50,7 @@ private RootEntityResultTransformer() {
* Return just the root entity from the row tuple. * Return just the root entity from the row tuple.
*/ */
@Override @Override
public Object transformTuple(Object[] tuple, String[] aliases) { public Object transformTuple(Object[] tuple, String[] aliases) {
return tuple[ tuple.length-1 ]; return tuple[ tuple.length-1 ];
} }

View File

@ -25,11 +25,9 @@
package org.hibernate.transform; package org.hibernate.transform;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* Tranforms each result row from a tuple into a {@link List}, such that what * Tranforms each result row from a tuple into a {@link java.util.List} whose elements are each tuple value
* you end up with is a {@link List} of {@link List Lists}.
*/ */
public class ToListResultTransformer extends BasicTransformerAdapter { public class ToListResultTransformer extends BasicTransformerAdapter {
public static final ToListResultTransformer INSTANCE = new ToListResultTransformer(); public static final ToListResultTransformer INSTANCE = new ToListResultTransformer();

View File

@ -25,7 +25,6 @@
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import org.hibernate.HibernateException;
/** /**
* A {@link ValueGeneration} based on a custom Java generator annotation type. * A {@link ValueGeneration} based on a custom Java generator annotation type.
@ -44,8 +43,8 @@ public interface AnnotationValueGeneration<A extends Annotation> extends ValueGe
* @param propertyType the type of the property annotated with the generator annotation. Implementations may use * @param propertyType the type of the property annotated with the generator annotation. Implementations may use
* the type to determine the right {@link ValueGenerator} to be applied. * the type to determine the right {@link ValueGenerator} to be applied.
* *
* @throws HibernateException in case an error occurred during initialization, e.g. if an implementation can't * @throws org.hibernate.HibernateException in case an error occurred during initialization, e.g. if
* create a value for the given property type. * an implementation can't create a value for the given property type.
*/ */
void initialize(A annotation, Class<?> propertyType); void initialize(A annotation, Class<?> propertyType);
} }

View File

@ -299,7 +299,7 @@ public List selectNodes(String xpath, String comparison, boolean removeDups) {
} }
public Node selectSingleNode(String xpath) { public Node selectSingleNode(String xpath) {
return element.selectSingleNode( xpath ); return element.selectSingleNode( xpath );
} }
public String valueOf(String xpath) { public String valueOf(String xpath) {

View File

@ -35,7 +35,6 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class IdentifierProperty extends AbstractAttribute implements IdentifierAttribute { public class IdentifierProperty extends AbstractAttribute implements IdentifierAttribute {
private boolean virtual; private boolean virtual;
private boolean embedded; private boolean embedded;
private IdentifierValue unsavedValue; private IdentifierValue unsavedValue;
@ -82,11 +81,11 @@ public IdentifierProperty(
* @param identifierGenerator The generator to use for id value generation. * @param identifierGenerator The generator to use for id value generation.
*/ */
public IdentifierProperty( public IdentifierProperty(
Type type, Type type,
boolean embedded, boolean embedded,
boolean hasIdentifierMapper, boolean hasIdentifierMapper,
IdentifierValue unsavedValue, IdentifierValue unsavedValue,
IdentifierGenerator identifierGenerator) { IdentifierGenerator identifierGenerator) {
super( null, type ); super( null, type );
this.virtual = true; this.virtual = true;
this.embedded = embedded; this.embedded = embedded;

View File

@ -27,6 +27,8 @@
* Defines the basic contract of a Property within the runtime metamodel. * Defines the basic contract of a Property within the runtime metamodel.
* *
* @author Steve Ebersole * @author Steve Ebersole
*
* @deprecated Use the direct {@link Attribute} hierarchy
*/ */
@Deprecated @Deprecated
public interface Property extends Attribute { public interface Property extends Attribute {

View File

@ -64,6 +64,7 @@ private PropertyFactory() {
* *
* @param mappedEntity The mapping definition of the entity. * @param mappedEntity The mapping definition of the entity.
* @param generator The identifier value generator to use for this identifier. * @param generator The identifier value generator to use for this identifier.
*
* @return The appropriate IdentifierProperty definition. * @return The appropriate IdentifierProperty definition.
*/ */
public static IdentifierProperty buildIdentifierAttribute( public static IdentifierProperty buildIdentifierAttribute(
@ -72,23 +73,23 @@ public static IdentifierProperty buildIdentifierAttribute(
String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue(); String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
Type type = mappedEntity.getIdentifier().getType(); Type type = mappedEntity.getIdentifier().getType();
Property property = mappedEntity.getIdentifierProperty(); Property property = mappedEntity.getIdentifierProperty();
IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue( IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
mappedUnsavedValue, mappedUnsavedValue,
getGetter( property ), getGetter( property ),
type, type,
getConstructor(mappedEntity) getConstructor( mappedEntity )
); );
if ( property == null ) { if ( property == null ) {
// this is a virtual id property... // this is a virtual id property...
return new IdentifierProperty( return new IdentifierProperty(
type, type,
mappedEntity.hasEmbeddedIdentifier(), mappedEntity.hasEmbeddedIdentifier(),
mappedEntity.hasIdentifierMapper(), mappedEntity.hasIdentifierMapper(),
unsavedValue, unsavedValue,
generator generator
); );
} }
else { else {
return new IdentifierProperty( return new IdentifierProperty(
@ -98,7 +99,7 @@ public static IdentifierProperty buildIdentifierAttribute(
mappedEntity.hasEmbeddedIdentifier(), mappedEntity.hasEmbeddedIdentifier(),
unsavedValue, unsavedValue,
generator generator
); );
} }
} }
@ -108,6 +109,7 @@ public static IdentifierProperty buildIdentifierAttribute(
* *
* @param property The version mapping Property. * @param property The version mapping Property.
* @param lazyAvailable Is property lazy loading currently available. * @param lazyAvailable Is property lazy loading currently available.
*
* @return The appropriate VersionProperty definition. * @return The appropriate VersionProperty definition.
*/ */
public static VersionProperty buildVersionProperty( public static VersionProperty buildVersionProperty(
@ -117,7 +119,7 @@ public static VersionProperty buildVersionProperty(
Property property, Property property,
boolean lazyAvailable) { boolean lazyAvailable) {
String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue(); String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();
VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue( VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
mappedUnsavedValue, mappedUnsavedValue,
getGetter( property ), getGetter( property ),
@ -131,8 +133,8 @@ public static VersionProperty buildVersionProperty(
persister, persister,
sessionFactory, sessionFactory,
attributeNumber, attributeNumber,
property.getName(), property.getName(),
property.getValue().getType(), property.getValue().getType(),
new BaselineAttributeInformation.Builder() new BaselineAttributeInformation.Builder()
.setLazy( lazy ) .setLazy( lazy )
.setInsertable( property.isInsertable() ) .setInsertable( property.isInsertable() )
@ -143,8 +145,8 @@ public static VersionProperty buildVersionProperty(
.setVersionable( property.isOptimisticLocked() ) .setVersionable( property.isOptimisticLocked() )
.setCascadeStyle( property.getCascadeStyle() ) .setCascadeStyle( property.getCascadeStyle() )
.createInformation(), .createInformation(),
unsavedValue unsavedValue
); );
} }
public static enum NonIdentifierAttributeNature { public static enum NonIdentifierAttributeNature {
@ -160,6 +162,7 @@ public static enum NonIdentifierAttributeNature {
* *
* @param property The mapped property. * @param property The mapped property.
* @param lazyAvailable Is property lazy loading currently available. * @param lazyAvailable Is property lazy loading currently available.
*
* @return The appropriate NonIdentifierProperty definition. * @return The appropriate NonIdentifierProperty definition.
*/ */
public static NonIdentifierAttribute buildEntityBasedAttribute( public static NonIdentifierAttribute buildEntityBasedAttribute(
@ -174,13 +177,13 @@ public static NonIdentifierAttribute buildEntityBasedAttribute(
// we need to dirty check collections, since they can cause an owner // we need to dirty check collections, since they can cause an owner
// version number increment // version number increment
// we need to dirty check many-to-ones with not-found="ignore" in order // we need to dirty check many-to-ones with not-found="ignore" in order
// to update the cache (not the database), since in this case a null // to update the cache (not the database), since in this case a null
// entity reference can lose information // entity reference can lose information
boolean alwaysDirtyCheck = type.isAssociationType() && boolean alwaysDirtyCheck = type.isAssociationType() &&
( (AssociationType) type ).isAlwaysDirtyChecked(); ( (AssociationType) type ).isAlwaysDirtyChecked();
switch ( nature ) { switch ( nature ) {
case BASIC: { case BASIC: {
@ -314,7 +317,7 @@ private static Constructor getConstructor(PersistentClass persistentClass) {
try { try {
return ReflectHelper.getDefaultConstructor( persistentClass.getMappedClass() ); return ReflectHelper.getDefaultConstructor( persistentClass.getMappedClass() );
} }
catch( Throwable t ) { catch (Throwable t) {
return null; return null;
} }
} }

View File

@ -59,7 +59,7 @@
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.jboss.logging.Logger; import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
@ -69,11 +69,7 @@
* @author Gavin King * @author Gavin King
*/ */
public abstract class AbstractEntityTuplizer implements EntityTuplizer { public abstract class AbstractEntityTuplizer implements EntityTuplizer {
private static final CoreMessageLogger LOG = messageLogger( AbstractEntityTuplizer.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
AbstractEntityTuplizer.class.getName()
);
//TODO: currently keeps Getters and Setters (instead of PropertyAccessors) because of the way getGetter() and getSetter() are implemented currently; yuck! //TODO: currently keeps Getters and Setters (instead of PropertyAccessors) because of the way getGetter() and getSetter() are implemented currently; yuck!
@ -99,6 +95,7 @@ public Type getIdentifierMapperType() {
* *
* @param mappedProperty The property to be accessed via the built Getter. * @param mappedProperty The property to be accessed via the built Getter.
* @param mappedEntity The entity information regarding the mapped entity owning this property. * @param mappedEntity The entity information regarding the mapped entity owning this property.
*
* @return An appropriate Getter instance. * @return An appropriate Getter instance.
*/ */
protected abstract Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity); protected abstract Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity);
@ -108,6 +105,7 @@ public Type getIdentifierMapperType() {
* *
* @param mappedProperty The property to be accessed via the built Setter. * @param mappedProperty The property to be accessed via the built Setter.
* @param mappedEntity The entity information regarding the mapped entity owning this property. * @param mappedEntity The entity information regarding the mapped entity owning this property.
*
* @return An appropriate Setter instance. * @return An appropriate Setter instance.
*/ */
protected abstract Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity); protected abstract Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity);
@ -116,6 +114,7 @@ public Type getIdentifierMapperType() {
* Build an appropriate Instantiator for the given mapped entity. * Build an appropriate Instantiator for the given mapped entity.
* *
* @param mappingInfo The mapping information regarding the mapped entity. * @param mappingInfo The mapping information regarding the mapped entity.
*
* @return An appropriate Instantiator instance. * @return An appropriate Instantiator instance.
*/ */
protected abstract Instantiator buildInstantiator(PersistentClass mappingInfo); protected abstract Instantiator buildInstantiator(PersistentClass mappingInfo);
@ -126,6 +125,7 @@ public Type getIdentifierMapperType() {
* @param mappingInfo The mapping information regarding the mapped entity. * @param mappingInfo The mapping information regarding the mapped entity.
* @param idGetter The constructed Getter relating to the entity's id property. * @param idGetter The constructed Getter relating to the entity's id property.
* @param idSetter The constructed Setter relating to the entity's id property. * @param idSetter The constructed Setter relating to the entity's id property.
*
* @return An appropriate ProxyFactory instance. * @return An appropriate ProxyFactory instance.
*/ */
protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter); protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter);
@ -150,17 +150,17 @@ public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass m
propertySpan = entityMetamodel.getPropertySpan(); propertySpan = entityMetamodel.getPropertySpan();
getters = new Getter[propertySpan]; getters = new Getter[propertySpan];
setters = new Setter[propertySpan]; setters = new Setter[propertySpan];
Iterator itr = mappingInfo.getPropertyClosureIterator(); Iterator itr = mappingInfo.getPropertyClosureIterator();
boolean foundCustomAccessor=false; boolean foundCustomAccessor = false;
int i=0; int i = 0;
while ( itr.hasNext() ) { while ( itr.hasNext() ) {
//TODO: redesign how PropertyAccessors are acquired... //TODO: redesign how PropertyAccessors are acquired...
Property property = (Property) itr.next(); Property property = (Property) itr.next();
getters[i] = buildPropertyGetter(property, mappingInfo); getters[i] = buildPropertyGetter( property, mappingInfo );
setters[i] = buildPropertySetter(property, mappingInfo); setters[i] = buildPropertySetter( property, mappingInfo );
if ( !property.isBasicPropertyAccessor() ) { if ( !property.isBasicPropertyAccessor() ) {
foundCustomAccessor = true; foundCustomAccessor = true;
} }
@ -168,11 +168,11 @@ public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass m
} }
hasCustomAccessors = foundCustomAccessor; hasCustomAccessors = foundCustomAccessor;
instantiator = buildInstantiator( mappingInfo ); instantiator = buildInstantiator( mappingInfo );
if ( entityMetamodel.isLazy() ) { if ( entityMetamodel.isLazy() ) {
proxyFactory = buildProxyFactory( mappingInfo, idGetter, idSetter ); proxyFactory = buildProxyFactory( mappingInfo, idGetter, idSetter );
if (proxyFactory == null) { if ( proxyFactory == null ) {
entityMetamodel.setLazy( false ); entityMetamodel.setLazy( false );
} }
} }
@ -194,7 +194,8 @@ public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass m
} }
} }
/** Retreives the defined entity-name for the tuplized entity. /**
* Retreives the defined entity-name for the tuplized entity.
* *
* @return The entity-name. * @return The entity-name.
*/ */
@ -228,7 +229,7 @@ else if ( HibernateProxy.class.isInstance( entity ) ) {
} }
else { else {
if ( idGetter == null ) { if ( idGetter == null ) {
if (identifierMapperType==null) { if ( identifierMapperType == null ) {
throw new HibernateException( "The class has no identifier property: " + getEntityName() ); throw new HibernateException( "The class has no identifier property: " + getEntityName() );
} }
else { else {
@ -236,14 +237,14 @@ else if ( HibernateProxy.class.isInstance( entity ) ) {
} }
} }
else { else {
id = idGetter.get( entity ); id = idGetter.get( entity );
} }
} }
try { try {
return (Serializable) id; return (Serializable) id;
} }
catch ( ClassCastException cce ) { catch (ClassCastException cce) {
StringBuilder msg = new StringBuilder( "Identifier classes must be serializable. " ); StringBuilder msg = new StringBuilder( "Identifier classes must be serializable. " );
if ( id != null ) { if ( id != null ) {
msg.append( id.getClass().getName() ).append( " is not serializable. " ); msg.append( id.getClass().getName() ).append( " is not serializable. " );
@ -280,6 +281,7 @@ else if ( identifierMapperType != null ) {
private static interface MappedIdentifierValueMarshaller { private static interface MappedIdentifierValueMarshaller {
public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session); public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session);
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session); public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session);
} }
@ -303,7 +305,7 @@ private static MappedIdentifierValueMarshaller buildMappedIdentifierValueMarshal
// the sizes being off is a much bigger problem that should have been caught already... // the sizes being off is a much bigger problem that should have been caught already...
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) { for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
if ( virtualIdComponent.getSubtypes()[i].isEntityType() if ( virtualIdComponent.getSubtypes()[i].isEntityType()
&& ! mappedIdClassComponentType.getSubtypes()[i].isEntityType() ) { && !mappedIdClassComponentType.getSubtypes()[i].isEntityType() ) {
wereAllEquivalent = false; wereAllEquivalent = false;
break; break;
} }
@ -311,14 +313,19 @@ private static MappedIdentifierValueMarshaller buildMappedIdentifierValueMarshal
return wereAllEquivalent return wereAllEquivalent
? new NormalMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType ) ? new NormalMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType )
: new IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType ); : new IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller(
virtualIdComponent,
mappedIdClassComponentType
);
} }
private static class NormalMappedIdentifierValueMarshaller implements MappedIdentifierValueMarshaller { private static class NormalMappedIdentifierValueMarshaller implements MappedIdentifierValueMarshaller {
private final ComponentType virtualIdComponent; private final ComponentType virtualIdComponent;
private final ComponentType mappedIdentifierType; private final ComponentType mappedIdentifierType;
private NormalMappedIdentifierValueMarshaller(ComponentType virtualIdComponent, ComponentType mappedIdentifierType) { private NormalMappedIdentifierValueMarshaller(
ComponentType virtualIdComponent,
ComponentType mappedIdentifierType) {
this.virtualIdComponent = virtualIdComponent; this.virtualIdComponent = virtualIdComponent;
this.mappedIdentifierType = mappedIdentifierType; this.mappedIdentifierType = mappedIdentifierType;
} }
@ -341,11 +348,14 @@ public void setIdentifier(Object entity, Serializable id, EntityMode entityMode,
} }
} }
private static class IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller implements MappedIdentifierValueMarshaller { private static class IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller
implements MappedIdentifierValueMarshaller {
private final ComponentType virtualIdComponent; private final ComponentType virtualIdComponent;
private final ComponentType mappedIdentifierType; private final ComponentType mappedIdentifierType;
private IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller(ComponentType virtualIdComponent, ComponentType mappedIdentifierType) { private IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller(
ComponentType virtualIdComponent,
ComponentType mappedIdentifierType) {
this.virtualIdComponent = virtualIdComponent; this.virtualIdComponent = virtualIdComponent;
this.mappedIdentifierType = mappedIdentifierType; this.mappedIdentifierType = mappedIdentifierType;
} }
@ -359,12 +369,12 @@ public Object getIdentifier(Object entity, EntityMode entityMode, SessionImpleme
final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session ); final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session );
final PersistenceContext persistenceContext = session.getPersistenceContext(); final PersistenceContext persistenceContext = session.getPersistenceContext();
final int length = subTypes.length; final int length = subTypes.length;
for ( int i = 0 ; i < length; i++ ) { for ( int i = 0; i < length; i++ ) {
if ( propertyValues[i] == null ) { if ( propertyValues[i] == null ) {
throw new HibernateException( "No part of a composite identifier may be null" ); throw new HibernateException( "No part of a composite identifier may be null" );
} }
//JPA 2 @MapsId + @IdClass points to the pk of the entity //JPA 2 @MapsId + @IdClass points to the pk of the entity
if ( subTypes[i].isAssociationType() && ! copierSubTypes[i].isAssociationType() ) { if ( subTypes[i].isAssociationType() && !copierSubTypes[i].isAssociationType() ) {
// we need a session to handle this use case // we need a session to handle this use case
if ( session == null ) { if ( session == null ) {
throw new AssertionError( throw new AssertionError(
@ -382,7 +392,11 @@ public Object getIdentifier(Object entity, EntityMode entityMode, SessionImpleme
} }
else { else {
LOG.debug( "Performing implicit derived identity cascade" ); LOG.debug( "Performing implicit derived identity cascade" );
final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session ); final PersistEvent event = new PersistEvent(
null,
propertyValues[i],
(EventSource) session
);
for ( PersistEventListener listener : persistEventListeners ) { for ( PersistEventListener listener : persistEventListeners ) {
listener.onPersist( event ); listener.onPersist( event );
} }
@ -405,12 +419,12 @@ public Object getIdentifier(Object entity, EntityMode entityMode, SessionImpleme
@Override @Override
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) { public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) {
final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode ); final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
final Object[] injectionValues = new Object[ extractedValues.length ]; final Object[] injectionValues = new Object[extractedValues.length];
final PersistenceContext persistenceContext = session.getPersistenceContext(); final PersistenceContext persistenceContext = session.getPersistenceContext();
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) { for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i]; final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i]; final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
if ( virtualPropertyType.isEntityType() && ! idClassPropertyType.isEntityType() ) { if ( virtualPropertyType.isEntityType() && !idClassPropertyType.isEntityType() ) {
if ( session == null ) { if ( session == null ) {
throw new AssertionError( throw new AssertionError(
"Deprecated version of getIdentifier (no session) was used but session was required" "Deprecated version of getIdentifier (no session) was used but session was required"
@ -459,6 +473,7 @@ public void resetIdentifier(
Serializable currentId, Serializable currentId,
Object currentVersion, Object currentVersion,
SessionImplementor session) { SessionImplementor session) {
//noinspection StatementWithEmptyBody
if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) { if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) {
} }
else { else {
@ -471,8 +486,8 @@ public void resetIdentifier(
VersionProperty versionProperty = entityMetamodel.getVersionProperty(); VersionProperty versionProperty = entityMetamodel.getVersionProperty();
if ( entityMetamodel.isVersioned() ) { if ( entityMetamodel.isVersioned() ) {
setPropertyValue( setPropertyValue(
entity, entity,
entityMetamodel.getVersionPropertyIndex(), entityMetamodel.getVersionPropertyIndex(),
versionProperty.getUnsavedValue().getDefaultValue( currentVersion ) versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
); );
} }
@ -481,8 +496,10 @@ public void resetIdentifier(
@Override @Override
public Object getVersion(Object entity) throws HibernateException { public Object getVersion(Object entity) throws HibernateException {
if ( !entityMetamodel.isVersioned() ) return null; if ( !entityMetamodel.isVersioned() ) {
return getters[ entityMetamodel.getVersionPropertyIndex() ].get( entity ); return null;
}
return getters[entityMetamodel.getVersionPropertyIndex()].get( entity );
} }
protected boolean shouldGetAllProperties(Object entity) { protected boolean shouldGetAllProperties(Object entity) {
@ -526,18 +543,18 @@ public Object getPropertyValue(Object entity, int i) throws HibernateException {
@Override @Override
public Object getPropertyValue(Object entity, String propertyPath) throws HibernateException { public Object getPropertyValue(Object entity, String propertyPath) throws HibernateException {
int loc = propertyPath.indexOf('.'); int loc = propertyPath.indexOf( '.' );
String basePropertyName = loc > 0 String basePropertyName = loc > 0
? propertyPath.substring( 0, loc ) ? propertyPath.substring( 0, loc )
: propertyPath; : propertyPath;
//final int index = entityMetamodel.getPropertyIndexOrNull( basePropertyName ); //final int index = entityMetamodel.getPropertyIndexOrNull( basePropertyName );
Integer index = entityMetamodel.getPropertyIndexOrNull( basePropertyName ); Integer index = entityMetamodel.getPropertyIndexOrNull( basePropertyName );
if (index == null) { if ( index == null ) {
propertyPath = PropertyPath.IDENTIFIER_MAPPER_PROPERTY + "." + propertyPath; propertyPath = PropertyPath.IDENTIFIER_MAPPER_PROPERTY + "." + propertyPath;
loc = propertyPath.indexOf('.'); loc = propertyPath.indexOf( '.' );
basePropertyName = loc > 0 basePropertyName = loc > 0
? propertyPath.substring( 0, loc ) ? propertyPath.substring( 0, loc )
: propertyPath; : propertyPath;
} }
index = entityMetamodel.getPropertyIndexOrNull( basePropertyName ); index = entityMetamodel.getPropertyIndexOrNull( basePropertyName );
final Object baseValue = getPropertyValue( entity, index ); final Object baseValue = getPropertyValue( entity, index );
@ -548,7 +565,7 @@ public Object getPropertyValue(Object entity, String propertyPath) throws Hibern
return getComponentValue( return getComponentValue(
(ComponentType) entityMetamodel.getPropertyTypes()[index], (ComponentType) entityMetamodel.getPropertyTypes()[index],
baseValue, baseValue,
propertyPath.substring(loc+1) propertyPath.substring( loc + 1 )
); );
} }
else { else {
@ -562,6 +579,7 @@ public Object getPropertyValue(Object entity, String propertyPath) throws Hibern
* @param type The component property types. * @param type The component property types.
* @param component The component instance itself. * @param component The component instance itself.
* @param propertyPath The property path for the property to be extracted. * @param propertyPath The property path for the property to be extracted.
*
* @return The property value extracted. * @return The property value extracted.
*/ */
protected Object getComponentValue(ComponentType type, Object component, String propertyPath) { protected Object getComponentValue(ComponentType type, Object component, String propertyPath) {
@ -578,7 +596,7 @@ protected Object getComponentValue(ComponentType type, Object component, String
return getComponentValue( return getComponentValue(
(ComponentType) type.getSubtypes()[index], (ComponentType) type.getSubtypes()[index],
baseValue, baseValue,
propertyPath.substring(loc+1) propertyPath.substring( loc + 1 )
); );
} }
else { else {
@ -589,7 +607,7 @@ protected Object getComponentValue(ComponentType type, Object component, String
private int findSubPropertyIndex(ComponentType type, String subPropertyName) { private int findSubPropertyIndex(ComponentType type, String subPropertyName) {
final String[] propertyNames = type.getPropertyNames(); final String[] propertyNames = type.getPropertyNames();
for ( int index = 0; index<propertyNames.length; index++ ) { for ( int index = 0; index < propertyNames.length; index++ ) {
if ( subPropertyName.equals( propertyNames[index] ) ) { if ( subPropertyName.equals( propertyNames[index] ) ) {
return index; return index;
} }
@ -615,7 +633,7 @@ public void setPropertyValue(Object entity, int i, Object value) throws Hibernat
@Override @Override
public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException { public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException {
setters[ entityMetamodel.getPropertyIndex( propertyName ) ].set( entity, value, getFactory() ); setters[entityMetamodel.getPropertyIndex( propertyName )].set( entity, value, getFactory() );
} }
@Override @Override
@ -640,7 +658,8 @@ public final Object instantiate() throws HibernateException {
} }
@Override @Override
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {} public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {
}
@Override @Override
public boolean hasUninitializedLazyProperties(Object entity) { public boolean hasUninitializedLazyProperties(Object entity) {
@ -650,7 +669,7 @@ public boolean hasUninitializedLazyProperties(Object entity) {
@Override @Override
public final boolean isInstance(Object object) { public final boolean isInstance(Object object) {
return getInstantiator().isInstance( object ); return getInstantiator().isInstance( object );
} }
@Override @Override
@ -660,7 +679,7 @@ public boolean hasProxy() {
@Override @Override
public final Object createProxy(Serializable id, SessionImplementor session) public final Object createProxy(Serializable id, SessionImplementor session)
throws HibernateException { throws HibernateException {
return getProxyFactory().getProxy( id, session ); return getProxyFactory().getProxy( id, session );
} }
@ -686,7 +705,7 @@ protected final ProxyFactory getProxyFactory() {
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getName() + '(' + getEntityMetamodel().getName() + ')'; return getClass().getName() + '(' + getEntityMetamodel().getName() + ')';
} }

View File

@ -52,7 +52,7 @@ public class DynamicMapEntityTuplizer extends AbstractEntityTuplizer {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DynamicMapEntityTuplizer.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DynamicMapEntityTuplizer.class );
DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
super(entityMetamodel, mappedEntity); super( entityMetamodel, mappedEntity );
} }
@Override @Override
@ -62,7 +62,7 @@ public EntityMode getEntityMode() {
private PropertyAccessor buildPropertyAccessor(Property mappedProperty) { private PropertyAccessor buildPropertyAccessor(Property mappedProperty) {
if ( mappedProperty.isBackRef() ) { if ( mappedProperty.isBackRef() ) {
return mappedProperty.getPropertyAccessor(null); return mappedProperty.getPropertyAccessor( null );
} }
else { else {
return PropertyAccessorFactory.getDynamicMapPropertyAccessor(); return PropertyAccessorFactory.getDynamicMapPropertyAccessor();
@ -70,22 +70,22 @@ private PropertyAccessor buildPropertyAccessor(Property mappedProperty) {
} }
@Override @Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() ); return buildPropertyAccessor( mappedProperty ).getGetter( null, mappedProperty.getName() );
} }
@Override @Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() ); return buildPropertyAccessor( mappedProperty ).getSetter( null, mappedProperty.getName() );
} }
@Override @Override
protected Instantiator buildInstantiator(PersistentClass mappingInfo) { protected Instantiator buildInstantiator(PersistentClass mappingInfo) {
return new DynamicMapInstantiator( mappingInfo ); return new DynamicMapInstantiator( mappingInfo );
} }
@Override @Override
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) { protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
ProxyFactory pf = new MapProxyFactory(); ProxyFactory pf = new MapProxyFactory();
try { try {
@ -99,7 +99,7 @@ protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idG
null null
); );
} }
catch ( HibernateException he ) { catch (HibernateException he) {
LOG.unableToCreateProxyFactory( getEntityName(), he ); LOG.unableToCreateProxyFactory( getEntityName(), he );
pf = null; pf = null;
} }
@ -123,16 +123,16 @@ public boolean isInstrumented() {
@Override @Override
public EntityNameResolver[] getEntityNameResolvers() { public EntityNameResolver[] getEntityNameResolvers() {
return new EntityNameResolver[] { BasicEntityNameResolver.INSTANCE }; return new EntityNameResolver[] {BasicEntityNameResolver.INSTANCE};
} }
@Override @Override
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) { public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
return extractEmbeddedEntityName( ( Map ) entityInstance ); return extractEmbeddedEntityName( (Map) entityInstance );
} }
public static String extractEmbeddedEntityName(Map entity) { public static String extractEmbeddedEntityName(Map entity) {
return ( String ) entity.get( DynamicMapInstantiator.KEY ); return (String) entity.get( DynamicMapInstantiator.KEY );
} }
public static class BasicEntityNameResolver implements EntityNameResolver { public static class BasicEntityNameResolver implements EntityNameResolver {
@ -140,10 +140,10 @@ public static class BasicEntityNameResolver implements EntityNameResolver {
@Override @Override
public String resolveEntityName(Object entity) { public String resolveEntityName(Object entity) {
if ( ! Map.class.isInstance( entity ) ) { if ( !Map.class.isInstance( entity ) ) {
return null; return null;
} }
final String entityName = extractEmbeddedEntityName( ( Map ) entity ); final String entityName = extractEmbeddedEntityName( (Map) entity );
if ( entityName == null ) { if ( entityName == null ) {
throw new HibernateException( "Could not determine type of dynamic map entity" ); throw new HibernateException( "Could not determine type of dynamic map entity" );
} }
@ -151,12 +151,12 @@ public String resolveEntityName(Object entity) {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return getClass().equals( obj.getClass() ); return getClass().equals( obj.getClass() );
} }
@Override @Override
public int hashCode() { public int hashCode() {
return getClass().hashCode(); return getClass().hashCode();
} }
} }

View File

@ -25,7 +25,6 @@
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -345,13 +344,13 @@ else if ( timing == GenerationTiming.ALWAYS ) {
if ( persistentClass.isAbstract() == null ) { if ( persistentClass.isAbstract() == null ) {
// legacy behavior (with no abstract attribute specified) // legacy behavior (with no abstract attribute specified)
isAbstract = persistentClass.hasPojoRepresentation() && isAbstract = persistentClass.hasPojoRepresentation() &&
ReflectHelper.isAbstractClass( persistentClass.getMappedClass() ); ReflectHelper.isAbstractClass( persistentClass.getMappedClass() );
} }
else { else {
isAbstract = persistentClass.isAbstract().booleanValue(); isAbstract = persistentClass.isAbstract().booleanValue();
if ( !isAbstract && persistentClass.hasPojoRepresentation() && if ( !isAbstract && persistentClass.hasPojoRepresentation() &&
ReflectHelper.isAbstractClass( persistentClass.getMappedClass() ) ) { ReflectHelper.isAbstractClass( persistentClass.getMappedClass() ) ) {
LOG.entityMappedAsNonAbstract(name); LOG.entityMappedAsNonAbstract(name);
} }
} }
selectBeforeUpdate = persistentClass.hasSelectBeforeUpdate(); selectBeforeUpdate = persistentClass.hasSelectBeforeUpdate();
@ -1033,7 +1032,7 @@ public String findEntityNameByEntityClass(Class inheritenceClass) {
} }
@Override @Override
public String toString() { public String toString() {
return "EntityMetamodel(" + name + ':' + ArrayHelper.toString(properties) + ')'; return "EntityMetamodel(" + name + ':' + ArrayHelper.toString(properties) + ')';
} }

View File

@ -67,7 +67,7 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
private final Class mappedClass; private final Class mappedClass;
private final Class proxyInterface; private final Class proxyInterface;
private final boolean lifecycleImplementor; private final boolean lifecycleImplementor;
private final Set lazyPropertyNames = new HashSet(); private final Set<String> lazyPropertyNames = new HashSet<String>();
private final ReflectionOptimizer optimizer; private final ReflectionOptimizer optimizer;
private final boolean isInstrumented; private final boolean isInstrumented;
@ -100,7 +100,12 @@ public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappe
} }
else { else {
// todo : YUCK!!! // todo : YUCK!!!
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes ); optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
mappedClass,
getterNames,
setterNames,
propTypes
);
// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer( // optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
// mappedClass, getterNames, setterNames, propTypes // mappedClass, getterNames, setterNames, propTypes
// ); // );
@ -108,9 +113,9 @@ public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappe
} }
@Override @Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any) // determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy // determine all interfaces needed by the resulting proxy
/* /*
* We need to preserve the order of the interfaces they were put into the set, since javassist will choose the * We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
@ -123,7 +128,7 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter
Class mappedClass = persistentClass.getMappedClass(); Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface(); Class proxyInterface = persistentClass.getProxyInterface();
if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) { if ( proxyInterface != null && !mappedClass.equals( proxyInterface ) ) {
if ( !proxyInterface.isInterface() ) { if ( !proxyInterface.isInterface() ) {
throw new MappingException( throw new MappingException(
"proxy must be either an interface, or the class itself: " + getEntityName() "proxy must be either an interface, or the class itself: " + getEntityName()
@ -136,12 +141,12 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter
proxyInterfaces.add( mappedClass ); proxyInterfaces.add( mappedClass );
} }
Iterator subclasses = persistentClass.getSubclassIterator(); Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
while ( subclasses.hasNext() ) { while ( subclasses.hasNext() ) {
final Subclass subclass = ( Subclass ) subclasses.next(); final Subclass subclass = subclasses.next();
final Class subclassProxy = subclass.getProxyInterface(); final Class subclassProxy = subclass.getProxyInterface();
final Class subclassClass = subclass.getMappedClass(); final Class subclassClass = subclass.getMappedClass();
if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) { if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) {
if ( !subclassProxy.isInterface() ) { if ( !subclassProxy.isInterface() ) {
throw new MappingException( throw new MappingException(
"proxy must be either an interface, or the class itself: " + subclass.getEntityName() "proxy must be either an interface, or the class itself: " + subclass.getEntityName()
@ -157,25 +162,25 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter
Class clazz = persistentClass.getMappedClass(); Class clazz = persistentClass.getMappedClass();
while ( properties.hasNext() ) { while ( properties.hasNext() ) {
Property property = (Property) properties.next(); Property property = (Property) properties.next();
Method method = property.getGetter(clazz).getMethod(); Method method = property.getGetter( clazz ).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName()); LOG.gettersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
} }
method = property.getSetter(clazz).getMethod(); method = property.getSetter( clazz ).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName()); LOG.settersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
} }
} }
Method idGetterMethod = idGetter==null ? null : idGetter.getMethod(); Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
Method idSetterMethod = idSetter==null ? null : idSetter.getMethod(); Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();
Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ? Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ?
null : null :
ReflectHelper.getMethod(proxyInterface, idGetterMethod); ReflectHelper.getMethod( proxyInterface, idGetterMethod );
Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ? Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ?
null : null :
ReflectHelper.getMethod(proxyInterface, idSetterMethod); ReflectHelper.getMethod( proxyInterface, idSetterMethod );
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter ); ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
try { try {
@ -186,25 +191,28 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter
proxyGetIdentifierMethod, proxyGetIdentifierMethod,
proxySetIdentifierMethod, proxySetIdentifierMethod,
persistentClass.hasEmbeddedIdentifier() ? persistentClass.hasEmbeddedIdentifier() ?
(CompositeType) persistentClass.getIdentifier().getType() : (CompositeType) persistentClass.getIdentifier().getType() :
null null
); );
} }
catch ( HibernateException he ) { catch (HibernateException he) {
LOG.unableToCreateProxyFactory(getEntityName(), he); LOG.unableToCreateProxyFactory( getEntityName(), he );
pf = null; pf = null;
} }
return pf; return pf;
} }
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { protected ProxyFactory buildProxyFactoryInternal(
PersistentClass persistentClass,
Getter idGetter,
Setter idSetter) {
// TODO : YUCK!!! fix after HHH-1907 is complete // TODO : YUCK!!! fix after HHH-1907 is complete
return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
// return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); // return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
} }
@Override @Override
protected Instantiator buildInstantiator(PersistentClass persistentClass) { protected Instantiator buildInstantiator(PersistentClass persistentClass) {
if ( optimizer == null ) { if ( optimizer == null ) {
return new PojoInstantiator( persistentClass, null ); return new PojoInstantiator( persistentClass, null );
} }
@ -214,7 +222,7 @@ protected Instantiator buildInstantiator(PersistentClass persistentClass) {
} }
@Override @Override
public void setPropertyValues(Object entity, Object[] values) throws HibernateException { public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) {
setPropertyValuesWithOptimizer( entity, values ); setPropertyValuesWithOptimizer( entity, values );
} }
@ -224,7 +232,7 @@ public void setPropertyValues(Object entity, Object[] values) throws HibernateEx
} }
@Override @Override
public Object[] getPropertyValues(Object entity) throws HibernateException { public Object[] getPropertyValues(Object entity) throws HibernateException {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity ); return getPropertyValuesWithOptimizer( entity );
} }
@ -234,7 +242,8 @@ public Object[] getPropertyValues(Object entity) throws HibernateException {
} }
@Override @Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session) throws HibernateException { public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session)
throws HibernateException {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) { if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity ); return getPropertyValuesWithOptimizer( entity );
} }
@ -262,17 +271,17 @@ public Class getMappedClass() {
} }
@Override @Override
public boolean isLifecycleImplementor() { public boolean isLifecycleImplementor() {
return lifecycleImplementor; return lifecycleImplementor;
} }
@Override @Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getGetter( mappedEntity.getMappedClass() ); return mappedProperty.getGetter( mappedEntity.getMappedClass() );
} }
@Override @Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getSetter( mappedEntity.getMappedClass() ); return mappedProperty.getSetter( mappedEntity.getMappedClass() );
} }
@ -281,26 +290,26 @@ public Class getConcreteProxyClass() {
return proxyInterface; return proxyInterface;
} }
//TODO: need to make the majority of this functionality into a top-level support class for custom impl support //TODO: need to make the majority of this functionality into a top-level support class for custom impl support
@Override @Override
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) { public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {
if ( isInstrumented() ) { if ( isInstrumented() ) {
Set lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ? Set<String> lazyProps = lazyPropertiesAreUnfetched && getEntityMetamodel().hasLazyProperties() ?
lazyPropertyNames : null; lazyPropertyNames : null;
//TODO: if we support multiple fetch groups, we would need //TODO: if we support multiple fetch groups, we would need
// to clone the set of lazy properties! // to clone the set of lazy properties!
FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session ); FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session );
//also clear the fields that are marked as dirty in the dirtyness tracker //also clear the fields that are marked as dirty in the dirtyness tracker
if(entity instanceof org.hibernate.engine.spi.SelfDirtinessTracker) { if ( entity instanceof org.hibernate.engine.spi.SelfDirtinessTracker ) {
((org.hibernate.engine.spi.SelfDirtinessTracker) entity).$$_hibernate_clearDirtyAttributes(); ( (org.hibernate.engine.spi.SelfDirtinessTracker) entity ).$$_hibernate_clearDirtyAttributes();
} }
} }
} }
@Override @Override
public boolean hasUninitializedLazyProperties(Object entity) { public boolean hasUninitializedLazyProperties(Object entity) {
if ( getEntityMetamodel().hasLazyProperties() ) { if ( getEntityMetamodel().hasLazyProperties() ) {
FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity ); FieldInterceptor callback = FieldInterceptionHelper.extractFieldInterceptor( entity );
return callback != null && !callback.isInitialized(); return callback != null && !callback.isInitialized();

View File

@ -36,8 +36,7 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class VersionProperty extends AbstractNonIdentifierAttribute { public class VersionProperty extends AbstractNonIdentifierAttribute {
private final VersionValue unsavedValue;
private final VersionValue unsavedValue;
/** /**
* Constructs VersionProperty instances. * Constructs VersionProperty instances.
@ -59,12 +58,13 @@ public VersionProperty(
int attributeNumber, int attributeNumber,
String attributeName, String attributeName,
Type attributeType, Type attributeType,
BaselineAttributeInformation attributeInformation, VersionValue unsavedValue) { BaselineAttributeInformation attributeInformation,
VersionValue unsavedValue) {
super( source, sessionFactory, attributeNumber, attributeName, attributeType, attributeInformation ); super( source, sessionFactory, attributeNumber, attributeName, attributeType, attributeInformation );
this.unsavedValue = unsavedValue; this.unsavedValue = unsavedValue;
} }
public VersionValue getUnsavedValue() { public VersionValue getUnsavedValue() {
return unsavedValue; return unsavedValue;
} }
} }

View File

@ -39,7 +39,6 @@
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;

View File

@ -26,16 +26,12 @@
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* A registry of {@link BasicType} instances * A registry of {@link BasicType} instances
@ -43,10 +39,10 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BasicTypeRegistry implements Serializable { public class BasicTypeRegistry implements Serializable {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( BasicTypeRegistry.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( BasicTypeRegistry.class );
// TODO : analyze these sizing params; unfortunately this seems to be the only way to give a "concurrencyLevel" // TODO : analyze these sizing params; unfortunately this seems to be the only way to give a "concurrencyLevel"
private Map<String,BasicType> registry = new ConcurrentHashMap<String, BasicType>( 100, .75f, 1 ); private Map<String, BasicType> registry = new ConcurrentHashMap<String, BasicType>( 100, .75f, 1 );
private boolean locked; private boolean locked;
public BasicTypeRegistry() { public BasicTypeRegistry() {
@ -124,7 +120,7 @@ public BasicTypeRegistry() {
* *
* @param registeredTypes The type map to copy over * @param registeredTypes The type map to copy over
*/ */
@SuppressWarnings({ "UnusedDeclaration" }) @SuppressWarnings({"UnusedDeclaration"})
private BasicTypeRegistry(Map<String, BasicType> registeredTypes) { private BasicTypeRegistry(Map<String, BasicType> registeredTypes) {
registry.putAll( registeredTypes ); registry.putAll( registeredTypes );
locked = true; locked = true;
@ -145,13 +141,13 @@ public void register(BasicType type) {
for ( String key : type.getRegistrationKeys() ) { for ( String key : type.getRegistrationKeys() ) {
// be safe... // be safe...
if (key == null) { if ( key == null ) {
continue; continue;
} }
LOG.debugf("Adding type registration %s -> %s", key, type); LOG.debugf( "Adding type registration %s -> %s", key, type );
final Type old = registry.put( key, type ); final Type old = registry.put( key, type );
if (old != null && old != type) { if ( old != null && old != type ) {
LOG.typeRegistrationOverridesPrevious(key, old); LOG.typeRegistrationOverridesPrevious( key, old );
} }
} }
} }

View File

@ -24,13 +24,12 @@
package org.hibernate.type; package org.hibernate.type;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Types;
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor; import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;
import org.hibernate.type.descriptor.sql.NumericTypeDescriptor; import org.hibernate.type.descriptor.sql.NumericTypeDescriptor;
/** /**
* A type that maps between a {@link Types#NUMERIC NUMERIC} and {@link BigDecimal}. * A type that maps between a {@link java.sql.Types#NUMERIC NUMERIC} and {@link BigDecimal}.
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -24,14 +24,13 @@
package org.hibernate.type; package org.hibernate.type;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Types;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor; import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;
import org.hibernate.type.descriptor.sql.BigIntTypeDescriptor; import org.hibernate.type.descriptor.sql.BigIntTypeDescriptor;
/** /**
* A type that maps between a {@link Types#NUMERIC NUMERIC} and {@link BigInteger}. * A type that maps between a {@link java.sql.Types#NUMERIC NUMERIC} and {@link BigInteger}.
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole

View File

@ -37,13 +37,13 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException; import org.hibernate.PropertyNotFoundException;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.tuple.StandardProperty; import org.hibernate.tuple.StandardProperty;
import org.hibernate.tuple.component.ComponentMetamodel; import org.hibernate.tuple.component.ComponentMetamodel;
import org.hibernate.tuple.component.ComponentTuplizer; import org.hibernate.tuple.component.ComponentTuplizer;
@ -76,11 +76,11 @@ public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamod
// for now, just "re-flatten" the metamodel since this is temporary stuff anyway (HHH-1907) // for now, just "re-flatten" the metamodel since this is temporary stuff anyway (HHH-1907)
this.isKey = metamodel.isKey(); this.isKey = metamodel.isKey();
this.propertySpan = metamodel.getPropertySpan(); this.propertySpan = metamodel.getPropertySpan();
this.propertyNames = new String[ propertySpan ]; this.propertyNames = new String[propertySpan];
this.propertyTypes = new Type[ propertySpan ]; this.propertyTypes = new Type[propertySpan];
this.propertyNullability = new boolean[ propertySpan ]; this.propertyNullability = new boolean[propertySpan];
this.cascade = new CascadeStyle[ propertySpan ]; this.cascade = new CascadeStyle[propertySpan];
this.joinedFetch = new FetchMode[ propertySpan ]; this.joinedFetch = new FetchMode[propertySpan];
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
StandardProperty prop = metamodel.getProperty( i ); StandardProperty prop = metamodel.getProperty( i );
@ -89,7 +89,7 @@ public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamod
this.propertyNullability[i] = prop.isNullable(); this.propertyNullability[i] = prop.isNullable();
this.cascade[i] = prop.getCascadeStyle(); this.cascade[i] = prop.getCascadeStyle();
this.joinedFetch[i] = prop.getFetchMode(); this.joinedFetch[i] = prop.getFetchMode();
if (!prop.isNullable()) { if ( !prop.isNullable() ) {
hasNotNullProperty = true; hasNotNullProperty = true;
} }
} }
@ -109,6 +109,7 @@ public EntityMode getEntityMode() {
public ComponentTuplizer getComponentTuplizer() { public ComponentTuplizer getComponentTuplizer() {
return componentTuplizer; return componentTuplizer;
} }
@Override @Override
public int getColumnSpan(Mapping mapping) throws MappingException { public int getColumnSpan(Mapping mapping) throws MappingException {
int span = 0; int span = 0;
@ -117,6 +118,7 @@ public int getColumnSpan(Mapping mapping) throws MappingException {
} }
return span; return span;
} }
@Override @Override
public int[] sqlTypes(Mapping mapping) throws MappingException { public int[] sqlTypes(Mapping mapping) throws MappingException {
//Not called at runtime so doesn't matter if its slow :) //Not called at runtime so doesn't matter if its slow :)
@ -134,7 +136,7 @@ public int[] sqlTypes(Mapping mapping) throws MappingException {
@Override @Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException { public Size[] dictatedSizes(Mapping mapping) throws MappingException {
//Not called at runtime so doesn't matter if its slow :) //Not called at runtime so doesn't matter if its slow :)
final Size[] sizes = new Size[ getColumnSpan( mapping ) ]; final Size[] sizes = new Size[getColumnSpan( mapping )];
int soFar = 0; int soFar = 0;
for ( Type propertyType : propertyTypes ) { for ( Type propertyType : propertyTypes ) {
final Size[] propertySizes = propertyType.dictatedSizes( mapping ); final Size[] propertySizes = propertyType.dictatedSizes( mapping );
@ -147,7 +149,7 @@ public Size[] dictatedSizes(Mapping mapping) throws MappingException {
@Override @Override
public Size[] defaultSizes(Mapping mapping) throws MappingException { public Size[] defaultSizes(Mapping mapping) throws MappingException {
//Not called at runtime so doesn't matter if its slow :) //Not called at runtime so doesn't matter if its slow :)
final Size[] sizes = new Size[ getColumnSpan( mapping ) ]; final Size[] sizes = new Size[getColumnSpan( mapping )];
int soFar = 0; int soFar = 0;
for ( Type propertyType : propertyTypes ) { for ( Type propertyType : propertyTypes ) {
final Size[] propertySizes = propertyType.defaultSizes( mapping ); final Size[] propertySizes = propertyType.defaultSizes( mapping );
@ -159,7 +161,7 @@ public Size[] defaultSizes(Mapping mapping) throws MappingException {
@Override @Override
public final boolean isComponentType() { public final boolean isComponentType() {
return true; return true;
} }
@ -168,7 +170,7 @@ public Class getReturnedClass() {
} }
@Override @Override
public boolean isSame(Object x, Object y) throws HibernateException { public boolean isSame(Object x, Object y) throws HibernateException {
if ( x == y ) { if ( x == y ) {
return true; return true;
} }
@ -202,7 +204,8 @@ public boolean isEqual(final Object x, final Object y) throws HibernateException
} }
@Override @Override
public boolean isEqual(final Object x, final Object y, final SessionFactoryImplementor factory) throws HibernateException { public boolean isEqual(final Object x, final Object y, final SessionFactoryImplementor factory)
throws HibernateException {
if ( x == y ) { if ( x == y ) {
return true; return true;
} }
@ -277,7 +280,8 @@ public boolean isDirty(final Object x, final Object y, final SessionImplementor
return false; return false;
} }
public boolean isDirty(final Object x, final Object y, final boolean[] checkable, final SessionImplementor session) throws HibernateException { public boolean isDirty(final Object x, final Object y, final boolean[] checkable, final SessionImplementor session)
throws HibernateException {
if ( x == y ) { if ( x == y ) {
return false; return false;
} }
@ -289,7 +293,7 @@ public boolean isDirty(final Object x, final Object y, final boolean[] checkable
int len = propertyTypes[i].getColumnSpan( session.getFactory() ); int len = propertyTypes[i].getColumnSpan( session.getFactory() );
if ( len <= 1 ) { if ( len <= 1 ) {
final boolean dirty = ( len == 0 || checkable[loc] ) && final boolean dirty = ( len == 0 || checkable[loc] ) &&
propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session ); propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session );
if ( dirty ) { if ( dirty ) {
return true; return true;
} }
@ -297,7 +301,12 @@ public boolean isDirty(final Object x, final Object y, final boolean[] checkable
else { else {
boolean[] subcheckable = new boolean[len]; boolean[] subcheckable = new boolean[len];
System.arraycopy( checkable, loc, subcheckable, 0, len ); System.arraycopy( checkable, loc, subcheckable, 0, len );
final boolean dirty = propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), subcheckable, session ); final boolean dirty = propertyTypes[i].isDirty(
getPropertyValue( x, i ),
getPropertyValue( y, i ),
subcheckable,
session
);
if ( dirty ) { if ( dirty ) {
return true; return true;
} }
@ -308,14 +317,18 @@ public boolean isDirty(final Object x, final Object y, final boolean[] checkable
} }
@Override @Override
public boolean isModified(final Object old, final Object current, final boolean[] checkable, final SessionImplementor session) throws HibernateException { public boolean isModified(
final Object old,
final Object current,
final boolean[] checkable,
final SessionImplementor session) throws HibernateException {
if ( current == null ) { if ( current == null ) {
return old != null; return old != null;
} }
if ( old == null ) { if ( old == null ) {
return true; return true;
} }
Object[] oldValues = ( Object[] ) old; Object[] oldValues = (Object[]) old;
int loc = 0; int loc = 0;
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
int len = propertyTypes[i].getColumnSpan( session.getFactory() ); int len = propertyTypes[i].getColumnSpan( session.getFactory() );
@ -329,11 +342,13 @@ public boolean isModified(final Object old, final Object current, final boolean[
return false; return false;
} }
@Override @Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException { throws HibernateException, SQLException {
return resolve( hydrate( rs, names, session, owner ), session, owner ); return resolve( hydrate( rs, names, session, owner ), session, owner );
} }
@Override @Override
public void nullSafeSet(PreparedStatement st, Object value, int begin, SessionImplementor session) public void nullSafeSet(PreparedStatement st, Object value, int begin, SessionImplementor session)
throws HibernateException, SQLException { throws HibernateException, SQLException {
@ -345,6 +360,7 @@ public void nullSafeSet(PreparedStatement st, Object value, int begin, SessionIm
begin += propertyTypes[i].getColumnSpan( session.getFactory() ); begin += propertyTypes[i].getColumnSpan( session.getFactory() );
} }
} }
@Override @Override
public void nullSafeSet( public void nullSafeSet(
PreparedStatement st, PreparedStatement st,
@ -359,6 +375,7 @@ public void nullSafeSet(
int loc = 0; int loc = 0;
for ( int i = 0; i < propertySpan; i++ ) { for ( int i = 0; i < propertySpan; i++ ) {
int len = propertyTypes[i].getColumnSpan( session.getFactory() ); int len = propertyTypes[i].getColumnSpan( session.getFactory() );
//noinspection StatementWithEmptyBody
if ( len == 0 ) { if ( len == 0 ) {
//noop //noop
} }
@ -386,17 +403,20 @@ private Object[] nullSafeGetValues(Object value, EntityMode entityMode) throws H
return getPropertyValues( value, entityMode ); return getPropertyValues( value, entityMode );
} }
} }
@Override @Override
public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
throws HibernateException, SQLException { throws HibernateException, SQLException {
return nullSafeGet( rs, new String[] {name}, session, owner ); return nullSafeGet( rs, new String[] {name}, session, owner );
} }
@Override @Override
public Object getPropertyValue(Object component, int i, SessionImplementor session) public Object getPropertyValue(Object component, int i, SessionImplementor session)
throws HibernateException { throws HibernateException {
return getPropertyValue( component, i ); return getPropertyValue( component, i );
} }
public Object getPropertyValue(Object component, int i, EntityMode entityMode) public Object getPropertyValue(Object component, int i, EntityMode entityMode)
throws HibernateException { throws HibernateException {
return getPropertyValue( component, i ); return getPropertyValue( component, i );
@ -409,8 +429,9 @@ public Object getPropertyValue(Object component, int i)
// Object[] (ex: QueryKey hash codes for cached queries). // Object[] (ex: QueryKey hash codes for cached queries).
// It's easiest to just check for the condition here prior to // It's easiest to just check for the condition here prior to
// trying reflection. // trying reflection.
return (( Object[] ) component)[i]; return ( (Object[]) component )[i];
} else { }
else {
return componentTuplizer.getPropertyValue( component, i ); return componentTuplizer.getPropertyValue( component, i );
} }
} }
@ -420,6 +441,7 @@ public Object[] getPropertyValues(Object component, SessionImplementor session)
throws HibernateException { throws HibernateException {
return getPropertyValues( component, entityMode ); return getPropertyValues( component, entityMode );
} }
@Override @Override
public Object[] getPropertyValues(Object component, EntityMode entityMode) public Object[] getPropertyValues(Object component, EntityMode entityMode)
throws HibernateException { throws HibernateException {
@ -428,24 +450,29 @@ public Object[] getPropertyValues(Object component, EntityMode entityMode)
// Object[] (ex: QueryKey hash codes for cached queries). // Object[] (ex: QueryKey hash codes for cached queries).
// It's easiest to just check for the condition here prior to // It's easiest to just check for the condition here prior to
// trying reflection. // trying reflection.
return ( Object[] ) component; return (Object[]) component;
} else { }
else {
return componentTuplizer.getPropertyValues( component ); return componentTuplizer.getPropertyValues( component );
} }
} }
@Override @Override
public void setPropertyValues(Object component, Object[] values, EntityMode entityMode) public void setPropertyValues(Object component, Object[] values, EntityMode entityMode)
throws HibernateException { throws HibernateException {
componentTuplizer.setPropertyValues( component, values ); componentTuplizer.setPropertyValues( component, values );
} }
@Override @Override
public Type[] getSubtypes() { public Type[] getSubtypes() {
return propertyTypes; return propertyTypes;
} }
@Override @Override
public String getName() { public String getName() {
return "component" + ArrayHelper.toString( propertyNames ); return "component" + ArrayHelper.toString( propertyNames );
} }
@Override @Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) public String toLoggableString(Object value, SessionFactoryImplementor factory)
throws HibernateException { throws HibernateException {
@ -456,17 +483,19 @@ public String toLoggableString(Object value, SessionFactoryImplementor factory)
if ( entityMode == null ) { if ( entityMode == null ) {
throw new ClassCastException( value.getClass().getName() ); throw new ClassCastException( value.getClass().getName() );
} }
Map<String,String> result = new HashMap<String, String>(); Map<String, String> result = new HashMap<String, String>();
Object[] values = getPropertyValues( value, entityMode ); Object[] values = getPropertyValues( value, entityMode );
for ( int i = 0; i < propertyTypes.length; i++ ) { for ( int i = 0; i < propertyTypes.length; i++ ) {
result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) ); result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) );
} }
return StringHelper.unqualify( getName() ) + result.toString(); return StringHelper.unqualify( getName() ) + result.toString();
} }
@Override @Override
public String[] getPropertyNames() { public String[] getPropertyNames() {
return propertyNames; return propertyNames;
} }
@Override @Override
public Object deepCopy(Object component, SessionFactoryImplementor factory) public Object deepCopy(Object component, SessionFactoryImplementor factory)
throws HibernateException { throws HibernateException {
@ -490,6 +519,7 @@ public Object deepCopy(Object component, SessionFactoryImplementor factory)
return result; return result;
} }
@Override @Override
public Object replace( public Object replace(
Object original, Object original,
@ -522,7 +552,7 @@ public Object replace(
} }
@Override @Override
public Object replace( public Object replace(
Object original, Object original,
Object target, Object target,
SessionImplementor session, SessionImplementor session,
@ -576,17 +606,19 @@ public Object instantiate(Object parent, SessionImplementor session)
return result; return result;
} }
@Override @Override
public CascadeStyle getCascadeStyle(int i) { public CascadeStyle getCascadeStyle(int i) {
return cascade[i]; return cascade[i];
} }
@Override @Override
public boolean isMutable() { public boolean isMutable() {
return true; return true;
} }
@Override @Override
public Serializable disassemble(Object value, SessionImplementor session, Object owner) public Serializable disassemble(Object value, SessionImplementor session, Object owner)
throws HibernateException { throws HibernateException {
if ( value == null ) { if ( value == null ) {
@ -602,30 +634,31 @@ public Serializable disassemble(Object value, SessionImplementor session, Object
} }
@Override @Override
public Object assemble(Serializable object, SessionImplementor session, Object owner) public Object assemble(Serializable object, SessionImplementor session, Object owner)
throws HibernateException { throws HibernateException {
if ( object == null ) { if ( object == null ) {
return null; return null;
} }
else { else {
Object[] values = ( Object[] ) object; Object[] values = (Object[]) object;
Object[] assembled = new Object[values.length]; Object[] assembled = new Object[values.length];
for ( int i = 0; i < propertyTypes.length; i++ ) { for ( int i = 0; i < propertyTypes.length; i++ ) {
assembled[i] = propertyTypes[i].assemble( ( Serializable ) values[i], session, owner ); assembled[i] = propertyTypes[i].assemble( (Serializable) values[i], session, owner );
} }
Object result = instantiate( owner, session ); Object result = instantiate( owner, session );
setPropertyValues( result, assembled, entityMode ); setPropertyValues( result, assembled, entityMode );
return result; return result;
} }
} }
@Override @Override
public FetchMode getFetchMode(int i) { public FetchMode getFetchMode(int i) {
return joinedFetch[i]; return joinedFetch[i];
} }
@Override @Override
public Object hydrate( public Object hydrate(
final ResultSet rs, final ResultSet rs,
final String[] names, final String[] names,
final SessionImplementor session, final SessionImplementor session,
@ -655,12 +688,12 @@ public Object hydrate(
} }
@Override @Override
public Object resolve(Object value, SessionImplementor session, Object owner) public Object resolve(Object value, SessionImplementor session, Object owner)
throws HibernateException { throws HibernateException {
if ( value != null ) { if ( value != null ) {
Object result = instantiate( owner, session ); Object result = instantiate( owner, session );
Object[] values = ( Object[] ) value; Object[] values = (Object[]) value;
Object[] resolvedValues = new Object[values.length]; //only really need new array during semiresolve! Object[] resolvedValues = new Object[values.length]; //only really need new array during semiresolve!
for ( int i = 0; i < values.length; i++ ) { for ( int i = 0; i < values.length; i++ ) {
resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner ); resolvedValues[i] = propertyTypes[i].resolve( values[i], session, owner );
@ -674,32 +707,36 @@ public Object resolve(Object value, SessionImplementor session, Object owner)
} }
@Override @Override
public Object semiResolve(Object value, SessionImplementor session, Object owner) public Object semiResolve(Object value, SessionImplementor session, Object owner)
throws HibernateException { throws HibernateException {
//note that this implementation is kinda broken //note that this implementation is kinda broken
//for components with many-to-one associations //for components with many-to-one associations
return resolve( value, session, owner ); return resolve( value, session, owner );
} }
@Override @Override
public boolean[] getPropertyNullability() { public boolean[] getPropertyNullability() {
return propertyNullability; return propertyNullability;
} }
@Override @Override
public boolean isXMLElement() { public boolean isXMLElement() {
return true; return true;
} }
@Override @Override
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
return xml; return xml;
} }
@Override @Override
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException { public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException {
replaceNode( node, ( Element ) value ); replaceNode( node, (Element) value );
} }
@Override @Override
public boolean[] toColumnNullness(Object value, Mapping mapping) { public boolean[] toColumnNullness(Object value, Mapping mapping) {
boolean[] result = new boolean[ getColumnSpan( mapping ) ]; boolean[] result = new boolean[getColumnSpan( mapping )];
if ( value == null ) { if ( value == null ) {
return result; return result;
} }
@ -712,6 +749,7 @@ public boolean[] toColumnNullness(Object value, Mapping mapping) {
} }
return result; return result;
} }
@Override @Override
public boolean isEmbedded() { public boolean isEmbedded() {
return false; return false;
@ -741,10 +779,10 @@ public boolean canDoExtraction() {
private boolean determineIfProcedureParamExtractionCanBePerformed() { private boolean determineIfProcedureParamExtractionCanBePerformed() {
for ( Type propertyType : propertyTypes ) { for ( Type propertyType : propertyTypes ) {
if ( ! ProcedureParameterExtractionAware.class.isInstance( propertyType ) ) { if ( !ProcedureParameterExtractionAware.class.isInstance( propertyType ) ) {
return false; return false;
} }
if ( ! ( (ProcedureParameterExtractionAware) propertyType ).canDoExtraction() ) { if ( !( (ProcedureParameterExtractionAware) propertyType ).canDoExtraction() ) {
return false; return false;
} }
} }
@ -773,7 +811,7 @@ public Object extract(CallableStatement statement, int startIndex, SessionImplem
currentIndex += propertyType.getColumnSpan( session.getFactory() ); currentIndex += propertyType.getColumnSpan( session.getFactory() );
} }
if ( ! notNull ) { if ( !notNull ) {
values = null; values = null;
} }
@ -781,7 +819,8 @@ public Object extract(CallableStatement statement, int startIndex, SessionImplem
} }
@Override @Override
public Object extract(CallableStatement statement, String[] paramNames, SessionImplementor session) throws SQLException { public Object extract(CallableStatement statement, String[] paramNames, SessionImplementor session)
throws SQLException {
// for this form to work all sub-property spans must be one (1)... // for this form to work all sub-property spans must be one (1)...
Object[] values = new Object[propertySpan]; Object[] values = new Object[propertySpan];
@ -791,7 +830,7 @@ public Object extract(CallableStatement statement, String[] paramNames, SessionI
for ( String paramName : paramNames ) { for ( String paramName : paramNames ) {
// we know this cast is safe from canDoExtraction // we know this cast is safe from canDoExtraction
final ProcedureParameterExtractionAware propertyType = (ProcedureParameterExtractionAware) propertyTypes[indx]; final ProcedureParameterExtractionAware propertyType = (ProcedureParameterExtractionAware) propertyTypes[indx];
final Object value = propertyType.extract( statement, new String[] { paramName }, session ); final Object value = propertyType.extract( statement, new String[] {paramName}, session );
if ( value == null ) { if ( value == null ) {
if ( isKey ) { if ( isKey ) {
return null; //different nullability rules for pk/fk return null; //different nullability rules for pk/fk
@ -803,13 +842,13 @@ public Object extract(CallableStatement statement, String[] paramNames, SessionI
values[indx] = value; values[indx] = value;
} }
if ( ! notNull ) { if ( !notNull ) {
values = null; values = null;
} }
return resolve( values, session, null ); return resolve( values, session, null );
} }
public boolean hasNotNullProperty() { public boolean hasNotNullProperty() {
return hasNotNullProperty; return hasNotNullProperty;
} }

View File

@ -46,12 +46,12 @@ public boolean isMethodOf(Method method) {
} }
public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { public Object instantiate(Object parent, SessionImplementor session) throws HibernateException {
final boolean useParent = parent!=null && final boolean useParent = parent != null &&
//TODO: Yuck! This is not quite good enough, it's a quick //TODO: Yuck! This is not quite good enough, it's a quick
//hack around the problem of having a to-one association //hack around the problem of having a to-one association
//that refers to an embedded component: //that refers to an embedded component:
super.getReturnedClass().isInstance(parent); super.getReturnedClass().isInstance( parent );
return useParent ? parent : super.instantiate(parent, session); return useParent ? parent : super.instantiate( parent, session );
} }
} }

View File

@ -66,6 +66,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
/** /**
* Cached because of performance * Cached because of performance
*
* @see #getIdentifierType(SessionImplementor) * @see #getIdentifierType(SessionImplementor)
* @see #getIdentifierType(Mapping) * @see #getIdentifierType(Mapping)
*/ */
@ -73,6 +74,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
/** /**
* Cached because of performance * Cached because of performance
*
* @see #getAssociatedEntityPersister * @see #getAssociatedEntityPersister
*/ */
private transient volatile EntityPersister associatedEntityPersister; private transient volatile EntityPersister associatedEntityPersister;
@ -117,7 +119,7 @@ protected EntityType(
* @param unwrapProxy Is unwrapping of proxies allowed for this association; unwrapping * @param unwrapProxy Is unwrapping of proxies allowed for this association; unwrapping
* says to return the "implementation target" of lazy prooxies; typically only possible * says to return the "implementation target" of lazy prooxies; typically only possible
* with lazy="no-proxy". * with lazy="no-proxy".
* *
* @deprecated Use {@link #EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean)} instead. * @deprecated Use {@link #EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean)} instead.
*/ */
@Deprecated @Deprecated
@ -245,6 +247,7 @@ public final String getAssociatedEntityName() {
* The name of the associated entity. * The name of the associated entity.
* *
* @param factory The session factory, for resolution. * @param factory The session factory, for resolution.
*
* @return The associated entity name. * @return The associated entity name.
*/ */
@Override @Override
@ -256,12 +259,14 @@ public String getAssociatedEntityName(SessionFactoryImplementor factory) {
* Retrieves the {@link Joinable} defining the associated entity. * Retrieves the {@link Joinable} defining the associated entity.
* *
* @param factory The session factory. * @param factory The session factory.
*
* @return The associated joinable * @return The associated joinable
*
* @throws MappingException Generally indicates an invalid entity name. * @throws MappingException Generally indicates an invalid entity name.
*/ */
@Override @Override
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory) throws MappingException { public Joinable getAssociatedJoinable(SessionFactoryImplementor factory) throws MappingException {
return ( Joinable ) getAssociatedEntityPersister( factory ); return (Joinable) getAssociatedEntityPersister( factory );
} }
/** /**
@ -282,16 +287,16 @@ public final Class getReturnedClass() {
return returnedClass; return returnedClass;
} }
private Class determineAssociatedEntityClass() { private Class determineAssociatedEntityClass() {
final String entityName = getAssociatedEntityName(); final String entityName = getAssociatedEntityName();
try { try {
return ReflectHelper.classForName(entityName); return ReflectHelper.classForName( entityName );
} }
catch ( ClassNotFoundException cnfe ) { catch (ClassNotFoundException cnfe) {
return this.scope.resolveFactory().getEntityPersister(entityName). return this.scope.resolveFactory().getEntityPersister( entityName ).
getEntityTuplizer().getMappedClass(); getEntityTuplizer().getMappedClass();
} }
} }
@Override @Override
public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner) public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
@ -305,15 +310,15 @@ public final Object nullSafeGet(
String[] names, String[] names,
SessionImplementor session, SessionImplementor session,
Object owner) throws HibernateException, SQLException { Object owner) throws HibernateException, SQLException {
return resolve( hydrate(rs, names, session, owner), session, owner ); return resolve( hydrate( rs, names, session, owner ), session, owner );
} }
/** /**
* Two entities are considered the same when their instances are the same. * Two entities are considered the same when their instances are the same.
* *
*
* @param x One entity instance * @param x One entity instance
* @param y Another entity instance * @param y Another entity instance
*
* @return True if x == y; false otherwise. * @return True if x == y; false otherwise.
*/ */
@Override @Override
@ -341,7 +346,7 @@ public Object replace(
if ( original == null ) { if ( original == null ) {
return null; return null;
} }
Object cached = copyCache.get(original); Object cached = copyCache.get( original );
if ( cached != null ) { if ( cached != null ) {
return cached; return cached;
} }
@ -349,7 +354,7 @@ public Object replace(
if ( original == target ) { if ( original == target ) {
return target; return target;
} }
if ( session.getContextEntityIdentifier( original ) == null && if ( session.getContextEntityIdentifier( original ) == null &&
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) { ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
final Object copy = session.getEntityPersister( associatedEntityName, original ) final Object copy = session.getEntityPersister( associatedEntityName, original )
.instantiate( null, session ); .instantiate( null, session );
@ -359,10 +364,13 @@ public Object replace(
else { else {
Object id = getIdentifier( original, session ); Object id = getIdentifier( original, session );
if ( id == null ) { if ( id == null ) {
throw new AssertionFailure("non-transient entity has a null id: " + original.getClass().getName()); throw new AssertionFailure(
"non-transient entity has a null id: " + original.getClass()
.getName()
);
} }
id = getIdentifierOrUniqueKeyType( session.getFactory() ) id = getIdentifierOrUniqueKeyType( session.getFactory() )
.replace(id, null, session, owner, copyCache); .replace( id, null, session, owner, copyCache );
return resolve( id, session, owner ); return resolve( id, session, owner );
} }
} }
@ -376,7 +384,7 @@ public int getHashCode(Object x, SessionFactoryImplementor factory) {
} }
final Serializable id; final Serializable id;
if (x instanceof HibernateProxy) { if ( x instanceof HibernateProxy ) {
id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier(); id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier();
} }
else { else {
@ -400,12 +408,12 @@ public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
EntityPersister persister = getAssociatedEntityPersister( factory ); EntityPersister persister = getAssociatedEntityPersister( factory );
if ( !persister.canExtractIdOutOfEntity() ) { if ( !persister.canExtractIdOutOfEntity() ) {
return super.isEqual(x, y ); return super.isEqual( x, y );
} }
final Class mappedClass = persister.getMappedClass(); final Class mappedClass = persister.getMappedClass();
Serializable xid; Serializable xid;
if (x instanceof HibernateProxy) { if ( x instanceof HibernateProxy ) {
xid = ( (HibernateProxy) x ).getHibernateLazyInitializer() xid = ( (HibernateProxy) x ).getHibernateLazyInitializer()
.getIdentifier(); .getIdentifier();
} }
@ -420,7 +428,7 @@ public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
} }
Serializable yid; Serializable yid;
if (y instanceof HibernateProxy) { if ( y instanceof HibernateProxy ) {
yid = ( (HibernateProxy) y ).getHibernateLazyInitializer() yid = ( (HibernateProxy) y ).getHibernateLazyInitializer()
.getIdentifier(); .getIdentifier();
} }
@ -435,7 +443,7 @@ public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
} }
return persister.getIdentifierType() return persister.getIdentifierType()
.isEqual(xid, yid, factory); .isEqual( xid, yid, factory );
} }
@Override @Override
@ -451,7 +459,7 @@ public boolean isXMLElement() {
@Override @Override
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
if ( !isEmbeddedInXML ) { if ( !isEmbeddedInXML ) {
return getIdentifierType(factory).fromXMLNode(xml, factory); return getIdentifierType( factory ).fromXMLNode( xml, factory );
} }
else { else {
return xml; return xml;
@ -461,11 +469,11 @@ public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
@Override @Override
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException { public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) throws HibernateException {
if ( !isEmbeddedInXML ) { if ( !isEmbeddedInXML ) {
getIdentifierType(factory).setToXMLNode(node, value, factory); getIdentifierType( factory ).setToXMLNode( node, value, factory );
} }
else { else {
Element elt = (Element) value; Element elt = (Element) value;
replaceNode( node, new ElementWrapper(elt) ); replaceNode( node, new ElementWrapper( elt ) );
} }
} }
@ -505,7 +513,7 @@ else if ( uniqueKeyPropertyName != null ) {
return loadByUniqueKey( getAssociatedEntityName(), uniqueKeyPropertyName, value, session ); return loadByUniqueKey( getAssociatedEntityName(), uniqueKeyPropertyName, value, session );
} }
} }
return null; return null;
} }
@ -529,12 +537,16 @@ protected EntityPersister getAssociatedEntityPersister(final SessionFactoryImple
} }
protected final Object getIdentifier(Object value, SessionImplementor session) throws HibernateException { protected final Object getIdentifier(Object value, SessionImplementor session) throws HibernateException {
if ( isNotEmbedded(session) ) { if ( isNotEmbedded( session ) ) {
return value; return value;
} }
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
return ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); //tolerates nulls return ForeignKeys.getEntityIdentifierIfNotUnsaved(
getAssociatedEntityName(),
value,
session
); //tolerates nulls
} }
else if ( value == null ) { else if ( value == null ) {
return null; return null;
@ -547,7 +559,7 @@ else if ( value == null ) {
// an entity type, in which case we need to resolve its identitifier // an entity type, in which case we need to resolve its identitifier
Type type = entityPersister.getPropertyType( uniqueKeyPropertyName ); Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type.isEntityType() ) {
propertyValue = ( ( EntityType ) type ).getIdentifier( propertyValue, session ); propertyValue = ( (EntityType) type ).getIdentifier( propertyValue, session );
} }
return propertyValue; return propertyValue;
@ -569,7 +581,9 @@ protected boolean isNotEmbedded(SessionImplementor session) {
* *
* @param value The instance to be logged. * @param value The instance to be logged.
* @param factory The session factory. * @param factory The session factory.
*
* @return The loggable string. * @return The loggable string.
*
* @throws HibernateException Generally some form of resolution problem. * @throws HibernateException Generally some form of resolution problem.
*/ */
@Override @Override
@ -577,7 +591,7 @@ public String toLoggableString(Object value, SessionFactoryImplementor factory)
if ( value == null ) { if ( value == null ) {
return "null"; return "null";
} }
EntityPersister persister = getAssociatedEntityPersister( factory ); EntityPersister persister = getAssociatedEntityPersister( factory );
StringBuilder result = new StringBuilder().append( associatedEntityName ); StringBuilder result = new StringBuilder().append( associatedEntityName );
@ -588,19 +602,20 @@ public String toLoggableString(Object value, SessionFactoryImplementor factory)
if ( isEmbeddedInXML ) { if ( isEmbeddedInXML ) {
throw new ClassCastException( value.getClass().getName() ); throw new ClassCastException( value.getClass().getName() );
} }
id = ( Serializable ) value; id = (Serializable) value;
} else if ( value instanceof HibernateProxy ) { }
HibernateProxy proxy = ( HibernateProxy ) value; else if ( value instanceof HibernateProxy ) {
HibernateProxy proxy = (HibernateProxy) value;
id = proxy.getHibernateLazyInitializer().getIdentifier(); id = proxy.getHibernateLazyInitializer().getIdentifier();
} }
else { else {
id = persister.getIdentifier( value ); id = persister.getIdentifier( value );
} }
result.append( '#' ) result.append( '#' )
.append( persister.getIdentifierType().toLoggableString( id, factory ) ); .append( persister.getIdentifierType().toLoggableString( id, factory ) );
} }
return result.toString(); return result.toString();
} }
@ -624,6 +639,7 @@ public boolean isLogicalOneToOne() {
* Convenience method to locate the identifier type of the associated entity. * Convenience method to locate the identifier type of the associated entity.
* *
* @param factory The mappings... * @param factory The mappings...
*
* @return The identifier type * @return The identifier type
*/ */
Type getIdentifierType(final Mapping factory) { Type getIdentifierType(final Mapping factory) {
@ -644,6 +660,7 @@ Type getIdentifierType(final Mapping factory) {
* Convenience method to locate the identifier type of the associated entity. * Convenience method to locate the identifier type of the associated entity.
* *
* @param session The originating session * @param session The originating session
*
* @return The identifier type * @return The identifier type
*/ */
Type getIdentifierType(final SessionImplementor session) { Type getIdentifierType(final SessionImplementor session) {
@ -663,18 +680,20 @@ Type getIdentifierType(final SessionImplementor session) {
* the property-ref). * the property-ref).
* *
* @param factory The mappings... * @param factory The mappings...
*
* @return The appropriate type. * @return The appropriate type.
*
* @throws MappingException Generally, if unable to resolve the associated entity name * @throws MappingException Generally, if unable to resolve the associated entity name
* or unique key property name. * or unique key property name.
*/ */
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
return getIdentifierType(factory); return getIdentifierType( factory );
} }
else { else {
Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type.isEntityType() ) {
type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory ); type = ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory );
} }
return type; return type;
} }
@ -685,11 +704,13 @@ public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingEx
* refers * refers
* *
* @param factory The mappings... * @param factory The mappings...
*
* @return The appropriate property name. * @return The appropriate property name.
*
* @throws MappingException Generally, if unable to resolve the associated entity name * @throws MappingException Generally, if unable to resolve the associated entity name
*/ */
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory) public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
throws MappingException { throws MappingException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
return factory.getIdentifierPropertyName( getAssociatedEntityName() ); return factory.getIdentifierPropertyName( getAssociatedEntityName() );
} }
@ -697,7 +718,7 @@ public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
return uniqueKeyPropertyName; return uniqueKeyPropertyName;
} }
} }
protected abstract boolean isNullable(); protected abstract boolean isNullable();
/** /**
@ -705,7 +726,9 @@ public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
* *
* @param id The entity id to resolve * @param id The entity id to resolve
* @param session The orginating session. * @param session The orginating session.
*
* @return The resolved identifier (i.e., loaded entity). * @return The resolved identifier (i.e., loaded entity).
*
* @throws org.hibernate.HibernateException Indicates problems performing the load. * @throws org.hibernate.HibernateException Indicates problems performing the load.
*/ */
protected final Object resolveIdentifier(Serializable id, SessionImplementor session) throws HibernateException { protected final Object resolveIdentifier(Serializable id, SessionImplementor session) throws HibernateException {
@ -721,7 +744,7 @@ protected final Object resolveIdentifier(Serializable id, SessionImplementor ses
); );
if ( proxyOrEntity instanceof HibernateProxy ) { if ( proxyOrEntity instanceof HibernateProxy ) {
( ( HibernateProxy ) proxyOrEntity ).getHibernateLazyInitializer() ( (HibernateProxy) proxyOrEntity ).getHibernateLazyInitializer()
.setUnwrap( isProxyUnwrapEnabled ); .setUnwrap( isProxyUnwrapEnabled );
} }
@ -739,23 +762,25 @@ protected boolean isNull(Object owner, SessionImplementor session) {
* @param uniqueKeyPropertyName The name of the property defining the uniqie key. * @param uniqueKeyPropertyName The name of the property defining the uniqie key.
* @param key The unique key property value. * @param key The unique key property value.
* @param session The originating session. * @param session The originating session.
*
* @return The loaded entity * @return The loaded entity
*
* @throws HibernateException generally indicates problems performing the load. * @throws HibernateException generally indicates problems performing the load.
*/ */
public Object loadByUniqueKey( public Object loadByUniqueKey(
String entityName, String entityName,
String uniqueKeyPropertyName, String uniqueKeyPropertyName,
Object key, Object key,
SessionImplementor session) throws HibernateException { SessionImplementor session) throws HibernateException {
final SessionFactoryImplementor factory = session.getFactory(); final SessionFactoryImplementor factory = session.getFactory();
UniqueKeyLoadable persister = ( UniqueKeyLoadable ) factory.getEntityPersister( entityName ); UniqueKeyLoadable persister = (UniqueKeyLoadable) factory.getEntityPersister( entityName );
//TODO: implement caching?! proxies?! //TODO: implement caching?! proxies?!
EntityUniqueKey euk = new EntityUniqueKey( EntityUniqueKey euk = new EntityUniqueKey(
entityName, entityName,
uniqueKeyPropertyName, uniqueKeyPropertyName,
key, key,
getIdentifierOrUniqueKeyType( factory ), getIdentifierOrUniqueKeyType( factory ),
persister.getEntityMode(), persister.getEntityMode(),
session.getFactory() session.getFactory()

View File

@ -37,6 +37,7 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.usertype.DynamicParameterizedType; import org.hibernate.usertype.DynamicParameterizedType;
@ -69,7 +70,7 @@
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class EnumType implements EnhancedUserType, DynamicParameterizedType,LoggableUserType, Serializable { public class EnumType implements EnhancedUserType, DynamicParameterizedType,LoggableUserType, Serializable {
private static final Logger LOG = Logger.getLogger( EnumType.class.getName() ); private static final Logger LOG = CoreLogging.logger( EnumType.class );
public static final String ENUM = "enumClass"; public static final String ENUM = "enumClass";
public static final String NAMED = "useNamed"; public static final String NAMED = "useNamed";
@ -458,9 +459,9 @@ public Enum getValue(ResultSet rs, String[] names) throws SQLException {
private Enum fromName(String name) { private Enum fromName(String name) {
try { try {
if(name == null) { if (name == null) {
return null; return null;
} }
return Enum.valueOf( enumClass, name.trim() ); return Enum.valueOf( enumClass, name.trim() );
} }
catch ( IllegalArgumentException iae ) { catch ( IllegalArgumentException iae ) {

View File

@ -56,14 +56,16 @@ public void setParameterValues(Properties parameters) {
ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE ); ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE );
if ( reader != null ) { if ( reader != null ) {
setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( reader.getReturnedClass() ) ); setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( reader.getReturnedClass() ) );
} else { }
else {
String className = parameters.getProperty( CLASS_NAME ); String className = parameters.getProperty( CLASS_NAME );
if ( className == null ) { if ( className == null ) {
throw new MappingException( "No class name defined for type: " + SerializableToBlobType.class.getName() ); throw new MappingException( "No class name defined for type: " + SerializableToBlobType.class.getName() );
} }
try { try {
setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( ReflectHelper.classForName( className ) ) ); setJavaTypeDescriptor( new SerializableTypeDescriptor<T>( ReflectHelper.classForName( className ) ) );
} catch ( ClassNotFoundException e ) { }
catch ( ClassNotFoundException e ) {
throw new MappingException( "Unable to load class from " + CLASS_NAME + " parameter", e ); throw new MappingException( "Unable to load class from " + CLASS_NAME + " parameter", e );
} }
} }

View File

@ -60,8 +60,8 @@ public PersistentCollection wrap(SessionImplementor session, Object collection)
public Object instantiate(int anticipatedSize) { public Object instantiate(int anticipatedSize) {
return anticipatedSize <= 0 return anticipatedSize <= 0
? new HashSet() ? new HashSet()
: new HashSet( anticipatedSize + (int)( anticipatedSize * .75f ), .75f ); : new HashSet( anticipatedSize + (int)( anticipatedSize * .75f ), .75f );
} }
} }

View File

@ -38,22 +38,21 @@
import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger; import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
* Used internally to build instances of {@link Type}, specifically it builds instances of * Used internally to build instances of {@link Type}, specifically it builds instances of
* * <p/>
* * <p/>
* Used internally to obtain instances of <tt>Type</tt>. Applications should use static methods * Used internally to obtain instances of <tt>Type</tt>. Applications should use static methods
* and constants on <tt>org.hibernate.Hibernate</tt>. * and constants on <tt>org.hibernate.Hibernate</tt>.
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({"unchecked"})
public final class TypeFactory implements Serializable { public final class TypeFactory implements Serializable {
private static final CoreMessageLogger LOG = messageLogger( TypeFactory.class );
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, TypeFactory.class.getName());
private final TypeScopeImpl typeScope = new TypeScopeImpl(); private final TypeScopeImpl typeScope = new TypeScopeImpl();
@ -135,10 +134,10 @@ public static void injectParameters(Object type, Properties parameters) {
( (ParameterizedType) type ).setParameterValues( EMPTY_PROPERTIES ); ( (ParameterizedType) type ).setParameterValues( EMPTY_PROPERTIES );
} }
else { else {
( (ParameterizedType) type ).setParameterValues(parameters); ( (ParameterizedType) type ).setParameterValues( parameters );
} }
} }
else if ( parameters!=null && !parameters.isEmpty() ) { else if ( parameters != null && !parameters.isEmpty() ) {
throw new MappingException( "type is not parameterized: " + type.getClass().getName() ); throw new MappingException( "type is not parameterized: " + type.getClass().getName() );
} }
} }
@ -151,14 +150,17 @@ public CompositeCustomType customComponent(Class<CompositeUserType> typeClass, P
* @deprecated Only for use temporary use by {@link org.hibernate.Hibernate} * @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
*/ */
@Deprecated @Deprecated
@SuppressWarnings({ "JavaDoc" }) @SuppressWarnings({"JavaDoc"})
public static CompositeCustomType customComponent(Class<CompositeUserType> typeClass, Properties parameters, TypeScope scope) { public static CompositeCustomType customComponent(
Class<CompositeUserType> typeClass,
Properties parameters,
TypeScope scope) {
try { try {
CompositeUserType userType = typeClass.newInstance(); CompositeUserType userType = typeClass.newInstance();
injectParameters( userType, parameters ); injectParameters( userType, parameters );
return new CompositeCustomType( userType ); return new CompositeCustomType( userType );
} }
catch ( Exception e ) { catch (Exception e) {
throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e ); throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e );
} }
} }
@ -179,7 +181,7 @@ public CollectionType customCollection(
try { try {
typeClass = ReflectHelper.classForName( typeName ); typeClass = ReflectHelper.classForName( typeName );
} }
catch ( ClassNotFoundException cnfe ) { catch (ClassNotFoundException cnfe) {
throw new MappingException( "user collection type class not found: " + typeName, cnfe ); throw new MappingException( "user collection type class not found: " + typeName, cnfe );
} }
CustomCollectionType result = new CustomCollectionType( typeScope, typeClass, role, propertyRef, embedded ); CustomCollectionType result = new CustomCollectionType( typeScope, typeClass, role, propertyRef, embedded );
@ -198,7 +200,7 @@ public CollectionType customCollection(
try { try {
typeClass = ReflectHelper.classForName( typeName ); typeClass = ReflectHelper.classForName( typeName );
} }
catch ( ClassNotFoundException cnfe ) { catch (ClassNotFoundException cnfe) {
throw new MappingException( "user collection type class not found: " + typeName, cnfe ); throw new MappingException( "user collection type class not found: " + typeName, cnfe );
} }
CustomCollectionType result = new CustomCollectionType( typeScope, typeClass, role, propertyRef ); CustomCollectionType result = new CustomCollectionType( typeScope, typeClass, role, propertyRef );
@ -216,13 +218,13 @@ public CustomType custom(Class<UserType> typeClass, Properties parameters) {
* @deprecated Only for use temporary use by {@link org.hibernate.Hibernate} * @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
*/ */
@Deprecated @Deprecated
public static CustomType custom(Class<UserType> typeClass, Properties parameters, TypeScope scope) { public static CustomType custom(Class<UserType> typeClass, Properties parameters, TypeScope scope) {
try { try {
UserType userType = typeClass.newInstance(); UserType userType = typeClass.newInstance();
injectParameters( userType, parameters ); injectParameters( userType, parameters );
return new CustomType( userType ); return new CustomType( userType );
} }
catch ( Exception e ) { catch (Exception e) {
throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e ); throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e );
} }
} }
@ -242,40 +244,6 @@ public static <T extends Serializable> SerializableType<T> serializable(Class<T>
// one-to-one type builders ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // one-to-one type builders ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @deprecated Use {@link #oneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
* See Jira issue: <a href="https://hibernate.onjira.com/browse/HHH-7771">HHH-7771</a>
*/
@Deprecated
public EntityType oneToOne(
String persistentClass,
ForeignKeyDirection foreignKeyType,
String uniqueKeyPropertyName,
boolean lazy,
boolean unwrapProxy,
boolean isEmbeddedInXML,
String entityName,
String propertyName) {
return oneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName,
propertyName );
}
/**
* @deprecated Use {@link #oneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
*/
@Deprecated
public EntityType oneToOne(
String persistentClass,
ForeignKeyDirection foreignKeyType,
String uniqueKeyPropertyName,
boolean lazy,
boolean unwrapProxy,
String entityName,
String propertyName) {
return oneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, entityName,
propertyName );
}
public EntityType oneToOne( public EntityType oneToOne(
String persistentClass, String persistentClass,
ForeignKeyDirection foreignKeyType, ForeignKeyDirection foreignKeyType,
@ -285,24 +253,10 @@ public EntityType oneToOne(
boolean unwrapProxy, boolean unwrapProxy,
String entityName, String entityName,
String propertyName) { String propertyName) {
return new OneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey, return new OneToOneType(
uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName ); typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey,
} uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName
);
/**
* @deprecated Use {@link #specialOneToOne(String, ForeignKeyDirection, String, boolean, boolean, String, String, boolean)} instead.
*/
@Deprecated
public EntityType specialOneToOne(
String persistentClass,
ForeignKeyDirection foreignKeyType,
String uniqueKeyPropertyName,
boolean lazy,
boolean unwrapProxy,
String entityName,
String propertyName) {
return specialOneToOne( persistentClass, foreignKeyType, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy,
entityName, propertyName );
} }
public EntityType specialOneToOne( public EntityType specialOneToOne(
@ -314,8 +268,10 @@ public EntityType specialOneToOne(
boolean unwrapProxy, boolean unwrapProxy,
String entityName, String entityName,
String propertyName) { String propertyName) {
return new SpecialOneToOneType( typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey, return new SpecialOneToOneType(
uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName ); typeScope, persistentClass, foreignKeyType, referenceToPrimaryKey,
uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName
);
} }
@ -342,8 +298,15 @@ public EntityType manyToOne(
boolean isEmbeddedInXML, boolean isEmbeddedInXML,
boolean ignoreNotFound, boolean ignoreNotFound,
boolean isLogicalOneToOne) { boolean isLogicalOneToOne) {
return manyToOne( persistentClass, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, return manyToOne(
isLogicalOneToOne ); persistentClass,
uniqueKeyPropertyName == null,
uniqueKeyPropertyName,
lazy,
unwrapProxy,
ignoreNotFound,
isLogicalOneToOne
);
} }
/** /**
@ -357,8 +320,15 @@ public EntityType manyToOne(
boolean unwrapProxy, boolean unwrapProxy,
boolean ignoreNotFound, boolean ignoreNotFound,
boolean isLogicalOneToOne) { boolean isLogicalOneToOne) {
return manyToOne( persistentClass, uniqueKeyPropertyName == null, uniqueKeyPropertyName, lazy, unwrapProxy, ignoreNotFound, return manyToOne(
isLogicalOneToOne ); persistentClass,
uniqueKeyPropertyName == null,
uniqueKeyPropertyName,
lazy,
unwrapProxy,
ignoreNotFound,
isLogicalOneToOne
);
} }
public EntityType manyToOne( public EntityType manyToOne(

View File

@ -27,7 +27,6 @@
import java.util.Properties; import java.util.Properties;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
@ -105,7 +104,7 @@ public Type heuristicType(String typeName) throws MappingException {
* look for 'typeName' as a class name and<ol> * look for 'typeName' as a class name and<ol>
* <li>if it names a {@link Type} implementor, return an instance</li> * <li>if it names a {@link Type} implementor, return an instance</li>
* <li>if it names a {@link CompositeUserType} or a {@link UserType}, return an instance of class wrapped intot the appropriate {@link Type} adapter</li> * <li>if it names a {@link CompositeUserType} or a {@link UserType}, return an instance of class wrapped intot the appropriate {@link Type} adapter</li>
* <li>if it implements {@link Lifecycle}, return the corresponding entity type</li> * <li>if it implements {@link org.hibernate.classic.Lifecycle}, return the corresponding entity type</li>
* <li>if it implements {@link Serializable}, return the corresponding serializable type</li> * <li>if it implements {@link Serializable}, return the corresponding serializable type</li>
* </ol> * </ol>
* </li> * </li>

View File

@ -29,16 +29,17 @@
import java.util.Map; import java.util.Map;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
* (Badly named) helper for dealing with standard JDBC types as defined by {@link java.sql.Types} * (Badly named) helper for dealing with standard JDBC types as defined by {@link java.sql.Types}
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public final class JdbcTypeNameMapper { public final class JdbcTypeNameMapper {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JdbcTypeNameMapper.class ); private static final CoreMessageLogger LOG = messageLogger( JdbcTypeNameMapper.class );
private static Map<Integer,String> JDBC_TYPE_MAP = buildJdbcTypeMap(); private static Map<Integer,String> JDBC_TYPE_MAP = buildJdbcTypeMap();
@ -52,7 +53,7 @@ private static Map<Integer, String> buildJdbcTypeMap() {
try { try {
final int code = field.getInt( null ); final int code = field.getInt( null );
String old = map.put( code, field.getName() ); String old = map.put( code, field.getName() );
if ( old != null ) { if ( old != null ) {
LOG.JavaSqlTypesMappedSameCodeMultipleTimes( code, old, field.getName() ); LOG.JavaSqlTypesMappedSameCodeMultipleTimes( code, old, field.getName() );
} }
} }

View File

@ -34,8 +34,6 @@
import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;

View File

@ -55,7 +55,7 @@ public SerializableMutabilityPlan(Class<S> type) {
} }
@Override @Override
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public S deepCopyNotNull(S value) { public S deepCopyNotNull(S value) {
return (S) SerializationHelper.clone( value ); return (S) SerializationHelper.clone( value );
} }

View File

@ -40,10 +40,10 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class BasicBinder<J> implements ValueBinder<J> { public abstract class BasicBinder<J> implements ValueBinder<J> {
private static final Logger log = CoreLogging.logger( BasicBinder.class ); private static final Logger log = CoreLogging.logger( BasicBinder.class );
private static final String BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [%s]"; private static final String BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [%s]";
private static final String NULL_BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [null]"; private static final String NULL_BIND_MSG_TEMPLATE = "binding parameter [%s] as [%s] - [null]";
private final JavaTypeDescriptor<J> javaDescriptor; private final JavaTypeDescriptor<J> javaDescriptor;
private final SqlTypeDescriptor sqlDescriptor; private final SqlTypeDescriptor sqlDescriptor;
@ -63,22 +63,22 @@ public BasicBinder(JavaTypeDescriptor<J> javaDescriptor, SqlTypeDescriptor sqlDe
@Override @Override
public final void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException { public final void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException {
final boolean traceEnabled = log.isTraceEnabled(); final boolean traceEnabled = log.isTraceEnabled();
if ( value == null ) { if ( value == null ) {
if ( traceEnabled ) { if ( traceEnabled ) {
log.trace( log.trace(
String.format( String.format(
NULL_BIND_MSG_TEMPLATE, NULL_BIND_MSG_TEMPLATE,
index, index,
JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() ) JdbcTypeNameMapper.getTypeName( getSqlDescriptor().getSqlType() )
) )
); );
} }
st.setNull( index, sqlDescriptor.getSqlType() ); st.setNull( index, sqlDescriptor.getSqlType() );
} }
else { else {
if ( traceEnabled ) { if ( traceEnabled ) {
log.trace( log.trace(
String.format( String.format(
BIND_MSG_TEMPLATE, BIND_MSG_TEMPLATE,
index, index,
@ -86,9 +86,9 @@ public final void bind(PreparedStatement st, J value, int index, WrapperOptions
getJavaDescriptor().extractLoggableRepresentation( value ) getJavaDescriptor().extractLoggableRepresentation( value )
) )
); );
} }
doBind( st, value, index, options ); doBind( st, value, index, options );
} }
} }
/** /**
@ -101,5 +101,6 @@ public final void bind(PreparedStatement st, J value, int index, WrapperOptions
* *
* @throws SQLException Indicates a problem binding to the prepared statement. * @throws SQLException Indicates a problem binding to the prepared statement.
*/ */
protected abstract void doBind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException; protected abstract void doBind(PreparedStatement st, J value, int index, WrapperOptions options)
throws SQLException;
} }

View File

@ -57,9 +57,9 @@ public boolean canBeRemapped() {
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getClob( name ), options ); return javaTypeDescriptor.wrap( rs.getClob( name ), options );
} }
@Override @Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
@ -78,7 +78,7 @@ protected X doExtract(CallableStatement statement, String name, WrapperOptions o
protected abstract <X> BasicBinder<X> getClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor); protected abstract <X> BasicBinder<X> getClobBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
@Override @Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return getClobBinder( javaTypeDescriptor ); return getClobBinder( javaTypeDescriptor );
} }
@ -88,7 +88,8 @@ public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
if ( options.useStreamForLobBinding() ) { if ( options.useStreamForLobBinding() ) {
STREAM_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); STREAM_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options );
} }
@ -120,7 +121,11 @@ public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDesc
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException { throws SQLException {
final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); final CharacterStream characterStream = javaTypeDescriptor.unwrap(
value,
CharacterStream.class,
options
);
st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
} }
}; };
@ -134,7 +139,11 @@ public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDesc
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException { throws SQLException {
final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); final CharacterStream characterStream = javaTypeDescriptor.unwrap(
value,
CharacterStream.class,
options
);
st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() );
} }
}; };

Some files were not shown because too many files have changed in this diff Show More