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");
}
};
}
};
}
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));
}
Aggregations