-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
193 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
hibernate-core/src/main/java/org/hibernate/query/sqm/TreatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 http://www.gnu.org/licenses/lgpl-2.1.html. | ||
*/ | ||
package org.hibernate.query.sqm; | ||
|
||
import org.hibernate.HibernateException; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* Indicates a problem with a TREAT usage | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class TreatException extends HibernateException { | ||
public TreatException(String message) { | ||
super( message ); | ||
} | ||
|
||
public TreatException(String message, @Nullable Throwable cause) { | ||
super( message, cause ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSimplePath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* 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 http://www.gnu.org/licenses/lgpl-2.1.html. | ||
*/ | ||
package org.hibernate.query.sqm.tree.domain; | ||
|
||
import org.hibernate.metamodel.model.domain.EntityDomainType; | ||
import org.hibernate.query.PathException; | ||
import org.hibernate.query.sqm.NodeBuilder; | ||
import org.hibernate.query.sqm.SemanticQueryWalker; | ||
import org.hibernate.query.sqm.SqmPathSource; | ||
import org.hibernate.query.sqm.tree.SqmCopyContext; | ||
import org.hibernate.spi.NavigablePath; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class SqmTreatedSimplePath<T, S extends T> | ||
extends SqmEntityValuedSimplePath<S> | ||
implements SqmSimplePath<S>, SqmTreatedPath<T,S> { | ||
|
||
private final EntityDomainType<S> treatTarget; | ||
private final SqmPath<T> wrappedPath; | ||
|
||
public SqmTreatedSimplePath( | ||
SqmPluralValuedSimplePath<T> wrappedPath, | ||
EntityDomainType<S> treatTarget, | ||
NodeBuilder nodeBuilder) { | ||
//noinspection unchecked | ||
super( | ||
wrappedPath.getNavigablePath().treatAs( | ||
treatTarget.getHibernateEntityName() | ||
), | ||
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(), | ||
wrappedPath.getLhs(), | ||
nodeBuilder | ||
); | ||
this.treatTarget = treatTarget; | ||
this.wrappedPath = wrappedPath; | ||
} | ||
|
||
public SqmTreatedSimplePath( | ||
SqmPath<T> wrappedPath, | ||
EntityDomainType<S> treatTarget, | ||
NodeBuilder nodeBuilder) { | ||
//noinspection unchecked | ||
super( | ||
wrappedPath.getNavigablePath().treatAs( | ||
treatTarget.getHibernateEntityName() | ||
), | ||
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(), | ||
wrappedPath.getLhs(), | ||
nodeBuilder | ||
); | ||
this.treatTarget = treatTarget; | ||
this.wrappedPath = wrappedPath; | ||
} | ||
|
||
private SqmTreatedSimplePath( | ||
NavigablePath navigablePath, | ||
SqmPath<T> wrappedPath, | ||
EntityDomainType<S> treatTarget, | ||
NodeBuilder nodeBuilder) { | ||
//noinspection unchecked | ||
super( | ||
navigablePath, | ||
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(), | ||
wrappedPath.getLhs(), | ||
nodeBuilder | ||
); | ||
this.treatTarget = treatTarget; | ||
this.wrappedPath = wrappedPath; | ||
} | ||
|
||
@Override | ||
public SqmTreatedSimplePath<T, S> copy(SqmCopyContext context) { | ||
final SqmTreatedSimplePath<T, S> existing = context.getCopy( this ); | ||
if ( existing != null ) { | ||
return existing; | ||
} | ||
|
||
final SqmTreatedSimplePath<T, S> path = context.registerCopy( | ||
this, | ||
new SqmTreatedSimplePath<>( | ||
getNavigablePath(), | ||
wrappedPath.copy( context ), | ||
getTreatTarget(), | ||
nodeBuilder() | ||
) | ||
); | ||
copyTo( path, context ); | ||
return path; | ||
} | ||
|
||
@Override | ||
public EntityDomainType<S> getTreatTarget() { | ||
return treatTarget; | ||
} | ||
|
||
@Override | ||
public SqmPath<T> getWrappedPath() { | ||
return wrappedPath; | ||
} | ||
|
||
@Override | ||
public EntityDomainType<S> getNodeType() { | ||
return treatTarget; | ||
} | ||
|
||
@Override | ||
public SqmPathSource<S> getReferencedPathSource() { | ||
return treatTarget; | ||
} | ||
|
||
@Override | ||
public SqmPathSource<?> getResolvedModel() { | ||
return treatTarget; | ||
} | ||
|
||
@Override | ||
public <S1 extends S> SqmTreatedEntityValuedSimplePath<S,S1> treatAs(Class<S1> treatJavaType) throws PathException { | ||
return super.treatAs( treatJavaType ); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public SqmPath<?> get(String attributeName) { | ||
return resolvePath( attributeName, treatTarget.getSubPathSource( attributeName ) ); | ||
} | ||
|
||
@Override | ||
public <X> X accept(SemanticQueryWalker<X> walker) { | ||
return walker.visitTreatedPath( this ); | ||
} | ||
|
||
@Override | ||
public void appendHqlString(StringBuilder sb) { | ||
sb.append( "treat(" ); | ||
wrappedPath.appendHqlString( sb ); | ||
sb.append( " as " ); | ||
sb.append( treatTarget.getName() ); | ||
sb.append( ')' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters