
org.hibernate.jpa.criteria.path.SingularAttributeJoin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-entitymanager
Show all versions of hibernate-entitymanager
A module of the Hibernate O/RM project
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.jpa.criteria.path;
import javax.persistence.criteria.JoinType;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.SingularAttribute;
import org.hibernate.jpa.criteria.CriteriaBuilderImpl;
import org.hibernate.jpa.criteria.CriteriaSubqueryImpl;
import org.hibernate.jpa.criteria.FromImplementor;
import org.hibernate.jpa.criteria.PathSource;
import org.hibernate.jpa.criteria.compile.RenderingContext;
/**
* Models a join based on a singular attribute
*
* @param Represents the parameterized type of the attribute owner
* @param Represents the parameterized type of the attribute
*
* @author Steve Ebersole
*/
public class SingularAttributeJoin extends AbstractJoinImpl {
private final Bindable model;
@SuppressWarnings({ "unchecked" })
public SingularAttributeJoin(
CriteriaBuilderImpl criteriaBuilder,
Class javaType,
PathSource pathSource,
SingularAttribute super O, ?> joinAttribute,
JoinType joinType) {
super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType );
this.model = (Bindable) (
Attribute.PersistentAttributeType.EMBEDDED == joinAttribute.getPersistentAttributeType()
? joinAttribute
: javaType != null
? criteriaBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType )
: joinAttribute.getType()
);
}
@Override
public SingularAttribute super O, ?> getAttribute() {
return (SingularAttribute super O, ?>) super.getAttribute();
}
@Override
public SingularAttributeJoin correlateTo(CriteriaSubqueryImpl subquery) {
return (SingularAttributeJoin) super.correlateTo( subquery );
}
@Override
protected FromImplementor createCorrelationDelegate() {
return new SingularAttributeJoin(
criteriaBuilder(),
getJavaType(),
getPathSource(),
getAttribute(),
getJoinType()
);
}
@Override
protected boolean canBeJoinSource() {
return true;
}
public Bindable getModel() {
return model;
}
@Override
public SingularAttributeJoin treatAs(Class treatAsType) {
return new TreatedSingularAttributeJoin( this, treatAsType );
}
public static class TreatedSingularAttributeJoin extends SingularAttributeJoin {
private final SingularAttributeJoin original;
private final Class treatAsType;
public TreatedSingularAttributeJoin(SingularAttributeJoin original, Class treatAsType) {
super(
original.criteriaBuilder(),
treatAsType,
original.getPathSource(),
original.getAttribute(),
original.getJoinType()
);
this.original = original;
this.treatAsType = treatAsType;
}
@Override
public String getAlias() {
return original.getAlias();
}
@Override
public void prepareAlias(RenderingContext renderingContext) {
// do nothing...
}
@Override
public String render(RenderingContext renderingContext) {
return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy