public JoinDefinedByMetadata createCollectionJoin( QuerySpace leftHandSide, String lhsPropertyName, CollectionQuerySpace rightHandSide, boolean rightHandSideRequired, CollectionType joinedPropertyType, SessionFactoryImplementor sessionFactory) { return new JoinImpl( leftHandSide, lhsPropertyName, rightHandSide, joinedPropertyType.getAssociatedJoinable( sessionFactory ).getKeyColumnNames(), joinedPropertyType, rightHandSideRequired ); }
/** * Get the columns of the associated table which are to be used in the join * * @param type The type * @param factory The SessionFactory * * @return The columns for the right-hand-side of the join */ public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { final String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); final Joinable joinable = type.getAssociatedJoinable( factory ); if ( uniqueKeyPropertyName == null ) { return joinable.getKeyColumnNames(); } else { return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames( uniqueKeyPropertyName ); } }
private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) { SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); String[] elementColumnNames = rhs.getKeyColumnNames(); frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases ); appendIndexColumns( frag, lhsAlias ); appendIdentifierColumns( frag, lhsAlias ); return frag.toFragmentString() .substring( 2 ); //strip leading ',' }
private static String[] determineRhsColumnNames(EntityType entityType, SessionFactoryImplementor sessionFactory) { final Joinable persister = entityType.getAssociatedJoinable( sessionFactory ); return entityType.getRHSUniqueKeyPropertyName() == null ? persister.getKeyColumnNames() : ( (PropertyMapping) persister ).toColumns( entityType.getRHSUniqueKeyPropertyName() ); } }
@Override public void startingEntity(EntityDefinition entityDefinition) { // see if the EntityDefinition is a root... final boolean isRoot = fetchSourceStack.isEmpty(); if ( ! isRoot ) { // if not, this call should represent a fetch which should have been handled in #startingAttribute return; } // if we get here, it is a root log.tracef( "%s Starting root entity : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), entityDefinition.getEntityPersister().getEntityName() ); if ( !supportsRootEntityReturns() ) { throw new HibernateException( "This strategy does not support root entity returns" ); } final EntityReturnImpl entityReturn = new EntityReturnImpl( entityDefinition, querySpaces ); addRootReturn( entityReturn ); pushToStack( entityReturn ); // also add an AssociationKey for the root so we can later on recognize circular references back to the root. final Joinable entityPersister = (Joinable) entityDefinition.getEntityPersister(); associationKeyRegistered( new AssociationKey( entityPersister.getTableName(), entityPersister.getKeyColumnNames() ) ); }
@Override public void startingCollection(CollectionDefinition collectionDefinition) { // see if the EntityDefinition is a root... final boolean isRoot = fetchSourceStack.isEmpty(); if ( ! isRoot ) { // if not, this call should represent a fetch which should have been handled in #startingAttribute return; } log.tracef( "%s Starting root collection : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), collectionDefinition.getCollectionPersister().getRole() ); // if we get here, it is a root if ( ! supportsRootCollectionReturns() ) { throw new HibernateException( "This strategy does not support root collection returns" ); } final CollectionReturn collectionReturn = new CollectionReturnImpl( collectionDefinition, querySpaces ); pushToCollectionStack( collectionReturn ); addRootReturn( collectionReturn ); associationKeyRegistered( new AssociationKey( ( (Joinable) collectionDefinition.getCollectionPersister() ).getTableName(), ( (Joinable) collectionDefinition.getCollectionPersister() ).getKeyColumnNames() ) ); }
@Override public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition) { final FetchStrategy fetchStrategy = determineFetchStrategy( attributeDefinition ); final AssociationKey associationKey = attributeDefinition.getAssociationKey(); // go ahead and build the bidirectional fetch if ( attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY ) { final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister(); final AssociationKey currentEntityReferenceAssociationKey = new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() ); // if associationKey is equal to currentEntityReferenceAssociationKey // that means that the current EntityPersister has a single primary key attribute // (i.e., derived attribute) which is mapped by attributeDefinition. // This is not a bidirectional association. // TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or // it must be loaded when the ID for the dependent entity is resolved. Is there some other way to // deal with this??? final FetchSource registeredFetchSource = registeredFetchSource( associationKey ); if ( registeredFetchSource != null && ! associationKey.equals( currentEntityReferenceAssociationKey ) ) { currentSource().buildBidirectionalEntityReference( attributeDefinition, fetchStrategy, registeredFetchSource( associationKey ).resolveEntityReference() ); } } else { // Do nothing for collection } }
@Override public String[] getJoinKeyColumnNames() { return joinable.getKeyColumnNames(); }
/** * Checks whether table name and key column names of the given joinable and inverse collection persister match. */ private static boolean isCollectionMatching(Joinable mainSideJoinable, OgmCollectionPersister inverseSidePersister) { boolean isSameTable = mainSideJoinable.getTableName().equals( inverseSidePersister.getTableName() ); if ( !isSameTable ) { return false; } return Arrays.equals( mainSideJoinable.getKeyColumnNames(), inverseSidePersister.getElementColumnNames() ); }
private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) { SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); String[] elementColumnNames = rhs.getKeyColumnNames(); frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases ); appendIndexColumns( frag, lhsAlias ); appendIdentifierColumns( frag, lhsAlias ); return frag.toFragmentString() .substring( 2 ); //strip leading ',' }
/** * Get the columns of the associated table which are to * be used in the join */ public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); Joinable joinable = type.getAssociatedJoinable(factory); if (uniqueKeyPropertyName==null) { return joinable.getKeyColumnNames(); } else { return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName); } } }
/** * Get the columns of the associated table which are to * be used in the join */ public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); Joinable joinable = type.getAssociatedJoinable(factory); if (uniqueKeyPropertyName==null) { return joinable.getKeyColumnNames(); } else { return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName); } } }
/** * Get the columns of the associated table which are to * be used in the join */ public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); Joinable joinable = type.getAssociatedJoinable(factory); if (uniqueKeyPropertyName==null) { return joinable.getKeyColumnNames(); } else { return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName); } } }
/** * Get the columns of the associated table which are to * be used in the join */ public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) { String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName(); Joinable joinable = type.getAssociatedJoinable(factory); if (uniqueKeyPropertyName==null) { return joinable.getKeyColumnNames(); } else { return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName); } } }
private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) { SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); String[] elementColumnNames = rhs.getKeyColumnNames(); frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases ); appendIndexColumns( frag, lhsAlias ); appendIdentifierColumns( frag, lhsAlias ); return frag.toFragmentString() .substring( 2 ); //strip leading ',' }
private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) { SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); String[] elementColumnNames = rhs.getKeyColumnNames(); frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases ); appendIndexColumns( frag, lhsAlias ); appendIdentifierColumns( frag, lhsAlias ); return frag.toFragmentString() .substring( 2 ); //strip leading ',' }
private String manyToManySelectFragment( Joinable rhs, String rhsAlias, String lhsAlias, String collectionSuffix) { SelectFragment frag = generateSelectFragment( lhsAlias, collectionSuffix ); String[] elementColumnNames = rhs.getKeyColumnNames(); frag.addColumns( rhsAlias, elementColumnNames, elementColumnAliases ); appendIndexColumns( frag, lhsAlias ); appendIdentifierColumns( frag, lhsAlias ); return frag.toFragmentString() .substring( 2 ); //strip leading ',' }