public static String toXml(OptimisticLockStyle lockMode) { return lockMode == null ? null : lockMode.name().toLowerCase( Locale.ENGLISH ); } }
public static OptimisticLockStyle fromXml(String name) { return OptimisticLockStyle.valueOf( name == null ? null : name.toUpperCase( Locale.ENGLISH ) ); }
@Override public NativeQuery setResultSetMapping(String name) { ResultSetMappingDefinition mapping = getProducer().getFactory().getNamedQueryRepository().getResultSetMappingDefinition( name ); if ( mapping == null ) { throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" ); } NativeSQLQueryReturn[] returns = mapping.getQueryReturns(); queryReturns.addAll( Arrays.asList( returns ) ); return this; }
protected FetchStrategy adjustJoinFetchIfNeeded( AssociationAttributeDefinition attributeDefinition, FetchStrategy fetchStrategy) { if ( lockMode.greaterThan( LockMode.READ ) ) { return new FetchStrategy( fetchStrategy.getTiming(), FetchStyle.SELECT ); } final Integer maxFetchDepth = sessionFactory().getSettings().getMaximumFetchDepth(); if ( maxFetchDepth != null && currentDepth() > maxFetchDepth ) { return new FetchStrategy( fetchStrategy.getTiming(), FetchStyle.SELECT ); } if ( attributeDefinition.getType().isCollectionType() && isTooManyCollections() ) { // todo : have this revert to batch or subselect fetching once "sql gen redesign" is in place return new FetchStrategy( fetchStrategy.getTiming(), FetchStyle.SELECT ); } return fetchStrategy; }
/** * Close an {@link Iterator} instances obtained from {@link org.hibernate.Query#iterate()} immediately * instead of waiting until the session is closed or disconnected. * * @param iterator an Iterator created by iterate() * * @throws HibernateException Indicates a problem closing the Hibernate iterator. * @throws IllegalArgumentException If the Iterator is not a "Hibernate Iterator". * * @see Query#iterate() */ public static void close(Iterator iterator) throws HibernateException { if ( iterator instanceof HibernateIterator ) { ( (HibernateIterator) iterator ).close(); } else { throw new IllegalArgumentException( "not a Hibernate iterator" ); } }
public void applyResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition) { final ResultSetMappingDefinition old = sqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); if ( old != null ) { throw new DuplicateMappingException( DuplicateMappingException.Type.RESULT_SET_MAPPING, resultSetMappingDefinition.getName() ); } }
private static void bind( ResultSetMappingBindingDefinition resultSetMappingSource, ResultSetMappingDefinition binding, HbmLocalMetadataBuildingContext context) { int cnt = 0; for ( Object valueMappingSource : resultSetMappingSource.getValueMappingSources() ) { if ( JaxbHbmNativeQueryReturnType.class.isInstance( valueMappingSource ) ) { binding.addQueryReturn( extractReturnDescription( (JaxbHbmNativeQueryReturnType) valueMappingSource, context, cnt++ ) ); } else if ( JaxbHbmNativeQueryCollectionLoadReturnType.class.isInstance( valueMappingSource ) ) { binding.addQueryReturn( extractReturnDescription( (JaxbHbmNativeQueryCollectionLoadReturnType) valueMappingSource, context, cnt++ ) ); } else if ( JaxbHbmNativeQueryJoinReturnType.class.isInstance( valueMappingSource ) ) { binding.addQueryReturn( extractReturnDescription( (JaxbHbmNativeQueryJoinReturnType) valueMappingSource, context, cnt++ ) ); } else if ( JaxbHbmNativeQueryScalarReturnType.class.isInstance( valueMappingSource ) ) { binding.addQueryReturn( extractReturnDescription( (JaxbHbmNativeQueryScalarReturnType) valueMappingSource, context ) ); } } }
@Override public void doSecondPass(Map persistentClasses) throws MappingException { final ResultSetMappingDefinition resultSetMappingDefinition = ResultSetMappingBinder.bind( implicitResultSetMappingDefinition, context ); context.getMetadataCollector().addResultSetMapping( resultSetMappingDefinition ); NativeSQLQueryReturn[] newQueryReturns = resultSetMappingDefinition.getQueryReturns(); final NamedSQLQueryDefinition queryDefinition = context.getMetadataCollector().getNamedNativeQueryDefinition( queryName ); if ( queryDefinition != null ) { queryDefinition.addQueryReturns( newQueryReturns ); } } }
/** * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements * * @param resultSetMappingSource The XML data as a JAXB binding * @param context The mapping state * @param prefix A prefix to apply to named ResultSet mapping; this is either {@code null} for * ResultSet mappings defined outside of any entity, or the name of the containing entity * if defined within the context of an entity * * @return The ResultSet mapping descriptor */ public static ResultSetMappingDefinition bind( ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context, String prefix) { if ( StringHelper.isEmpty( prefix ) ) { throw new AssertionFailure( "Passed prefix was null; perhaps you meant to call the alternate #bind form?" ); } final String resultSetName = prefix + '.' + resultSetMappingSource.getName(); final ResultSetMappingDefinition binding = new ResultSetMappingDefinition( resultSetName ); bind( resultSetMappingSource, binding, context ); return binding; }
@Override public FetchStrategy determineFetchPlan(LoadQueryInfluencers loadQueryInfluencers, PropertyPath propertyPath) { final EntityPersister owningPersister = getSource().locateOwningPersister(); FetchStyle style = FetchStrategyHelper.determineFetchStyleByProfile( loadQueryInfluencers, owningPersister, propertyPath, attributeNumber() ); if ( style == null ) { style = determineFetchStyleByMetadata( getFetchMode(), getType() ); } return new FetchStrategy( determineFetchTiming( style ), style ); }
/** * @deprecated prefer {@link #getOptimisticLockStyle} */ @Deprecated public int getOptimisticLockMode() { return getOptimisticLockStyle().getOldCode(); }
/** * @deprecated prefer {@link #setOptimisticLockStyle} */ @Deprecated public void setOptimisticLockMode(int optimisticLockMode) { setOptimisticLockStyle( OptimisticLockStyle.interpretOldCode( optimisticLockMode ) ); }
@Override public void addDefaultResultSetMapping(ResultSetMappingDefinition definition) { final String name = definition.getName(); if ( !defaultSqlResultSetMappingNames.contains( name ) && sqlResultSetMappingMap.containsKey( name ) ) { sqlResultSetMappingMap.remove( name ); } applyResultSetMapping( definition ); defaultSqlResultSetMappingNames.add( name ); }
@Override public FetchStrategy determineFetchPlan(LoadQueryInfluencers loadQueryInfluencers, PropertyPath propertyPath) { final EntityPersister owningPersister = getSource().getEntityPersister(); FetchStyle style = FetchStrategyHelper.determineFetchStyleByProfile( loadQueryInfluencers, owningPersister, propertyPath, attributeNumber() ); if ( style == null ) { style = FetchStrategyHelper.determineFetchStyleByMetadata( ( (OuterJoinLoadable) getSource().getEntityPersister() ).getFetchMode( attributeNumber() ), getType(), sessionFactory() ); } return new FetchStrategy( FetchStrategyHelper.determineFetchTiming( style, getType(), sessionFactory() ), style ); }
@Override protected FetchStrategy determineFetchStrategy(AssociationAttributeDefinition attributeDefinition) { FetchStrategy fetchStrategy = attributeDefinition.determineFetchPlan( loadQueryInfluencers, currentPropertyPath ); if ( fetchStrategy.getTiming() == FetchTiming.IMMEDIATE && fetchStrategy.getStyle() == FetchStyle.JOIN ) { // see if we need to alter the join fetch to another form for any reason fetchStrategy = adjustJoinFetchIfNeeded( attributeDefinition, fetchStrategy ); } return fetchStrategy; }
@Override public void addResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition) { if ( resultSetMappingDefinition == null ) { throw new IllegalArgumentException( "Result-set mapping was null" ); } final String name = resultSetMappingDefinition.getName(); if ( name == null ) { throw new IllegalArgumentException( "Result-set mapping name is null: " + resultSetMappingDefinition ); } if ( defaultSqlResultSetMappingNames.contains( name ) ) { return; } applyResultSetMapping( resultSetMappingDefinition ); }
@Override protected FetchStrategy resolveImplicitFetchStrategyFromEntityGraph( final AssociationAttributeDefinition attributeDefinition) { FetchStrategy fetchStrategy = attributeDefinition.determineFetchPlan( loadQueryInfluencers, currentPropertyPath ); if ( fetchStrategy.getTiming() == FetchTiming.IMMEDIATE && fetchStrategy.getStyle() == FetchStyle.JOIN ) { // see if we need to alter the join fetch to another form for any reason fetchStrategy = adjustJoinFetchIfNeeded( attributeDefinition, fetchStrategy ); } return fetchStrategy; }
public void processingFetch(Fetch fetch) { if ( ! hasSubselectFetch ) { if ( fetch.getFetchStrategy().getStyle() == FetchStyle.SUBSELECT && fetch.getFetchStrategy().getTiming() != FetchTiming.IMMEDIATE ) { hasSubselectFetch = true; } } if ( isJoinFetchedBag( fetch ) ) { if ( joinedBagAttributeFetches == null ) { joinedBagAttributeFetches = new HashSet<>(); } joinedBagAttributeFetches.add( (CollectionAttributeFetch) fetch ); } }