Query hints - native query synchronized spaces
+ cleaned up unused contracts in `org.hibernate.query.sql`
This commit is contained in:
parent
0c674deda5
commit
bc4b0c9d08
|
@ -1,105 +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.engine.query.spi.sql;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
||||
/**
|
||||
* Represents a return defined as part of a native sql query which
|
||||
* names a collection role in the form {className}.{collectionRole}; it
|
||||
* is used in defining a custom sql query for loading an entity's
|
||||
* collection in non-fetching scenarios (i.e., loading the collection
|
||||
* itself as the "root" of the result).
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQueryCollectionReturn extends NativeSQLQueryNonScalarReturn {
|
||||
private final String ownerEntityName;
|
||||
private final String ownerProperty;
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* Construct a native-sql return representing a collection initializer
|
||||
*
|
||||
* @param alias The result alias
|
||||
* @param ownerEntityName The entity-name of the entity owning the collection
|
||||
* to be initialized.
|
||||
* @param ownerProperty The property name (on the owner) which represents
|
||||
* the collection to be initialized.
|
||||
* @param propertyResults Any user-supplied column->property mappings
|
||||
* @param lockMode The lock mode to apply to the collection.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public NativeSQLQueryCollectionReturn(
|
||||
String alias,
|
||||
String ownerEntityName,
|
||||
String ownerProperty,
|
||||
Map propertyResults,
|
||||
LockMode lockMode) {
|
||||
super( alias, propertyResults, lockMode );
|
||||
this.ownerEntityName = ownerEntityName;
|
||||
this.ownerProperty = ownerProperty;
|
||||
this.hashCode = determineHashCode();
|
||||
}
|
||||
|
||||
private int determineHashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + ( ownerEntityName != null ? ownerEntityName.hashCode() : 0 );
|
||||
result = 31 * result + ( ownerProperty != null ? ownerProperty.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class owning the collection.
|
||||
*
|
||||
* @return The class owning the collection.
|
||||
*/
|
||||
public String getOwnerEntityName() {
|
||||
return ownerEntityName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the property representing the collection from the {@link #getOwnerEntityName}.
|
||||
*
|
||||
* @return The name of the property representing the collection on the owner class.
|
||||
*/
|
||||
public String getOwnerProperty() {
|
||||
return ownerProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
if ( !super.equals( o ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQueryCollectionReturn that = (NativeSQLQueryCollectionReturn) o;
|
||||
|
||||
if ( ownerEntityName != null ? !ownerEntityName.equals( that.ownerEntityName ) : that.ownerEntityName != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( ownerProperty != null ? !ownerProperty.equals( that.ownerProperty ) : that.ownerProperty != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
|
@ -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.engine.query.spi.sql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes a {@link javax.persistence.ConstructorResult}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQueryConstructorReturn implements NativeSQLQueryReturn {
|
||||
private final Class targetClass;
|
||||
private final NativeSQLQueryScalarReturn[] columnReturns;
|
||||
|
||||
public NativeSQLQueryConstructorReturn(Class targetClass, List<NativeSQLQueryScalarReturn> columnReturns) {
|
||||
this.targetClass = targetClass;
|
||||
this.columnReturns = columnReturns.toArray( new NativeSQLQueryScalarReturn[ columnReturns.size() ] );
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
public NativeSQLQueryScalarReturn[] getColumnReturns() {
|
||||
return columnReturns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(final TraceLogger logger) {
|
||||
logger.writeLine( "Constructor[" );
|
||||
logger.writeLine( " targetClass=" + targetClass + "," );
|
||||
logger.writeLine( " columns=[" );
|
||||
|
||||
TraceLogger nestedLogger = new TraceLogger() {
|
||||
@Override
|
||||
public void writeLine(String traceLine) {
|
||||
logger.writeLine( " " + traceLine );
|
||||
}
|
||||
};
|
||||
|
||||
for ( NativeSQLQueryScalarReturn columnReturn : columnReturns ) {
|
||||
columnReturn.traceLog( nestedLogger );
|
||||
}
|
||||
|
||||
logger.writeLine( " ]" );
|
||||
logger.writeLine( "]" );
|
||||
}
|
||||
}
|
|
@ -1,100 +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.engine.query.spi.sql;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
||||
/**
|
||||
* Represents a return defined as part of a native sql query which
|
||||
* names a fetched role.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQueryJoinReturn extends NativeSQLQueryNonScalarReturn {
|
||||
private final String ownerAlias;
|
||||
private final String ownerProperty;
|
||||
private final int hashCode;
|
||||
/**
|
||||
* Construct a return descriptor representing some form of fetch.
|
||||
*
|
||||
* @param alias The result alias
|
||||
* @param ownerAlias The owner's result alias
|
||||
* @param ownerProperty The owner's property representing the thing to be fetched
|
||||
* @param propertyResults Any user-supplied column->property mappings
|
||||
* @param lockMode The lock mode to apply
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public NativeSQLQueryJoinReturn(
|
||||
String alias,
|
||||
String ownerAlias,
|
||||
String ownerProperty,
|
||||
Map propertyResults,
|
||||
LockMode lockMode) {
|
||||
super( alias, propertyResults, lockMode );
|
||||
this.ownerAlias = ownerAlias;
|
||||
this.ownerProperty = ownerProperty;
|
||||
this.hashCode = determineHashCode();
|
||||
}
|
||||
|
||||
private int determineHashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + ( ownerAlias != null ? ownerAlias.hashCode() : 0 );
|
||||
result = 31 * result + ( ownerProperty != null ? ownerProperty.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the alias of the owner of this fetched association.
|
||||
*
|
||||
* @return The owner's alias.
|
||||
*/
|
||||
public String getOwnerAlias() {
|
||||
return ownerAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the property name (relative to the owner) which maps to
|
||||
* the association to be fetched.
|
||||
*
|
||||
* @return The property name.
|
||||
*/
|
||||
public String getOwnerProperty() {
|
||||
return ownerProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
if ( !super.equals( o ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQueryJoinReturn that = (NativeSQLQueryJoinReturn) o;
|
||||
|
||||
if ( ownerAlias != null ? !ownerAlias.equals( that.ownerAlias ) : that.ownerAlias != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( ownerProperty != null ? !ownerProperty.equals( that.ownerProperty ) : that.ownerProperty != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
|
@ -1,128 +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.engine.query.spi.sql;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
|
||||
/**
|
||||
* Represents the base information for a non-scalar return defined as part of
|
||||
* a native sql query.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class NativeSQLQueryNonScalarReturn implements NativeSQLQueryReturn, Serializable {
|
||||
private final String alias;
|
||||
private final LockMode lockMode;
|
||||
private final Map<String,String[]> propertyResults = new HashMap<>();
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* Constructs some form of non-scalar return descriptor
|
||||
*
|
||||
* @param alias The result alias
|
||||
* @param propertyResults Any user-supplied column->property mappings
|
||||
* @param lockMode The lock mode to apply to the return.
|
||||
*/
|
||||
protected NativeSQLQueryNonScalarReturn(String alias, Map<String,String[]> propertyResults, LockMode lockMode) {
|
||||
this.alias = alias;
|
||||
if ( alias == null ) {
|
||||
throw new HibernateException("alias must be specified");
|
||||
}
|
||||
this.lockMode = lockMode;
|
||||
if ( propertyResults != null ) {
|
||||
this.propertyResults.putAll( propertyResults );
|
||||
}
|
||||
this.hashCode = determineHashCode();
|
||||
}
|
||||
|
||||
private int determineHashCode() {
|
||||
int result = alias != null ? alias.hashCode() : 0;
|
||||
result = 31 * result + ( getClass().getName().hashCode() );
|
||||
result = 31 * result + ( lockMode != null ? lockMode.hashCode() : 0 );
|
||||
result = 31 * result + propertyResults.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the defined result alias
|
||||
*
|
||||
* @return The result alias.
|
||||
*/
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the lock-mode to apply to this return
|
||||
*
|
||||
* @return The lock mode
|
||||
*/
|
||||
public LockMode getLockMode() {
|
||||
return lockMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user-supplied column->property mappings.
|
||||
*
|
||||
* @return The property mappings.
|
||||
*/
|
||||
public Map<String,String[]> getPropertyResultsMap() {
|
||||
return Collections.unmodifiableMap( propertyResults );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQueryNonScalarReturn that = (NativeSQLQueryNonScalarReturn) o;
|
||||
|
||||
if ( alias != null ? !alias.equals( that.alias ) : that.alias != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( lockMode != null ? !lockMode.equals( that.lockMode ) : that.lockMode != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( !propertyResults.equals( that.propertyResults ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(TraceLogger logger) {
|
||||
if ( NativeSQLQueryRootReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Entity(...)" );
|
||||
}
|
||||
else if ( NativeSQLQueryCollectionReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Collection(...)" );
|
||||
}
|
||||
else if ( NativeSQLQueryJoinReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Join(...)" );
|
||||
}
|
||||
else {
|
||||
logger.writeLine( getClass().getName() + "(...)" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +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.engine.query.spi.sql;
|
||||
|
||||
/**
|
||||
* Describes a return in a native SQL query.
|
||||
* <p/>
|
||||
* IMPL NOTE : implementations should be immutable as they are used as part of cache keys for result caching.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface NativeSQLQueryReturn {
|
||||
public static interface TraceLogger {
|
||||
public void writeLine(String traceLine);
|
||||
}
|
||||
|
||||
public void traceLog(TraceLogger logger);
|
||||
}
|
|
@ -1,90 +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.engine.query.spi.sql;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
||||
/**
|
||||
* Represents a return defined as part of a native sql query which
|
||||
* names a "root" entity. A root entity means it is explicitly a
|
||||
* "column" in the result, as opposed to a fetched relationship or role.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQueryRootReturn extends NativeSQLQueryNonScalarReturn {
|
||||
private final String returnEntityName;
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* Construct a return representing an entity returned at the root
|
||||
* of the result.
|
||||
*
|
||||
* @param alias The result alias
|
||||
* @param entityName The entity name.
|
||||
* @param lockMode The lock mode to apply
|
||||
*/
|
||||
public NativeSQLQueryRootReturn(String alias, String entityName, LockMode lockMode) {
|
||||
this( alias, entityName, null, lockMode );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param alias The result alias
|
||||
* @param entityName The entity name.
|
||||
* @param propertyResults Any user-supplied column->property mappings
|
||||
* @param lockMode The lock mode to apply
|
||||
*/
|
||||
public NativeSQLQueryRootReturn(String alias, String entityName, Map<String,String[]> propertyResults, LockMode lockMode) {
|
||||
super( alias, propertyResults, lockMode );
|
||||
this.returnEntityName = entityName;
|
||||
this.hashCode = determineHashCode();
|
||||
}
|
||||
|
||||
private int determineHashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + ( returnEntityName != null ? returnEntityName.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the entity to be returned.
|
||||
*
|
||||
* @return The entity name
|
||||
*/
|
||||
public String getReturnEntityName() {
|
||||
return returnEntityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! super.equals( o ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQueryRootReturn that = (NativeSQLQueryRootReturn) o;
|
||||
|
||||
if ( returnEntityName != null ? !returnEntityName.equals( that.returnEntityName ) : that.returnEntityName != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
|
@ -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.engine.query.spi.sql;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Describes a scalar return in a native SQL query.
|
||||
*
|
||||
* @author gloegl
|
||||
*/
|
||||
public class NativeSQLQueryScalarReturn implements NativeSQLQueryReturn {
|
||||
private final BasicDomainType type;
|
||||
private final String columnAlias;
|
||||
private final int hashCode;
|
||||
|
||||
public NativeSQLQueryScalarReturn(String alias, BasicDomainType type) {
|
||||
this.type = type;
|
||||
this.columnAlias = alias;
|
||||
this.hashCode = determineHashCode();
|
||||
}
|
||||
|
||||
private int determineHashCode() {
|
||||
int result = type != null ? type.hashCode() : 0;
|
||||
result = 31 * result + ( getClass().getName().hashCode() );
|
||||
result = 31 * result + ( columnAlias != null ? columnAlias.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getColumnAlias() {
|
||||
return columnAlias;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return (Type) type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQueryScalarReturn that = (NativeSQLQueryScalarReturn) o;
|
||||
if ( columnAlias != null ? !columnAlias.equals( that.columnAlias ) : that.columnAlias != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( type != null ? !type.equals( that.type ) : that.type != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(TraceLogger logger) {
|
||||
logger.writeLine( "Scalar[" );
|
||||
logger.writeLine( " columnAlias=" + columnAlias + "," );
|
||||
logger.writeLine( " type=" + ( type == null ? "<unknown>" : type.getTypeName() ) + "," );
|
||||
logger.writeLine( "]" );
|
||||
}
|
||||
}
|
|
@ -1,86 +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.engine.query.spi.sql;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
|
||||
/**
|
||||
* Defines the specification or blue-print for a native-sql query.
|
||||
* Essentially a simple struct containing the information needed to "translate"
|
||||
* a native-sql query and cache that translated representation. Also used as
|
||||
* the key by which the native-sql query plans are cached.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NativeSQLQuerySpecification {
|
||||
private final String queryString;
|
||||
private final NativeSQLQueryReturn[] queryReturns;
|
||||
private final Set querySpaces;
|
||||
private final int hashCode;
|
||||
|
||||
public NativeSQLQuerySpecification(
|
||||
String queryString,
|
||||
NativeSQLQueryReturn[] queryReturns,
|
||||
Collection querySpaces) {
|
||||
this.queryString = queryString;
|
||||
this.queryReturns = queryReturns;
|
||||
if ( querySpaces == null ) {
|
||||
this.querySpaces = Collections.EMPTY_SET;
|
||||
}
|
||||
else {
|
||||
Set tmp = new HashSet( querySpaces );
|
||||
this.querySpaces = Collections.unmodifiableSet( tmp );
|
||||
}
|
||||
|
||||
// pre-determine and cache the hashcode
|
||||
int hashCode = queryString.hashCode();
|
||||
hashCode = 29 * hashCode + this.querySpaces.hashCode();
|
||||
if ( this.queryReturns != null ) {
|
||||
hashCode = 29 * hashCode + ArrayHelper.toList( this.queryReturns ).hashCode();
|
||||
}
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
return queryString;
|
||||
}
|
||||
|
||||
public NativeSQLQueryReturn[] getQueryReturns() {
|
||||
return queryReturns;
|
||||
}
|
||||
|
||||
public Set getQuerySpaces() {
|
||||
return querySpaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQuerySpecification that = (NativeSQLQuerySpecification) o;
|
||||
|
||||
return querySpaces.equals( that.querySpaces )
|
||||
&& queryString.equals( that.queryString )
|
||||
&& Arrays.equals( queryReturns, that.queryReturns );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
|
@ -47,7 +47,6 @@ import org.hibernate.engine.jdbc.LobCreator;
|
|||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.jdbc.ReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
|
@ -55,7 +54,6 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||
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;
|
||||
|
@ -191,16 +189,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
|
|||
return delegate.instantiate( entityName, id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.list( spec, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException {
|
||||
return delegate.scroll( spec, queryParameters );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDontFlushFromFind() {
|
||||
return delegate.getDontFlushFromFind();
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.engine.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.FlushModeType;
|
||||
|
@ -26,11 +24,9 @@ import org.hibernate.collection.spi.PersistentCollection;
|
|||
import org.hibernate.engine.jdbc.LobCreationContext;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.query.spi.QueryProducerImplementor;
|
||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder.Options;
|
||||
|
@ -326,31 +322,6 @@ public interface SharedSessionContractImplementor
|
|||
*/
|
||||
Object instantiate(EntityPersister persister, Object id) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a native SQL query, and return the results as a fully built list.
|
||||
*
|
||||
* @param spec The specification of the native SQL query to execute.
|
||||
* @param queryParameters The parameters by which to perform the execution.
|
||||
*
|
||||
* @return The result list.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a native SQL query, and return the results as a scrollable result.
|
||||
*
|
||||
* @param spec The specification of the native SQL query to execute.
|
||||
* @param queryParameters The parameters by which to perform the execution.
|
||||
*
|
||||
* @return The resulting scrollable result.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters);
|
||||
|
||||
int getDontFlushFromFind();
|
||||
|
||||
boolean isDefaultReadOnly();
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.SessionEventListener;
|
||||
import org.hibernate.SessionException;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -43,7 +42,6 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.ExceptionConverter;
|
||||
import org.hibernate.engine.spi.QueryParameters;
|
||||
import org.hibernate.engine.spi.SessionEventListenerManager;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
@ -67,7 +65,6 @@ import org.hibernate.query.named.NamedResultSetMappingMemento;
|
|||
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;
|
||||
|
@ -910,18 +907,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
|
||||
protected abstract Object load(String entityName, Object identifier);
|
||||
|
||||
@Override
|
||||
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
|
||||
// return listCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) {
|
||||
// return scrollCustomQuery( getNativeQueryPlan( spec ).getCustomQuery(), queryParameters );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExceptionConverter getExceptionConverter() {
|
||||
if ( exceptionConverter == null ) {
|
||||
|
|
|
@ -87,6 +87,7 @@ import static org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE;
|
|||
import static org.hibernate.jpa.QueryHints.HINT_FLUSH_MODE;
|
||||
import static org.hibernate.jpa.QueryHints.HINT_FOLLOW_ON_LOCKING;
|
||||
import static org.hibernate.jpa.QueryHints.HINT_LOADGRAPH;
|
||||
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_SPACES;
|
||||
import static org.hibernate.jpa.QueryHints.HINT_READONLY;
|
||||
import static org.hibernate.jpa.QueryHints.HINT_TIMEOUT;
|
||||
import static org.hibernate.jpa.QueryHints.SPEC_HINT_TIMEOUT;
|
||||
|
@ -511,6 +512,9 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
|||
else if ( HINT_FOLLOW_ON_LOCKING.equals( hintName ) ) {
|
||||
applied = applyFollowOnLockingHint( ConfigurationHelper.getBoolean( value ) );
|
||||
}
|
||||
else if ( HINT_NATIVE_SPACES.equals( hintName ) ) {
|
||||
applied = applySynchronizeSpacesHint( value );
|
||||
}
|
||||
else {
|
||||
log.ignoringUnrecognizedQueryHint( hintName );
|
||||
}
|
||||
|
@ -554,6 +558,10 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean applySynchronizeSpacesHint(Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the query timeout hint.
|
||||
*
|
||||
|
|
|
@ -935,6 +935,43 @@ public class NativeQueryImpl<R>
|
|||
putIfNotNull( hints, HINT_NATIVE_LOCKMODE, getLockOptions().getLockMode() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applySynchronizeSpacesHint(Object value) {
|
||||
if ( value instanceof String ) {
|
||||
addSynchronizedQuerySpace( (String) value );
|
||||
}
|
||||
else if ( value instanceof String[] ) {
|
||||
final String[] strings = (String[]) value;
|
||||
for ( int i = 0; i < strings.length; i++ ) {
|
||||
addSynchronizedQuerySpace( strings[i] );
|
||||
}
|
||||
}
|
||||
else if ( value instanceof Class ) {
|
||||
addSynchronizedEntityClass( (Class<?>) value );
|
||||
}
|
||||
else if ( value instanceof Class[] ) {
|
||||
final Class<?>[] classes = (Class<?>[]) value;
|
||||
for ( int i = 0; i < classes.length; i++ ) {
|
||||
addSynchronizedEntityClass( classes[i] );
|
||||
}
|
||||
}
|
||||
else if ( value instanceof List ) {
|
||||
final List<?> list = (List<?>) value;
|
||||
list.forEach( this::applySynchronizeSpacesHint );
|
||||
}
|
||||
else if ( value instanceof Collection ) {
|
||||
final Collection<?> values = (Collection<?>) value;
|
||||
for ( Object element : values ) {
|
||||
applySynchronizeSpacesHint( element );
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyNativeQueryLockMode(Object value) {
|
||||
if ( value instanceof LockMode ) {
|
||||
|
|
|
@ -509,6 +509,11 @@ public class QuerySqmImpl<R>
|
|||
);
|
||||
}
|
||||
|
||||
protected boolean applySynchronizeSpacesHint(Object value) {
|
||||
throw new IllegalStateException(
|
||||
"Illegal attempt to set synchronized spaces on non-native query via hint"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectHints(Map<String, Object> hints) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* 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>.
|
||||
* 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.test.query.sql;
|
||||
package org.hibernate.orm.test.query.sql;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -61,13 +61,13 @@ public class SynchronizedSpaceTests extends BaseNonConfigCoreFunctionalTestCase
|
|||
|
||||
private void checkUseCase(
|
||||
String table,
|
||||
Consumer<Query> queryConsumer,
|
||||
Consumer<Query> updateQueryConfigurer,
|
||||
boolean shouldExistAfter) {
|
||||
|
||||
checkUseCase(
|
||||
(session) -> {
|
||||
final Query nativeQuery = session.createNativeQuery( "update " + table + " set name = 'updated'" );
|
||||
queryConsumer.accept( nativeQuery );
|
||||
updateQueryConfigurer.accept( nativeQuery );
|
||||
return nativeQuery;
|
||||
},
|
||||
Query::executeUpdate,
|
|
@ -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.test.queryplan;
|
||||
|
||||
|
||||
/**
|
||||
* Leaf subclass
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Customer extends User {
|
||||
private String company;
|
||||
|
||||
protected Customer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Customer(String name, char sex, String username, String company) {
|
||||
super( name, sex, username );
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
}
|
|
@ -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.test.queryplan;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Leaf subclass
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Employee extends User {
|
||||
private Date hireDate;
|
||||
|
||||
protected Employee() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Employee(String name, char sex, String username, Date hireDate) {
|
||||
super( name, sex, username );
|
||||
this.hireDate = hireDate;
|
||||
}
|
||||
|
||||
public Date getHireDate() {
|
||||
return hireDate;
|
||||
}
|
||||
|
||||
public void setHireDate(Date hireDate) {
|
||||
this.hireDate = hireDate;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping
|
||||
SYSTEM
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.queryplan">
|
||||
<class name="Person" table="FILTER_HQL_JOINED_PERSON">
|
||||
<id column="ID" name="id" type="long">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<property name="name" type="string"/>
|
||||
<property name="sex" column="SEX_CODE" type="char"/>
|
||||
<joined-subclass name="User" table="FILTER_HQL_JOINED_USER">
|
||||
<key column="USER_ID"/>
|
||||
<property name="username" type="string"/>
|
||||
<joined-subclass name="Employee" table="FILTER_HQL_JOINED_EMP">
|
||||
<key column="EMP_ID"/>
|
||||
<property name="hireDate" type="date"/>
|
||||
</joined-subclass>
|
||||
<joined-subclass name="Customer" table="FILTER_HQL_JOINED_CUST">
|
||||
<key column="CUST_ID"/>
|
||||
<property name="company" type="string"/>
|
||||
</joined-subclass>
|
||||
</joined-subclass>
|
||||
<filter name="sex"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -1,265 +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.test.queryplan;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryCollectionReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryJoinReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn;
|
||||
import org.hibernate.type.BasicType;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests equals() and hashCode() for NativeSQLQueryReturn implementations.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class NativeSQLQueryReturnEqualsAndHashCodeTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSQLQueryScalarReturn() {
|
||||
NativeSQLQueryScalarReturn typeNoAlias = new NativeSQLQueryScalarReturn( null, basicType( "int" ) );
|
||||
NativeSQLQueryScalarReturn aliasNoType = new NativeSQLQueryScalarReturn( "abc", null );
|
||||
NativeSQLQueryScalarReturn aliasTypeInt = new NativeSQLQueryScalarReturn( "abc", basicType( "int" ) );
|
||||
NativeSQLQueryScalarReturn aliasTypeLong = new NativeSQLQueryScalarReturn( "abc", basicType( "long" ) );
|
||||
NativeSQLQueryScalarReturn aliasTypeLongClass = new NativeSQLQueryScalarReturn( "abc", basicType( Long.class.getName() ) );
|
||||
NativeSQLQueryScalarReturn aliasTypeString = new NativeSQLQueryScalarReturn( "abc", basicType( "string" ) );
|
||||
NativeSQLQueryScalarReturn aliasTypeStringClass = new NativeSQLQueryScalarReturn( "abc", basicType( String.class.getName() ) );
|
||||
|
||||
check( false, typeNoAlias, aliasNoType );
|
||||
check( false, typeNoAlias, aliasTypeInt );
|
||||
check( false, typeNoAlias, aliasTypeLong );
|
||||
check( false, typeNoAlias, aliasTypeLongClass );
|
||||
check( false, typeNoAlias, aliasTypeString );
|
||||
check( false, typeNoAlias, aliasTypeStringClass );
|
||||
|
||||
check( false, aliasNoType, aliasTypeInt );
|
||||
check( false, aliasNoType, aliasTypeLong );
|
||||
check( false, aliasNoType, aliasTypeLongClass );
|
||||
check( false, aliasNoType, aliasTypeString );
|
||||
check( false, aliasNoType, aliasTypeStringClass );
|
||||
|
||||
check( false, aliasTypeInt, aliasTypeLong );
|
||||
check( false, aliasTypeInt, aliasTypeLongClass );
|
||||
check( false, aliasTypeInt, aliasTypeString );
|
||||
check( false, aliasTypeInt, aliasTypeStringClass );
|
||||
|
||||
check( true, aliasTypeLong, aliasTypeLongClass );
|
||||
check( false, aliasTypeLong, aliasTypeString );
|
||||
check( false, aliasTypeLong, aliasTypeStringClass );
|
||||
|
||||
check( false, aliasTypeLongClass, aliasTypeString );
|
||||
check( false, aliasTypeLongClass, aliasTypeStringClass );
|
||||
|
||||
check( true, aliasTypeString, aliasTypeStringClass );
|
||||
|
||||
check( true, typeNoAlias, new NativeSQLQueryScalarReturn( null, basicType( "int" ) ) );
|
||||
check( true, aliasNoType, new NativeSQLQueryScalarReturn( "abc", null ) );
|
||||
check( true, aliasTypeInt, new NativeSQLQueryScalarReturn( "abc", basicType( "int" ) ) );
|
||||
check( true, aliasTypeLong, new NativeSQLQueryScalarReturn( "abc", basicType( "long" ) ) );
|
||||
check( true, aliasTypeLongClass, new NativeSQLQueryScalarReturn( "abc", basicType( Long.class.getName() ) ) );
|
||||
check( true, aliasTypeString, new NativeSQLQueryScalarReturn( "abc", basicType( "string" ) ) );
|
||||
check( true, aliasTypeStringClass, new NativeSQLQueryScalarReturn( "abc", basicType( String.class.getName() ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSQLQueryRootReturn() {
|
||||
NativeSQLQueryRootReturn alias = new NativeSQLQueryRootReturn( "abc", null, null);
|
||||
NativeSQLQueryRootReturn diffAlias = new NativeSQLQueryRootReturn( "def", null, null);
|
||||
NativeSQLQueryRootReturn aliasEntityName = new NativeSQLQueryRootReturn( "abc", "Person", null);
|
||||
NativeSQLQueryRootReturn aliasDiffEntityName = new NativeSQLQueryRootReturn( "abc", "Customer", null);
|
||||
NativeSQLQueryRootReturn aliasEntityNameLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE );
|
||||
NativeSQLQueryRootReturn aliasEntityNameDiffLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC );
|
||||
|
||||
check( false, alias, diffAlias );
|
||||
check( false, alias, aliasEntityName );
|
||||
check( false, alias, aliasDiffEntityName );
|
||||
check( false, alias, aliasEntityNameLockMode );
|
||||
check( false, alias, aliasEntityNameDiffLockMode );
|
||||
|
||||
check( false, diffAlias, aliasEntityName );
|
||||
check( false, diffAlias, aliasDiffEntityName );
|
||||
check( false, diffAlias, aliasEntityNameLockMode );
|
||||
check( false, diffAlias, aliasEntityNameDiffLockMode );
|
||||
|
||||
check( false, aliasEntityName, aliasDiffEntityName );
|
||||
check( false, aliasEntityName, aliasEntityNameLockMode );
|
||||
check( false, aliasEntityName, aliasEntityNameDiffLockMode );
|
||||
|
||||
check( false, aliasDiffEntityName, aliasEntityNameLockMode );
|
||||
check( false, aliasDiffEntityName, aliasEntityNameDiffLockMode );
|
||||
|
||||
check( false, aliasEntityNameLockMode, aliasEntityNameDiffLockMode );
|
||||
|
||||
check( true, alias, new NativeSQLQueryRootReturn( "abc", null, null) );
|
||||
check( true, diffAlias, new NativeSQLQueryRootReturn( "def", null, null) );
|
||||
check( true, aliasEntityName, new NativeSQLQueryRootReturn( "abc", "Person", null) );
|
||||
check( true, aliasDiffEntityName, new NativeSQLQueryRootReturn( "abc", "Customer", null) );
|
||||
check( true, aliasEntityNameLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE ) );
|
||||
check( true, aliasEntityNameDiffLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSQLQueryJoinReturn() {
|
||||
NativeSQLQueryJoinReturn r1 = new NativeSQLQueryJoinReturn( "a", "b", "c", null, null);
|
||||
NativeSQLQueryJoinReturn r2 = new NativeSQLQueryJoinReturn( "a", "c", "b", null, null);
|
||||
NativeSQLQueryJoinReturn r3NullMap = new NativeSQLQueryJoinReturn( "b", "c", "a", null, null);
|
||||
NativeSQLQueryJoinReturn r3EmptyMap= new NativeSQLQueryJoinReturn( "b", "c", "a", new HashMap(), null);
|
||||
NativeSQLQueryJoinReturn r4 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null);
|
||||
NativeSQLQueryJoinReturn r5 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null);
|
||||
NativeSQLQueryJoinReturn r6 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE );
|
||||
NativeSQLQueryJoinReturn r7 = new NativeSQLQueryJoinReturn( "b", "c", "a", null, LockMode.NONE );
|
||||
|
||||
check( false, r1, r2 );
|
||||
check( false, r1, r3NullMap );
|
||||
check( false, r1, r3EmptyMap );
|
||||
check( false, r1, r4 );
|
||||
check( false, r1, r5 );
|
||||
check( false, r1, r6 );
|
||||
check( false, r1, r7 );
|
||||
|
||||
check( false, r2, r3NullMap );
|
||||
check( false, r2, r3EmptyMap );
|
||||
check( false, r2, r4 );
|
||||
check( false, r2, r5 );
|
||||
check( false, r2, r6 );
|
||||
check( false, r2, r7 );
|
||||
|
||||
check( true, r3NullMap, r3EmptyMap );
|
||||
check( false, r3NullMap, r4 );
|
||||
check( false, r3NullMap, r5 );
|
||||
check( false, r3NullMap, r6 );
|
||||
check( false, r3NullMap, r7 );
|
||||
|
||||
check( false, r3EmptyMap, r4 );
|
||||
check( false, r3EmptyMap, r5 );
|
||||
check( false, r3EmptyMap, r6 );
|
||||
check( false, r3EmptyMap, r7 );
|
||||
|
||||
check( false, r4, r5 );
|
||||
check( false, r4, r6 );
|
||||
check( false, r4, r7 );
|
||||
|
||||
check( false, r5, r6 );
|
||||
check( false, r5, r7 );
|
||||
|
||||
check( false, r6, r7 );
|
||||
|
||||
check( true, r1, new NativeSQLQueryJoinReturn( "a", "b", "c", null, null) );
|
||||
check( true, r2, new NativeSQLQueryJoinReturn( "a", "c", "b", null, null) );
|
||||
check( true, r3NullMap, new NativeSQLQueryJoinReturn( "b", "c", "a", null, null) );
|
||||
check( true, r3EmptyMap, new NativeSQLQueryJoinReturn( "b", "c", "a", new HashMap(), null) );
|
||||
check( true, r4, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null) );
|
||||
check( true, r5, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null) );
|
||||
check( true, r6, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE ) );
|
||||
check( true, r7, new NativeSQLQueryJoinReturn( "b", "c", "a", null, LockMode.NONE ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSQLQueryCollectionReturn() {
|
||||
NativeSQLQueryCollectionReturn r1 = new NativeSQLQueryCollectionReturn( "a", "b", "c", null, null);
|
||||
NativeSQLQueryCollectionReturn r2 = new NativeSQLQueryCollectionReturn( "a", "c", "b", null, null);
|
||||
NativeSQLQueryCollectionReturn r3NullMap = new NativeSQLQueryCollectionReturn( "b", "c", "a", null, null);
|
||||
NativeSQLQueryCollectionReturn r3EmptyMap= new NativeSQLQueryCollectionReturn( "b", "c", "a", new HashMap(), null);
|
||||
NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null);
|
||||
NativeSQLQueryCollectionReturn r5 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null);
|
||||
NativeSQLQueryCollectionReturn r6 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE );
|
||||
NativeSQLQueryCollectionReturn r7 = new NativeSQLQueryCollectionReturn( "b", "c", "a", null, LockMode.NONE );
|
||||
|
||||
check( false, r1, r2 );
|
||||
check( false, r1, r3NullMap );
|
||||
check( false, r1, r3EmptyMap );
|
||||
check( false, r1, r4 );
|
||||
check( false, r1, r5 );
|
||||
check( false, r1, r6 );
|
||||
check( false, r1, r7 );
|
||||
|
||||
check( false, r2, r3NullMap );
|
||||
check( false, r2, r3EmptyMap );
|
||||
check( false, r2, r4 );
|
||||
check( false, r2, r5 );
|
||||
check( false, r2, r6 );
|
||||
check( false, r2, r7 );
|
||||
|
||||
check( true, r3NullMap, r3EmptyMap );
|
||||
check( false, r3NullMap, r4 );
|
||||
check( false, r3NullMap, r5 );
|
||||
check( false, r3NullMap, r6 );
|
||||
check( false, r3NullMap, r7 );
|
||||
|
||||
check( false, r3EmptyMap, r4 );
|
||||
check( false, r3EmptyMap, r5 );
|
||||
check( false, r3EmptyMap, r6 );
|
||||
check( false, r3EmptyMap, r7 );
|
||||
|
||||
check( false, r4, r5 );
|
||||
check( false, r4, r6 );
|
||||
check( false, r4, r7 );
|
||||
|
||||
check( false, r5, r6 );
|
||||
check( false, r5, r7 );
|
||||
|
||||
check( false, r6, r7 );
|
||||
|
||||
check( true, r1, new NativeSQLQueryCollectionReturn( "a", "b", "c", null, null) );
|
||||
check( true, r2, new NativeSQLQueryCollectionReturn( "a", "c", "b", null, null) );
|
||||
check( true, r3NullMap, new NativeSQLQueryCollectionReturn( "b", "c", "a", null, null) );
|
||||
check( true, r3EmptyMap, new NativeSQLQueryCollectionReturn( "b", "c", "a", new HashMap(), null) );
|
||||
check( true, r4, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null) );
|
||||
check( true, r5, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null) );
|
||||
check( true, r6, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE ) );
|
||||
check( true, r7, new NativeSQLQueryCollectionReturn( "b", "c", "a", null, LockMode.NONE ) );
|
||||
}
|
||||
|
||||
private BasicType<?> basicType(String registeredName) {
|
||||
return sessionFactory().getTypeConfiguration().getBasicTypeRegistry().getRegisteredType( registeredName );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeSQLQueryReturnTypes() {
|
||||
NativeSQLQueryScalarReturn r1 = new NativeSQLQueryScalarReturn( "a", basicType( "int" ) );
|
||||
NativeSQLQueryRootReturn r2 = new NativeSQLQueryRootReturn( "a", "b", LockMode.NONE );
|
||||
NativeSQLQueryJoinReturn r3 = new NativeSQLQueryJoinReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE );
|
||||
NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE);
|
||||
|
||||
check( false, r1, r2 );
|
||||
check( false, r1, r3 );
|
||||
check( false, r1, r4 );
|
||||
|
||||
check( false, r2, r3 );
|
||||
check( false, r2, r4 );
|
||||
|
||||
check( false, r3, r4 );
|
||||
}
|
||||
|
||||
private void check(boolean expectedEquals, NativeSQLQueryReturn queryReturn1, NativeSQLQueryReturn queryReturn2) {
|
||||
if ( expectedEquals ) {
|
||||
assertTrue( queryReturn1.equals( queryReturn2 ) );
|
||||
assertTrue( queryReturn2.equals( queryReturn1 ) );
|
||||
assertTrue( queryReturn1.hashCode() == queryReturn2.hashCode() );
|
||||
}
|
||||
else {
|
||||
assertFalse( queryReturn1.equals( queryReturn2 ) );
|
||||
assertFalse( queryReturn2.equals( queryReturn1 ) );
|
||||
assertFalse( queryReturn1.hashCode() == queryReturn2.hashCode() );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.test.queryplan;
|
||||
|
||||
|
||||
/**
|
||||
* Base of inheritence hierarchy
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Person {
|
||||
private Long id;
|
||||
private String name;
|
||||
private char sex;
|
||||
|
||||
/**
|
||||
* Used by persistence
|
||||
*/
|
||||
protected Person() {
|
||||
}
|
||||
|
||||
public Person(String name, char sex) {
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public char getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(char sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
}
|
|
@ -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.test.queryplan;
|
||||
|
||||
|
||||
/**
|
||||
* Non-leaf subclass
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class User extends Person {
|
||||
private String username;
|
||||
|
||||
protected User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(String name, char sex, String username) {
|
||||
super( name, sex );
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping
|
||||
SYSTEM
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.queryplan">
|
||||
<filter-def name="sex" condition="SEX_CODE = :sexCode">
|
||||
<filter-param name="sexCode" type="char"/>
|
||||
</filter-def>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue