Search in sources :

Example 21 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable in project hibernate-orm by hibernate.

the class AbstractCompositionAttribute method getAttributes.

@Override
public Iterable<AttributeDefinition> getAttributes() {
    return new Iterable<AttributeDefinition>() {

        @Override
        public Iterator<AttributeDefinition> iterator() {
            return new Iterator<AttributeDefinition>() {

                private final int numberOfAttributes = getType().getSubtypes().length;

                private int currentSubAttributeNumber;

                private int currentColumnPosition = columnStartPosition;

                @Override
                public boolean hasNext() {
                    return currentSubAttributeNumber < numberOfAttributes;
                }

                @Override
                public AttributeDefinition next() {
                    final int subAttributeNumber = currentSubAttributeNumber;
                    currentSubAttributeNumber++;
                    final String name = getType().getPropertyNames()[subAttributeNumber];
                    final Type type = getType().getSubtypes()[subAttributeNumber];
                    int columnPosition = currentColumnPosition;
                    currentColumnPosition += type.getColumnSpan(sessionFactory());
                    final CompositeType cType = getType();
                    final boolean nullable = cType.getPropertyNullability() == null || cType.getPropertyNullability()[subAttributeNumber];
                    if (type.isAssociationType()) {
                        // we build the association-key here because of the "goofiness" with 'currentColumnPosition'
                        final AssociationKey associationKey;
                        final AssociationType aType = (AssociationType) type;
                        final Joinable joinable = aType.getAssociatedJoinable(sessionFactory());
                        if (aType.isAnyType()) {
                            associationKey = new AssociationKey(JoinHelper.getLHSTableName(aType, attributeNumber(), (OuterJoinLoadable) locateOwningPersister()), JoinHelper.getLHSColumnNames(aType, attributeNumber(), columnPosition, (OuterJoinLoadable) locateOwningPersister(), sessionFactory()));
                        } else if (aType.getForeignKeyDirection() == ForeignKeyDirection.FROM_PARENT) {
                            final String lhsTableName;
                            final String[] lhsColumnNames;
                            if (joinable.isCollection()) {
                                final QueryableCollection collectionPersister = (QueryableCollection) joinable;
                                lhsTableName = collectionPersister.getTableName();
                                lhsColumnNames = collectionPersister.getElementColumnNames();
                            } else {
                                final OuterJoinLoadable entityPersister = (OuterJoinLoadable) locateOwningPersister();
                                lhsTableName = getLHSTableName(aType, attributeNumber(), entityPersister);
                                lhsColumnNames = getLHSColumnNames(aType, attributeNumber(), columnPosition, entityPersister, sessionFactory());
                            }
                            associationKey = new AssociationKey(lhsTableName, lhsColumnNames);
                        } else {
                            associationKey = new AssociationKey(joinable.getTableName(), getRHSColumnNames(aType, sessionFactory()));
                        }
                        return new CompositeBasedAssociationAttribute(AbstractCompositionAttribute.this, sessionFactory(), attributeNumber(), name, (AssociationType) type, new BaselineAttributeInformation.Builder().setInsertable(AbstractCompositionAttribute.this.isInsertable()).setUpdateable(AbstractCompositionAttribute.this.isUpdateable()).setNullable(nullable).setDirtyCheckable(true).setVersionable(AbstractCompositionAttribute.this.isVersionable()).setCascadeStyle(getType().getCascadeStyle(subAttributeNumber)).setFetchMode(getType().getFetchMode(subAttributeNumber)).createInformation(), subAttributeNumber, associationKey);
                    } else if (type.isComponentType()) {
                        return new CompositionBasedCompositionAttribute(AbstractCompositionAttribute.this, sessionFactory(), attributeNumber(), name, (CompositeType) type, columnPosition, new BaselineAttributeInformation.Builder().setInsertable(AbstractCompositionAttribute.this.isInsertable()).setUpdateable(AbstractCompositionAttribute.this.isUpdateable()).setNullable(nullable).setDirtyCheckable(true).setVersionable(AbstractCompositionAttribute.this.isVersionable()).setCascadeStyle(getType().getCascadeStyle(subAttributeNumber)).setFetchMode(getType().getFetchMode(subAttributeNumber)).createInformation());
                    } else {
                        return new CompositeBasedBasicAttribute(AbstractCompositionAttribute.this, sessionFactory(), subAttributeNumber, name, type, new BaselineAttributeInformation.Builder().setInsertable(AbstractCompositionAttribute.this.isInsertable()).setUpdateable(AbstractCompositionAttribute.this.isUpdateable()).setNullable(nullable).setDirtyCheckable(true).setVersionable(AbstractCompositionAttribute.this.isVersionable()).setCascadeStyle(getType().getCascadeStyle(subAttributeNumber)).setFetchMode(getType().getFetchMode(subAttributeNumber)).createInformation());
                    }
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Remove operation not supported here");
                }
            };
        }
    };
}
Also used : AssociationKey(org.hibernate.persister.walking.spi.AssociationKey) OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) AttributeDefinition(org.hibernate.persister.walking.spi.AttributeDefinition) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) Joinable(org.hibernate.persister.entity.Joinable) Iterator(java.util.Iterator) BaselineAttributeInformation(org.hibernate.tuple.BaselineAttributeInformation) CompositeType(org.hibernate.type.CompositeType)

Example 22 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable in project hibernate-orm by hibernate.

the class EntityLoadQueryDetails method applyRootReturnTableFragments.

/**
 * Applies "table fragments" to the FROM-CLAUSE of the given SelectStatementBuilder for the given Loadable
 *
 * @param select The SELECT statement builder
 *
 * @see org.hibernate.persister.entity.OuterJoinLoadable#fromTableFragment(java.lang.String)
 * @see org.hibernate.persister.entity.Joinable#fromJoinFragment(java.lang.String, boolean, boolean)
 */
protected void applyRootReturnTableFragments(SelectStatementBuilder select) {
    final String fromTableFragment;
    final String rootAlias = entityReferenceAliases.getTableAlias();
    final OuterJoinLoadable outerJoinLoadable = (OuterJoinLoadable) getRootEntityReturn().getEntityPersister();
    final Dialect dialect = getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect();
    if (getQueryBuildingParameters().getLockOptions() != null) {
        fromTableFragment = dialect.appendLockHint(getQueryBuildingParameters().getLockOptions(), outerJoinLoadable.fromTableFragment(rootAlias));
        select.setLockOptions(getQueryBuildingParameters().getLockOptions());
    } else if (getQueryBuildingParameters().getLockMode() != null) {
        fromTableFragment = dialect.appendLockHint(getQueryBuildingParameters().getLockMode(), outerJoinLoadable.fromTableFragment(rootAlias));
        select.setLockMode(getQueryBuildingParameters().getLockMode());
    } else {
        fromTableFragment = outerJoinLoadable.fromTableFragment(rootAlias);
    }
    select.appendFromClauseFragment(fromTableFragment + outerJoinLoadable.fromJoinFragment(rootAlias, true, true));
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) Dialect(org.hibernate.dialect.Dialect)

Aggregations

OuterJoinLoadable (org.hibernate.persister.entity.OuterJoinLoadable)22 Joinable (org.hibernate.persister.entity.Joinable)6 UniqueKeyLoadable (org.hibernate.persister.entity.UniqueKeyLoadable)6 AssociationType (org.hibernate.type.AssociationType)5 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)3 Configuration (org.hibernate.cfg.Configuration)2 EntityReturn (org.hibernate.loader.plan.spi.EntityReturn)2 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)2 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)2 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 Dialect (org.hibernate.dialect.Dialect)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 FetchStyle (org.hibernate.engine.FetchStyle)1 Fetch (org.hibernate.engine.profile.Fetch)1 FetchProfile (org.hibernate.engine.profile.FetchProfile)1 CriteriaJoinWalker (org.hibernate.loader.criteria.CriteriaJoinWalker)1 CollectionFetchableElementEntityGraph (org.hibernate.loader.plan.build.internal.returns.CollectionFetchableElementEntityGraph)1