|
Hibernate example source code file (EntityJoinWalker.java)
The Hibernate EntityJoinWalker.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2010, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.loader.entity; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import org.hibernate.FetchMode; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.loader.AbstractEntityJoinWalker; import org.hibernate.loader.OuterJoinableAssociation; import org.hibernate.loader.PropertyPath; import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.sql.JoinType; import org.hibernate.type.AssociationType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; /** * A walker for loaders that fetch entities * * @see EntityLoader * @author Gavin King */ public class EntityJoinWalker extends AbstractEntityJoinWalker { private final LockOptions lockOptions = new LockOptions(); private final int[][] compositeKeyManyToOneTargetIndices; public EntityJoinWalker( OuterJoinLoadable persister, String[] uniqueKey, int batchSize, LockMode lockMode, final SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { super( persister, factory, loadQueryInfluencers ); this.lockOptions.setLockMode(lockMode); StringBuffer whereCondition = whereString( getAlias(), uniqueKey, batchSize ) //include the discriminator and class-level where, but not filters .append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) ); AssociationInitCallbackImpl callback = new AssociationInitCallbackImpl( factory ); initAll( whereCondition.toString(), "", lockOptions, callback ); this.compositeKeyManyToOneTargetIndices = callback.resolve(); } public EntityJoinWalker( OuterJoinLoadable persister, String[] uniqueKey, int batchSize, LockOptions lockOptions, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { super( persister, factory, loadQueryInfluencers ); LockOptions.copy(lockOptions, this.lockOptions); StringBuffer whereCondition = whereString( getAlias(), uniqueKey, batchSize ) //include the discriminator and class-level where, but not filters .append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) ); AssociationInitCallbackImpl callback = new AssociationInitCallbackImpl( factory ); initAll( whereCondition.toString(), "", lockOptions, callback ); this.compositeKeyManyToOneTargetIndices = callback.resolve(); } protected JoinType getJoinType( OuterJoinLoadable persister, PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth) throws MappingException { // NOTE : we override this form here specifically to account for // fetch profiles. // TODO : how to best handle criteria queries? if ( lockOptions.getLockMode().greaterThan( LockMode.READ ) ) { return JoinType.NONE; } if ( isTooDeep( currentDepth ) || ( associationType.isCollectionType() && isTooManyCollections() ) ) { return JoinType.NONE; } if ( !isJoinedFetchEnabledInMapping( metadataFetchMode, associationType ) && !isJoinFetchEnabledByProfile( persister, path, propertyNumber ) ) { return JoinType.NONE; } if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) { return JoinType.NONE; } return getJoinType( nullable, currentDepth ); } public String getComment() { return "load " + getPersister().getEntityName(); } public int[][] getCompositeKeyManyToOneTargetIndices() { return compositeKeyManyToOneTargetIndices; } private static class AssociationInitCallbackImpl implements AssociationInitCallback { private final SessionFactoryImplementor factory; private final HashMap<String,OuterJoinableAssociation> associationsByAlias = new HashMap<String, OuterJoinableAssociation>(); private final HashMap<String,Integer> positionsByAlias = new HashMap Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate EntityJoinWalker.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.