use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class JoinWalker method selectString.
/**
* Generate a select list of columns containing all properties of the entity classes
*/
protected final String selectString(List associations) throws MappingException {
if (associations.size() == 0) {
return "";
} else {
StringBuilder buf = new StringBuilder(associations.size() * 100);
int entityAliasCount = 0;
int collectionAliasCount = 0;
for (int i = 0; i < associations.size(); i++) {
OuterJoinableAssociation join = (OuterJoinableAssociation) associations.get(i);
OuterJoinableAssociation next = (i == associations.size() - 1) ? null : (OuterJoinableAssociation) associations.get(i + 1);
final Joinable joinable = join.getJoinable();
final String entitySuffix = (suffixes == null || entityAliasCount >= suffixes.length) ? null : suffixes[entityAliasCount];
final String collectionSuffix = (collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.length) ? null : collectionSuffixes[collectionAliasCount];
final String selectFragment = joinable.selectFragment(next == null ? null : next.getJoinable(), next == null ? null : next.getRHSAlias(), join.getRHSAlias(), entitySuffix, collectionSuffix, join.getJoinType() == JoinType.LEFT_OUTER_JOIN);
if (selectFragment.trim().length() > 0) {
buf.append(", ").append(selectFragment);
}
if (joinable.consumesEntityAlias()) {
entityAliasCount++;
}
if (joinable.consumesCollectionAlias() && join.getJoinType() == JoinType.LEFT_OUTER_JOIN && !join.hasRestriction()) {
collectionAliasCount++;
}
}
return buf.toString();
}
}
use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class JoinHelper method getRHSColumnNames.
/**
* 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);
}
}
use of org.hibernate.persister.entity.Joinable 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.Joinable in project midpoint by Evolveum.
the class RUtil method getTableName.
public static String getTableName(Class<?> hqlType, Session session) {
SessionFactory factory = session.getSessionFactory();
MetamodelImpl model = (MetamodelImpl) factory.getMetamodel();
EntityPersister ep = model.entityPersister(hqlType);
if (ep instanceof Joinable) {
Joinable joinable = (Joinable) ep;
return joinable.getTableName();
}
throw new SystemException("Couldn't get table name for class " + hqlType.getName());
}
Aggregations