6 - SQM based on JPA type system
- work on `org.hibernate.query` (especially `NamedQueryRepository` and friends) - work on `org.hibernate.sql.exec` - work on `org.hibernate.sql.results` - work on `org.hibernate.sql.exec` - work on `org.hibernate.sql.results` - work related to `org.hibernate.metamodel.model.mapping.spi.ValueMapping` - including "sketching in" the hooks with `org.hibernate.persister.walking`
This commit is contained in:
parent
8d0ff71dfc
commit
f8a75994e1
documentation/src/test/java/org/hibernate/userguide/proxy/tuplizer
hibernate-core/src/main/java/org/hibernate
Session.javaSharedSessionContract.java
annotations
boot
cache/spi
cfg
criterion
AbstractEmptinessExpression.javaAggregateProjection.javaAliasedProjection.javaAvgProjection.javaBetweenExpression.javaConjunction.javaCountProjection.javaCriteriaQuery.javaCriteriaSpecification.javaCriterion.javaDetachedCriteria.javaDisjunction.javaDistinct.javaEmptyExpression.javaEnhancedProjection.javaExample.javaExistsSubqueryExpression.javaExpression.javaIdentifierEqExpression.javaIdentifierProjection.javaIlikeExpression.javaInExpression.javaJunction.javaLikeExpression.javaLogicalExpression.javaMatchMode.javaNaturalIdentifier.javaNotEmptyExpression.javaNotExpression.javaNotNullExpression.javaNullExpression.javaOrder.javaParameterInfoCollector.javaProjection.javaProjectionList.javaProjections.javaPropertiesSubqueryExpression.javaProperty.javaPropertyExpression.javaPropertyProjection.javaPropertySubqueryExpression.javaRestrictions.javaRowCountProjection.javaSQLCriterion.javaSQLProjection.javaSimpleExpression.javaSimpleProjection.javaSimpleSubqueryExpression.javaSizeExpression.javaSubqueries.javaSubqueryExpression.javapackage.html
dialect
engine
internal
AbstractSharedSessionContract.javaFetchingScrollableResultsImpl.javaScrollableResultsImpl.javaSessionImpl.javaStatelessSessionImpl.java
util/collections
jpa/spi
loader
Loader.java
collection
DynamicBatchingCollectionInitializerBuilder.javaSubselectCollectionLoader.javaSubselectOneToManyLoader.java
plan
criteria
custom
entity
hql
plan/exec/internal
|
@ -8,7 +8,7 @@
|
|||
//$Id$
|
||||
package org.hibernate.userguide.proxy.tuplizer;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.metamodel.spi.Instantiator;
|
||||
import org.hibernate.tuple.component.PojoComponentTuplizer;
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.property.access.spi.Getter;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.metamodel.spi.Instantiator;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.tuple.entity.PojoEntityTuplizer;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ package org.hibernate.userguide.proxy.tuplizer;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.tuple.Instantiator;
|
||||
import org.hibernate.metamodel.spi.Instantiator;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.graph.RootGraph;
|
|||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.jpa.HibernateEntityManager;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.stat.SessionStatistics;
|
||||
|
||||
/**
|
||||
|
@ -677,21 +676,6 @@ public interface Session extends SharedSessionContract, EntityManager, Hibernate
|
|||
*/
|
||||
LockMode getCurrentLockMode(Object object);
|
||||
|
||||
/**
|
||||
* Create a {@link Query} instance for the given collection and filter string. Contains an implicit {@code FROM}
|
||||
* element named {@code this} which refers to the defined table for the collection elements, as well as an implicit
|
||||
* {@code WHERE} restriction for this particular collection instance's key value.
|
||||
*
|
||||
* @param collection a persistent collection
|
||||
* @param queryString a Hibernate query fragment.
|
||||
*
|
||||
* @return The query instance for manipulation and execution
|
||||
*
|
||||
* @deprecated (since 5.3) with no real replacement.
|
||||
*/
|
||||
@Deprecated
|
||||
org.hibernate.Query createFilter(Object collection, String queryString);
|
||||
|
||||
/**
|
||||
* Completely clear the session. Evict all loaded instances and cancel all pending
|
||||
* saves, updates and deletions. Do not close open iterators or instances of
|
||||
|
@ -1178,7 +1162,4 @@ public interface Session extends SharedSessionContract, EntityManager, Hibernate
|
|||
|
||||
|
||||
<T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> resultType);
|
||||
|
||||
@Override
|
||||
NativeQuery createSQLQuery(String queryString);
|
||||
}
|
||||
|
|
|
@ -114,57 +114,6 @@ public interface SharedSessionContract extends QueryProducer, Serializable {
|
|||
*/
|
||||
ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings);
|
||||
|
||||
/**
|
||||
* Create {@link Criteria} instance for the given class (entity or subclasses/implementors).
|
||||
*
|
||||
* @param persistentClass The class, which is an entity, or has entity subclasses/implementors
|
||||
*
|
||||
* @return The criteria instance for manipulation and execution
|
||||
*
|
||||
* @deprecated (since 5.2) for Session, use the JPA Criteria
|
||||
*/
|
||||
@Deprecated
|
||||
Criteria createCriteria(Class persistentClass);
|
||||
|
||||
/**
|
||||
* Create {@link Criteria} instance for the given class (entity or subclasses/implementors), using a specific
|
||||
* alias.
|
||||
*
|
||||
* @param persistentClass The class, which is an entity, or has entity subclasses/implementors
|
||||
* @param alias The alias to use
|
||||
*
|
||||
* @return The criteria instance for manipulation and execution
|
||||
*
|
||||
* @deprecated (since 5.2) for Session, use the JPA Criteria
|
||||
*/
|
||||
@Deprecated
|
||||
Criteria createCriteria(Class persistentClass, String alias);
|
||||
|
||||
/**
|
||||
* Create {@link Criteria} instance for the given entity name.
|
||||
*
|
||||
* @param entityName The entity name
|
||||
|
||||
* @return The criteria instance for manipulation and execution
|
||||
*
|
||||
* @deprecated (since 5.2) for Session, use the JPA Criteria
|
||||
*/
|
||||
@Deprecated
|
||||
Criteria createCriteria(String entityName);
|
||||
|
||||
/**
|
||||
* Create {@link Criteria} instance for the given entity name, using a specific alias.
|
||||
*
|
||||
* @param entityName The entity name
|
||||
* @param alias The alias to use
|
||||
*
|
||||
* @return The criteria instance for manipulation and execution
|
||||
*
|
||||
* @deprecated (since 5.2) for Session, use the JPA Criteria
|
||||
*/
|
||||
@Deprecated
|
||||
Criteria createCriteria(String entityName, String alias);
|
||||
|
||||
/**
|
||||
* Get the Session-level JDBC batch size for the current Session.
|
||||
* Overrides the SessionFactory JDBC batch size defined by the {@code hibernate.default_batch_fetch_size} configuration property for the scope of the current {@code Session}.
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.annotations;
|
||||
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.graph.GraphSemantic;
|
||||
|
||||
/**
|
||||
|
|
|
@ -752,6 +752,20 @@ public interface SessionFactoryBuilder {
|
|||
*/
|
||||
SessionFactoryBuilder enableJpaClosedCompliance(boolean enabled);
|
||||
|
||||
/**
|
||||
* See the discussion on {@link org.hibernate.cfg.AvailableSettings#NATIVE_QUERY_ORDINAL_PARAMETER_BASE}
|
||||
* <p/>
|
||||
* The passed value will be validated to be either:<ul>
|
||||
* <li>0</li>
|
||||
* <li>1</li>
|
||||
* <li>{@code null}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param base The base to use.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
SessionFactoryBuilder applyNonJpaNativeQueryOrdinalParameterBase(Integer base);
|
||||
|
||||
/**
|
||||
* Allows unwrapping this builder as another, more specific type.
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.hibernate.cfg.BaselineSessionEventsListenerBuilder;
|
|||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
|
@ -318,6 +317,42 @@ public interface SessionFactoryOptions {
|
|||
|
||||
SqmFunctionRegistry getSqmFunctionRegistry();
|
||||
|
||||
/**
|
||||
* See {@link org.hibernate.cfg.AvailableSettings#NATIVE_QUERY_ORDINAL_PARAMETER_BASE} and
|
||||
* {@link org.hibernate.boot.SessionFactoryBuilder#applyNonJpaNativeQueryOrdinalParameterBase(Integer)} for details.
|
||||
*
|
||||
* @return The base integer for ordinal parameters
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
Integer getNonJpaNativeQueryOrdinalParameterBase();
|
||||
|
||||
/**
|
||||
* Controls whether Hibernate should try to map named parameter names
|
||||
* specified in a {@link org.hibernate.procedure.ProcedureCall} or
|
||||
* {@link javax.persistence.StoredProcedureQuery} to named parameters in
|
||||
* the JDBC {@link java.sql.CallableStatement}.
|
||||
* <p/>
|
||||
* As JPA is defined, the use of named parameters is essentially of dubious
|
||||
* value since by spec the parameters have to be defined in the order they are
|
||||
* defined in the procedure/function declaration - we can always bind them
|
||||
* positionally. The whole idea of named parameters for CallableStatement
|
||||
* is the ability to bind these in any order, but since we unequivocally
|
||||
* know the order anyway binding them via name really gains nothing.
|
||||
* <p/>
|
||||
* If this is {@code true}, we still need to make sure the Dialect supports
|
||||
* named binding. Setting this to {@code false} simply circumvents that
|
||||
* check and always performs positional binding.
|
||||
*
|
||||
* @return {@code true} indicates we should try to use {@link java.sql.CallableStatement}
|
||||
* named parameters, if the Dialect says it is supported; {@code false}
|
||||
* indicates that we should never try to use {@link java.sql.CallableStatement}
|
||||
* named parameters, regardless of what the Dialect says.
|
||||
*
|
||||
* @see org.hibernate.cfg.AvailableSettings#CALLABLE_NAMED_PARAMS_ENABLED
|
||||
*/
|
||||
boolean isUseOfJdbcNamedParametersEnabled();
|
||||
|
||||
boolean isOmitJoinOfSuperclassTablesEnabled();
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.cache.spi.TimestampsCacheFactory;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
|
@ -868,6 +869,46 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
|||
*/
|
||||
String ENFORCE_LEGACY_PROXY_CLASSNAMES = "hibernate.bytecode.enforce_legacy_proxy_classnames";
|
||||
|
||||
|
||||
/**
|
||||
* Controls the base integer for binding JDBC-style ({@code ?}) ordinal
|
||||
* parameters when the Hibernate SessionFactory is bootstrapped via the native
|
||||
* bootstrapping API. JPA says that all non-named parameter binding is explicitly
|
||||
* 1-based; so when bootstrapped via JPA, Hibernate always treats these as 1-based.
|
||||
* <p/>
|
||||
* Note that this affects only ordinal parameters. Positional
|
||||
* parameters (e.g. {@code ?1}) explicitly define the binding position (1) in
|
||||
* their declaration, whereas the binding position is implicit with ordinal
|
||||
* parameters based on its ordinal position in the query. As of 6.0, support
|
||||
* for this ordinal parameter declaration form has been removed from HQL and
|
||||
* is now only valid for {@link org.hibernate.query.NativeQuery}s.
|
||||
* <p/>
|
||||
* Historically Hibernate followed JDBC conventions for ordinal parameter binding
|
||||
* such that the implied positions were 0-based. This presents a mismatch between
|
||||
* how to bind ordinal parameters based on how the SessionFactory was bootstrapped,
|
||||
* which is not ideal. This setting then seeks to allow unifying how these are
|
||||
* handled regardless of the bootstrap method. The expected value of this setting
|
||||
* is an integer value of either 0 (the default) or 1. The default follows the legacy
|
||||
* expectations and allows legacy Hibernate apps to continue to work. Setting this
|
||||
* to 1 (one) allows all non-named parameter binding to be unified as 1-based.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
String NATIVE_QUERY_ORDINAL_PARAMETER_BASE = "hibernate.query.native.ordinal_parameter_base";
|
||||
|
||||
/**
|
||||
* Global setting name for controlling whether Hibernate should try to map
|
||||
* named parameter names specified in a
|
||||
* {@link org.hibernate.procedure.ProcedureCall} or
|
||||
* {@link javax.persistence.StoredProcedureQuery} to named parameters in
|
||||
* the JDBC {@link java.sql.CallableStatement}.
|
||||
*
|
||||
* @see SessionFactoryOptions#isUseOfJdbcNamedParametersEnabled()
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
String CALLABLE_NAMED_PARAMS_ENABLED = "hibernate.query.proc.callable_named_params_enabled";
|
||||
|
||||
/**
|
||||
* Should Hibernate use enhanced entities "as a proxy"?
|
||||
*
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.persister.entity.Loadable;
|
||||
import org.hibernate.persister.entity.PropertyMapping;
|
||||
import org.hibernate.sql.ConditionFragment;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Base expression implementation for (not) emptiness checking of collection properties
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractEmptinessExpression implements Criterion {
|
||||
|
||||
private static final TypedValue[] NO_VALUES = new TypedValue[0];
|
||||
|
||||
protected final String propertyName;
|
||||
|
||||
protected AbstractEmptinessExpression(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should empty rows be excluded?
|
||||
*
|
||||
* @return {@code true} Indicates the expression should be 'exists'; {@code false} indicates 'not exists'
|
||||
*/
|
||||
protected abstract boolean excludeEmpty();
|
||||
|
||||
@Override
|
||||
public final String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String entityName = criteriaQuery.getEntityName( criteria, propertyName );
|
||||
final String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
|
||||
final String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );
|
||||
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final QueryableCollection collectionPersister = getQueryableCollection( entityName, actualPropertyName, factory );
|
||||
|
||||
final String[] collectionKeys = collectionPersister.getKeyColumnNames();
|
||||
final String[] ownerKeys = ( (Loadable) factory.getEntityPersister( entityName ) ).getIdentifierColumnNames();
|
||||
|
||||
final String innerSelect = "(select 1 from " + collectionPersister.getTableName() + " where "
|
||||
+ new ConditionFragment().setTableAlias( sqlAlias ).setCondition( ownerKeys, collectionKeys ).toFragmentString()
|
||||
+ ")";
|
||||
|
||||
return excludeEmpty()
|
||||
? "exists " + innerSelect
|
||||
: "not exists " + innerSelect;
|
||||
}
|
||||
|
||||
|
||||
protected QueryableCollection getQueryableCollection(
|
||||
String entityName,
|
||||
String propertyName,
|
||||
SessionFactoryImplementor factory) throws HibernateException {
|
||||
final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
|
||||
final Type type = ownerMapping.toType( propertyName );
|
||||
if ( !type.isCollectionType() ) {
|
||||
throw new MappingException(
|
||||
"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
|
||||
);
|
||||
}
|
||||
|
||||
final String role = ( (CollectionType) type ).getRole();
|
||||
try {
|
||||
return (QueryableCollection) factory.getCollectionPersister( role );
|
||||
}
|
||||
catch ( ClassCastException cce ) {
|
||||
throw new QueryException( "collection role is not queryable: " + role );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new QueryException( "collection role not found: " + role );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException {
|
||||
return NO_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return propertyName + ( excludeEmpty() ? " is not empty" : " is empty" );
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Base class for standard aggregation functions.
|
||||
*
|
||||
* @author max
|
||||
*/
|
||||
public class AggregateProjection extends SimpleProjection {
|
||||
protected final String propertyName;
|
||||
private final String functionName;
|
||||
|
||||
protected AggregateProjection(String functionName, String propertyName) {
|
||||
this.functionName = functionName;
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public String getFunctionName() {
|
||||
return functionName;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new Type[] {
|
||||
getFunction( criteriaQuery ).getReturnType(
|
||||
criteriaQuery.getType( criteria, getPropertyName() ),
|
||||
criteriaQuery.getFactory()
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String functionFragment = getFunction( criteriaQuery ).render(
|
||||
criteriaQuery.getType( criteria, getPropertyName() ),
|
||||
buildFunctionParameterList( criteria, criteriaQuery ),
|
||||
criteriaQuery.getFactory()
|
||||
);
|
||||
return functionFragment + " as y" + loc + '_';
|
||||
}
|
||||
|
||||
protected SQLFunction getFunction(CriteriaQuery criteriaQuery) {
|
||||
return getFunction( getFunctionName(), criteriaQuery );
|
||||
}
|
||||
|
||||
protected SQLFunction getFunction(String functionName, CriteriaQuery criteriaQuery) {
|
||||
final SQLFunction function = criteriaQuery.getFactory()
|
||||
.getSqlFunctionRegistry()
|
||||
.findSQLFunction( functionName );
|
||||
if ( function == null ) {
|
||||
throw new HibernateException( "Unable to locate mapping for function named [" + functionName + "]" );
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
protected List buildFunctionParameterList(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return buildFunctionParameterList( criteriaQuery.getColumn( criteria, getPropertyName() ) );
|
||||
}
|
||||
|
||||
protected List buildFunctionParameterList(String column) {
|
||||
return Collections.singletonList( column );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return functionName + "(" + propertyName + ')';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Represents a projection that specifies an alias
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class AliasedProjection implements EnhancedProjection {
|
||||
private final Projection projection;
|
||||
private final String alias;
|
||||
|
||||
protected AliasedProjection(Projection projection, String alias) {
|
||||
this.projection = projection;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return projection.toSqlString( criteria, position, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return projection.toGroupSqlString( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return projection.getTypes( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc) {
|
||||
return projection.getColumnAliases( loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return projection instanceof EnhancedProjection
|
||||
? ( (EnhancedProjection) projection ).getColumnAliases( loc, criteria, criteriaQuery )
|
||||
: getColumnAliases( loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return this.alias.equals( alias )
|
||||
? getTypes( criteria, criteriaQuery )
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc) {
|
||||
return this.alias.equals( alias )
|
||||
? getColumnAliases( loc )
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return this.alias.equals( alias )
|
||||
? getColumnAliases( loc, criteria, criteriaQuery )
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[] { alias };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return projection.isGrouped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return projection.toString() + " as " + alias;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* An avg() projection
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class AvgProjection extends AggregateProjection {
|
||||
/**
|
||||
* Constructs the AvgProjection
|
||||
*
|
||||
* @param propertyName The name of the property to average
|
||||
*/
|
||||
public AvgProjection(String propertyName) {
|
||||
super( "avg", propertyName );
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Constrains a property to between two values
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class BetweenExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final Object low;
|
||||
private final Object high;
|
||||
|
||||
protected BetweenExpression(String propertyName, Object low, Object high) {
|
||||
this.propertyName = propertyName;
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
final String[] expressions = StringHelper.suffix( columns, " between ? and ?" );
|
||||
return String.join( " and ", expressions );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] {
|
||||
criteriaQuery.getTypedValue( criteria, propertyName, low),
|
||||
criteriaQuery.getTypedValue( criteria, propertyName, high)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + " between " + low + " and " + high;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* Defines a conjunction (AND series).
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see Disjunction
|
||||
*/
|
||||
public class Conjunction extends Junction {
|
||||
/**
|
||||
* Constructs a Conjunction
|
||||
*/
|
||||
public Conjunction() {
|
||||
super( Nature.AND );
|
||||
}
|
||||
|
||||
protected Conjunction(Criterion... criterion) {
|
||||
super( Nature.AND, criterion );
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
|
||||
/**
|
||||
* A count projection
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class CountProjection extends AggregateProjection {
|
||||
private boolean distinct;
|
||||
|
||||
/**
|
||||
* Constructs the count projection.
|
||||
*
|
||||
* @param prop The property name
|
||||
*
|
||||
* @see Projections#count(String)
|
||||
* @see Projections#countDistinct(String)
|
||||
*/
|
||||
protected CountProjection(String prop) {
|
||||
super( "count", prop );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List buildFunctionParameterList(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final String[] cols = criteriaQuery.getColumns( propertyName, criteria );
|
||||
return ( distinct ? buildCountDistinctParameterList( cols ) : Arrays.asList( cols ) );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List buildCountDistinctParameterList(String[] cols) {
|
||||
final List params = new ArrayList( cols.length + 1 );
|
||||
params.add( "distinct" );
|
||||
params.addAll( Arrays.asList( cols ) );
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the count as being distinct
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public CountProjection setDistinct() {
|
||||
distinct = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if ( distinct ) {
|
||||
return "distinct " + super.toString();
|
||||
}
|
||||
else {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* An instance of <tt>CriteriaQuery</tt> is passed to criterion,
|
||||
* order and projection instances when actually compiling and
|
||||
* executing the query. This interface is not used by application
|
||||
* code.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public interface CriteriaQuery {
|
||||
/**
|
||||
* Provides access to the SessionFactory
|
||||
*
|
||||
* @return The SessionFactory
|
||||
*/
|
||||
public SessionFactoryImplementor getFactory();
|
||||
|
||||
/**
|
||||
* Resolve a property path to the name of the column it maps to. Ignores projection aliases.
|
||||
*
|
||||
* @param criteria The overall criteria
|
||||
* @param propertyPath The property path to resolve
|
||||
*
|
||||
* @return The column name
|
||||
*
|
||||
* @throws HibernateException if the property maps to more than 1 column, or if the property could not be resolved
|
||||
*
|
||||
* @see #getColumns
|
||||
*/
|
||||
public String getColumn(Criteria criteria, String propertyPath) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Resolve a property path to the names of the columns it maps to. Ignores projection aliases
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path to resolve
|
||||
*
|
||||
* @return The column names
|
||||
*
|
||||
* @throws HibernateException if the property maps to more than 1 column, or if the property could not be resolved
|
||||
*/
|
||||
public String[] getColumns(String propertyPath, Criteria criteria) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the names of the columns mapped by a property path; if the property path is not found in criteria, try
|
||||
* the "outer" query. Projection aliases are ignored.
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path to resolve
|
||||
*
|
||||
* @return The column names
|
||||
*
|
||||
* @throws HibernateException if the property could not be resolved
|
||||
*/
|
||||
public String[] findColumns(String propertyPath, Criteria criteria) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the type of a property path.
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path to resolve
|
||||
*
|
||||
* @return The type
|
||||
*
|
||||
* @throws HibernateException if the property could not be resolved
|
||||
*/
|
||||
public Type getType(Criteria criteria, String propertyPath) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the names of the columns mapped by a property path. Here, the property path can refer to
|
||||
* a projection alias.
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path to resolve or projection alias
|
||||
*
|
||||
* @return The column names
|
||||
*
|
||||
* @throws HibernateException if the property/alias could not be resolved
|
||||
*/
|
||||
public String[] getColumnsUsingProjection(Criteria criteria, String propertyPath) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the type of a property path. Here, the property path can refer to a projection alias.
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path to resolve or projection alias
|
||||
*
|
||||
* @return The type
|
||||
*
|
||||
* @throws HibernateException if the property/alias could not be resolved
|
||||
*/
|
||||
public Type getTypeUsingProjection(Criteria criteria, String propertyPath) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Build a typed-value for the property/value combo. Essentially the same as manually building a TypedValue
|
||||
* using the given value and the resolved type using {@link #getTypeUsingProjection}.
|
||||
*
|
||||
* @param criteria The criteria query
|
||||
* @param propertyPath The property path/alias to resolve to type.
|
||||
* @param value The value
|
||||
*
|
||||
* @return The TypedValue
|
||||
*
|
||||
* @throws HibernateException if the property/alias could not be resolved
|
||||
*/
|
||||
public TypedValue getTypedValue(Criteria criteria, String propertyPath, Object value) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the entity name of an entity
|
||||
*
|
||||
* @param criteria The criteria
|
||||
*
|
||||
* @return The entity name
|
||||
*/
|
||||
public String getEntityName(Criteria criteria);
|
||||
|
||||
/**
|
||||
* Get the entity name of an entity, taking into account the qualifier of the property path
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path that (supposedly) references an entity
|
||||
*
|
||||
* @return The entity name
|
||||
*/
|
||||
public String getEntityName(Criteria criteria, String propertyPath);
|
||||
|
||||
/**
|
||||
* Get the root table alias of an entity
|
||||
*
|
||||
* @param criteria The criteria
|
||||
*
|
||||
* @return The SQL table alias for the given criteria
|
||||
*/
|
||||
public String getSQLAlias(Criteria criteria);
|
||||
|
||||
/**
|
||||
* Get the root table alias of an entity, taking into account
|
||||
* the qualifier of the property path
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param propertyPath The property path whose SQL alias should be returned.
|
||||
*
|
||||
* @return The SQL table alias for the given criteria
|
||||
*/
|
||||
public String getSQLAlias(Criteria criteria, String propertyPath);
|
||||
|
||||
/**
|
||||
* Get the property name, given a possibly qualified property name
|
||||
*
|
||||
* @param propertyName The (possibly qualified) property name
|
||||
*
|
||||
* @return The simple property name
|
||||
*/
|
||||
public String getPropertyName(String propertyName);
|
||||
|
||||
/**
|
||||
* Get the identifier column names of this entity
|
||||
*
|
||||
* @param criteria The criteria
|
||||
*
|
||||
* @return The identifier column names
|
||||
*/
|
||||
public String[] getIdentifierColumns(Criteria criteria);
|
||||
|
||||
/**
|
||||
* Get the identifier type of this entity
|
||||
*
|
||||
* @param criteria The criteria
|
||||
*
|
||||
* @return The identifier type.
|
||||
*/
|
||||
public Type getIdentifierType(Criteria criteria);
|
||||
|
||||
/**
|
||||
* Build a TypedValue for the given identifier value.
|
||||
*
|
||||
* @param criteria The criteria whose identifier is referenced.
|
||||
* @param value The identifier value
|
||||
*
|
||||
* @return The TypedValue
|
||||
*/
|
||||
public TypedValue getTypedIdentifierValue(Criteria criteria, Object value);
|
||||
|
||||
/**
|
||||
* Generate a unique SQL alias
|
||||
*
|
||||
* @return The generated alias
|
||||
*/
|
||||
public String generateSQLAlias();
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.sql.JoinType;
|
||||
import org.hibernate.transform.AliasToEntityMapResultTransformer;
|
||||
import org.hibernate.transform.DistinctRootEntityResultTransformer;
|
||||
import org.hibernate.transform.PassThroughResultTransformer;
|
||||
import org.hibernate.transform.ResultTransformer;
|
||||
import org.hibernate.transform.RootEntityResultTransformer;
|
||||
|
||||
/**
|
||||
* Commonality between different types of Criteria.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public interface CriteriaSpecification {
|
||||
|
||||
/**
|
||||
* The alias that refers to the "root" entity of the criteria query.
|
||||
*/
|
||||
public static final String ROOT_ALIAS = "this";
|
||||
|
||||
/**
|
||||
* Each row of results is a <tt>Map</tt> from alias to entity instance
|
||||
*/
|
||||
public static final ResultTransformer ALIAS_TO_ENTITY_MAP = AliasToEntityMapResultTransformer.INSTANCE;
|
||||
|
||||
/**
|
||||
* Each row of results is an instance of the root entity
|
||||
*/
|
||||
public static final ResultTransformer ROOT_ENTITY = RootEntityResultTransformer.INSTANCE;
|
||||
|
||||
/**
|
||||
* Each row of results is a distinct instance of the root entity
|
||||
*/
|
||||
public static final ResultTransformer DISTINCT_ROOT_ENTITY = DistinctRootEntityResultTransformer.INSTANCE;
|
||||
|
||||
/**
|
||||
* This result transformer is selected implicitly by calling <tt>setProjection()</tt>
|
||||
*/
|
||||
public static final ResultTransformer PROJECTION = PassThroughResultTransformer.INSTANCE;
|
||||
|
||||
/**
|
||||
* Specifies joining to an entity based on an inner join.
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.sql.JoinType#INNER_JOIN}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int INNER_JOIN = JoinType.INNER_JOIN.getJoinTypeValue();
|
||||
|
||||
/**
|
||||
* Specifies joining to an entity based on a full join.
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.sql.JoinType#FULL_JOIN}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int FULL_JOIN = JoinType.FULL_JOIN.getJoinTypeValue();
|
||||
|
||||
/**
|
||||
* Specifies joining to an entity based on a left outer join.
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int LEFT_JOIN = JoinType.LEFT_OUTER_JOIN.getJoinTypeValue();
|
||||
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* An object-oriented representation of a query criterion that may be used
|
||||
* as a restriction in a <tt>Criteria</tt> query.
|
||||
* Built-in criterion types are provided by the <tt>Restrictions</tt> factory
|
||||
* class. This interface might be implemented by application classes that
|
||||
* define custom restriction criteria.
|
||||
*
|
||||
* @see Restrictions
|
||||
* @see Criteria
|
||||
* @author Gavin King
|
||||
*/
|
||||
public interface Criterion extends Serializable {
|
||||
|
||||
/**
|
||||
* Render the SQL fragment
|
||||
*
|
||||
* @param criteria The local criteria
|
||||
* @param criteriaQuery The overal criteria query
|
||||
*
|
||||
* @return The generated SQL fragment
|
||||
* @throws org.hibernate.HibernateException Problem during rendering.
|
||||
*/
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Return typed values for all parameters in the rendered SQL fragment
|
||||
*
|
||||
* @param criteria The local criteria
|
||||
* @param criteriaQuery The overal criteria query
|
||||
*
|
||||
* @return The types values (for binding)
|
||||
* @throws HibernateException Problem determining types.
|
||||
*/
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException;
|
||||
|
||||
}
|
|
@ -1,442 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.CriteriaImpl;
|
||||
import org.hibernate.sql.JoinType;
|
||||
import org.hibernate.transform.ResultTransformer;
|
||||
|
||||
/**
|
||||
* Models a detached form of a Criteria (not associated with a Session).
|
||||
*
|
||||
* Some applications need to create criteria queries in "detached mode", where the Hibernate Session is
|
||||
* not available. Applications would create a DetachableCriteria to describe the query, and then later
|
||||
* associated it with a Session to obtain the "executable" Criteria:
|
||||
* <code>
|
||||
* DetachedCriteria detached = new DetachedCriteria();
|
||||
* ...
|
||||
* Criteria criteria = detached.getExecutableCriteria( session );
|
||||
* ...
|
||||
* criteria.list();
|
||||
* </code>
|
||||
*
|
||||
* All methods have the same semantics and behavior as the corresponding methods of the Criteria interface.
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @see org.hibernate.Criteria
|
||||
*/
|
||||
public class DetachedCriteria implements CriteriaSpecification, Serializable {
|
||||
private final CriteriaImpl impl;
|
||||
private final Criteria criteria;
|
||||
|
||||
protected DetachedCriteria(String entityName) {
|
||||
impl = new CriteriaImpl( entityName, null );
|
||||
criteria = impl;
|
||||
}
|
||||
|
||||
protected DetachedCriteria(String entityName, String alias) {
|
||||
impl = new CriteriaImpl( entityName, alias, null );
|
||||
criteria = impl;
|
||||
}
|
||||
|
||||
protected DetachedCriteria(CriteriaImpl impl, Criteria criteria) {
|
||||
this.impl = impl;
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an executable instance of Criteria to actually run the query.
|
||||
*
|
||||
* @param session The session to associate the built Criteria with
|
||||
*
|
||||
* @return The "executable" Criteria
|
||||
*/
|
||||
public Criteria getExecutableCriteria(Session session) {
|
||||
impl.setSession( (SessionImplementor) session );
|
||||
return impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the alias associated with this DetachedCriteria
|
||||
*
|
||||
* @return The alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
return criteria.getAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the CriteriaImpl used internally to hold the DetachedCriteria state
|
||||
*
|
||||
* @return The internally maintained CriteriaImpl
|
||||
*/
|
||||
CriteriaImpl getCriteriaImpl() {
|
||||
return impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static builder to create a DetachedCriteria for the given entity.
|
||||
*
|
||||
* @param entityName The name of the entity to create a DetachedCriteria for
|
||||
*
|
||||
* @return The DetachedCriteria
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static DetachedCriteria forEntityName(String entityName) {
|
||||
return new DetachedCriteria( entityName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Static builder to create a DetachedCriteria for the given entity.
|
||||
*
|
||||
* @param entityName The name of the entity to create a DetachedCriteria for
|
||||
* @param alias The alias to apply to the entity
|
||||
*
|
||||
* @return The DetachedCriteria
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static DetachedCriteria forEntityName(String entityName, String alias) {
|
||||
return new DetachedCriteria( entityName, alias );
|
||||
}
|
||||
|
||||
/**
|
||||
* Static builder to create a DetachedCriteria for the given entity, by its Class.
|
||||
*
|
||||
* @param clazz The entity class
|
||||
*
|
||||
* @return The DetachedCriteria
|
||||
*/
|
||||
public static DetachedCriteria forClass(Class clazz) {
|
||||
return new DetachedCriteria( clazz.getName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Static builder to create a DetachedCriteria for the given entity, by its Class.
|
||||
*
|
||||
* @param clazz The entity class
|
||||
* @param alias The alias to apply to the entity
|
||||
*
|
||||
* @return The DetachedCriteria
|
||||
*/
|
||||
public static DetachedCriteria forClass(Class clazz, String alias) {
|
||||
return new DetachedCriteria( clazz.getName() , alias );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a restriction
|
||||
*
|
||||
* @param criterion The restriction
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria add(Criterion criterion) {
|
||||
criteria.add( criterion );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an ordering
|
||||
*
|
||||
* @param order The ordering
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria addOrder(Order order) {
|
||||
criteria.addOrder( order );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fetch mode for a given association
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param mode The fetch mode to apply
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setFetchMode(String associationPath, FetchMode mode) {
|
||||
criteria.setFetchMode( associationPath, mode );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the projection to use.
|
||||
*
|
||||
* @param projection The projection to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setProjection(Projection projection) {
|
||||
criteria.setProjection( projection );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the result transformer to use.
|
||||
*
|
||||
* @param resultTransformer The result transformer to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer) {
|
||||
criteria.setResultTransformer( resultTransformer );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an association path alias within this DetachedCriteria. The alias can then be used in further
|
||||
* alias creations or restrictions, etc.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria createAlias(String associationPath, String alias) {
|
||||
criteria.createAlias( associationPath, alias );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an association path alias within this DetachedCriteria specifying the type of join. The alias
|
||||
* can then be used in further alias creations or restrictions, etc.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria createAlias(String associationPath, String alias, JoinType joinType) {
|
||||
criteria.createAlias( associationPath, alias, joinType );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an association path alias within this DetachedCriteria specifying the type of join. The alias
|
||||
* can then be used in further alias creations or restrictions, etc.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
* @param joinType The type of join to use
|
||||
* @param withClause An additional restriction on the join
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) {
|
||||
criteria.createAlias( associationPath, alias, joinType, withClause );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated!
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @deprecated use {@link #createAlias(String, String, JoinType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DetachedCriteria createAlias(String associationPath, String alias, int joinType) {
|
||||
return createAlias( associationPath, alias, JoinType.parse( joinType ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated!
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
* @param joinType The type of join to use
|
||||
* @param withClause An additional restriction on the join
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @deprecated use {@link #createAlias(String, String, JoinType, Criterion)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DetachedCriteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) {
|
||||
return createAlias( associationPath, alias, JoinType.parse( joinType ), withClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested DetachedCriteria representing the association path.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to apply to that association path
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*/
|
||||
public DetachedCriteria createCriteria(String associationPath, String alias) {
|
||||
return new DetachedCriteria( impl, criteria.createCriteria( associationPath, alias ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested DetachedCriteria representing the association path.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*/
|
||||
public DetachedCriteria createCriteria(String associationPath) {
|
||||
return new DetachedCriteria( impl, criteria.createCriteria( associationPath ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*/
|
||||
public DetachedCriteria createCriteria(String associationPath, JoinType joinType) {
|
||||
return new DetachedCriteria( impl, criteria.createCriteria( associationPath, joinType ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested DetachedCriteria representing the association path, specifying the type of join to use.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to associate with this "join".
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*/
|
||||
public DetachedCriteria createCriteria(String associationPath, String alias, JoinType joinType) {
|
||||
return new DetachedCriteria( impl, criteria.createCriteria( associationPath, alias, joinType ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nested DetachedCriteria representing the association path, specifying the type of join to use and
|
||||
* an additional join restriction.
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to associate with this "join".
|
||||
* @param joinType The type of join to use
|
||||
* @param withClause The additional join restriction
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*/
|
||||
public DetachedCriteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) {
|
||||
return new DetachedCriteria(impl, criteria.createCriteria( associationPath, alias, joinType, withClause ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated!
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*
|
||||
* @deprecated use {@link #createCriteria(String, JoinType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DetachedCriteria createCriteria(String associationPath, int joinType) {
|
||||
return createCriteria( associationPath, JoinType.parse( joinType ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated!
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias
|
||||
* @param joinType The type of join to use
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*
|
||||
* @deprecated use {@link #createCriteria(String, String, JoinType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType) {
|
||||
return createCriteria( associationPath, alias, JoinType.parse( joinType ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated!
|
||||
*
|
||||
* @param associationPath The association path
|
||||
* @param alias The alias to associate with this "join".
|
||||
* @param joinType The type of join to use
|
||||
* @param withClause The additional join restriction
|
||||
*
|
||||
* @return the newly created, nested DetachedCriteria
|
||||
*
|
||||
* @deprecated use {@link #createCriteria(String, String, JoinType, Criterion)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) {
|
||||
return createCriteria( associationPath, alias, JoinType.parse( joinType ), withClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SQL comment to use.
|
||||
*
|
||||
* @param comment The SQL comment to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setComment(String comment) {
|
||||
criteria.setComment( comment );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lock mode to use.
|
||||
*
|
||||
* @param lockMode The lock mode to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setLockMode(LockMode lockMode) {
|
||||
criteria.setLockMode( lockMode );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an alias-specific lock mode. The specified lock mode applies only to that alias.
|
||||
*
|
||||
* @param alias The alias to apply the lock to
|
||||
* @param lockMode The lock mode to use.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public DetachedCriteria setLockMode(String alias, LockMode lockMode) {
|
||||
criteria.setLockMode( alias, lockMode );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a timeout for the underlying JDBC query.
|
||||
*
|
||||
* @param timeout The timeout value to apply.
|
||||
* @return this (for method chaining)
|
||||
*
|
||||
* @see java.sql.Statement#setQueryTimeout
|
||||
*/
|
||||
public DetachedCriteria setTimeout(int timeout) {
|
||||
criteria.setTimeout( timeout );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DetachableCriteria(" + criteria.toString() + ')';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* Defines a disjunction (OR series).
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see Conjunction
|
||||
*/
|
||||
public class Disjunction extends Junction {
|
||||
/**
|
||||
* Constructs a Disjunction
|
||||
*/
|
||||
protected Disjunction() {
|
||||
super( Nature.OR );
|
||||
}
|
||||
|
||||
protected Disjunction(Criterion[] conditions) {
|
||||
super( Nature.OR, conditions );
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A wrappedProjection that is a wrapper around other projections to apply distinction.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class Distinct implements EnhancedProjection {
|
||||
private final Projection wrappedProjection;
|
||||
|
||||
/**
|
||||
* Constructs a Distinct
|
||||
*
|
||||
* @param wrappedProjection The wrapped projection
|
||||
*/
|
||||
public Distinct(Projection wrappedProjection) {
|
||||
this.wrappedProjection = wrappedProjection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) {
|
||||
return "distinct " + wrappedProjection.toSqlString( criteria, position, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return wrappedProjection.toGroupSqlString( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return wrappedProjection.getTypes( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return wrappedProjection.getTypes( alias, criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc) {
|
||||
return wrappedProjection.getColumnAliases( loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return wrappedProjection instanceof EnhancedProjection
|
||||
? ( (EnhancedProjection) wrappedProjection).getColumnAliases( loc, criteria, criteriaQuery )
|
||||
: getColumnAliases( loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc) {
|
||||
return wrappedProjection.getColumnAliases( alias, loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return wrappedProjection instanceof EnhancedProjection
|
||||
? ( (EnhancedProjection) wrappedProjection).getColumnAliases( alias, loc, criteria, criteriaQuery )
|
||||
: getColumnAliases( alias, loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return wrappedProjection.getAliases();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return wrappedProjection.isGrouped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "distinct " + wrappedProjection.toString();
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* An expression asserting that a collection property is empty
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class EmptyExpression extends AbstractEmptinessExpression implements Criterion {
|
||||
/**
|
||||
* Constructs an EmptyExpression
|
||||
*
|
||||
* @param propertyName The collection property name
|
||||
*
|
||||
* @see Restrictions#isEmpty
|
||||
*/
|
||||
protected EmptyExpression(String propertyName) {
|
||||
super( propertyName );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean excludeEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
|
||||
/**
|
||||
* An "enhanced" Projection for a {@link Criteria} query.
|
||||
*
|
||||
* @author Gail Badner
|
||||
* @see Projection
|
||||
* @see Criteria
|
||||
*/
|
||||
public interface EnhancedProjection extends Projection {
|
||||
|
||||
/**
|
||||
* Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
|
||||
* <tt>SELECT</tt> clause ({@link #toSqlString}. Hibernate always uses column aliases to extract data from the
|
||||
* JDBC {@link java.sql.ResultSet}, so it is important that these be implemented correctly in order for
|
||||
* Hibernate to be able to extract these val;ues correctly.
|
||||
*
|
||||
* @param position Just as in {@link #toSqlString}, represents the number of <b>columns</b> rendered
|
||||
* prior to this projection.
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The columns aliases.
|
||||
*/
|
||||
public String[] getColumnAliases(int position, Criteria criteria, CriteriaQuery criteriaQuery);
|
||||
|
||||
/**
|
||||
* Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
|
||||
* <tt>SELECT</tt> clause ({@link #toSqlString} <i>for a particular criteria-level alias</i>.
|
||||
*
|
||||
* @param alias The criteria-level alias
|
||||
* @param position Just as in {@link #toSqlString}, represents the number of <b>columns</b> rendered
|
||||
* prior to this projection.
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The columns aliases pertaining to a particular criteria-level alias; expected to return null if
|
||||
* this projection does not understand this alias.
|
||||
*/
|
||||
public String[] getColumnAliases(String alias, int position, Criteria criteria, CriteriaQuery criteriaQuery);
|
||||
}
|
|
@ -1,484 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Support for query by example.
|
||||
*
|
||||
* <pre>
|
||||
* List results = session.createCriteria(Parent.class)
|
||||
* .add( Example.create(parent).ignoreCase() )
|
||||
* .createCriteria("child")
|
||||
* .add( Example.create( parent.getChild() ) )
|
||||
* .list();
|
||||
* </pre>
|
||||
*
|
||||
* "Examples" may be mixed and matched with "Expressions" in the same Criteria.
|
||||
*
|
||||
* @see org.hibernate.Criteria
|
||||
* @author Gavin King
|
||||
*/
|
||||
|
||||
public class Example implements Criterion {
|
||||
private final Object exampleEntity;
|
||||
private PropertySelector selector;
|
||||
|
||||
private boolean isLikeEnabled;
|
||||
private Character escapeCharacter;
|
||||
private boolean isIgnoreCaseEnabled;
|
||||
private MatchMode matchMode;
|
||||
|
||||
private final Set<String> excludedProperties = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Create a new Example criterion instance, which includes all non-null properties by default
|
||||
*
|
||||
* @param exampleEntity The example bean to use.
|
||||
*
|
||||
* @return a new instance of Example
|
||||
*/
|
||||
public static Example create(Object exampleEntity) {
|
||||
if ( exampleEntity == null ) {
|
||||
throw new NullPointerException( "null example entity" );
|
||||
}
|
||||
return new Example( exampleEntity, NotNullPropertySelector.INSTANCE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow subclasses to instantiate as needed.
|
||||
*
|
||||
* @param exampleEntity The example bean
|
||||
* @param selector The property selector to use
|
||||
*/
|
||||
protected Example(Object exampleEntity, PropertySelector selector) {
|
||||
this.exampleEntity = exampleEntity;
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set escape character for "like" clause if like matching was enabled
|
||||
*
|
||||
* @param escapeCharacter The escape character
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see #enableLike
|
||||
*/
|
||||
public Example setEscapeCharacter(Character escapeCharacter) {
|
||||
this.escapeCharacter = escapeCharacter;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the "like" operator for all string-valued properties. This form implicitly uses {@link MatchMode#EXACT}
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Example enableLike() {
|
||||
return enableLike( MatchMode.EXACT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the "like" operator for all string-valued properties
|
||||
*
|
||||
* @param matchMode The match mode to use.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Example enableLike(MatchMode matchMode) {
|
||||
this.isLikeEnabled = true;
|
||||
this.matchMode = matchMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore case for all string-valued properties
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Example ignoreCase() {
|
||||
this.isIgnoreCaseEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property selector to use.
|
||||
*
|
||||
* The property selector operates separate from excluding a property.
|
||||
*
|
||||
* @param selector The selector to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see #excludeProperty
|
||||
*/
|
||||
public Example setPropertySelector(PropertySelector selector) {
|
||||
this.selector = selector;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude zero-valued properties.
|
||||
*
|
||||
* Equivalent to calling {@link #setPropertySelector} passing in {@link NotNullOrZeroPropertySelector#INSTANCE}
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see #setPropertySelector
|
||||
*/
|
||||
public Example excludeZeroes() {
|
||||
setPropertySelector( NotNullOrZeroPropertySelector.INSTANCE );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include all properties.
|
||||
*
|
||||
* Equivalent to calling {@link #setPropertySelector} passing in {@link AllPropertySelector#INSTANCE}
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see #setPropertySelector
|
||||
*/
|
||||
public Example excludeNone() {
|
||||
setPropertySelector( AllPropertySelector.INSTANCE );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude a particular property by name.
|
||||
*
|
||||
* @param name The name of the property to exclude
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see #setPropertySelector
|
||||
*/
|
||||
public Example excludeProperty(String name) {
|
||||
excludedProperties.add( name );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final StringBuilder buf = new StringBuilder().append( '(' );
|
||||
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
|
||||
criteriaQuery.getEntityName( criteria )
|
||||
);
|
||||
final String[] propertyNames = meta.getPropertyNames();
|
||||
final Type[] propertyTypes = meta.getPropertyTypes();
|
||||
|
||||
final Object[] propertyValues = meta.getPropertyValues( exampleEntity );
|
||||
for ( int i=0; i<propertyNames.length; i++ ) {
|
||||
final Object propertyValue = propertyValues[i];
|
||||
final String propertyName = propertyNames[i];
|
||||
|
||||
final boolean isVersionProperty = i == meta.getVersionProperty();
|
||||
if ( ! isVersionProperty && isPropertyIncluded( propertyValue, propertyName, propertyTypes[i] ) ) {
|
||||
if ( propertyTypes[i].isComponentType() ) {
|
||||
appendComponentCondition(
|
||||
propertyName,
|
||||
propertyValue,
|
||||
(CompositeType) propertyTypes[i],
|
||||
criteria,
|
||||
criteriaQuery,
|
||||
buf
|
||||
);
|
||||
}
|
||||
else {
|
||||
appendPropertyCondition(
|
||||
propertyName,
|
||||
propertyValue,
|
||||
criteria,
|
||||
criteriaQuery,
|
||||
buf
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( buf.length()==1 ) {
|
||||
buf.append( "1=1" );
|
||||
}
|
||||
|
||||
return buf.append( ')' ).toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("SimplifiableIfStatement")
|
||||
private boolean isPropertyIncluded(Object value, String name, Type type) {
|
||||
if ( excludedProperties.contains( name ) ) {
|
||||
// was explicitly excluded
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( type.isAssociationType() ) {
|
||||
// associations are implicitly excluded
|
||||
return false;
|
||||
}
|
||||
|
||||
return selector.include( value, name, type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
|
||||
criteriaQuery.getEntityName( criteria )
|
||||
);
|
||||
final String[] propertyNames = meta.getPropertyNames();
|
||||
final Type[] propertyTypes = meta.getPropertyTypes();
|
||||
|
||||
final Object[] values = meta.getPropertyValues( exampleEntity );
|
||||
final List<TypedValue> list = new ArrayList<TypedValue>();
|
||||
for ( int i=0; i<propertyNames.length; i++ ) {
|
||||
final Object value = values[i];
|
||||
final Type type = propertyTypes[i];
|
||||
final String name = propertyNames[i];
|
||||
|
||||
final boolean isVersionProperty = i == meta.getVersionProperty();
|
||||
|
||||
if ( ! isVersionProperty && isPropertyIncluded( value, name, type ) ) {
|
||||
if ( propertyTypes[i].isComponentType() ) {
|
||||
addComponentTypedValues( name, value, (CompositeType) type, list, criteria, criteriaQuery );
|
||||
}
|
||||
else {
|
||||
addPropertyTypedValue( value, type, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray( new TypedValue[ list.size() ] );
|
||||
}
|
||||
|
||||
protected void addPropertyTypedValue(Object value, Type type, List<TypedValue> list) {
|
||||
if ( value != null ) {
|
||||
if ( value instanceof String ) {
|
||||
String string = (String) value;
|
||||
if ( isIgnoreCaseEnabled ) {
|
||||
string = string.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
if ( isLikeEnabled ) {
|
||||
string = matchMode.toMatchString( string );
|
||||
}
|
||||
value = string;
|
||||
}
|
||||
list.add( new TypedValue( type, value ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected void addComponentTypedValues(
|
||||
String path,
|
||||
Object component,
|
||||
CompositeType type,
|
||||
List<TypedValue> list,
|
||||
Criteria criteria,
|
||||
CriteriaQuery criteriaQuery) {
|
||||
if ( component != null ) {
|
||||
final String[] propertyNames = type.getPropertyNames();
|
||||
final Type[] subtypes = type.getSubtypes();
|
||||
final Object[] values = type.getPropertyValues( component, getEntityMode( criteria, criteriaQuery ) );
|
||||
for ( int i=0; i<propertyNames.length; i++ ) {
|
||||
final Object value = values[i];
|
||||
final Type subtype = subtypes[i];
|
||||
final String subpath = StringHelper.qualify( path, propertyNames[i] );
|
||||
if ( isPropertyIncluded( value, subpath, subtype ) ) {
|
||||
if ( subtype.isComponentType() ) {
|
||||
addComponentTypedValues( subpath, value, (CompositeType) subtype, list, criteria, criteriaQuery );
|
||||
}
|
||||
else {
|
||||
addPropertyTypedValue( value, subtype, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EntityMode getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
|
||||
criteriaQuery.getEntityName( criteria )
|
||||
);
|
||||
final EntityMode result = meta.getEntityMode();
|
||||
if ( ! meta.getEntityMetamodel().getTuplizer().isInstance( exampleEntity ) ) {
|
||||
throw new ClassCastException( exampleEntity.getClass().getName() );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void appendPropertyCondition(
|
||||
String propertyName,
|
||||
Object propertyValue,
|
||||
Criteria criteria,
|
||||
CriteriaQuery cq,
|
||||
StringBuilder buf) {
|
||||
final Criterion condition;
|
||||
if ( propertyValue != null ) {
|
||||
final boolean isString = propertyValue instanceof String;
|
||||
if ( isLikeEnabled && isString ) {
|
||||
condition = new LikeExpression(
|
||||
propertyName,
|
||||
(String) propertyValue,
|
||||
matchMode,
|
||||
escapeCharacter,
|
||||
isIgnoreCaseEnabled
|
||||
);
|
||||
}
|
||||
else {
|
||||
condition = new SimpleExpression( propertyName, propertyValue, "=", isIgnoreCaseEnabled && isString );
|
||||
}
|
||||
}
|
||||
else {
|
||||
condition = new NullExpression(propertyName);
|
||||
}
|
||||
|
||||
final String conditionFragment = condition.toSqlString( criteria, cq );
|
||||
if ( conditionFragment.trim().length() > 0 ) {
|
||||
if ( buf.length() > 1 ) {
|
||||
buf.append( " and " );
|
||||
}
|
||||
buf.append( conditionFragment );
|
||||
}
|
||||
}
|
||||
|
||||
protected void appendComponentCondition(
|
||||
String path,
|
||||
Object component,
|
||||
CompositeType type,
|
||||
Criteria criteria,
|
||||
CriteriaQuery criteriaQuery,
|
||||
StringBuilder buf) {
|
||||
if ( component != null ) {
|
||||
final String[] propertyNames = type.getPropertyNames();
|
||||
final Object[] values = type.getPropertyValues( component, getEntityMode( criteria, criteriaQuery ) );
|
||||
final Type[] subtypes = type.getSubtypes();
|
||||
for ( int i=0; i<propertyNames.length; i++ ) {
|
||||
final String subPath = StringHelper.qualify( path, propertyNames[i] );
|
||||
final Object value = values[i];
|
||||
if ( isPropertyIncluded( value, subPath, subtypes[i] ) ) {
|
||||
final Type subtype = subtypes[i];
|
||||
if ( subtype.isComponentType() ) {
|
||||
appendComponentCondition(
|
||||
subPath,
|
||||
value,
|
||||
(CompositeType) subtype,
|
||||
criteria,
|
||||
criteriaQuery,
|
||||
buf
|
||||
);
|
||||
}
|
||||
else {
|
||||
appendPropertyCondition(
|
||||
subPath,
|
||||
value,
|
||||
criteria,
|
||||
criteriaQuery,
|
||||
buf
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "example (" + exampleEntity + ')';
|
||||
}
|
||||
|
||||
|
||||
// PropertySelector definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* A strategy for choosing property values for inclusion in the query criteria. Note that
|
||||
* property selection (for inclusion) operates separately from excluding a property. Excluded
|
||||
* properties are not even passed in to the PropertySelector for consideration.
|
||||
*/
|
||||
public static interface PropertySelector extends Serializable {
|
||||
/**
|
||||
* Determine whether the given property should be used in the criteria.
|
||||
*
|
||||
* @param propertyValue The property value (from the example bean)
|
||||
* @param propertyName The name of the property
|
||||
* @param type The type of the property
|
||||
*
|
||||
* @return {@code true} indicates the property should be included; {@code false} indiates it should not.
|
||||
*/
|
||||
public boolean include(Object propertyValue, String propertyName, Type type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Property selector that includes all properties
|
||||
*/
|
||||
public static final class AllPropertySelector implements PropertySelector {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final AllPropertySelector INSTANCE = new AllPropertySelector();
|
||||
|
||||
@Override
|
||||
public boolean include(Object object, String propertyName, Type type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property selector that includes only properties that are not {@code null}
|
||||
*/
|
||||
public static final class NotNullPropertySelector implements PropertySelector {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final NotNullPropertySelector INSTANCE = new NotNullPropertySelector();
|
||||
|
||||
@Override
|
||||
public boolean include(Object object, String propertyName, Type type) {
|
||||
return object!=null;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Property selector that includes only properties that are not {@code null} and non-zero (if numeric)
|
||||
*/
|
||||
public static final class NotNullOrZeroPropertySelector implements PropertySelector {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final NotNullOrZeroPropertySelector INSTANCE = new NotNullOrZeroPropertySelector();
|
||||
|
||||
@Override
|
||||
public boolean include(Object object, String propertyName, Type type) {
|
||||
return object != null
|
||||
&& ( !(object instanceof Number) || ( (Number) object ).longValue()!=0
|
||||
);
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
|
||||
/**
|
||||
* Expression that checks the existence of rows in a sub-query
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class ExistsSubqueryExpression extends SubqueryExpression {
|
||||
/**
|
||||
* Constructs the ExistsSubqueryExpression
|
||||
*
|
||||
* @param quantifier The "exists"/"not exists" sub-query quantifier
|
||||
* @param dc The DetachedCriteria representing the sub-query
|
||||
*
|
||||
* @see Subqueries#exists
|
||||
* @see Subqueries#notExists
|
||||
*/
|
||||
protected ExistsSubqueryExpression(String quantifier, DetachedCriteria dc) {
|
||||
super( null, quantifier, dc );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toLeftSqlString(Criteria criteria, CriteriaQuery outerQuery) {
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Factory for Criterion objects. Deprecated!
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @see Restrictions
|
||||
*
|
||||
* @deprecated Use {@link Restrictions} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Expression extends Restrictions {
|
||||
/**
|
||||
* Apply a constraint expressed in SQL, with JDBC parameters. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The sql
|
||||
* @param values The parameter values
|
||||
* @param types The parameter types
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.criterion.Restrictions#sqlRestriction(String, Object[], Type[])}
|
||||
*/
|
||||
@Deprecated
|
||||
public static Criterion sql(String sql, Object[] values, Type[] types) {
|
||||
return new SQLCriterion( sql, values, types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a constraint expressed in SQL, with a JDBC parameter. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The sql
|
||||
* @param value The parameter value
|
||||
* @param type The parameter type
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.criterion.Restrictions#sqlRestriction(String, Object, Type)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static Criterion sql(String sql, Object value, Type type) {
|
||||
return new SQLCriterion( sql, value, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a constraint expressed in SQL with no parameters. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The sql
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @deprecated use {@link org.hibernate.criterion.Restrictions#sqlRestriction(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static Criterion sql(String sql) {
|
||||
return new SQLCriterion( sql );
|
||||
}
|
||||
|
||||
private Expression() {
|
||||
//cannot be instantiated
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* An identifier constraint
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class IdentifierEqExpression implements Criterion {
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Constructs an IdentifierEqExpression
|
||||
*
|
||||
* @param value The identifier value
|
||||
*
|
||||
* @see Restrictions#idEq
|
||||
*/
|
||||
protected IdentifierEqExpression(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final String[] columns = criteriaQuery.getIdentifierColumns( criteria );
|
||||
|
||||
String result = String.join( " and ", StringHelper.suffix( columns, " = ?" ) );
|
||||
if ( columns.length > 1) {
|
||||
result = '(' + result + ')';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return new TypedValue[] { criteriaQuery.getTypedIdentifierValue( criteria, value ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "id = " + value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A property value, or grouped property value
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class IdentifierProjection extends SimpleProjection {
|
||||
private boolean grouped;
|
||||
|
||||
/**
|
||||
* Constructs a non-grouped identifier projection
|
||||
*
|
||||
* @see Projections#id
|
||||
*/
|
||||
protected IdentifierProjection() {
|
||||
this( false );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Not used externally
|
||||
*/
|
||||
private IdentifierProjection(boolean grouped) {
|
||||
this.grouped = grouped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return new Type[] { criteriaQuery.getIdentifierType( criteria ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
final String[] cols = criteriaQuery.getIdentifierColumns( criteria );
|
||||
for ( int i=0; i<cols.length; i++ ) {
|
||||
buf.append( cols[i] )
|
||||
.append( " as y" )
|
||||
.append( position + i )
|
||||
.append( '_' );
|
||||
if ( i < cols.length -1 ) {
|
||||
buf.append( ", " );
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return grouped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
if ( !grouped ) {
|
||||
return super.toGroupSqlString( criteria, criteriaQuery );
|
||||
}
|
||||
else {
|
||||
return String.join( ", ", criteriaQuery.getIdentifierColumns( criteria ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "id";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* A case-insensitive "like".
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Prefer {@link LikeExpression} which now has case-insensitivity capability.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({"deprecation", "UnusedDeclaration"})
|
||||
public class IlikeExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final Object value;
|
||||
|
||||
protected IlikeExpression(String propertyName, Object value) {
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected IlikeExpression(String propertyName, String value, MatchMode matchMode) {
|
||||
this( propertyName, matchMode.toMatchString( value ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final Dialect dialect = criteriaQuery.getFactory().getDialect();
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
if ( columns.length != 1 ) {
|
||||
throw new HibernateException( "ilike may only be used with single-column properties" );
|
||||
}
|
||||
if ( dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) {
|
||||
return columns[0] + " ilike ?";
|
||||
}
|
||||
else {
|
||||
return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return new TypedValue[] {
|
||||
criteriaQuery.getTypedValue(
|
||||
criteria,
|
||||
propertyName,
|
||||
value.toString().toLowerCase(Locale.ROOT)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + " ilike " + value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Constrains the property to a specified list of values
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class InExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final Object[] values;
|
||||
|
||||
/**
|
||||
* Constructs an InExpression
|
||||
*
|
||||
* @param propertyName The property name to check
|
||||
* @param values The values to check against
|
||||
*
|
||||
* @see Restrictions#in(String, java.util.Collection)
|
||||
* @see Restrictions#in(String, Object...)
|
||||
*/
|
||||
protected InExpression(String propertyName, Object[] values) {
|
||||
this.propertyName = propertyName;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString( Criteria criteria, CriteriaQuery criteriaQuery ) {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
if ( criteriaQuery.getFactory().getDialect().supportsRowValueConstructorSyntaxInInList() || columns.length <= 1 ) {
|
||||
String singleValueParam = StringHelper.repeat( "?, ", columns.length - 1 ) + "?";
|
||||
if ( columns.length > 1 ) {
|
||||
singleValueParam = '(' + singleValueParam + ')';
|
||||
}
|
||||
final String params = values.length > 0
|
||||
? StringHelper.repeat( singleValueParam + ", ", values.length - 1 ) + singleValueParam
|
||||
: "";
|
||||
String cols = String.join( ", ", columns );
|
||||
if ( columns.length > 1 ) {
|
||||
cols = '(' + cols + ')';
|
||||
}
|
||||
return cols + " in (" + params + ')';
|
||||
}
|
||||
else {
|
||||
String cols = " ( " + String.join( " = ? and ", columns ) + "= ? ) ";
|
||||
cols = values.length > 0
|
||||
? StringHelper.repeat( cols + "or ", values.length - 1 ) + cols
|
||||
: "";
|
||||
cols = " ( " + cols + " ) ";
|
||||
return cols;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final ArrayList<TypedValue> list = new ArrayList<TypedValue>();
|
||||
final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName );
|
||||
if ( type.isComponentType() ) {
|
||||
final CompositeType compositeType = (CompositeType) type;
|
||||
final Type[] subTypes = compositeType.getSubtypes();
|
||||
for ( Object value : values ) {
|
||||
for ( int i = 0; i < subTypes.length; i++ ) {
|
||||
final Object subValue = value == null
|
||||
? null
|
||||
: compositeType.getPropertyValues( value, EntityMode.POJO )[i];
|
||||
list.add( new TypedValue( subTypes[i], subValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ( Object value : values ) {
|
||||
list.add( criteriaQuery.getTypedValue( criteria, propertyName, value ) );
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray( new TypedValue[ list.size() ] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + " in (" + StringHelper.toString( values ) + ')';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* A sequence of a logical expressions combined by some
|
||||
* associative logical operator
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Junction implements Criterion {
|
||||
private final Nature nature;
|
||||
private final List<Criterion> conditions = new ArrayList<Criterion>();
|
||||
|
||||
protected Junction(Nature nature) {
|
||||
this.nature = nature;
|
||||
}
|
||||
|
||||
protected Junction(Nature nature, Criterion... criterion) {
|
||||
this( nature );
|
||||
Collections.addAll( conditions, criterion );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a criterion to the junction (and/or)
|
||||
*
|
||||
* @param criterion The criterion to add
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Junction add(Criterion criterion) {
|
||||
conditions.add( criterion );
|
||||
return this;
|
||||
}
|
||||
|
||||
public Nature getNature() {
|
||||
return nature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the conditions making up the junction
|
||||
*
|
||||
* @return the criterion
|
||||
*/
|
||||
public Iterable<Criterion> conditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria crit, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final ArrayList<TypedValue> typedValues = new ArrayList<TypedValue>();
|
||||
for ( Criterion condition : conditions ) {
|
||||
final TypedValue[] subValues = condition.getTypedValues( crit, criteriaQuery );
|
||||
Collections.addAll( typedValues, subValues );
|
||||
}
|
||||
return typedValues.toArray( new TypedValue[ typedValues.size() ] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria crit, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
if ( conditions.size()==0 ) {
|
||||
return "1=1";
|
||||
}
|
||||
|
||||
final StringBuilder buffer = new StringBuilder().append( '(' );
|
||||
final Iterator itr = conditions.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
buffer.append( ( (Criterion) itr.next() ).toSqlString( crit, criteriaQuery ) );
|
||||
if ( itr.hasNext() ) {
|
||||
buffer.append( ' ' )
|
||||
.append( nature.getOperator() )
|
||||
.append( ' ' );
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.append( ')' ).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '(' + StringHelper.join( ' ' + nature.getOperator() + ' ', conditions.iterator() ) + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of junction
|
||||
*/
|
||||
public static enum Nature {
|
||||
/**
|
||||
* An AND
|
||||
*/
|
||||
AND,
|
||||
/**
|
||||
* An OR
|
||||
*/
|
||||
OR;
|
||||
|
||||
/**
|
||||
* The corresponding SQL operator
|
||||
*
|
||||
* @return SQL operator
|
||||
*/
|
||||
public String getOperator() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* A criterion representing a "like" expression
|
||||
*
|
||||
* @author Scott Marlow
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class LikeExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final Object value;
|
||||
private final Character escapeChar;
|
||||
private final boolean ignoreCase;
|
||||
|
||||
protected LikeExpression(
|
||||
String propertyName,
|
||||
String value,
|
||||
Character escapeChar,
|
||||
boolean ignoreCase) {
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
this.escapeChar = escapeChar;
|
||||
this.ignoreCase = ignoreCase;
|
||||
}
|
||||
|
||||
protected LikeExpression(String propertyName, String value) {
|
||||
this( propertyName, value, null, false );
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
protected LikeExpression(String propertyName, String value, MatchMode matchMode) {
|
||||
this( propertyName, matchMode.toMatchString( value ) );
|
||||
}
|
||||
|
||||
protected LikeExpression(
|
||||
String propertyName,
|
||||
String value,
|
||||
MatchMode matchMode,
|
||||
Character escapeChar,
|
||||
boolean ignoreCase) {
|
||||
this( propertyName, matchMode.toMatchString( value ), escapeChar, ignoreCase );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria,CriteriaQuery criteriaQuery) {
|
||||
final Dialect dialect = criteriaQuery.getFactory().getDialect();
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
if ( columns.length != 1 ) {
|
||||
throw new HibernateException( "Like may only be used with single-column properties" );
|
||||
}
|
||||
|
||||
final String escape = escapeChar == null ? "" : " escape \'" + escapeChar + "\'";
|
||||
final String column = columns[0];
|
||||
if ( ignoreCase ) {
|
||||
if ( dialect.supportsCaseInsensitiveLike() ) {
|
||||
return column +" " + dialect.getCaseInsensitiveLike() + " ?" + escape;
|
||||
}
|
||||
else {
|
||||
return dialect.getLowercaseFunction() + '(' + column + ')' + " like ?" + escape;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return column + " like ?" + escape;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final String matchValue = ignoreCase ? value.toString().toLowerCase(Locale.ROOT) : value.toString();
|
||||
|
||||
return new TypedValue[] { criteriaQuery.getTypedValue( criteria, propertyName, matchValue ) };
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* Superclass of binary logical expressions
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class LogicalExpression implements Criterion {
|
||||
private final Criterion lhs;
|
||||
private final Criterion rhs;
|
||||
private final String op;
|
||||
|
||||
protected LogicalExpression(Criterion lhs, Criterion rhs, String op) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final TypedValue[] lhsTypedValues = lhs.getTypedValues( criteria, criteriaQuery );
|
||||
final TypedValue[] rhsTypedValues = rhs.getTypedValues( criteria, criteriaQuery );
|
||||
|
||||
final TypedValue[] result = new TypedValue[ lhsTypedValues.length + rhsTypedValues.length ];
|
||||
System.arraycopy( lhsTypedValues, 0, result, 0, lhsTypedValues.length );
|
||||
System.arraycopy( rhsTypedValues, 0, result, lhsTypedValues.length, rhsTypedValues.length );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return '('
|
||||
+ lhs.toSqlString( criteria, criteriaQuery )
|
||||
+ ' '
|
||||
+ getOp()
|
||||
+ ' '
|
||||
+ rhs.toSqlString( criteria, criteriaQuery )
|
||||
+ ')';
|
||||
}
|
||||
|
||||
public String getOp() {
|
||||
return op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return lhs.toString() + ' ' + getOp() + ' ' + rhs.toString();
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* Represents a strategy for matching strings using "like".
|
||||
*
|
||||
* @author Gavin King
|
||||
* @see Example#enableLike(MatchMode)
|
||||
*/
|
||||
public enum MatchMode {
|
||||
|
||||
/**
|
||||
* Match the entire string to the pattern
|
||||
*/
|
||||
EXACT {
|
||||
@Override
|
||||
public String toMatchString(String pattern) {
|
||||
return pattern;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Match the start of the string to the pattern
|
||||
*/
|
||||
START {
|
||||
@Override
|
||||
public String toMatchString(String pattern) {
|
||||
return pattern + '%';
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Match the end of the string to the pattern
|
||||
*/
|
||||
END {
|
||||
@Override
|
||||
public String toMatchString(String pattern) {
|
||||
return '%' + pattern;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Match the pattern anywhere in the string
|
||||
*/
|
||||
ANYWHERE {
|
||||
@Override
|
||||
public String toMatchString(String pattern) {
|
||||
return '%' + pattern + '%';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the pattern, by appending/prepending "%"
|
||||
*
|
||||
* @param pattern The pattern for convert according to the mode
|
||||
*
|
||||
* @return The converted pattern
|
||||
*/
|
||||
public abstract String toMatchString(String pattern);
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* An expression pertaining to an entity's defined natural identifier
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @see org.hibernate.Session#byNaturalId(Class)
|
||||
* @see org.hibernate.Session#byNaturalId(String)
|
||||
* @see org.hibernate.Session#bySimpleNaturalId(Class)
|
||||
* @see org.hibernate.Session#bySimpleNaturalId(String)
|
||||
*/
|
||||
public class NaturalIdentifier implements Criterion {
|
||||
private final Conjunction conjunction = new Conjunction();
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return conjunction.getTypedValues( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return conjunction.toSqlString( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a map of set of the natural identifier values set on this criterion (for composite natural identifiers
|
||||
* this need not be the full set of properties).
|
||||
*
|
||||
* @return The value map.
|
||||
*/
|
||||
public Map<String, Object> getNaturalIdValues() {
|
||||
final Map<String, Object> naturalIdValueMap = new ConcurrentHashMap<String, Object>();
|
||||
for ( Criterion condition : conjunction.conditions() ) {
|
||||
if ( !SimpleExpression.class.isInstance( condition ) ) {
|
||||
continue;
|
||||
}
|
||||
final SimpleExpression equalsCondition = SimpleExpression.class.cast( condition );
|
||||
if ( !"=".equals( equalsCondition.getOp() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
naturalIdValueMap.put( equalsCondition.getPropertyName(), equalsCondition.getValue() );
|
||||
}
|
||||
return naturalIdValueMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a natural identifier value for this expression
|
||||
*
|
||||
* @param property The specific property name
|
||||
* @param value The value to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public NaturalIdentifier set(String property, Object value) {
|
||||
conjunction.add( Restrictions.eq( property, value ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* An expression asserting that a collection property is empty
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class NotEmptyExpression extends AbstractEmptinessExpression implements Criterion {
|
||||
/**
|
||||
* Constructs an EmptyExpression
|
||||
*
|
||||
* @param propertyName The collection property name
|
||||
*
|
||||
* @see Restrictions#isNotEmpty
|
||||
*/
|
||||
protected NotEmptyExpression(String propertyName) {
|
||||
super( propertyName );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean excludeEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* A criterion that is a wrapper for another, negating the wrapped one.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class NotExpression implements Criterion {
|
||||
private Criterion criterion;
|
||||
|
||||
/**
|
||||
* Constructs a NotExpression
|
||||
*
|
||||
* @param criterion The expression to wrap and negate
|
||||
*
|
||||
* @see Restrictions#not
|
||||
*/
|
||||
protected NotExpression(Criterion criterion) {
|
||||
this.criterion = criterion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return criteriaQuery.getFactory().getDialect().getNotExpression(
|
||||
criterion.toSqlString( criteria, criteriaQuery )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return criterion.getTypedValues( criteria, criteriaQuery );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "not " + criterion.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Constrains a property to be non-null
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class NotNullExpression implements Criterion {
|
||||
private static final TypedValue[] NO_VALUES = new TypedValue[0];
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
protected NotNullExpression(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
String result = String.join(
|
||||
" or ",
|
||||
StringHelper.suffix( columns, " is not null" )
|
||||
);
|
||||
if ( columns.length > 1 ) {
|
||||
result = '(' + result + ')';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return NO_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + " is not null";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Constrains a property to be null
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class NullExpression implements Criterion {
|
||||
private static final TypedValue[] NO_VALUES = new TypedValue[0];
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
/**
|
||||
* Constructs a NullExpression
|
||||
*
|
||||
* @param propertyName The name of the property to check for null
|
||||
*
|
||||
* @see Restrictions#isNull
|
||||
*/
|
||||
protected NullExpression(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
String result = String.join(
|
||||
" and ",
|
||||
StringHelper.suffix( columns, " is null" )
|
||||
);
|
||||
if ( columns.length > 1 ) {
|
||||
result = '(' + result + ')';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return NO_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + " is null";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Types;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.NullPrecedence;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Represents an ordering imposed upon the results of a Criteria
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class Order implements Serializable {
|
||||
private boolean ascending;
|
||||
private boolean ignoreCase;
|
||||
private String propertyName;
|
||||
private NullPrecedence nullPrecedence;
|
||||
|
||||
/**
|
||||
* Ascending order
|
||||
*
|
||||
* @param propertyName The property to order on
|
||||
*
|
||||
* @return The build Order instance
|
||||
*/
|
||||
public static Order asc(String propertyName) {
|
||||
return new Order( propertyName, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Descending order.
|
||||
*
|
||||
* @param propertyName The property to order on
|
||||
*
|
||||
* @return The build Order instance
|
||||
*/
|
||||
public static Order desc(String propertyName) {
|
||||
return new Order( propertyName, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Order. Order instances are generally created by factory methods.
|
||||
*
|
||||
* @see #asc
|
||||
* @see #desc
|
||||
*/
|
||||
protected Order(String propertyName, boolean ascending) {
|
||||
this.propertyName = propertyName;
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should this ordering ignore case? Has no effect on non-character properties.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Order ignoreCase() {
|
||||
ignoreCase = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines precedence for nulls.
|
||||
*
|
||||
* @param nullPrecedence The null precedence to use
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public Order nulls(NullPrecedence nullPrecedence) {
|
||||
this.nullPrecedence = nullPrecedence;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public boolean isAscending() {
|
||||
return ascending;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public boolean isIgnoreCase() {
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the SQL fragment
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param criteriaQuery The overall query
|
||||
*
|
||||
* @return The ORDER BY fragment for this ordering
|
||||
*/
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, propertyName );
|
||||
final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName );
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final int[] sqlTypes = type.sqlTypes( factory );
|
||||
|
||||
final StringBuilder fragment = new StringBuilder();
|
||||
for ( int i=0; i<columns.length; i++ ) {
|
||||
final StringBuilder expression = new StringBuilder();
|
||||
boolean lower = false;
|
||||
if ( ignoreCase ) {
|
||||
final int sqlType = sqlTypes[i];
|
||||
lower = sqlType == Types.VARCHAR
|
||||
|| sqlType == Types.CHAR
|
||||
|| sqlType == Types.LONGVARCHAR;
|
||||
}
|
||||
|
||||
if ( lower ) {
|
||||
expression.append( factory.getDialect().getLowercaseFunction() )
|
||||
.append( '(' );
|
||||
}
|
||||
expression.append( columns[i] );
|
||||
if ( lower ) {
|
||||
expression.append( ')' );
|
||||
}
|
||||
|
||||
fragment.append(
|
||||
factory.getDialect().renderOrderByElement(
|
||||
expression.toString(),
|
||||
null,
|
||||
ascending ? "asc" : "desc",
|
||||
nullPrecedence != null ? nullPrecedence : factory.getSettings().getDefaultNullPrecedence()
|
||||
)
|
||||
);
|
||||
if ( i < columns.length-1 ) {
|
||||
fragment.append( ", " );
|
||||
}
|
||||
}
|
||||
|
||||
return fragment.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + ' '
|
||||
+ ( ascending ? "asc" : "desc" )
|
||||
+ ( nullPrecedence != null ? ' ' + nullPrecedence.name().toLowerCase(Locale.ROOT) : "" );
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ParameterInfoCollector {
|
||||
void addNamedParameter(String name, Type type);
|
||||
void addPositionalParameter(int label, Type type);
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* An object-oriented representation of a query result set projection in a {@link Criteria} query.
|
||||
* Built-in projection types are provided by the {@link Projections} factory class. This interface might be
|
||||
* implemented by application classes that define custom projections.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see Projections
|
||||
* @see Criteria
|
||||
*/
|
||||
public interface Projection extends Serializable {
|
||||
|
||||
/**
|
||||
* Render the SQL fragment to be used in the <tt>SELECT</tt> clause.
|
||||
*
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param position The number of columns rendered in the <tt>SELECT</tt> clause before this projection. Generally
|
||||
* speaking this is useful to ensure uniqueness of the individual columns aliases.
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The SQL fragment to plug into the <tt>SELECT</tt>
|
||||
* @throws HibernateException Indicates a problem performing the rendering
|
||||
*/
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Render the SQL fragment to be used in the <tt>GROUP BY</tt> clause
|
||||
*
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The SQL fragment to plug into the <tt>GROUP BY</tt>
|
||||
* @throws HibernateException Indicates a problem performing the rendering
|
||||
*/
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Types returned by the rendered SQL {@link #toSqlString fragment}. In other words what are the types
|
||||
* that would represent the values this projection asked to be pulled into the result set?
|
||||
*
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The return types.
|
||||
* @throws HibernateException Indicates a problem resolving the types
|
||||
*/
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the return types for a particular user-visible alias.
|
||||
* <p/>
|
||||
* Differs from {@link #getTypes(org.hibernate.Criteria, CriteriaQuery)} in that here we are only interested in
|
||||
* the types related to the given criteria-level alias.
|
||||
*
|
||||
* @param alias The criteria-level alias for which to find types.
|
||||
* @param criteria The local criteria to which this project is attached (for resolution).
|
||||
* @param criteriaQuery The overall criteria query instance.
|
||||
* @return The return types; expected to return null if this projection does not understand this alias.
|
||||
* @throws HibernateException Indicates a problem resolving the types
|
||||
*/
|
||||
public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException;
|
||||
|
||||
|
||||
/**
|
||||
* Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
|
||||
* <tt>SELECT</tt> clause ({@link #toSqlString}. Hibernate always uses column aliases to extract data from the
|
||||
* JDBC {@link java.sql.ResultSet}, so it is important that these be implemented correctly in order for
|
||||
* Hibernate to be able to extract these val;ues correctly.
|
||||
*
|
||||
* @param position Just as in {@link #toSqlString}, represents the number of <b>columns</b> rendered
|
||||
* prior to this projection.
|
||||
* @return The columns aliases.
|
||||
*/
|
||||
public String[] getColumnAliases(int position);
|
||||
|
||||
/**
|
||||
* Get the SQL column aliases used by this projection for the columns it writes for inclusion into the
|
||||
* <tt>SELECT</tt> clause ({@link #toSqlString} <i>for a particular criteria-level alias</i>.
|
||||
*
|
||||
* @param alias The criteria-level alias
|
||||
* @param position Just as in {@link #toSqlString}, represents the number of <b>columns</b> rendered
|
||||
* prior to this projection.
|
||||
* @return The columns aliases pertaining to a particular criteria-level alias; expected to return null if
|
||||
* this projection does not understand this alias.
|
||||
*/
|
||||
public String[] getColumnAliases(String alias, int position);
|
||||
|
||||
/**
|
||||
* Get the criteria-level aliases for this projection (ie. the ones that will be passed to the
|
||||
* {@link org.hibernate.transform.ResultTransformer})
|
||||
*
|
||||
* @return The aliases
|
||||
*/
|
||||
public String[] getAliases();
|
||||
|
||||
/**
|
||||
* Is this projection fragment (<tt>SELECT</tt> clause) also part of the <tt>GROUP BY</tt>
|
||||
*
|
||||
* @return True if the projection is also part of the <tt>GROUP BY</tt>; false otherwise.
|
||||
*/
|
||||
public boolean isGrouped();
|
||||
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A projection that wraps other projections to allow selecting multiple values.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class ProjectionList implements EnhancedProjection {
|
||||
private List<Projection> elements = new ArrayList<Projection>();
|
||||
|
||||
/**
|
||||
* Constructs a ProjectionList
|
||||
*
|
||||
* @see Projections#projectionList()
|
||||
*/
|
||||
protected ProjectionList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lol
|
||||
*
|
||||
* @return duh
|
||||
*
|
||||
* @deprecated an instance factory method does not make sense
|
||||
*
|
||||
* @see Projections#projectionList()
|
||||
*/
|
||||
@Deprecated
|
||||
public ProjectionList create() {
|
||||
return new ProjectionList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a projection to this list of projections
|
||||
*
|
||||
* @param projection The projection to add
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public ProjectionList add(Projection projection) {
|
||||
elements.add( projection );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a projection to this list of projections after wrapping it with an alias
|
||||
*
|
||||
* @param projection The projection to add
|
||||
* @param alias The alias to apply to the projection
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see Projections#alias
|
||||
*/
|
||||
public ProjectionList add(Projection projection, String alias) {
|
||||
return add( Projections.alias( projection, alias ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
for ( Projection projection : elements ) {
|
||||
if ( projection.isGrouped() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final List<Type> types = new ArrayList<Type>( getLength() );
|
||||
for ( Projection projection : elements ) {
|
||||
final Type[] elemTypes = projection.getTypes( criteria, criteriaQuery );
|
||||
Collections.addAll( types, elemTypes );
|
||||
}
|
||||
return types.toArray( new Type[types.size()] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
String separator = "";
|
||||
|
||||
for ( Projection projection : elements ) {
|
||||
buf.append( separator ).append( projection.toSqlString( criteria, loc, criteriaQuery ) );
|
||||
loc += getColumnAliases( loc, criteria, criteriaQuery, projection ).length;
|
||||
separator = ", ";
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
String separator = "";
|
||||
for ( Projection projection : elements ) {
|
||||
if ( ! projection.isGrouped() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf.append( separator ).append( projection.toGroupSqlString( criteria, criteriaQuery ) );
|
||||
separator = ", ";
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(final int loc) {
|
||||
int position = loc;
|
||||
final List<String> result = new ArrayList<String>( getLength() );
|
||||
for ( Projection projection : elements ) {
|
||||
final String[] aliases = projection.getColumnAliases( position );
|
||||
Collections.addAll( result, aliases );
|
||||
position += aliases.length;
|
||||
}
|
||||
return result.toArray( new String[ result.size() ] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(final int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
int position = loc;
|
||||
final List<String> result = new ArrayList<String>( getLength() );
|
||||
for ( Projection projection : elements ) {
|
||||
final String[] aliases = getColumnAliases( position, criteria, criteriaQuery, projection );
|
||||
Collections.addAll( result, aliases );
|
||||
position += aliases.length;
|
||||
}
|
||||
return result.toArray( new String[result.size()] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, final int loc) {
|
||||
int position = loc;
|
||||
for ( Projection projection : elements ) {
|
||||
final String[] aliases = projection.getColumnAliases( alias, position );
|
||||
if ( aliases != null ) {
|
||||
return aliases;
|
||||
}
|
||||
position += projection.getColumnAliases( position ).length;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
int position = loc;
|
||||
for ( Projection projection : elements ) {
|
||||
final String[] aliases = getColumnAliases( alias, position, criteria, criteriaQuery, projection );
|
||||
if ( aliases != null ) {
|
||||
return aliases;
|
||||
}
|
||||
position += getColumnAliases( position, criteria, criteriaQuery, projection ).length;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String[] getColumnAliases(int loc, Criteria criteria, CriteriaQuery criteriaQuery, Projection projection) {
|
||||
return projection instanceof EnhancedProjection
|
||||
? ( (EnhancedProjection) projection ).getColumnAliases( loc, criteria, criteriaQuery )
|
||||
: projection.getColumnAliases( loc );
|
||||
}
|
||||
|
||||
private static String[] getColumnAliases(String alias, int loc, Criteria criteria, CriteriaQuery criteriaQuery, Projection projection) {
|
||||
return projection instanceof EnhancedProjection
|
||||
? ( (EnhancedProjection) projection ).getColumnAliases( alias, loc, criteria, criteriaQuery )
|
||||
: projection.getColumnAliases( alias, loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
for ( Projection projection : elements ) {
|
||||
final Type[] types = projection.getTypes( alias, criteria, criteriaQuery );
|
||||
if ( types != null ) {
|
||||
return types;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
final List<String> result = new ArrayList<String>( getLength() );
|
||||
for ( Projection projection : elements ) {
|
||||
final String[] aliases = projection.getAliases();
|
||||
Collections.addAll( result, aliases );
|
||||
}
|
||||
return result.toArray( new String[result.size()] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Access a wrapped projection by index
|
||||
*
|
||||
* @param i The index of the projection to return
|
||||
*
|
||||
* @return The projection
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Projection getProjection(int i) {
|
||||
return elements.get( i );
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return elements.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* The <tt>criterion</tt> package may be used by applications as a framework for building
|
||||
* new kinds of <tt>Projection</tt>. However, it is intended that most applications will
|
||||
* simply use the built-in projection types via the static factory methods of this class.
|
||||
*
|
||||
* The factory methods that take an alias allow the projected value to be referred to by
|
||||
* criterion and order instances.
|
||||
*
|
||||
* See also the {@link Restrictions} factory methods for generating {@link Criterion} instances
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see org.hibernate.Criteria
|
||||
*/
|
||||
public final class Projections {
|
||||
/**
|
||||
* A property value projection
|
||||
*
|
||||
* @param propertyName The name of the property whose values should be projected
|
||||
*
|
||||
* @return The property projection
|
||||
*
|
||||
* @see PropertyProjection
|
||||
*/
|
||||
public static PropertyProjection property(String propertyName) {
|
||||
return new PropertyProjection( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* A grouping property value projection
|
||||
*
|
||||
* @param propertyName The name of the property to group
|
||||
*
|
||||
* @return The grouped projection
|
||||
*
|
||||
* @see PropertyProjection
|
||||
*/
|
||||
public static PropertyProjection groupProperty(String propertyName) {
|
||||
return new PropertyProjection( propertyName, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* An identifier value projection.
|
||||
*
|
||||
* @return The identifier projection
|
||||
*
|
||||
* @see IdentifierProjection
|
||||
*/
|
||||
public static IdentifierProjection id() {
|
||||
return new IdentifierProjection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a distinct projection from a projection.
|
||||
*
|
||||
* @param projection The project to treat distinctly
|
||||
*
|
||||
* @return The distinct projection
|
||||
*
|
||||
* @see Distinct
|
||||
*/
|
||||
public static Projection distinct(Projection projection) {
|
||||
return new Distinct( projection );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new projection list.
|
||||
*
|
||||
* @return The projection list
|
||||
*/
|
||||
public static ProjectionList projectionList() {
|
||||
return new ProjectionList();
|
||||
}
|
||||
|
||||
/**
|
||||
* The query row count, ie. <tt>count(*)</tt>
|
||||
*
|
||||
* @return The projection representing the row count
|
||||
*
|
||||
* @see RowCountProjection
|
||||
*/
|
||||
public static Projection rowCount() {
|
||||
return new RowCountProjection();
|
||||
}
|
||||
|
||||
/**
|
||||
* A property value count projection
|
||||
*
|
||||
* @param propertyName The name of the property to count over
|
||||
*
|
||||
* @return The count projection
|
||||
*
|
||||
* @see CountProjection
|
||||
*/
|
||||
public static CountProjection count(String propertyName) {
|
||||
return new CountProjection( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* A distinct property value count projection
|
||||
*
|
||||
* @param propertyName The name of the property to count over
|
||||
*
|
||||
* @return The count projection
|
||||
*
|
||||
* @see CountProjection
|
||||
*/
|
||||
public static CountProjection countDistinct(String propertyName) {
|
||||
return new CountProjection( propertyName ).setDistinct();
|
||||
}
|
||||
|
||||
/**
|
||||
* A property maximum value projection
|
||||
*
|
||||
* @param propertyName The property for which to find the max
|
||||
*
|
||||
* @return the max projection
|
||||
*
|
||||
* @see AggregateProjection
|
||||
*/
|
||||
public static AggregateProjection max(String propertyName) {
|
||||
return new AggregateProjection( "max", propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* A property minimum value projection
|
||||
*
|
||||
* @param propertyName The property for which to find the min
|
||||
*
|
||||
* @return the min projection
|
||||
*
|
||||
* @see AggregateProjection
|
||||
*/
|
||||
public static AggregateProjection min(String propertyName) {
|
||||
return new AggregateProjection( "min", propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* A property average value projection
|
||||
*
|
||||
* @param propertyName The property over which to find the average
|
||||
*
|
||||
* @return the avg projection
|
||||
*
|
||||
* @see AvgProjection
|
||||
*/
|
||||
public static AggregateProjection avg(String propertyName) {
|
||||
return new AvgProjection( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* A property value sum projection
|
||||
*
|
||||
* @param propertyName The property over which to sum
|
||||
*
|
||||
* @return the sum projection
|
||||
*
|
||||
* @see AggregateProjection
|
||||
*/
|
||||
public static AggregateProjection sum(String propertyName) {
|
||||
return new AggregateProjection( "sum", propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign an alias to a projection, by wrapping it
|
||||
*
|
||||
* @param projection The projection to be aliased
|
||||
* @param alias The alias to apply
|
||||
*
|
||||
* @return The aliased projection
|
||||
*
|
||||
* @see AliasedProjection
|
||||
*/
|
||||
public static Projection alias(Projection projection, String alias) {
|
||||
return new AliasedProjection( projection, alias );
|
||||
}
|
||||
|
||||
/**
|
||||
* A SQL projection, a typed select clause fragment
|
||||
*
|
||||
* @param sql The SQL fragment
|
||||
* @param columnAliases The column aliases
|
||||
* @param types The resulting types
|
||||
*
|
||||
* @return The SQL projection
|
||||
*
|
||||
* @see SQLProjection
|
||||
*/
|
||||
public static Projection sqlProjection(String sql, String[] columnAliases, Type[] types) {
|
||||
return new SQLProjection( sql, columnAliases, types );
|
||||
}
|
||||
|
||||
/**
|
||||
* A grouping SQL projection, specifying both select clause and group by clause fragments
|
||||
*
|
||||
* @param sql The SQL SELECT fragment
|
||||
* @param groupBy The SQL GROUP BY fragment
|
||||
* @param columnAliases The column aliases
|
||||
* @param types The resulting types
|
||||
*
|
||||
* @return The SQL projection
|
||||
*
|
||||
* @see SQLProjection
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Projection sqlGroupProjection(String sql, String groupBy, String[] columnAliases, Type[] types) {
|
||||
return new SQLProjection(sql, groupBy, columnAliases, types);
|
||||
}
|
||||
|
||||
private Projections() {
|
||||
//cannot be instantiated
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
|
||||
/**
|
||||
* A comparison between several properties value in the outer query and the result of a multicolumn subquery.
|
||||
*
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class PropertiesSubqueryExpression extends SubqueryExpression {
|
||||
private final String[] propertyNames;
|
||||
|
||||
protected PropertiesSubqueryExpression(String[] propertyNames, String op, DetachedCriteria dc) {
|
||||
super( op, null, dc );
|
||||
this.propertyNames = propertyNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toLeftSqlString(Criteria criteria, CriteriaQuery outerQuery) {
|
||||
final StringBuilder left = new StringBuilder( "(" );
|
||||
final String[] sqlColumnNames = new String[propertyNames.length];
|
||||
for ( int i = 0; i < sqlColumnNames.length; ++i ) {
|
||||
sqlColumnNames[i] = outerQuery.getColumn( criteria, propertyNames[i] );
|
||||
}
|
||||
left.append( String.join( ", ", sqlColumnNames ) );
|
||||
return left.append( ")" ).toString();
|
||||
}
|
||||
}
|
|
@ -1,741 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A factory for property-specific criterion and projection instances
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Property extends PropertyProjection {
|
||||
/**
|
||||
* Factory for Property instances.
|
||||
*
|
||||
* @param propertyName The name of the property.
|
||||
*
|
||||
* @return The Property instance
|
||||
*/
|
||||
public static Property forName(String propertyName) {
|
||||
return new Property( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Property. non-private to allow subclassing.
|
||||
*
|
||||
* @param propertyName The property name.
|
||||
*/
|
||||
protected Property(String propertyName) {
|
||||
super( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BETWEEN restriction for this property between the given min and max
|
||||
*
|
||||
* @param min The minimum
|
||||
* @param max The maximum
|
||||
*
|
||||
* @return The BETWEEN restriction
|
||||
*
|
||||
* @see Restrictions#between(String, Object, Object)
|
||||
*/
|
||||
public Criterion between(Object min, Object max) {
|
||||
return Restrictions.between( getPropertyName(), min, max );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an IN restriction for this property based on the given list of literals
|
||||
*
|
||||
* @param values The literal values
|
||||
*
|
||||
* @return The IN restriction
|
||||
*
|
||||
* @see Restrictions#in(String, Collection)
|
||||
*/
|
||||
public Criterion in(Collection values) {
|
||||
return Restrictions.in( getPropertyName(), values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an IN restriction for this property based on the given list of literals
|
||||
*
|
||||
* @param values The literal values
|
||||
*
|
||||
* @return The IN restriction
|
||||
*
|
||||
* @see Restrictions#in(String, Object[])
|
||||
*/
|
||||
public Criterion in(Object... values) {
|
||||
return Restrictions.in( getPropertyName(), values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LIKE restriction for this property
|
||||
*
|
||||
* @param value The value to like compare with
|
||||
*
|
||||
* @return The LIKE restriction
|
||||
*
|
||||
* @see Restrictions#like(String, Object)
|
||||
*/
|
||||
public SimpleExpression like(Object value) {
|
||||
return Restrictions.like( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LIKE restriction for this property
|
||||
*
|
||||
* @param value The value to like compare with
|
||||
* @param matchMode The match mode to apply to the LIKE
|
||||
*
|
||||
* @return The LIKE restriction
|
||||
*
|
||||
* @see Restrictions#like(String, String, MatchMode)
|
||||
*/
|
||||
public SimpleExpression like(String value, MatchMode matchMode) {
|
||||
return Restrictions.like( getPropertyName(), value, matchMode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an equality restriction.
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The equality restriction.
|
||||
*
|
||||
* @see Restrictions#eq(String, Object)
|
||||
*/
|
||||
public SimpleExpression eq(Object value) {
|
||||
return Restrictions.eq( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an equality restriction capable of also rendering as IS NULL if the given value is {@code null}
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The equality restriction.
|
||||
*
|
||||
* @see Restrictions#eqOrIsNull(String, Object)
|
||||
* @see #eq
|
||||
* @see #isNull
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion eqOrIsNull(Object value) {
|
||||
return Restrictions.eqOrIsNull( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-equality restriction.
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The non-equality restriction.
|
||||
*
|
||||
* @see Restrictions#ne(String, Object)
|
||||
*/
|
||||
public SimpleExpression ne(Object value) {
|
||||
return Restrictions.ne( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-equality restriction capable of also rendering as IS NOT NULL if the given value is {@code null}
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The non-equality restriction.
|
||||
*
|
||||
* @see Restrictions#neOrIsNotNull(String, Object)
|
||||
* @see #ne
|
||||
* @see #isNotNull
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion neOrIsNotNull(Object value) {
|
||||
return Restrictions.neOrIsNotNull( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a greater-than restriction based on this property
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The greater-than restriction
|
||||
*
|
||||
* @see Restrictions#gt(String, Object)
|
||||
*/
|
||||
public SimpleExpression gt(Object value) {
|
||||
return Restrictions.gt( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a less-than restriction based on this property
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The less-than restriction
|
||||
*
|
||||
* @see Restrictions#lt(String, Object)
|
||||
*/
|
||||
public SimpleExpression lt(Object value) {
|
||||
return Restrictions.lt( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a less-than-or-equal-to restriction based on this property
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The less-than-or-equal-to restriction
|
||||
*
|
||||
* @see Restrictions#le(String, Object)
|
||||
*/
|
||||
public SimpleExpression le(Object value) {
|
||||
return Restrictions.le( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a greater-than-or-equal-to restriction based on this property
|
||||
*
|
||||
* @param value The value to check against
|
||||
*
|
||||
* @return The greater-than-or-equal-to restriction
|
||||
*
|
||||
* @see Restrictions#ge(String, Object)
|
||||
*/
|
||||
public SimpleExpression ge(Object value) {
|
||||
return Restrictions.ge( getPropertyName(), value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an equality restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#eqProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression eqProperty(Property other) {
|
||||
return Restrictions.eqProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an equality restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#eqProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression eqProperty(String other) {
|
||||
return Restrictions.eqProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-equality restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#neProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression neProperty(Property other) {
|
||||
return Restrictions.neProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-equality restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#neProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression neProperty(String other) {
|
||||
return Restrictions.neProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-or-equal-to restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#leProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression leProperty(Property other) {
|
||||
return Restrictions.leProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-or-equal-to restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#leProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression leProperty(String other) {
|
||||
return Restrictions.leProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-or-equal-to restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#geProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression geProperty(Property other) {
|
||||
return Restrictions.geProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-or-equal-to restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#geProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression geProperty(String other) {
|
||||
return Restrictions.geProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#ltProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression ltProperty(Property other) {
|
||||
return Restrictions.ltProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#ltProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression ltProperty(String other) {
|
||||
return Restrictions.ltProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#geProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression gtProperty(Property other) {
|
||||
return Restrictions.gtProperty( getPropertyName(), other.getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than restriction between 2 properties
|
||||
*
|
||||
* @param other The other property to compare against
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#geProperty(String, String)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public PropertyExpression gtProperty(String other) {
|
||||
return Restrictions.gtProperty( getPropertyName(), other );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a NULL restriction
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#isNull(String)
|
||||
*/
|
||||
public Criterion isNull() {
|
||||
return Restrictions.isNull( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a NOT NULL restriction
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#isNotNull(String)
|
||||
*/
|
||||
public Criterion isNotNull() {
|
||||
return Restrictions.isNotNull( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a restriction to check that a collection is empty
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#isEmpty(String)
|
||||
*/
|
||||
public Criterion isEmpty() {
|
||||
return Restrictions.isEmpty( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a restriction to check that a collection is not empty
|
||||
*
|
||||
* @return The restriction
|
||||
*
|
||||
* @see Restrictions#isNotEmpty(String)
|
||||
*/
|
||||
public Criterion isNotEmpty() {
|
||||
return Restrictions.isNotEmpty( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property count projection
|
||||
*
|
||||
* @return The projection
|
||||
*
|
||||
* @see Projections#count
|
||||
*/
|
||||
public CountProjection count() {
|
||||
return Projections.count( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property max projection
|
||||
*
|
||||
* @return The projection
|
||||
*
|
||||
* @see Projections#max
|
||||
*/
|
||||
public AggregateProjection max() {
|
||||
return Projections.max( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property min projection
|
||||
*
|
||||
* @return The projection
|
||||
*
|
||||
* @see Projections#min
|
||||
*/
|
||||
public AggregateProjection min() {
|
||||
return Projections.min( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property avg projection
|
||||
*
|
||||
* @return The projection
|
||||
*
|
||||
* @see Projections#avg
|
||||
*/
|
||||
public AggregateProjection avg() {
|
||||
return Projections.avg( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a projection for this property as a group expression
|
||||
*
|
||||
* @return The group projection
|
||||
*
|
||||
* @see Projections#groupProperty
|
||||
*/
|
||||
public PropertyProjection group() {
|
||||
return Projections.groupProperty( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ascending ordering for this property
|
||||
*
|
||||
* @return The order
|
||||
*/
|
||||
public Order asc() {
|
||||
return Order.asc( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a descending ordering for this property
|
||||
*
|
||||
* @return The order
|
||||
*/
|
||||
public Order desc() {
|
||||
return Order.desc( getPropertyName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a component attribute of this property.
|
||||
*
|
||||
* @param propertyName The sub property name
|
||||
*
|
||||
* @return The property
|
||||
*/
|
||||
public Property getProperty(String propertyName) {
|
||||
return forName( getPropertyName() + '.' + propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query equality expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyEq(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion eq(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyEq( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query non-equality expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyNe(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion ne(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyNe( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query less-than expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLt(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion lt(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLt( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query less-than-or-equal-to expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLe(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion le(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLe( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query greater-than expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGt(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion gt(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGt( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query greater-than-or-equal-to expression for this property
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGe(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion ge(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGe( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query NOT IN expression for this property. I.e., {@code [prop] NOT IN [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyNotIn(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion notIn(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyNotIn( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub-query IN expression for this property. I.e., {@code [prop] IN [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyIn(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion in(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyIn( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a equals-all sub-query expression for this property. I.e., {@code [prop] = ALL [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyEqAll(String, DetachedCriteria)
|
||||
*/
|
||||
public Criterion eqAll(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyEqAll( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-all sub-query expression for this property. I.e., {@code [prop] > ALL [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGtAll(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion gtAll(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGtAll( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-all sub-query expression for this property. I.e., {@code [prop] < ALL [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLtAll(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion ltAll(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLtAll( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-or-equal-to-all sub-query expression for this property. I.e., {@code [prop] <= ALL [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLeAll(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion leAll(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLeAll( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-or-equal-to-all sub-query expression for this property. I.e., {@code [prop] >= ALL [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGeAll(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion geAll(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGeAll( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-some sub-query expression for this property. I.e., {@code [prop] > SOME [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGtSome(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion gtSome(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGtSome( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-some sub-query expression for this property. I.e., {@code [prop] < SOME [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLtSome(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion ltSome(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLtSome( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a less-than-or-equal-to-some sub-query expression for this property. I.e., {@code [prop] <= SOME [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyLeSome(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion leSome(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyLeSome( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a greater-than-or-equal-to-some sub-query expression for this property. I.e., {@code [prop] >= SOME [subquery]}
|
||||
*
|
||||
* @param subselect The sub-query
|
||||
*
|
||||
* @return The expression
|
||||
*
|
||||
* @see Subqueries#propertyGeSome(String, DetachedCriteria)
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public Criterion geSome(DetachedCriteria subselect) {
|
||||
return Subqueries.propertyGeSome( getPropertyName(), subselect );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* superclass for comparisons between two properties (with SQL binary operators)
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PropertyExpression implements Criterion {
|
||||
private static final TypedValue[] NO_TYPED_VALUES = new TypedValue[0];
|
||||
|
||||
private final String propertyName;
|
||||
private final String otherPropertyName;
|
||||
private final String op;
|
||||
|
||||
protected PropertyExpression(String propertyName, String otherPropertyName, String op) {
|
||||
this.propertyName = propertyName;
|
||||
this.otherPropertyName = otherPropertyName;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public String getOp() {
|
||||
return op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] lhsColumns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
final String[] rhsColumns = criteriaQuery.findColumns( otherPropertyName, criteria );
|
||||
|
||||
final String[] comparisons = StringHelper.add( lhsColumns, getOp(), rhsColumns );
|
||||
if ( comparisons.length > 1 ) {
|
||||
return '(' + String.join( " and ", comparisons ) + ')';
|
||||
}
|
||||
else {
|
||||
return comparisons[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return NO_TYPED_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + getOp() + otherPropertyName;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A property value, or grouped property value
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PropertyProjection extends SimpleProjection {
|
||||
private String propertyName;
|
||||
private boolean grouped;
|
||||
|
||||
protected PropertyProjection(String prop, boolean grouped) {
|
||||
this.propertyName = prop;
|
||||
this.grouped = grouped;
|
||||
}
|
||||
|
||||
protected PropertyProjection(String prop) {
|
||||
this( prop, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return grouped;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new Type[] { criteriaQuery.getType( criteria, propertyName ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
final String[] cols = criteriaQuery.getColumns( propertyName, criteria );
|
||||
for ( int i=0; i<cols.length; i++ ) {
|
||||
buf.append( cols[i] )
|
||||
.append( " as y" )
|
||||
.append( position + i )
|
||||
.append( '_' );
|
||||
if (i < cols.length -1) {
|
||||
buf.append( ", " );
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
if ( !grouped ) {
|
||||
return super.toGroupSqlString( criteria, criteriaQuery );
|
||||
}
|
||||
else {
|
||||
return String.join( ", ", criteriaQuery.getColumns( propertyName, criteria ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
|
||||
/**
|
||||
* A comparison between a property value in the outer query and the result of a subquery
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PropertySubqueryExpression extends SubqueryExpression {
|
||||
private String propertyName;
|
||||
|
||||
protected PropertySubqueryExpression(String propertyName, String op, String quantifier, DetachedCriteria dc) {
|
||||
super( op, quantifier, dc );
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toLeftSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return criteriaQuery.getColumn( criteria, propertyName );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,680 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* The <tt>criterion</tt> package may be used by applications as a framework for building
|
||||
* new kinds of <tt>Criterion</tt>. However, it is intended that most applications will
|
||||
* simply use the built-in criterion types via the static factory methods of this class.
|
||||
*
|
||||
* See also the {@link Projections} factory methods for generating {@link Projection} instances
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see org.hibernate.Criteria
|
||||
*/
|
||||
public class Restrictions {
|
||||
/**
|
||||
* Apply an "equal" constraint to the identifier property
|
||||
*
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @see IdentifierEqExpression
|
||||
*/
|
||||
public static Criterion idEq(Object value) {
|
||||
return new IdentifierEqExpression( value );
|
||||
}
|
||||
/**
|
||||
* Apply an "equal" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return SimpleExpression
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression eq(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, "=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to the named property. If the value
|
||||
* is null, instead apply "is null".
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see #eq
|
||||
* @see #isNull
|
||||
*/
|
||||
public static Criterion eqOrIsNull(String propertyName, Object value) {
|
||||
return value == null
|
||||
? isNull( propertyName )
|
||||
: eq( propertyName, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression ne(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, "<>" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to the named property. If the value
|
||||
* is null, instead apply "is not null".
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see #ne
|
||||
* @see #isNotNull
|
||||
*/
|
||||
public static Criterion neOrIsNotNull(String propertyName, Object value) {
|
||||
return value == null
|
||||
? isNotNull( propertyName )
|
||||
: ne( propertyName, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression like(String propertyName, Object value) {
|
||||
// todo : update this to use LikeExpression
|
||||
return new SimpleExpression( propertyName, value, " like " );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint to the named property using the provided match mode
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
* @param matchMode The match mode to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression like(String propertyName, String value, MatchMode matchMode) {
|
||||
// todo : update this to use LikeExpression
|
||||
return new SimpleExpression( propertyName, matchMode.toMatchString( value ), " like " );
|
||||
}
|
||||
|
||||
/**
|
||||
* A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator)
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see LikeExpression
|
||||
*/
|
||||
public static Criterion ilike(String propertyName, Object value) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Comparison value passed to ilike cannot be null" );
|
||||
}
|
||||
return ilike( propertyName, value.toString(), MatchMode.EXACT );
|
||||
}
|
||||
|
||||
/**
|
||||
* A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator) using the provided match mode
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
* @param matchMode The match mode to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see LikeExpression
|
||||
*/
|
||||
public static Criterion ilike(String propertyName, String value, MatchMode matchMode) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Comparison value passed to ilike cannot be null" );
|
||||
}
|
||||
return new LikeExpression( propertyName, value, matchMode, null, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression gt(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, ">" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression lt(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, "<" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression le(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, "<=" );
|
||||
}
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The value to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleExpression
|
||||
*/
|
||||
public static SimpleExpression ge(String propertyName, Object value) {
|
||||
return new SimpleExpression( propertyName, value, ">=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "between" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param low The low value
|
||||
* @param high The high value
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see BetweenExpression
|
||||
*/
|
||||
public static Criterion between(String propertyName, Object low, Object high) {
|
||||
return new BetweenExpression( propertyName, low, high );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint to the named property.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param values The literal values to use in the IN restriction
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see InExpression
|
||||
*/
|
||||
public static Criterion in(String propertyName, Object... values) {
|
||||
return new InExpression( propertyName, values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint to the named property.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param values The literal values to use in the IN restriction
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see InExpression
|
||||
*/
|
||||
public static Criterion in(String propertyName, Collection values) {
|
||||
return new InExpression( propertyName, values.toArray() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is null" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @see NullExpression
|
||||
*/
|
||||
public static Criterion isNull(String propertyName) {
|
||||
return new NullExpression( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is not null" constraint to the named property
|
||||
*
|
||||
* @param propertyName The property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see NotNullExpression
|
||||
*/
|
||||
public static Criterion isNotNull(String propertyName) {
|
||||
return new NotNullExpression( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression eqProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, "=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression neProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, "<>" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression ltProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, "<" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression leProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, "<=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression gtProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, ">" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint to two properties
|
||||
*
|
||||
* @param propertyName One property name
|
||||
* @param otherPropertyName The other property name
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertyExpression
|
||||
*/
|
||||
public static PropertyExpression geProperty(String propertyName, String otherPropertyName) {
|
||||
return new PropertyExpression( propertyName, otherPropertyName, ">=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the conjuction of two expressions
|
||||
*
|
||||
* @param lhs One expression
|
||||
* @param rhs The other expression
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
public static LogicalExpression and(Criterion lhs, Criterion rhs) {
|
||||
return new LogicalExpression(lhs, rhs, "and");
|
||||
}
|
||||
/**
|
||||
* Return the conjuction of multiple expressions
|
||||
*
|
||||
* @param predicates The predicates making up the initial junction
|
||||
*
|
||||
* @return The conjunction
|
||||
*/
|
||||
public static Conjunction and(Criterion... predicates) {
|
||||
return conjunction( predicates );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the disjuction of two expressions
|
||||
*
|
||||
* @param lhs One expression
|
||||
* @param rhs The other expression
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
public static LogicalExpression or(Criterion lhs, Criterion rhs) {
|
||||
return new LogicalExpression( lhs, rhs, "or" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the disjuction of multiple expressions
|
||||
*
|
||||
* @param predicates The predicates making up the initial junction
|
||||
*
|
||||
* @return The conjunction
|
||||
*/
|
||||
public static Disjunction or(Criterion... predicates) {
|
||||
return disjunction( predicates );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the negation of an expression
|
||||
*
|
||||
* @param expression The expression to be negated
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @see NotExpression
|
||||
*/
|
||||
public static Criterion not(Criterion expression) {
|
||||
return new NotExpression( expression );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a restriction expressed in SQL with JDBC parameters. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The SQL restriction
|
||||
* @param values The parameter values
|
||||
* @param types The parameter types
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SQLCriterion
|
||||
*/
|
||||
public static Criterion sqlRestriction(String sql, Object[] values, Type[] types) {
|
||||
return new SQLCriterion( sql, values, types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a restriction expressed in SQL with one JDBC parameter. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The SQL restriction
|
||||
* @param value The parameter value
|
||||
* @param type The parameter type
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SQLCriterion
|
||||
*/
|
||||
public static Criterion sqlRestriction(String sql, Object value, Type type) {
|
||||
return new SQLCriterion( sql, value, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a constraint expressed in SQL with no JDBC parameters. Any occurrences of <tt>{alias}</tt> will be
|
||||
* replaced by the table alias.
|
||||
*
|
||||
* @param sql The SQL restriction
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SQLCriterion
|
||||
*/
|
||||
public static Criterion sqlRestriction(String sql) {
|
||||
return new SQLCriterion( sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single conjunction (A and B and C...).
|
||||
*
|
||||
* This form creates an empty conjunction. See {@link Conjunction#add(Criterion)}
|
||||
*
|
||||
* @return Conjunction
|
||||
*/
|
||||
public static Conjunction conjunction() {
|
||||
return new Conjunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single conjunction (A and B and C...).
|
||||
*
|
||||
* @param conditions The initial set of conditions to put into the Conjunction
|
||||
*
|
||||
* @return Conjunction
|
||||
*/
|
||||
public static Conjunction conjunction(Criterion... conditions) {
|
||||
return new Conjunction( conditions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single disjunction (A or B or C...).
|
||||
*
|
||||
* This form creates an empty disjunction. See {@link Disjunction#add(Criterion)}
|
||||
*
|
||||
* @return Conjunction
|
||||
*/
|
||||
public static Disjunction disjunction() {
|
||||
return new Disjunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Group expressions together in a single disjunction (A or B or C...).
|
||||
*
|
||||
* @param conditions The initial set of conditions to put into the Disjunction
|
||||
*
|
||||
* @return Conjunction
|
||||
*/
|
||||
public static Disjunction disjunction(Criterion... conditions) {
|
||||
return new Disjunction( conditions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equals" constraint to each property in the key set of a <tt>Map</tt>
|
||||
*
|
||||
* @param propertyNameValues a map from property names to values
|
||||
*
|
||||
* @return Criterion
|
||||
*
|
||||
* @see Conjunction
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion allEq(Map<String,?> propertyNameValues) {
|
||||
final Conjunction conj = conjunction();
|
||||
|
||||
for ( Map.Entry<String,?> entry : propertyNameValues.entrySet() ) {
|
||||
conj.add( eq( entry.getKey(), entry.getValue() ) );
|
||||
}
|
||||
return conj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property to be empty
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see EmptyExpression
|
||||
*/
|
||||
public static Criterion isEmpty(String propertyName) {
|
||||
return new EmptyExpression( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property to be non-empty
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see NotEmptyExpression
|
||||
*/
|
||||
public static Criterion isNotEmpty(String propertyName) {
|
||||
return new NotEmptyExpression( propertyName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
public static Criterion sizeEq(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, "=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion sizeNe(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, "<>" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion sizeGt(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, "<" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion sizeLt(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, ">" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion sizeGe(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, "<=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrain a collection valued property by size
|
||||
*
|
||||
* @param propertyName The name of the collection property
|
||||
* @param size The size to use in comparison
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SizeExpression
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static Criterion sizeLe(String propertyName, int size) {
|
||||
return new SizeExpression( propertyName, size, ">=" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Consider using any of the natural id based loading stuff from session instead, especially in cases
|
||||
* where the restriction is the full set of natural id values.
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see NaturalIdentifier
|
||||
*
|
||||
* @see org.hibernate.Session#byNaturalId(Class)
|
||||
* @see org.hibernate.Session#byNaturalId(String)
|
||||
* @see org.hibernate.Session#bySimpleNaturalId(Class)
|
||||
* @see org.hibernate.Session#bySimpleNaturalId(String)
|
||||
*/
|
||||
public static NaturalIdentifier naturalId() {
|
||||
return new NaturalIdentifier();
|
||||
}
|
||||
|
||||
protected Restrictions() {
|
||||
// cannot be instantiated, but needs to be protected so Expression can extend it
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.function.SQLFunctionRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A row count
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class RowCountProjection extends SimpleProjection {
|
||||
private static final List ARGS = java.util.Collections.singletonList( "*" );
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final Type countFunctionReturnType = getFunction( criteriaQuery ).getReturnType( null, criteriaQuery.getFactory() );
|
||||
return new Type[] { countFunctionReturnType };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() ) + " as y" + position + '_';
|
||||
}
|
||||
|
||||
protected SQLFunction getFunction(CriteriaQuery criteriaQuery) {
|
||||
final SQLFunctionRegistry sqlFunctionRegistry = criteriaQuery.getFactory().getSqlFunctionRegistry();
|
||||
final SQLFunction function = sqlFunctionRegistry.findSQLFunction( "count" );
|
||||
if ( function == null ) {
|
||||
throw new HibernateException( "Unable to locate count function mapping" );
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "count(*)";
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A SQL fragment. The string {alias} will be replaced by the
|
||||
* alias of the root entity.
|
||||
*/
|
||||
public class SQLCriterion implements Criterion {
|
||||
private final String sql;
|
||||
private final TypedValue[] typedValues;
|
||||
|
||||
protected SQLCriterion(String sql, Object[] values, Type[] types) {
|
||||
this.sql = sql;
|
||||
this.typedValues = new TypedValue[values.length];
|
||||
for ( int i=0; i<typedValues.length; i++ ) {
|
||||
typedValues[i] = new TypedValue( types[i], values[i] );
|
||||
}
|
||||
}
|
||||
|
||||
protected SQLCriterion(String sql, Object value, Type type) {
|
||||
this.sql = sql;
|
||||
this.typedValues = new TypedValue[] { new TypedValue( type, value ) };
|
||||
}
|
||||
|
||||
protected SQLCriterion(String sql) {
|
||||
this.sql = sql;
|
||||
this.typedValues = new TypedValue[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return typedValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sql;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A SQL fragment. The string {alias} will be replaced by the
|
||||
* alias of the root entity.
|
||||
*/
|
||||
public class SQLProjection implements Projection {
|
||||
private final String sql;
|
||||
private final String groupBy;
|
||||
private final Type[] types;
|
||||
private String[] aliases;
|
||||
private String[] columnAliases;
|
||||
private boolean grouped;
|
||||
|
||||
protected SQLProjection(String sql, String[] columnAliases, Type[] types) {
|
||||
this( sql, null, columnAliases, types );
|
||||
}
|
||||
|
||||
protected SQLProjection(String sql, String groupBy, String[] columnAliases, Type[] types) {
|
||||
this.sql = sql;
|
||||
this.types = types;
|
||||
this.aliases = columnAliases;
|
||||
this.columnAliases = columnAliases;
|
||||
this.grouped = groupBy!=null;
|
||||
this.groupBy = groupBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) {
|
||||
return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return StringHelper.replace( groupBy, "{alias}", criteriaQuery.getSQLAlias( criteria ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria crit, CriteriaQuery criteriaQuery) {
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc) {
|
||||
return columnAliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return grouped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(String alias, Criteria crit, CriteriaQuery criteriaQuery) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* superclass for "simple" comparisons (with SQL binary operators)
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class SimpleExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final Object value;
|
||||
private boolean ignoreCase;
|
||||
private final String op;
|
||||
|
||||
protected SimpleExpression(String propertyName, Object value, String op) {
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
protected SimpleExpression(String propertyName, Object value, String op, boolean ignoreCase) {
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
this.ignoreCase = ignoreCase;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
protected final String getOp() {
|
||||
return op;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make case insensitive. No effect for non-String values
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*/
|
||||
public SimpleExpression ignoreCase() {
|
||||
ignoreCase = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName );
|
||||
final StringBuilder fragment = new StringBuilder();
|
||||
|
||||
if ( columns.length > 1 ) {
|
||||
fragment.append( '(' );
|
||||
}
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final int[] sqlTypes = type.sqlTypes( factory );
|
||||
for ( int i = 0; i < columns.length; i++ ) {
|
||||
final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR ||
|
||||
sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR);
|
||||
if ( lower ) {
|
||||
fragment.append( factory.getDialect().getLowercaseFunction() ).append( '(' );
|
||||
}
|
||||
fragment.append( columns[i] );
|
||||
if ( lower ) {
|
||||
fragment.append( ')' );
|
||||
}
|
||||
|
||||
fragment.append( getOp() ).append( "?" );
|
||||
if ( i < columns.length - 1 ) {
|
||||
fragment.append( " and " );
|
||||
}
|
||||
}
|
||||
if ( columns.length > 1 ) {
|
||||
fragment.append( ')' );
|
||||
}
|
||||
return fragment.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final Object casedValue = ignoreCase ? value.toString().toLowerCase(Locale.ROOT) : value;
|
||||
return new TypedValue[] { criteriaQuery.getTypedValue( criteria, propertyName, casedValue ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return propertyName + getOp() + value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A single-column projection that may be aliased
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public abstract class SimpleProjection implements EnhancedProjection {
|
||||
private static final int NUM_REUSABLE_ALIASES = 40;
|
||||
private static final String[] REUSABLE_ALIASES = initializeReusableAliases();
|
||||
|
||||
private static String[] initializeReusableAliases() {
|
||||
final String[] aliases = new String[NUM_REUSABLE_ALIASES];
|
||||
for ( int i = 0; i < NUM_REUSABLE_ALIASES; i++ ) {
|
||||
aliases[i] = aliasForLocation( i );
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
private static String aliasForLocation(final int loc) {
|
||||
return "y" + loc + "_";
|
||||
}
|
||||
|
||||
private static String getAliasForLocation(final int loc) {
|
||||
if ( loc >= NUM_REUSABLE_ALIASES ) {
|
||||
return aliasForLocation( loc );
|
||||
}
|
||||
else {
|
||||
return REUSABLE_ALIASES[loc];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased form of this projection
|
||||
*
|
||||
* @param alias The alias to apply
|
||||
*
|
||||
* @return The aliased projection
|
||||
*/
|
||||
public Projection as(String alias) {
|
||||
return Projections.alias( this, alias );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(String alias, int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return getColumnAliases( alias, loc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(String alias, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc) {
|
||||
return new String[] { getAliasForLocation( loc ) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of columns this projection uses.
|
||||
*
|
||||
* @param criteria The criteria
|
||||
* @param criteriaQuery The query
|
||||
*
|
||||
* @return The number of columns
|
||||
*/
|
||||
public int getColumnCount(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final Type[] types = getTypes( criteria, criteriaQuery );
|
||||
int count = 0;
|
||||
for ( Type type : types ) {
|
||||
count += type.getColumnSpan( criteriaQuery.getFactory() );
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnAliases(int loc, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final int numColumns = getColumnCount( criteria, criteriaQuery );
|
||||
final String[] aliases = new String[ numColumns ];
|
||||
for (int i = 0; i < numColumns; i++) {
|
||||
aliases[i] = getAliasForLocation( loc );
|
||||
loc++;
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
throw new UnsupportedOperationException( "not a grouping projection" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrouped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
/**
|
||||
* A comparison between a constant value and the the result of a subquery
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class SimpleSubqueryExpression extends SubqueryExpression {
|
||||
private Object value;
|
||||
|
||||
protected SimpleSubqueryExpression(Object value, String op, String quantifier, DetachedCriteria dc) {
|
||||
super( op, quantifier, dc );
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final TypedValue[] subQueryTypedValues = super.getTypedValues( criteria, criteriaQuery );
|
||||
final TypedValue[] result = new TypedValue[subQueryTypedValues.length+1];
|
||||
System.arraycopy( subQueryTypedValues, 0, result, 1, subQueryTypedValues.length );
|
||||
result[0] = new TypedValue( getTypes()[0], value );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toLeftSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
return "?";
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.persister.entity.Loadable;
|
||||
import org.hibernate.sql.ConditionFragment;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
* Used to define a restriction on a collection property based on its size.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SizeExpression implements Criterion {
|
||||
private final String propertyName;
|
||||
private final int size;
|
||||
private final String op;
|
||||
|
||||
protected SizeExpression(String propertyName, int size, String op) {
|
||||
this.propertyName = propertyName;
|
||||
this.size = size;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String entityName =criteriaQuery.getEntityName( criteria, propertyName );
|
||||
final String role = entityName + '.' + criteriaQuery.getPropertyName( propertyName );
|
||||
final QueryableCollection cp = (QueryableCollection) criteriaQuery.getFactory().getCollectionPersister( role );
|
||||
|
||||
final String[] fk = cp.getKeyColumnNames();
|
||||
final String[] pk = ( (Loadable) cp.getOwnerEntityPersister() ).getIdentifierColumnNames();
|
||||
|
||||
final ConditionFragment subQueryRestriction = new ConditionFragment()
|
||||
.setTableAlias( criteriaQuery.getSQLAlias( criteria, propertyName ) )
|
||||
.setCondition( pk, fk );
|
||||
|
||||
return String.format(
|
||||
Locale.ROOT,
|
||||
"? %s (select count(*) from %s where %s)",
|
||||
op,
|
||||
cp.getTableName(),
|
||||
subQueryRestriction.toFragmentString()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] { new TypedValue( StandardBasicTypes.INTEGER, size ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(size) + op + propertyName + ".size";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,631 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
/**
|
||||
* Factory class for criterion instances that represent expressions
|
||||
* involving subqueries.
|
||||
*
|
||||
* @see Restrictions
|
||||
* @see Projection
|
||||
* @see org.hibernate.Criteria
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
public class Subqueries {
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks for the existence of rows in the subquery result
|
||||
*
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see ExistsSubqueryExpression
|
||||
*/
|
||||
public static Criterion exists(DetachedCriteria dc) {
|
||||
return new ExistsSubqueryExpression( "exists", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks for the non-existence of rows in the subquery result
|
||||
*
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see ExistsSubqueryExpression
|
||||
*/
|
||||
public static Criterion notExists(DetachedCriteria dc) {
|
||||
return new ExistsSubqueryExpression( "not exists", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property equals ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyEqAll(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyGtAll(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyLtAll(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than-or-equal-to ALL the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyGeAll(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than-or-equal-to ALL the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyLeAll(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than SOME of the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyGtSome(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than SOME of the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyLtSome(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than-or-equal-to SOME of the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyGeSome(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">=", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than-or-equal-to SOME of the
|
||||
* values in the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyLeSome(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<=", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is in the set of values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyIn(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "in", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is not-in the set of values in
|
||||
* the subquery result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyNotIn(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "not in", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property as being equal to the set of values in
|
||||
* the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyEq(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "=", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is not equal to the value in the
|
||||
* subquery result. The assumption is that the subquery returns a single result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
*/
|
||||
public static Criterion propertyNe(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression(propertyName, "<>", null, dc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than the value in the
|
||||
* subquery result. The assumption is that the subquery returns a single result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
* @see #propertyGtAll
|
||||
* @see #propertyGtSome
|
||||
*/
|
||||
public static Criterion propertyGt(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than the value in the
|
||||
* subquery result. The assumption is that the subquery returns a single result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
* @see #propertyLtAll
|
||||
* @see #propertyLtSome
|
||||
*/
|
||||
public static Criterion propertyLt(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is greater-than-or-equal-to the value
|
||||
* in the subquery result. The assumption is that the subquery returns a single result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
* @see #propertyGeAll
|
||||
* @see #propertyGeSome
|
||||
*/
|
||||
public static Criterion propertyGe(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, ">=", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given property is less-than-or-equal-to the value
|
||||
* in the subquery result. The assumption is that the subquery returns a single result.
|
||||
*
|
||||
* @param propertyName The name of the property to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertySubqueryExpression
|
||||
* @see #propertyLeAll
|
||||
* @see #propertyLeSome
|
||||
*/
|
||||
public static Criterion propertyLe(String propertyName, DetachedCriteria dc) {
|
||||
return new PropertySubqueryExpression( propertyName, "<=", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of multiple given properties as being equal to the set of
|
||||
* values in the subquery result. The implication is that the subquery returns a single result. This form is
|
||||
* however implicitly using tuple comparisons
|
||||
*
|
||||
* @param propertyNames The names of the properties to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertiesSubqueryExpression
|
||||
*/
|
||||
public static Criterion propertiesEq(String[] propertyNames, DetachedCriteria dc) {
|
||||
return new PropertiesSubqueryExpression( propertyNames, "=", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of multiple given properties as being not-equal to the set of
|
||||
* values in the subquery result. The assumption is that the subquery returns a single result. This form is
|
||||
* however implicitly using tuple comparisons
|
||||
*
|
||||
* @param propertyNames The names of the properties to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertiesSubqueryExpression
|
||||
*/
|
||||
public static Criterion propertiesNotEq(String[] propertyNames, DetachedCriteria dc) {
|
||||
return new PropertiesSubqueryExpression( propertyNames, "<>", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of multiple given properties as being in to the set of
|
||||
* values in the subquery result. This form is implicitly using tuple comparisons
|
||||
*
|
||||
* @param propertyNames The names of the properties to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertiesSubqueryExpression
|
||||
*/
|
||||
public static Criterion propertiesIn(String[] propertyNames, DetachedCriteria dc) {
|
||||
return new PropertiesSubqueryExpression( propertyNames, "in", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of multiple given properties as being not-in to the set of
|
||||
* values in the subquery result. This form is implicitly using tuple comparisons
|
||||
*
|
||||
* @param propertyNames The names of the properties to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see PropertiesSubqueryExpression
|
||||
*/
|
||||
public static Criterion propertiesNotIn(String[] propertyNames, DetachedCriteria dc) {
|
||||
return new PropertiesSubqueryExpression( propertyNames, "not in", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal equals ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion eqAll(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is greater-than ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion gtAll(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is less-than ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion ltAll(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is greater-than-or-equal-to ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion geAll(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is less-than-or-equal-to ALL the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion leAll(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<=", "all", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is greater-than SOME of the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion gtSome(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is less-than SOME of the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion ltSome(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is greater-than-or-equal-to SOME of the values
|
||||
* in the subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion geSome(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">=", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is less-than-or-equal-to SOME of the values
|
||||
* in the subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion leSome(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<=", "some", dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is IN the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion in(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "in", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a literal is NOT IN the values in the
|
||||
* subquery result.
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion notIn(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "not in", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being equal to the value in
|
||||
* the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion eq(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "=", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being not-equal to the value in
|
||||
* the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion ne(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression(value, "<>", null, dc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being greater-than the value in
|
||||
* the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion gt(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being less-than the value in
|
||||
* the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion lt(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being greater-than-or-equal-to the
|
||||
* value in the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion ge(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, ">=", null, dc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion which checks that the value of a given literal as being less-than-or-equal-to the
|
||||
* value in the subquery result. The implication is that the subquery returns a single result..
|
||||
*
|
||||
* @param value The literal value to use in comparison
|
||||
* @param dc The detached criteria representing the subquery
|
||||
*
|
||||
* @return The Criterion
|
||||
*
|
||||
* @see SimpleSubqueryExpression
|
||||
*/
|
||||
public static Criterion le(Object value, DetachedCriteria dc) {
|
||||
return new SimpleSubqueryExpression( value, "<=", null, dc );
|
||||
}
|
||||
|
||||
private Subqueries() {
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* 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.criterion;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.CriteriaImpl;
|
||||
import org.hibernate.loader.criteria.CriteriaJoinWalker;
|
||||
import org.hibernate.loader.criteria.CriteriaQueryTranslator;
|
||||
import org.hibernate.persister.entity.OuterJoinLoadable;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A criterion that involves a subquery
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class SubqueryExpression implements Criterion {
|
||||
private CriteriaImpl criteriaImpl;
|
||||
private String quantifier;
|
||||
private String op;
|
||||
private QueryParameters params;
|
||||
private Type[] types;
|
||||
private CriteriaQueryTranslator innerQuery;
|
||||
|
||||
protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) {
|
||||
this.criteriaImpl = dc.getCriteriaImpl();
|
||||
this.quantifier = quantifier;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
protected Type[] getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
protected abstract String toLeftSqlString(Criteria criteria, CriteriaQuery outerQuery);
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final StringBuilder buf = new StringBuilder( toLeftSqlString( criteria, criteriaQuery ) );
|
||||
if ( op != null ) {
|
||||
buf.append( ' ' ).append( op ).append( ' ' );
|
||||
}
|
||||
if ( quantifier != null ) {
|
||||
buf.append( quantifier ).append( ' ' );
|
||||
}
|
||||
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final OuterJoinLoadable persister =
|
||||
(OuterJoinLoadable) factory.getMetamodel().entityPersister( criteriaImpl.getEntityOrClassName() );
|
||||
|
||||
createAndSetInnerQuery( criteriaQuery, factory );
|
||||
criteriaImpl.setSession( deriveRootSession( criteria ) );
|
||||
|
||||
final CriteriaJoinWalker walker = new CriteriaJoinWalker(
|
||||
persister,
|
||||
innerQuery,
|
||||
factory,
|
||||
criteriaImpl,
|
||||
criteriaImpl.getEntityOrClassName(),
|
||||
criteriaImpl.getSession().getLoadQueryInfluencers(),
|
||||
innerQuery.getRootSQLALias()
|
||||
);
|
||||
|
||||
return buf.append( '(' ).append( walker.getSQLString() ).append( ')' ).toString();
|
||||
}
|
||||
|
||||
private SharedSessionContractImplementor deriveRootSession(Criteria criteria) {
|
||||
if ( criteria instanceof CriteriaImpl ) {
|
||||
return ( (CriteriaImpl) criteria ).getSession();
|
||||
}
|
||||
else if ( criteria instanceof CriteriaImpl.Subcriteria ) {
|
||||
return deriveRootSession( ( (CriteriaImpl.Subcriteria) criteria ).getParent() );
|
||||
}
|
||||
else {
|
||||
// could happen for custom Criteria impls. Not likely, but...
|
||||
// for long term solution, see HHH-3514
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
//the following two lines were added to ensure that this.params is not null, which
|
||||
//can happen with two-deep nested subqueries
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
createAndSetInnerQuery( criteriaQuery, factory );
|
||||
|
||||
final Type[] ppTypes = params.getPositionalParameterTypes();
|
||||
final Object[] ppValues = params.getPositionalParameterValues();
|
||||
final TypedValue[] tv = new TypedValue[ppTypes.length];
|
||||
for ( int i=0; i<ppTypes.length; i++ ) {
|
||||
tv[i] = new TypedValue( ppTypes[i], ppValues[i] );
|
||||
}
|
||||
return tv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the inner query used to extract some useful information about types, since it is needed in both methods.
|
||||
*
|
||||
* @param criteriaQuery The criteria query
|
||||
* @param factory The session factory.
|
||||
*/
|
||||
private void createAndSetInnerQuery(CriteriaQuery criteriaQuery, SessionFactoryImplementor factory) {
|
||||
if ( innerQuery == null ) {
|
||||
//with two-deep subqueries, the same alias would get generated for
|
||||
//both using the old method (criteriaQuery.generateSQLAlias()), so
|
||||
//that is now used as a fallback if the main criteria alias isn't set
|
||||
String alias;
|
||||
if ( this.criteriaImpl.getAlias() == null ) {
|
||||
alias = criteriaQuery.generateSQLAlias();
|
||||
}
|
||||
else {
|
||||
alias = this.criteriaImpl.getAlias() + "_";
|
||||
}
|
||||
|
||||
innerQuery = new CriteriaQueryTranslator(
|
||||
factory,
|
||||
criteriaImpl,
|
||||
criteriaImpl.getEntityOrClassName(),
|
||||
alias,
|
||||
criteriaQuery
|
||||
);
|
||||
|
||||
params = innerQuery.getQueryParameters();
|
||||
types = innerQuery.getProjectedTypes();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<p>
|
||||
A framework for defining restriction criteria and order criteria.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -71,7 +71,6 @@ import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
|
|||
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
|
||||
import org.hibernate.engine.jdbc.env.spi.SchemaNameResolver;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.exception.spi.ConversionContext;
|
||||
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.hibernate.dialect.function.VarArgsSQLFunction;
|
|||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.hibernate.exception.LockAcquisitionException;
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.dialect.function.SQLFunctionTemplate;
|
|||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.Teradata14IdentityColumnSupport;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
|
||||
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
|
||||
import org.hibernate.mapping.Column;
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Iterator;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
package org.hibernate.engine.query;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.query.spi.ParamLocationRecognizer;
|
||||
import org.hibernate.query.sql.spi.ParameterRecognizer;
|
||||
|
||||
/**
|
||||
* Indicates a problem during parameter recognition via
|
||||
* {@link ParamLocationRecognizer}
|
||||
* Indicates a problem during parameter recognition via {@link ParameterRecognizer}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
|
@ -8,30 +8,25 @@ package org.hibernate.engine.query.internal;
|
|||
|
||||
import org.hibernate.engine.query.spi.NativeQueryInterpreter;
|
||||
import org.hibernate.engine.query.spi.NativeSQLQueryPlan;
|
||||
import org.hibernate.engine.query.spi.ParamLocationRecognizer;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.loader.custom.CustomQuery;
|
||||
import org.hibernate.loader.custom.sql.SQLCustomQuery;
|
||||
import org.hibernate.query.internal.ParameterMetadataImpl;
|
||||
import org.hibernate.query.sql.internal.ParameterParser;
|
||||
import org.hibernate.query.sql.spi.ParameterRecognizer;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeQueryInterpreterStandardImpl implements NativeQueryInterpreter {
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
public NativeQueryInterpreterStandardImpl(SessionFactoryImplementor sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final NativeQueryInterpreterStandardImpl INSTANCE = new NativeQueryInterpreterStandardImpl();
|
||||
|
||||
@Override
|
||||
public ParameterMetadataImpl getParameterMetadata(String nativeQuery) {
|
||||
final ParamLocationRecognizer recognizer = ParamLocationRecognizer.parseLocations( nativeQuery, sessionFactory );
|
||||
return new ParameterMetadataImpl(
|
||||
recognizer.getOrdinalParameterDescriptionMap(),
|
||||
recognizer.getNamedParameterDescriptionMap()
|
||||
);
|
||||
public void recognizeParameters(String nativeQuery, ParameterRecognizer recognizer) {
|
||||
ParameterParser.parse( nativeQuery, recognizer );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Set;
|
|||
import org.hibernate.Filter;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
|
|
@ -6,11 +6,18 @@
|
|||
*/
|
||||
package org.hibernate.engine.query.spi;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.loader.custom.CustomLoader;
|
||||
import org.hibernate.loader.custom.CustomQuery;
|
||||
import org.hibernate.query.internal.ParameterMetadataImpl;
|
||||
import org.hibernate.query.sql.internal.NativeSelectQueryPlanImpl;
|
||||
import org.hibernate.query.sql.spi.NativeNonSelectQueryDefinition;
|
||||
import org.hibernate.query.sql.spi.NativeNonSelectQueryPlan;
|
||||
import org.hibernate.query.sql.spi.NativeSelectQueryDefinition;
|
||||
import org.hibernate.query.sql.spi.NativeSelectQueryPlan;
|
||||
import org.hibernate.query.sql.spi.ParameterRecognizer;
|
||||
import org.hibernate.service.Service;
|
||||
|
||||
/**
|
||||
|
@ -20,38 +27,38 @@ import org.hibernate.service.Service;
|
|||
* @author Gunnar Morling
|
||||
* @author Guillaume Smet
|
||||
*/
|
||||
@Incubating
|
||||
public interface NativeQueryInterpreter extends Service {
|
||||
/**
|
||||
* Returns a meta-data object with information about the named and ordinal
|
||||
* parameters contained in the given native query.
|
||||
* Parse the given native query and inform the recognizer of all
|
||||
* recognized parameter markers.
|
||||
*
|
||||
* @param nativeQuery the native query to analyze.
|
||||
*
|
||||
* @return a meta-data object describing the parameters of the given query.
|
||||
* Must not be {@code null}.
|
||||
* @param nativeQuery The query to recognize parameters in
|
||||
* @param recognizer The recognizer to call
|
||||
*/
|
||||
ParameterMetadataImpl getParameterMetadata(String nativeQuery);
|
||||
void recognizeParameters(String nativeQuery, ParameterRecognizer recognizer);
|
||||
|
||||
/**
|
||||
* Creates a new query plan for the specified native query.
|
||||
*
|
||||
* @param specification Describes the query to create a plan for
|
||||
* @param sessionFactory The current session factory
|
||||
*
|
||||
* @return A query plan for the specified native query.
|
||||
* Creates a new query plan for the passed native query definition
|
||||
*/
|
||||
NativeSQLQueryPlan createQueryPlan(NativeSQLQuerySpecification specification, SessionFactoryImplementor sessionFactory);
|
||||
default <R> NativeSelectQueryPlan<R> createQueryPlan(
|
||||
NativeSelectQueryDefinition<R> queryDefinition,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
return new NativeSelectQueryPlanImpl<R>(
|
||||
queryDefinition.getSqlString(),
|
||||
queryDefinition.getAffectedTableNames(),
|
||||
queryDefinition.getQueryParameterList(),
|
||||
queryDefinition.getResultSetMapping(),
|
||||
queryDefinition.getRowTransformer()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link CustomLoader} for the given {@link CustomQuery}.
|
||||
*
|
||||
* @param customQuery The CustomQuery to create a loader for
|
||||
* @param sessionFactory The current session factory
|
||||
*
|
||||
* @deprecated This method will be removed in 6.
|
||||
* Creates a new query plan for the passed native query values
|
||||
*/
|
||||
@Deprecated
|
||||
default CustomLoader createCustomLoader(CustomQuery customQuery, SessionFactoryImplementor sessionFactory) {
|
||||
return new CustomLoader( customQuery, sessionFactory );
|
||||
default NativeNonSelectQueryPlan createQueryPlan(
|
||||
NativeNonSelectQueryDefinition queryDefinition,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
throw new NotYetImplementedFor6Exception( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.sql.SQLException;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.action.internal.BulkOperationCleanupAction;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
|
|
|
@ -15,6 +15,8 @@ import java.util.Map;
|
|||
import org.hibernate.engine.query.ParameterRecognitionException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.query.sql.internal.ParameterParser;
|
||||
import org.hibernate.query.sql.spi.ParameterRecognizer;
|
||||
|
||||
/**
|
||||
* Implements a parameter parser recognizer specifically for the purpose
|
||||
|
@ -22,7 +24,7 @@ import org.hibernate.internal.util.collections.ArrayHelper;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
||||
public class ParamLocationRecognizer implements ParameterRecognizer {
|
||||
|
||||
private Map<String, NamedParameterDescriptor> namedParameterDescriptors;
|
||||
private Map<Integer, OrdinalParameterDescriptor> ordinalParameterDescriptors;
|
||||
|
@ -57,8 +59,7 @@ public class ParamLocationRecognizer implements ParameterParser.Recognizer {
|
|||
return recognizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete() {
|
||||
public void validate() {
|
||||
if ( inFlightNamedStateMap != null && ( inFlightOrdinalStateMap != null || inFlightJpaOrdinalStateMap != null ) ) {
|
||||
throw mixedParamStrategy();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.engine.spi;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -23,11 +22,9 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|||
import javax.persistence.criteria.CriteriaDelete;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.CriteriaUpdate;
|
||||
import javax.persistence.criteria.Selection;
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Filter;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -38,9 +35,7 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MultiIdentifierLoadAccess;
|
||||
import org.hibernate.NaturalIdLoadAccess;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.ReplicationMode;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionEventListener;
|
||||
import org.hibernate.SharedSessionBuilder;
|
||||
|
@ -61,9 +56,9 @@ import org.hibernate.jdbc.Work;
|
|||
import org.hibernate.loader.custom.CustomQuery;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.query.spi.NativeQueryImplementor;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.stat.SessionStatistics;
|
||||
|
@ -172,15 +167,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.buildLockOptions( lockModeType, properties );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> QueryImplementor<T> createQuery(
|
||||
String jpaqlString,
|
||||
Class<T> resultClass,
|
||||
Selection selection,
|
||||
QueryOptions queryOptions) {
|
||||
return delegate.createQuery( jpaqlString,resultClass, selection, queryOptions );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException {
|
||||
delegate.initializeCollection( collection, writing );
|
||||
|
@ -206,41 +192,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.getFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List list(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.list( query, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.iterate( query, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.scroll( query, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
|
||||
return delegate.scroll( criteria, scrollMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List list(Criteria criteria) {
|
||||
return delegate.list( criteria );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List listFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.listFilter( collection, filter, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.iterateFilter( collection, filter, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException {
|
||||
return delegate.getEntityPersister( entityName, object );
|
||||
|
@ -561,11 +512,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.getNamedQuery( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor getNamedSQLQuery(String name) {
|
||||
return delegate.getNamedSQLQuery( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor getNamedNativeQuery(String name) {
|
||||
return delegate.getNamedNativeQuery( name );
|
||||
|
@ -641,6 +587,11 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.createStoredProcedureQuery( procedureName, resultSetMappings );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareForQueryExecution(boolean requiresTxn) {
|
||||
delegate.prepareForQueryExecution( requiresTxn );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinTransaction() {
|
||||
delegate.joinTransaction();
|
||||
|
@ -695,26 +646,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.createStoredProcedureCall( procedureName, resultSetMappings );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(Class persistentClass) {
|
||||
return delegate.createCriteria( persistentClass );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(Class persistentClass, String alias) {
|
||||
return delegate.createCriteria( persistentClass, alias );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(String entityName) {
|
||||
return delegate.createCriteria( entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(String entityName, String alias) {
|
||||
return delegate.createCriteria( entityName, alias );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedSessionBuilder sessionWithOptions() {
|
||||
return delegate.sessionWithOptions();
|
||||
|
@ -980,11 +911,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.getCurrentLockMode( object );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query createFilter(Object collection, String queryString) {
|
||||
return delegate.createFilter( collection, queryString );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
delegate.clear();
|
||||
|
|
|
@ -20,8 +20,8 @@ import org.hibernate.graph.RootGraph;
|
|||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.query.spi.NativeQueryImplementor;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||
|
||||
|
@ -57,6 +57,11 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
|||
public interface SessionImplementor
|
||||
extends Session, SharedSessionContractImplementor, HibernateEntityManagerImplementor {
|
||||
|
||||
@Override
|
||||
default SessionImplementor getSession() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
SessionFactoryImplementor getSessionFactory();
|
||||
|
||||
|
@ -98,23 +103,18 @@ public interface SessionImplementor
|
|||
NativeQueryImplementor createNativeQuery(String sqlString);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass);
|
||||
|
||||
@Override
|
||||
NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMapping);
|
||||
|
||||
@Override
|
||||
NativeQueryImplementor createSQLQuery(String sqlString);
|
||||
|
||||
@Override
|
||||
NativeQueryImplementor getNamedNativeQuery(String name);
|
||||
|
||||
@Override
|
||||
QueryImplementor getNamedQuery(String queryName);
|
||||
|
||||
@Override
|
||||
NativeQueryImplementor getNamedSQLQuery(String name);
|
||||
|
||||
@Override
|
||||
<T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery);
|
||||
|
||||
|
@ -124,21 +124,6 @@ public interface SessionImplementor
|
|||
@Override
|
||||
QueryImplementor createQuery(CriteriaDelete deleteQuery);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated (since 5.2) - see deprecation note on super
|
||||
*
|
||||
* @return The typed query
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
<T> QueryImplementor<T> createQuery(
|
||||
String jpaqlString,
|
||||
Class<T> resultClass,
|
||||
Selection selection,
|
||||
QueryOptions queryOptions);
|
||||
|
||||
/**
|
||||
* @deprecated OperationalContext should cover this overload I believe; Gail?
|
||||
*/
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.engine.spi;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.FlushModeType;
|
||||
|
@ -16,11 +15,9 @@ import javax.persistence.TransactionRequiredException;
|
|||
import javax.persistence.criteria.Selection;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.SharedSessionContract;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cache.spi.CacheTransactionSynchronization;
|
||||
|
@ -119,6 +116,11 @@ public interface SharedSessionContractImplementor
|
|||
*/
|
||||
UUID getSessionIdentifier();
|
||||
|
||||
@Override
|
||||
default SharedSessionContractImplementor getSession() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the session is closed. Provided separately from
|
||||
* {@link #isOpen()} as this method does not attempt any JTA synchronization
|
||||
|
@ -277,42 +279,6 @@ public interface SharedSessionContractImplementor
|
|||
Object immediateLoad(String entityName, Serializable id) throws HibernateException;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a <tt>find()</tt> query
|
||||
*/
|
||||
List list(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute an <tt>iterate()</tt> query
|
||||
*/
|
||||
Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a <tt>scroll()</tt> query
|
||||
*/
|
||||
ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a criteria query
|
||||
*/
|
||||
ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode);
|
||||
|
||||
/**
|
||||
* Execute a criteria query
|
||||
*/
|
||||
List list(Criteria criteria);
|
||||
|
||||
/**
|
||||
* Execute a filter
|
||||
*/
|
||||
List listFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Iterate a filter
|
||||
*/
|
||||
Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the <tt>EntityPersister</tt> for any instance
|
||||
*
|
||||
|
|
|
@ -22,7 +22,6 @@ import javax.persistence.criteria.CriteriaQuery;
|
|||
import javax.persistence.criteria.CriteriaUpdate;
|
||||
import javax.persistence.criteria.Selection;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.EmptyInterceptor;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
|
@ -39,9 +38,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
|||
import org.hibernate.cache.spi.CacheTransactionSynchronization;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
|
||||
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
|
||||
import org.hibernate.query.sql.spi.ResultSetMappingDescriptor;
|
||||
import org.hibernate.engine.internal.SessionEventListenerManagerImpl;
|
||||
import org.hibernate.engine.jdbc.LobCreationContext;
|
||||
import org.hibernate.engine.jdbc.LobCreator;
|
||||
|
@ -49,15 +45,9 @@ import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
|||
import org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
||||
import org.hibernate.engine.query.spi.NativeSQLQueryPlan;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.ExceptionConverter;
|
||||
import org.hibernate.query.hql.internal.NamedHqlQueryMementoImpl;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionEventListenerManager;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -65,27 +55,31 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
|||
import org.hibernate.engine.transaction.internal.TransactionImpl;
|
||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.id.uuid.StandardRandomStrategy;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
||||
import org.hibernate.jpa.spi.NativeQueryTupleTransformer;
|
||||
import org.hibernate.jpa.spi.TupleBuilderTransformer;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
|
||||
import org.hibernate.procedure.internal.ProcedureCallImpl;
|
||||
import org.hibernate.query.ParameterMetadata;
|
||||
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.query.sql.internal.NativeQueryImpl;
|
||||
import org.hibernate.query.internal.QueryImpl;
|
||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||
import org.hibernate.query.sql.internal.NativeQueryImpl;
|
||||
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
|
||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||
import org.hibernate.query.sql.spi.ResultSetMappingDescriptor;
|
||||
import org.hibernate.query.sqm.internal.QuerySqmImpl;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
|
||||
import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
|
||||
/**
|
||||
|
@ -605,111 +599,13 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
this.cacheMode = cacheMode;
|
||||
}
|
||||
|
||||
protected HQLQueryPlan getQueryPlan(String query, boolean shallow) throws HibernateException {
|
||||
return getFactory().getQueryInterpretationCache().getHQLQueryPlan( query, shallow, getLoadQueryInfluencers().getEnabledFilters() );
|
||||
}
|
||||
|
||||
protected NativeSQLQueryPlan getNativeQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException {
|
||||
return getFactory().getQueryInterpretationCache().getNativeSQLQueryPlan( spec );
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor getNamedQuery(String name) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
// look as HQL/JPQL first
|
||||
final NamedHqlQueryMemento hqlQueryMemento = factory.getNamedQueryRepository().getHqlQueryMemento( name );
|
||||
if ( hqlQueryMemento != null ) {
|
||||
return hqlQueryMemento.toQuery( this );
|
||||
}
|
||||
|
||||
// then as a native query
|
||||
final NamedNativeQueryMemento nativeQueryMemento = factory.getNamedQueryRepository().getNativeQueryMemento( name );
|
||||
if ( nativeQueryMemento != null ) {
|
||||
return nativeQueryMemento.toQuery( this );
|
||||
}
|
||||
|
||||
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
|
||||
}
|
||||
|
||||
protected QueryImplementor createQuery(NamedHqlQueryMemento memento) {
|
||||
//noinspection unchecked
|
||||
return new QuerySqmImpl( memento, null, this );
|
||||
}
|
||||
|
||||
private NativeQueryImplementor createNativeQuery(NamedNativeQueryMemento queryDefinition, boolean isOrdinalParameterZeroBased) {
|
||||
final ParameterMetadata parameterMetadata = factory.getQueryInterpretationCache().getSQLParameterMetadata(
|
||||
queryDefinition.getQueryString(),
|
||||
isOrdinalParameterZeroBased
|
||||
);
|
||||
return getNativeQueryImplementor( queryDefinition, parameterMetadata );
|
||||
}
|
||||
|
||||
private NativeQueryImplementor getNativeQueryImplementor(
|
||||
NamedNativeQueryMemento memento,
|
||||
ParameterMetadata parameterMetadata) {
|
||||
final NativeQueryImpl query = new NativeQueryImpl( memento, this, parameterMetadata );
|
||||
|
||||
initQueryFromNamedDefinition( query, memento );
|
||||
applyQuerySettingsAndHints( query );
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
protected void initQueryFromNamedDefinition(Query query, NamedHqlQueryMementoImpl nqd) {
|
||||
// todo : cacheable and readonly should be Boolean rather than boolean...
|
||||
query.setCacheable( nqd.getCacheable() );
|
||||
query.setCacheRegion( nqd.getCacheRegion() );
|
||||
query.setReadOnly( nqd.getReadOnly() );
|
||||
|
||||
if ( nqd.getTimeout() != null ) {
|
||||
query.setTimeout( nqd.getTimeout() );
|
||||
}
|
||||
if ( nqd.getFetchSize() != null ) {
|
||||
query.setFetchSize( nqd.getFetchSize() );
|
||||
}
|
||||
if ( nqd.getCacheMode() != null ) {
|
||||
query.setCacheMode( nqd.getCacheMode() );
|
||||
}
|
||||
if ( nqd.getComment() != null ) {
|
||||
query.setComment( nqd.getComment() );
|
||||
}
|
||||
if ( nqd.getFirstResult() != null ) {
|
||||
query.setFirstResult( nqd.getFirstResult() );
|
||||
}
|
||||
if ( nqd.getMaxResults() != null ) {
|
||||
query.setMaxResults( nqd.getMaxResults() );
|
||||
}
|
||||
if ( nqd.getFlushMode() != null ) {
|
||||
query.setHibernateFlushMode( nqd.getFlushMode() );
|
||||
}
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// dynamic HQL handling
|
||||
|
||||
@Override
|
||||
public QueryImplementor createQuery(String queryString) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
final QueryImpl query = new QueryImpl(
|
||||
this,
|
||||
getQueryPlan( queryString, false ).getParameterMetadata(),
|
||||
queryString
|
||||
);
|
||||
query.setComment( queryString );
|
||||
applyQuerySettingsAndHints( query );
|
||||
return query;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
markForRollbackOnly();
|
||||
throw getExceptionConverter().convert( e );
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyQuerySettingsAndHints(Query query) {
|
||||
return createQuery( queryString, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -720,256 +616,40 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
// do the translation
|
||||
final QueryImplementor<T> query = createQuery( queryString );
|
||||
resultClassChecking( resultClass, query );
|
||||
final QueryEngine queryEngine = getFactory().getQueryEngine();
|
||||
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
|
||||
final SqmStatement sqm = interpretationCache.resolveSqmStatement(
|
||||
queryString,
|
||||
s -> queryEngine.getSemanticQueryProducer().interpret( queryString )
|
||||
);
|
||||
|
||||
final QuerySqmImpl query = new QuerySqmImpl(
|
||||
queryString,
|
||||
sqm,
|
||||
resultClass,
|
||||
this
|
||||
);
|
||||
|
||||
query.setComment( queryString );
|
||||
applyQuerySettingsAndHints( query );
|
||||
|
||||
return query;
|
||||
}
|
||||
catch ( RuntimeException e ) {
|
||||
catch (RuntimeException e) {
|
||||
markForRollbackOnly();
|
||||
throw getExceptionConverter().convert( e );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "WeakerAccess", "StatementWithEmptyBody"})
|
||||
protected void resultClassChecking(Class resultClass, Query hqlQuery) {
|
||||
// make sure the query is a select -> HHH-7192
|
||||
final HQLQueryPlan queryPlan = getFactory().getQueryInterpretationCache().getHQLQueryPlan(
|
||||
hqlQuery.getQueryString(),
|
||||
false,
|
||||
getLoadQueryInfluencers().getEnabledFilters()
|
||||
);
|
||||
if ( queryPlan.getTranslators()[0].isManipulationStatement() ) {
|
||||
throw new IllegalArgumentException( "Update/delete queries cannot be typed" );
|
||||
}
|
||||
|
||||
// do some return type validation checking
|
||||
if ( Object[].class.equals( resultClass ) ) {
|
||||
// no validation needed
|
||||
}
|
||||
else if ( Tuple.class.equals( resultClass ) ) {
|
||||
TupleBuilderTransformer tupleTransformer = new TupleBuilderTransformer( hqlQuery );
|
||||
hqlQuery.setResultTransformer( tupleTransformer );
|
||||
}
|
||||
else {
|
||||
final Class dynamicInstantiationClass = queryPlan.getDynamicInstantiationResultType();
|
||||
if ( dynamicInstantiationClass != null ) {
|
||||
if ( ! resultClass.isAssignableFrom( dynamicInstantiationClass ) ) {
|
||||
throw new IllegalArgumentException(
|
||||
"Mismatch in requested result type [" + resultClass.getName() +
|
||||
"] and actual result type [" + dynamicInstantiationClass.getName() + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
else if ( queryPlan.getTranslators()[0].getReturnTypes().length == 1 ) {
|
||||
// if we have only a single return expression, its java type should match with the requested type
|
||||
final Type queryResultType = queryPlan.getTranslators()[0].getReturnTypes()[0];
|
||||
if ( !resultClass.isAssignableFrom( queryResultType.getReturnedClass() ) ) {
|
||||
throw new IllegalArgumentException(
|
||||
"Type specified for TypedQuery [" +
|
||||
resultClass.getName() +
|
||||
"] is incompatible with query return type [" +
|
||||
queryResultType.getReturnedClass() + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot create TypedQuery for query with more than one return using requested result type [" +
|
||||
resultClass.getName() + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor createNamedQuery(String name) {
|
||||
return buildQueryFromName( name, null );
|
||||
}
|
||||
|
||||
protected <T> QueryImplementor<T> buildQueryFromName(String name, Class<T> resultType) {
|
||||
checkOpen();
|
||||
try {
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
// todo : apply stored setting at the JPA Query level too
|
||||
|
||||
final NamedHqlQueryMemento hqlQueryMemento = getFactory().getQueryEngine().getNamedQueryRepository().getHqlQueryMemento( name );
|
||||
if ( hqlQueryMemento != null ) {
|
||||
return createQuery( hqlQueryMemento, resultType );
|
||||
}
|
||||
|
||||
final NamedNativeQueryMemento nativeQueryMemento = getFactory().getQueryEngine().getNamedQueryRepository().getNativeQueryMemento( name );
|
||||
if ( nativeQueryMemento != null ) {
|
||||
return (QueryImplementor<T>) createNativeQuery( nativeQueryMemento, resultType );
|
||||
}
|
||||
|
||||
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw !( e instanceof IllegalArgumentException ) ? new IllegalArgumentException( e ) : e;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unchecked"})
|
||||
protected <T> QueryImplementor<T> createQuery(NamedHqlQueryMemento namedQueryDefinition, Class<T> resultType) {
|
||||
final QueryImplementor query = createQuery( namedQueryDefinition );
|
||||
if ( resultType != null ) {
|
||||
resultClassChecking( resultType, query );
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unchecked"})
|
||||
protected <T> NativeQueryImplementor createNativeQuery(NamedNativeQueryMemento queryDefinition, Class<T> resultType) {
|
||||
if ( resultType != null && !Tuple.class.equals( resultType ) ) {
|
||||
resultClassChecking( resultType, queryDefinition );
|
||||
}
|
||||
|
||||
final NativeQueryImpl query = new NativeQueryImpl(
|
||||
queryDefinition,
|
||||
this,
|
||||
factory.getQueryInterpretationCache().getSQLParameterMetadata( queryDefinition.getQueryString(), false )
|
||||
);
|
||||
if ( Tuple.class.equals( resultType ) ) {
|
||||
query.setResultTransformer( new NativeQueryTupleTransformer() );
|
||||
}
|
||||
query.setHibernateFlushMode( queryDefinition.getFlushMode() );
|
||||
query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() );
|
||||
if ( queryDefinition.getLockOptions() != null ) {
|
||||
query.setLockOptions( queryDefinition.getLockOptions() );
|
||||
}
|
||||
|
||||
initQueryFromNamedDefinition( query, queryDefinition );
|
||||
applyQuerySettingsAndHints( query );
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "WeakerAccess"})
|
||||
protected void resultClassChecking(Class resultType, NamedNativeQueryMemento namedQueryDefinition) {
|
||||
final NativeSQLQueryReturn[] queryReturns;
|
||||
if ( namedQueryDefinition.getQueryReturns() != null ) {
|
||||
queryReturns = namedQueryDefinition.getQueryReturns();
|
||||
}
|
||||
else if ( namedQueryDefinition.getResultSetRef() != null ) {
|
||||
final ResultSetMappingDescriptor rsMapping = getFactory().getNamedQueryRepository().getResultSetMappingDefinition( namedQueryDefinition.getResultSetRef() );
|
||||
queryReturns = rsMapping.getQueryReturns();
|
||||
}
|
||||
else {
|
||||
throw new AssertionFailure( "Unsupported named query model. Please report the bug in Hibernate EntityManager");
|
||||
}
|
||||
|
||||
if ( queryReturns.length > 1 ) {
|
||||
throw new IllegalArgumentException( "Cannot create TypedQuery for query with more than one return" );
|
||||
}
|
||||
|
||||
final NativeSQLQueryReturn nativeSQLQueryReturn = queryReturns[0];
|
||||
|
||||
if ( nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn ) {
|
||||
final Class<?> actualReturnedClass;
|
||||
final String entityClassName = ( (NativeSQLQueryRootReturn) nativeSQLQueryReturn ).getReturnEntityName();
|
||||
try {
|
||||
actualReturnedClass = fastSessionServices.classLoaderService.classForName( entityClassName );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
throw new AssertionFailure(
|
||||
"Unable to load class [" + entityClassName + "] declared on named native query [" +
|
||||
namedQueryDefinition.getRegistrationName() + "]"
|
||||
);
|
||||
}
|
||||
if ( !resultType.isAssignableFrom( actualReturnedClass ) ) {
|
||||
throw buildIncompatibleException( resultType, actualReturnedClass );
|
||||
}
|
||||
}
|
||||
else if ( nativeSQLQueryReturn instanceof NativeSQLQueryConstructorReturn ) {
|
||||
final NativeSQLQueryConstructorReturn ctorRtn = (NativeSQLQueryConstructorReturn) nativeSQLQueryReturn;
|
||||
if ( !resultType.isAssignableFrom( ctorRtn.getTargetClass() ) ) {
|
||||
throw buildIncompatibleException( resultType, ctorRtn.getTargetClass() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.debugf( "Skiping unhandled NativeSQLQueryReturn type : " + nativeSQLQueryReturn );
|
||||
}
|
||||
}
|
||||
|
||||
private IllegalArgumentException buildIncompatibleException(Class<?> resultClass, Class<?> actualResultClass) {
|
||||
return new IllegalArgumentException(
|
||||
"Type specified for TypedQuery [" + resultClass.getName() +
|
||||
"] is incompatible with query return type [" + actualResultClass + "]"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultClass) {
|
||||
return buildQueryFromName( name, resultClass );
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// dynamic native (SQL) query handling
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor createNativeQuery(String sqlString) {
|
||||
return getNativeQueryImplementor( sqlString, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
NativeQueryImplementor query = createNativeQuery( sqlString );
|
||||
handleNativeQueryResult(query, resultClass);
|
||||
return query;
|
||||
}
|
||||
catch ( RuntimeException he ) {
|
||||
throw getExceptionConverter().convert( he );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNativeQueryResult(NativeQueryImplementor query, Class resultClass) {
|
||||
if ( Tuple.class.equals( resultClass ) ) {
|
||||
query.setResultTransformer( new NativeQueryTupleTransformer() );
|
||||
}
|
||||
else {
|
||||
query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMapping) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
NativeQueryImplementor query = createNativeQuery( sqlString );
|
||||
query.setResultSetMapping( resultSetMapping );
|
||||
return query;
|
||||
}
|
||||
catch ( RuntimeException he ) {
|
||||
throw getExceptionConverter().convert( he );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor getNamedNativeQuery(String name) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
final NamedNativeQueryMemento nativeQueryDefinition = factory.getQueryEngine().getNamedQueryRepository().getNativeQueryMemento( name );
|
||||
if ( nativeQueryDefinition != null ) {
|
||||
return createNativeQuery( nativeQueryDefinition, true );
|
||||
}
|
||||
|
||||
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + name + "]" ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor createSQLQuery(String queryString) {
|
||||
return getNativeQueryImplementor( queryString, true );
|
||||
}
|
||||
|
||||
protected NativeQueryImplementor getNativeQueryImplementor(
|
||||
String queryString,
|
||||
boolean isOrdinalParameterZeroBased) {
|
||||
|
@ -978,26 +658,130 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
NativeQueryImpl query = new NativeQueryImpl(
|
||||
queryString,
|
||||
false,
|
||||
this,
|
||||
getFactory().getQueryInterpretationCache().getSQLParameterMetadata( queryString, isOrdinalParameterZeroBased )
|
||||
);
|
||||
NativeQueryImpl query = new NativeQueryImpl( queryString, this );
|
||||
query.setComment( "dynamic native SQL query" );
|
||||
return query;
|
||||
}
|
||||
catch ( RuntimeException he ) {
|
||||
catch (RuntimeException he) {
|
||||
throw getExceptionConverter().convert( he );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
try {
|
||||
NativeQueryImplementor query = createNativeQuery( sqlString );
|
||||
query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
||||
return query;
|
||||
}
|
||||
catch (RuntimeException he) {
|
||||
throw getExceptionConverter().convert( he );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor getNamedSQLQuery(String name) {
|
||||
return getNamedNativeQuery( name );
|
||||
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMapping) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
final NativeQueryImplementor query;
|
||||
try {
|
||||
if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
|
||||
final ResultSetMappingDescriptor resultSetMappingDescriptor = getFactory().getQueryEngine()
|
||||
.getNamedQueryRepository()
|
||||
.getResultSetMappingDescriptor( resultSetMapping );
|
||||
|
||||
if ( resultSetMappingDescriptor == null ) {
|
||||
throw new HibernateException( "Could not resolve specified result-set mapping name : " + resultSetMapping );
|
||||
}
|
||||
|
||||
query = new NativeQueryImpl( sqlString, resultSetMappingDescriptor, this );
|
||||
}
|
||||
else {
|
||||
query = new NativeQueryImpl( sqlString, this );
|
||||
}
|
||||
}
|
||||
catch ( RuntimeException he ) {
|
||||
throw getExceptionConverter().convert( he );
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// named query handling
|
||||
|
||||
@Override
|
||||
public QueryImplementor getNamedQuery(String queryName) {
|
||||
return buildNamedQuery( queryName, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor createNamedQuery(String name) {
|
||||
return buildNamedQuery( name, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultClass) {
|
||||
return buildNamedQuery( name, resultClass );
|
||||
}
|
||||
|
||||
protected <T> QueryImplementor<T> buildNamedQuery(String queryName, Class<T> resultType) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
delayedAfterCompletion();
|
||||
|
||||
// this method can be called for either a named HQL query or a named native query
|
||||
|
||||
// first see if it is a named HQL query
|
||||
final NamedHqlQueryMemento namedHqlDescriptor = getFactory().getQueryEngine()
|
||||
.getNamedQueryRepository()
|
||||
.getHqlQueryMemento( queryName );
|
||||
|
||||
if ( namedHqlDescriptor != null ) {
|
||||
return namedHqlDescriptor.toQuery( this, resultType );
|
||||
}
|
||||
|
||||
// otherwise, see if it is a named native query
|
||||
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
|
||||
.getNamedQueryRepository()
|
||||
.getNativeQueryMemento( queryName );
|
||||
|
||||
if ( namedNativeDescriptor != null ) {
|
||||
return namedNativeDescriptor.toQuery( this, resultType );
|
||||
}
|
||||
|
||||
// todo (6.0) : allow this for named stored procedures as well?
|
||||
// ultimately they are treated as a Query
|
||||
|
||||
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) );
|
||||
}
|
||||
|
||||
protected void applyQuerySettingsAndHints(Query query) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NativeQueryImplementor getNamedNativeQuery(String queryName) {
|
||||
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
|
||||
.getNamedQueryRepository()
|
||||
.getNativeQueryMemento( queryName );
|
||||
|
||||
if ( namedNativeDescriptor != null ) {
|
||||
return namedNativeDescriptor.toQuery( this );
|
||||
}
|
||||
|
||||
throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
public ProcedureCall getNamedProcedureCall(String name) {
|
||||
|
@ -1014,6 +798,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
return procedureCall;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// dynamic ProcedureCall support
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
public ProcedureCall createStoredProcedureCall(String procedureName) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.hql.internal.HolderInstantiator;
|
||||
import org.hibernate.loader.Loader;
|
||||
|
|
|
@ -14,9 +14,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.hql.internal.HolderInstantiator;
|
||||
import org.hibernate.loader.Loader;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -31,6 +29,7 @@ import java.util.Set;
|
|||
import java.util.function.Supplier;
|
||||
import javax.persistence.CacheRetrieveMode;
|
||||
import javax.persistence.CacheStoreMode;
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.FlushModeType;
|
||||
|
@ -40,9 +39,11 @@ import javax.persistence.PessimisticLockScope;
|
|||
import javax.persistence.StoredProcedureQuery;
|
||||
import javax.persistence.TransactionRequiredException;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaDelete;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.CriteriaUpdate;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Filter;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -56,9 +57,7 @@ import org.hibernate.MultiIdentifierLoadAccess;
|
|||
import org.hibernate.NaturalIdLoadAccess;
|
||||
import org.hibernate.ObjectDeletedException;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.ReplicationMode;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionEventListener;
|
||||
import org.hibernate.SessionException;
|
||||
|
@ -71,29 +70,23 @@ import org.hibernate.TypeMismatchException;
|
|||
import org.hibernate.UnknownProfileException;
|
||||
import org.hibernate.UnresolvableObjectException;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.criterion.NaturalIdentifier;
|
||||
import org.hibernate.engine.internal.StatefulPersistenceContext;
|
||||
import org.hibernate.engine.jdbc.LobCreator;
|
||||
import org.hibernate.engine.jdbc.NonContextualLobCreator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.query.spi.FilterQueryPlan;
|
||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
||||
import org.hibernate.engine.query.spi.NativeSQLQueryPlan;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.ActionQueue;
|
||||
import org.hibernate.engine.spi.CollectionEntry;
|
||||
import org.hibernate.engine.spi.EffectiveEntityGraph;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.query.hql.internal.NamedHqlQueryMementoImpl;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.Status;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.engine.transaction.spi.TransactionObserver;
|
||||
import org.hibernate.event.spi.AutoFlushEvent;
|
||||
|
@ -132,9 +125,6 @@ import org.hibernate.graph.GraphSemantic;
|
|||
import org.hibernate.graph.RootGraph;
|
||||
import org.hibernate.graph.internal.RootGraphImpl;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.hql.spi.QueryTranslator;
|
||||
import org.hibernate.internal.CriteriaImpl.CriterionEntry;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.jdbc.WorkExecutor;
|
||||
|
@ -147,28 +137,25 @@ import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
|
|||
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
||||
import org.hibernate.jpa.internal.util.LockOptionsHelper;
|
||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
||||
import org.hibernate.loader.criteria.CriteriaLoader;
|
||||
import org.hibernate.loader.custom.CustomLoader;
|
||||
import org.hibernate.loader.custom.CustomQuery;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.param.CollectionFilterKeyParameterSpecification;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.MultiLoadOptions;
|
||||
import org.hibernate.persister.entity.OuterJoinLoadable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
|
||||
import org.hibernate.query.UnknownSqlResultSetMappingException;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.query.criteria.internal.compile.CompilableCriteria;
|
||||
import org.hibernate.query.criteria.internal.compile.CriteriaCompiler;
|
||||
import org.hibernate.query.criteria.internal.expression.CompoundSelectionImpl;
|
||||
import org.hibernate.query.UnknownSqlResultSetMappingException;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||
import org.hibernate.query.sqm.internal.QuerySqmImpl;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
|
||||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.resource.transaction.TransactionRequiredForJoinException;
|
||||
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
|
@ -1392,35 +1379,6 @@ public final class SessionImpl
|
|||
doFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List list(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
queryParameters.validateParameters();
|
||||
|
||||
HQLQueryPlan plan = queryParameters.getQueryPlan();
|
||||
if ( plan == null ) {
|
||||
plan = getQueryPlan( query, false );
|
||||
}
|
||||
|
||||
autoFlushIfRequired( plan.getQuerySpaces() );
|
||||
|
||||
final List results;
|
||||
boolean success = false;
|
||||
|
||||
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
|
||||
try {
|
||||
results = plan.performList( queryParameters, this );
|
||||
success = true;
|
||||
}
|
||||
finally {
|
||||
dontFlushFromFind--;
|
||||
afterOperation( success );
|
||||
delayedAfterCompletion();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
|
@ -1515,66 +1473,6 @@ public final class SessionImpl
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
queryParameters.validateParameters();
|
||||
|
||||
HQLQueryPlan plan = queryParameters.getQueryPlan();
|
||||
if ( plan == null ) {
|
||||
plan = getQueryPlan( query, true );
|
||||
}
|
||||
|
||||
autoFlushIfRequired( plan.getQuerySpaces() );
|
||||
|
||||
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
|
||||
try {
|
||||
return plan.performIterate( queryParameters, this );
|
||||
}
|
||||
finally {
|
||||
delayedAfterCompletion();
|
||||
dontFlushFromFind--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
|
||||
HQLQueryPlan plan = queryParameters.getQueryPlan();
|
||||
if ( plan == null ) {
|
||||
plan = getQueryPlan( query, false );
|
||||
}
|
||||
|
||||
autoFlushIfRequired( plan.getQuerySpaces() );
|
||||
|
||||
dontFlushFromFind++;
|
||||
try {
|
||||
return plan.performScroll( queryParameters, this );
|
||||
}
|
||||
finally {
|
||||
delayedAfterCompletion();
|
||||
dontFlushFromFind--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hibernate.query.Query createFilter(Object collection, String queryString) {
|
||||
checkOpen();
|
||||
pulseTransactionCoordinator();
|
||||
CollectionFilterImpl filter = new CollectionFilterImpl(
|
||||
queryString,
|
||||
collection,
|
||||
this,
|
||||
getFilterQueryPlan( collection, queryString, null, false ).getParameterMetadata()
|
||||
);
|
||||
filter.setComment( queryString );
|
||||
delayedAfterCompletion();
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object instantiate(String entityName, Serializable id) throws HibernateException {
|
||||
|
@ -1667,297 +1565,6 @@ public final class SessionImpl
|
|||
return ( (HibernateProxy) proxy ).getHibernateLazyInitializer().getIdentifier();
|
||||
}
|
||||
|
||||
private FilterQueryPlan getFilterQueryPlan(
|
||||
Object collection,
|
||||
String filter,
|
||||
QueryParameters parameters,
|
||||
boolean shallow) throws HibernateException {
|
||||
if ( collection == null ) {
|
||||
throw new NullPointerException( "null collection passed to filter" );
|
||||
}
|
||||
|
||||
CollectionEntry entry = persistenceContext.getCollectionEntryOrNull( collection );
|
||||
final CollectionPersister roleBeforeFlush = ( entry == null ) ? null : entry.getLoadedPersister();
|
||||
|
||||
FilterQueryPlan plan = null;
|
||||
final Map<String, Filter> enabledFilters = getLoadQueryInfluencers().getEnabledFilters();
|
||||
final SessionFactoryImplementor factory = getFactory();
|
||||
if ( roleBeforeFlush == null ) {
|
||||
// if it was previously unreferenced, we need to flush in order to
|
||||
// get its state into the database in order to execute query
|
||||
flush();
|
||||
entry = persistenceContext.getCollectionEntryOrNull( collection );
|
||||
CollectionPersister roleAfterFlush = ( entry == null ) ? null : entry.getLoadedPersister();
|
||||
if ( roleAfterFlush == null ) {
|
||||
throw new QueryException( "The collection was unreferenced" );
|
||||
}
|
||||
plan = factory.getQueryInterpretationCache().getFilterQueryPlan(
|
||||
filter,
|
||||
roleAfterFlush.getRole(),
|
||||
shallow,
|
||||
enabledFilters
|
||||
);
|
||||
}
|
||||
else {
|
||||
// otherwise, we only need to flush if there are in-memory changes
|
||||
// to the queried tables
|
||||
plan = factory.getQueryInterpretationCache().getFilterQueryPlan(
|
||||
filter,
|
||||
roleBeforeFlush.getRole(),
|
||||
shallow,
|
||||
enabledFilters
|
||||
);
|
||||
if ( autoFlushIfRequired( plan.getQuerySpaces() ) ) {
|
||||
// might need to run a different filter entirely after the flush
|
||||
// because the collection role may have changed
|
||||
entry = persistenceContext.getCollectionEntryOrNull( collection );
|
||||
CollectionPersister roleAfterFlush = ( entry == null ) ? null : entry.getLoadedPersister();
|
||||
if ( roleBeforeFlush != roleAfterFlush ) {
|
||||
if ( roleAfterFlush == null ) {
|
||||
throw new QueryException( "The collection was dereferenced" );
|
||||
}
|
||||
plan = factory.getQueryInterpretationCache().getFilterQueryPlan(
|
||||
filter,
|
||||
roleAfterFlush.getRole(),
|
||||
shallow,
|
||||
enabledFilters
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( parameters != null ) {
|
||||
parameters.getNamedParameters().put(
|
||||
CollectionFilterKeyParameterSpecification.PARAM_KEY,
|
||||
new TypedValue(
|
||||
entry.getLoadedPersister().getKeyType(),
|
||||
entry.getLoadedKey()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List listFilter(Object collection, String filter, QueryParameters queryParameters) {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, false );
|
||||
List results = Collections.EMPTY_LIST;
|
||||
|
||||
boolean success = false;
|
||||
dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called
|
||||
try {
|
||||
results = plan.performList( queryParameters, this );
|
||||
success = true;
|
||||
}
|
||||
finally {
|
||||
dontFlushFromFind--;
|
||||
afterOperation( success );
|
||||
delayedAfterCompletion();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
FilterQueryPlan plan = getFilterQueryPlan( collection, filter, queryParameters, true );
|
||||
Iterator itr = plan.performIterate( queryParameters, this );
|
||||
delayedAfterCompletion();
|
||||
return itr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(Class persistentClass, String alias) {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedLegacyCriteria();
|
||||
checkOpen();
|
||||
checkTransactionSynchStatus();
|
||||
return new CriteriaImpl( persistentClass.getName(), alias, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(String entityName, String alias) {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedLegacyCriteria();
|
||||
checkOpen();
|
||||
checkTransactionSynchStatus();
|
||||
return new CriteriaImpl( entityName, alias, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(Class persistentClass) {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedLegacyCriteria();
|
||||
checkOpen();
|
||||
checkTransactionSynchStatus();
|
||||
return new CriteriaImpl( persistentClass.getName(), this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Criteria createCriteria(String entityName) {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedLegacyCriteria();
|
||||
checkOpen();
|
||||
checkTransactionSynchStatus();
|
||||
return new CriteriaImpl( entityName, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
|
||||
// TODO: Is this guaranteed to always be CriteriaImpl?
|
||||
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
|
||||
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
pulseTransactionCoordinator();
|
||||
|
||||
String entityName = criteriaImpl.getEntityOrClassName();
|
||||
CriteriaLoader loader = new CriteriaLoader(
|
||||
getOuterJoinLoadable( entityName ),
|
||||
getFactory(),
|
||||
criteriaImpl,
|
||||
entityName,
|
||||
getLoadQueryInfluencers()
|
||||
);
|
||||
autoFlushIfRequired( loader.getQuerySpaces() );
|
||||
dontFlushFromFind++;
|
||||
try {
|
||||
return loader.scroll( this, scrollMode );
|
||||
}
|
||||
finally {
|
||||
delayedAfterCompletion();
|
||||
dontFlushFromFind--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List list(Criteria criteria) throws HibernateException {
|
||||
// TODO: Is this guaranteed to always be CriteriaImpl?
|
||||
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
|
||||
if ( criteriaImpl.getMaxResults() != null && criteriaImpl.getMaxResults() == 0 ) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteriaImpl );
|
||||
if ( naturalIdLoadAccess != null ) {
|
||||
// EARLY EXIT!
|
||||
return Arrays.asList( naturalIdLoadAccess.load() );
|
||||
}
|
||||
|
||||
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
// checkTransactionSynchStatus();
|
||||
|
||||
String[] implementors = getFactory().getMetamodel().getImplementors( criteriaImpl.getEntityOrClassName() );
|
||||
int size = implementors.length;
|
||||
|
||||
CriteriaLoader[] loaders = new CriteriaLoader[size];
|
||||
Set spaces = new HashSet();
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
|
||||
loaders[i] = new CriteriaLoader(
|
||||
getOuterJoinLoadable( implementors[i] ),
|
||||
getFactory(),
|
||||
criteriaImpl,
|
||||
implementors[i],
|
||||
getLoadQueryInfluencers()
|
||||
);
|
||||
|
||||
spaces.addAll( loaders[i].getQuerySpaces() );
|
||||
|
||||
}
|
||||
|
||||
autoFlushIfRequired( spaces );
|
||||
|
||||
List results = Collections.EMPTY_LIST;
|
||||
dontFlushFromFind++;
|
||||
boolean success = false;
|
||||
try {
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
final List currentResults = loaders[i].list( this );
|
||||
currentResults.addAll( results );
|
||||
results = currentResults;
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
finally {
|
||||
dontFlushFromFind--;
|
||||
afterOperation( success );
|
||||
delayedAfterCompletion();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the CriteriaImpl is a naturalId lookup that can be done via
|
||||
* NaturalIdLoadAccess
|
||||
*
|
||||
* @param criteria The criteria to check as a complete natural identifier lookup.
|
||||
*
|
||||
* @return A fully configured NaturalIdLoadAccess or null, if null is returned the standard CriteriaImpl execution
|
||||
* should be performed
|
||||
*/
|
||||
private NaturalIdLoadAccess tryNaturalIdLoadAccess(CriteriaImpl criteria) {
|
||||
// See if the criteria lookup is by naturalId
|
||||
if ( !criteria.isLookupByNaturalKey() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String entityName = criteria.getEntityOrClassName();
|
||||
final EntityPersister entityPersister = getFactory().getMetamodel().entityPersister( entityName );
|
||||
|
||||
// Verify the entity actually has a natural id, needed for legacy support as NaturalIdentifier criteria
|
||||
// queries did no natural id validation
|
||||
if ( !entityPersister.hasNaturalIdentifier() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Since isLookupByNaturalKey is true there can be only one CriterionEntry and getCriterion() will
|
||||
// return an instanceof NaturalIdentifier
|
||||
final CriterionEntry criterionEntry = criteria.iterateExpressionEntries().next();
|
||||
final NaturalIdentifier naturalIdentifier = (NaturalIdentifier) criterionEntry.getCriterion();
|
||||
|
||||
final Map<String, Object> naturalIdValues = naturalIdentifier.getNaturalIdValues();
|
||||
final int[] naturalIdentifierProperties = entityPersister.getNaturalIdentifierProperties();
|
||||
|
||||
// Verify the NaturalIdentifier criterion includes all naturalId properties, first check that the property counts match
|
||||
if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] propertyNames = entityPersister.getPropertyNames();
|
||||
final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );
|
||||
|
||||
// Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
|
||||
for ( int naturalIdentifierProperty : naturalIdentifierProperties ) {
|
||||
final String naturalIdProperty = propertyNames[naturalIdentifierProperty];
|
||||
final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );
|
||||
|
||||
if ( naturalIdValue == null ) {
|
||||
// A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
|
||||
return null;
|
||||
}
|
||||
|
||||
naturalIdLoader.using( naturalIdProperty, naturalIdValue );
|
||||
}
|
||||
|
||||
// Criteria query contains a valid naturalId, use the new API
|
||||
log.warn(
|
||||
"Session.byNaturalId(" + entityName
|
||||
+ ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria"
|
||||
);
|
||||
|
||||
return naturalIdLoader;
|
||||
}
|
||||
|
||||
private OuterJoinLoadable getOuterJoinLoadable(String entityName) throws MappingException {
|
||||
EntityPersister persister = getFactory().getMetamodel().entityPersister( entityName );
|
||||
if ( !( persister instanceof OuterJoinLoadable ) ) {
|
||||
throw new MappingException( "class persister is not OuterJoinLoadable: " + entityName );
|
||||
}
|
||||
return (OuterJoinLoadable) persister;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object object) {
|
||||
checkOpen();
|
||||
|
@ -2032,6 +1639,7 @@ public final class SessionImpl
|
|||
}
|
||||
|
||||
try {
|
||||
//noinspection RedundantClassCall
|
||||
if ( !HibernateProxy.class.isInstance( object ) && persistenceContext.getEntry( object ) == null ) {
|
||||
// check if it is an entity -> if not throw an exception (per JPA)
|
||||
try {
|
||||
|
@ -3577,16 +3185,53 @@ public final class SessionImpl
|
|||
return Collections.unmodifiableMap( properties );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initQueryFromNamedDefinition(Query query, NamedHqlQueryMementoImpl namedQueryDefinition) {
|
||||
super.initQueryFromNamedDefinition( query, namedQueryDefinition );
|
||||
|
||||
if ( namedQueryDefinition.getLockOptions() != null ) {
|
||||
if ( namedQueryDefinition.getLockOptions().getLockMode() != null ) {
|
||||
query.setLockMode(
|
||||
LockModeTypeHelper.getLockModeType( namedQueryDefinition.getLockOptions().getLockMode() )
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public <T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
return new QuerySqmImpl<>(
|
||||
"<criteria>",
|
||||
(SqmStatement) criteriaQuery,
|
||||
criteriaQuery.getResultType(),
|
||||
this
|
||||
);
|
||||
}
|
||||
catch ( RuntimeException e ) {
|
||||
throw exceptionConverter.convert( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor createQuery(CriteriaUpdate criteriaUpdate) {
|
||||
checkOpen();
|
||||
try {
|
||||
return new QuerySqmImpl<>(
|
||||
"<criteria>",
|
||||
(SqmUpdateStatement) criteriaUpdate,
|
||||
null,
|
||||
this
|
||||
);
|
||||
}
|
||||
catch ( RuntimeException e ) {
|
||||
throw exceptionConverter.convert( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryImplementor createQuery(CriteriaDelete criteriaDelete) {
|
||||
checkOpen();
|
||||
try {
|
||||
return new QuerySqmImpl<>(
|
||||
"<criteria>",
|
||||
(SqmDeleteStatement) criteriaDelete,
|
||||
null,
|
||||
this
|
||||
);
|
||||
}
|
||||
catch ( RuntimeException e ) {
|
||||
throw exceptionConverter.convert( e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3594,7 +3239,9 @@ public final class SessionImpl
|
|||
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
|
||||
checkOpen();
|
||||
try {
|
||||
final NamedCallableQueryMemento memento = getFactory().getNamedQueryRepository().getNamedProcedureCallMemento( name );
|
||||
final NamedCallableQueryMemento memento = getFactory().getQueryEngine()
|
||||
.getNamedQueryRepository()
|
||||
.getCallableQueryMemento( name );
|
||||
if ( memento == null ) {
|
||||
throw new IllegalArgumentException( "No @NamedStoredProcedureQuery was found with that name : " + name );
|
||||
}
|
||||
|
@ -3720,21 +3367,20 @@ public final class SessionImpl
|
|||
@Override
|
||||
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> rootType) {
|
||||
checkOpen();
|
||||
return new RootGraphImpl<T>( null, getMetamodel().entity( rootType ), getEntityManagerFactory() );
|
||||
return new RootGraphImpl<T>( null, getMetamodel().entity( rootType ), getEntityManagerFactory().getJpaMetamodel() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public RootGraphImplementor<?> createEntityGraph(String graphName) {
|
||||
checkOpen();
|
||||
final RootGraphImplementor named = getEntityManagerFactory().findEntityGraphByName( graphName );
|
||||
if ( named != null ) {
|
||||
return named.makeRootGraph( graphName, true );
|
||||
if ( named == null ) {
|
||||
return null;
|
||||
}
|
||||
return named;
|
||||
return named.makeRootGraph( graphName, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public RootGraphImplementor<?> getEntityGraph(String graphName) {
|
||||
checkOpen();
|
||||
final RootGraphImplementor named = getEntityManagerFactory().findEntityGraphByName( graphName );
|
||||
|
@ -3745,7 +3391,7 @@ public final class SessionImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public List getEntityGraphs(Class entityClass) {
|
||||
public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) {
|
||||
checkOpen();
|
||||
return getEntityManagerFactory().findEntityGraphsByType( entityClass );
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
|||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper;
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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.internal.util.collections;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
|
||||
/**
|
||||
* A collection of values that is simultaneously a List (ordered) and a Set (unique)
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings({"NullableProblems", "unused", "WeakerAccess"})
|
||||
public class UniqueList<E> extends AbstractList<E> implements Set<E>, List<E> {
|
||||
private final List<E> elements;
|
||||
|
||||
public UniqueList() {
|
||||
this( new ArrayList<>() );
|
||||
}
|
||||
|
||||
public UniqueList(List<E> elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public UniqueList(int size) {
|
||||
this.elements = CollectionHelper.arrayList( size );
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
return elements.get( index );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
if ( elements.contains( element ) ) {
|
||||
return;
|
||||
}
|
||||
elements.add( index, element );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return elements.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
return elements.listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
return elements.listIterator( index );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return elements.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("SuspiciousToArrayCall")
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return elements.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<E> spliterator() {
|
||||
return Spliterators.spliterator( this, Spliterator.ORDERED );
|
||||
}
|
||||
}
|
|
@ -9,15 +9,10 @@ package org.hibernate.jpa.spi;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.criteria.Selection;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.StaleStateException;
|
||||
import org.hibernate.ejb.HibernateEntityManager;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.query.criteria.internal.ValueHandlerFactory;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -107,27 +102,4 @@ public interface HibernateEntityManagerImplementor extends HibernateEntityManage
|
|||
*/
|
||||
Map<String, Class> getNamedParameterExplicitTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used during "compiling" a JPA criteria query.
|
||||
*
|
||||
* @param jpaqlString The criteria query rendered as a JPA QL string
|
||||
* @param resultClass The result type (the type expected in the result list)
|
||||
* @param selection The selection(s)
|
||||
* @param queryOptions The options to use to build the query.
|
||||
* @param <T> The query type
|
||||
*
|
||||
* @deprecated (since 5.2) this method form is used to construct a "compiled" representation of
|
||||
* a JPA Criteria query. However it assumes the old yucky implementation of "compilation" that
|
||||
* converted the Criteria into a HQL/JPQL string. In 6.0 that is re-written from scratch to
|
||||
* compile to SQM, and so this method would not be needed in 6.0
|
||||
*
|
||||
* @return The typed query
|
||||
*/
|
||||
@Deprecated
|
||||
<T> Query<T> createQuery(
|
||||
String jpaqlString,
|
||||
Class<T> resultClass,
|
||||
Selection selection,
|
||||
QueryOptions queryOptions);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ import org.hibernate.engine.spi.EntityUniqueKey;
|
|||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
@ -70,7 +69,6 @@ import org.hibernate.event.spi.PostLoadEvent;
|
|||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.event.spi.PreLoadEvent;
|
||||
import org.hibernate.event.spi.PreLoadEventListener;
|
||||
import org.hibernate.hql.internal.HolderInstantiator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.FetchingScrollableResultsImpl;
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.sql.SQLException;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.ScrollMode;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.CriteriaImpl;
|
||||
|
|
|
@ -9,12 +9,10 @@ package org.hibernate.loader.criteria;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -29,10 +27,7 @@ import org.hibernate.QueryException;
|
|||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.EnhancedProjection;
|
||||
import org.hibernate.criterion.ParameterInfoCollector;
|
||||
import org.hibernate.criterion.Projection;
|
||||
import org.hibernate.engine.query.spi.OrdinalParameterDescriptor;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.Session;
|
|||
import org.hibernate.cache.spi.QueryKey;
|
||||
import org.hibernate.cache.spi.QueryResultsCache;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.hql.internal.HolderInstantiator;
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.loader.custom.sql;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.param.ParameterBinder;
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.loader.custom.sql;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.param.ParameterBinder;
|
||||
|
|
|
@ -13,11 +13,12 @@ import java.util.Map;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.engine.query.spi.ParameterParser;
|
||||
import org.hibernate.query.sql.internal.ParameterParser;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.param.ParameterBinder;
|
||||
import org.hibernate.persister.collection.SQLLoadableCollection;
|
||||
import org.hibernate.persister.entity.SQLLoadable;
|
||||
import org.hibernate.query.sql.spi.ParameterRecognizer;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
|
@ -289,7 +290,7 @@ public class SQLQueryParser {
|
|||
return recognizer.result.toString();
|
||||
}
|
||||
|
||||
public static class ParameterSubstitutionRecognizer implements ParameterParser.Recognizer {
|
||||
public static class ParameterSubstitutionRecognizer implements ParameterRecognizer {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int jdbcPositionalParamCount;
|
||||
|
@ -348,9 +349,5 @@ public class SQLQueryParser {
|
|||
public List<ParameterBinder> getParameterValueBinders() {
|
||||
return paramValueBinders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,17 +9,14 @@ package org.hibernate.loader.entity;
|
|||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.loader.OuterJoinLoader;
|
||||
import org.hibernate.param.ParameterBinder;
|
||||
import org.hibernate.persister.entity.OuterJoinLoadable;
|
||||
import org.hibernate.transform.ResultTransformer;
|
||||
import org.hibernate.type.Type;
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.internal.BatchFetchQueueHelper;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.loader.Loader;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.hibernate.engine.spi.EntityEntry;
|
|||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.AssertionFailure;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.EffectiveEntityGraph;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.graph.GraphSemantic;
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.loader.Loader;
|
||||
import org.hibernate.loader.entity.UniqueEntityLoader;
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
|||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jdbc.spi.ResultSetWrapper;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.RowSelection;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue