HHH-8774 : Add Javadoc for load plans
This commit is contained in:
parent
c901e5f951
commit
eb5f605068
|
@ -40,9 +40,7 @@ import org.hibernate.loader.plan.build.spi.MetamodelDrivenLoadPlanBuilder;
|
|||
import org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader;
|
||||
import org.hibernate.loader.plan.exec.internal.BatchingLoadQueryDetailsFactory;
|
||||
import org.hibernate.loader.plan.exec.query.spi.QueryBuildingParameters;
|
||||
import org.hibernate.loader.plan.exec.internal.BasicCollectionLoadQueryDetails;
|
||||
import org.hibernate.loader.plan.exec.spi.LoadQueryDetails;
|
||||
import org.hibernate.loader.plan.exec.internal.OneToManyLoadQueryDetails;
|
||||
import org.hibernate.loader.plan.spi.LoadPlan;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
|
|
@ -26,6 +26,11 @@ package org.hibernate.loader.plan.build.spi;
|
|||
import org.hibernate.loader.plan.spi.CollectionQuerySpace;
|
||||
|
||||
/**
|
||||
* Describes a collection query space that allows adding joins with other
|
||||
* query spaces; used while building a {@link CollectionQuerySpace}.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.Join
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface ExpandingCollectionQuerySpace extends CollectionQuerySpace, ExpandingQuerySpace {
|
||||
|
|
|
@ -26,6 +26,11 @@ package org.hibernate.loader.plan.build.spi;
|
|||
import org.hibernate.loader.plan.spi.CompositeQuerySpace;
|
||||
|
||||
/**
|
||||
* Describes a composite query space that allows adding joins with other
|
||||
* query spaces; used while building a {@link CompositeQuerySpace}.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.Join
|
||||
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface ExpandingCompositeQuerySpace extends CompositeQuerySpace, ExpandingQuerySpace {
|
||||
|
|
|
@ -26,6 +26,9 @@ package org.hibernate.loader.plan.build.spi;
|
|||
import org.hibernate.loader.plan.spi.EntityIdentifierDescription;
|
||||
|
||||
/**
|
||||
* Describes an entity identifier description that allows adding fetches; used while
|
||||
* building a {@link EntityIdentifierDescription}.
|
||||
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ExpandingEntityIdentifierDescription extends EntityIdentifierDescription, ExpandingFetchSource {
|
||||
|
|
|
@ -26,8 +26,20 @@ package org.hibernate.loader.plan.build.spi;
|
|||
import org.hibernate.loader.plan.spi.EntityQuerySpace;
|
||||
|
||||
/**
|
||||
* Describes an entity query space that allows adding joins with other
|
||||
* query spaces; used while building an {@link EntityQuerySpace}.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.Join
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ExpandingEntityQuerySpace extends EntityQuerySpace, ExpandingQuerySpace {
|
||||
|
||||
/**
|
||||
* Builds a composite query space that allows adding joins used if
|
||||
* the entity has a composite entity identifier.
|
||||
*
|
||||
* @return The expanding composite query space.
|
||||
*/
|
||||
public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace();
|
||||
}
|
||||
|
|
|
@ -44,29 +44,63 @@ public interface ExpandingFetchSource extends FetchSource {
|
|||
/**
|
||||
* Is the asserted plan valid from this owner to a fetch?
|
||||
*
|
||||
* @param fetchStrategy The type of fetch to validate
|
||||
* @param attributeDefinition The attribute to be fetched
|
||||
* @param fetchStrategy The type of fetch to validate.
|
||||
* @param attributeDefinition The attribute to be fetched.
|
||||
*/
|
||||
public void validateFetchPlan(FetchStrategy fetchStrategy, AttributeDefinition attributeDefinition);
|
||||
|
||||
/**
|
||||
* Builds a fetch for an entity attribute.
|
||||
*
|
||||
* @param attributeDefinition The entity attribute.
|
||||
* @param fetchStrategy The fetch strategy for the attribute.
|
||||
* @return The entity fetch.
|
||||
*/
|
||||
public EntityFetch buildEntityAttributeFetch(
|
||||
AssociationAttributeDefinition attributeDefinition,
|
||||
FetchStrategy fetchStrategy);
|
||||
|
||||
/**
|
||||
* Builds a bidirectional entity reference for an entity attribute.
|
||||
*
|
||||
* @param attributeDefinition The attribute definition.
|
||||
* @param fetchStrategy The fetch strategy for the attribute.
|
||||
* @param targetEntityReference The associated (target) entity reference.
|
||||
* @return The bidirectional entity reference.
|
||||
*/
|
||||
public BidirectionalEntityReference buildBidirectionalEntityReference(
|
||||
AssociationAttributeDefinition attributeDefinition,
|
||||
FetchStrategy fetchStrategy,
|
||||
EntityReference targetEntityReference);
|
||||
|
||||
/**
|
||||
* Builds a fetch for a composite attribute.
|
||||
*
|
||||
* @param attributeDefinition The attribute definition.
|
||||
* @return The composite attribute fetch.
|
||||
*/
|
||||
public CompositeAttributeFetch buildCompositeAttributeFetch(
|
||||
AttributeDefinition attributeDefinition);
|
||||
|
||||
/**
|
||||
* Builds a fetch for a collection attribute.
|
||||
*
|
||||
* @param attributeDefinition The attribute definition.
|
||||
* @param fetchStrategy The fetch strategy for the attribute.
|
||||
* @return The collection attribute fetch.
|
||||
*/
|
||||
public CollectionAttributeFetch buildCollectionAttributeFetch(
|
||||
AssociationAttributeDefinition attributeDefinition,
|
||||
FetchStrategy fetchStrategy);
|
||||
|
||||
/**
|
||||
* Builds a fetch for an "any" attribute.
|
||||
*
|
||||
* @param attributeDefinition The attribute definition.
|
||||
* @param fetchStrategy The fetch strategy for the attibute.
|
||||
* @return The "any" attribute fetch.
|
||||
*/
|
||||
public AnyAttributeFetch buildAnyAttributeFetch(
|
||||
AssociationAttributeDefinition attributeDefinition,
|
||||
FetchStrategy fetchStrategy);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,12 +27,22 @@ import org.hibernate.loader.plan.spi.Join;
|
|||
import org.hibernate.loader.plan.spi.QuerySpace;
|
||||
|
||||
/**
|
||||
* Describes a query space that allows adding joins with other
|
||||
* query spaces; used while building a {@link QuerySpace}.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.Join
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ExpandingQuerySpace extends QuerySpace {
|
||||
|
||||
public boolean canJoinsBeRequired();
|
||||
|
||||
/**
|
||||
* Adds a join with another query space.
|
||||
*
|
||||
* @param join The join to add.
|
||||
*/
|
||||
public void addJoin(Join join);
|
||||
|
||||
public ExpandingQuerySpaces getExpandingQuerySpaces();
|
||||
|
|
|
@ -25,38 +25,152 @@ package org.hibernate.loader.plan.build.spi;
|
|||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.loader.plan.build.internal.spaces.CompositePropertyMapping;
|
||||
import org.hibernate.loader.plan.spi.Join;
|
||||
import org.hibernate.loader.plan.spi.QuerySpace;
|
||||
import org.hibernate.loader.plan.spi.QuerySpaces;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
/**
|
||||
* Models a collection of {@link QuerySpace} references and
|
||||
* exposes the ability to create an {@link ExpandingQuerySpace} for "returns" and fetches;
|
||||
* used when building a load plan.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ExpandingQuerySpaces extends QuerySpaces {
|
||||
|
||||
/**
|
||||
* Generate a unique ID to be used when creating an {@link ExpandingQuerySpace}.
|
||||
* <p/>
|
||||
* Using this method to generate a unique ID ensures that this object
|
||||
* does not contain a {@link QuerySpace} with the returned unique ID.
|
||||
*
|
||||
* @return The unique ID.
|
||||
*/
|
||||
public String generateImplicitUid();
|
||||
|
||||
/**
|
||||
* Create an {@link ExpandingEntityQuerySpace} for an entity "return" with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* The unique ID should be generated using {@link #generateImplicitUid()},
|
||||
*
|
||||
* A unique suffix may be added to the unique ID for an existing {@link QuerySpace}.
|
||||
* In this case, it is the caller's responsibility to ensure uniqueness.
|
||||
*
|
||||
* @param uid The unique ID for the root entity query space.
|
||||
* @param entityPersister The entity persister.
|
||||
* @return the {@link ExpandingEntityQuerySpace} with the specified unique ID.
|
||||
* @throws IllegalStateException if there is already a query space with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.EntityReturn
|
||||
*/
|
||||
public ExpandingEntityQuerySpace makeRootEntityQuerySpace(
|
||||
String uid,
|
||||
EntityPersister entityPersister);
|
||||
|
||||
/**
|
||||
* Create an {@link ExpandingEntityQuerySpace} for an entity (that is not a "return")
|
||||
* with the specified unique ID.
|
||||
*
|
||||
* The unique ID should be generated using {@link #generateImplicitUid()},
|
||||
*
|
||||
* A unique suffix may be added to the unique ID for an existing {@link QuerySpace}.
|
||||
* In this case, it is the caller's responsibility to ensure uniqueness.
|
||||
*
|
||||
* @param uid The unique ID for the entity query space.
|
||||
* @param entityPersister The entity persister.
|
||||
* @param canJoinsBeRequired <code>true</code> if joins added to the returned value
|
||||
* can be required joins; <code>false</code>, otherwise.
|
||||
*
|
||||
* @return the {@link ExpandingEntityQuerySpace} with the specified unique ID.
|
||||
* @throws IllegalStateException if there is already a query space with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* @see Join
|
||||
*/
|
||||
public ExpandingEntityQuerySpace makeEntityQuerySpace(
|
||||
String uid,
|
||||
EntityPersister entityPersister,
|
||||
boolean canJoinsBeRequired);
|
||||
|
||||
/**
|
||||
* Create an {@link ExpandingCollectionQuerySpace} for a collection "return" with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* The unique ID should be generated using {@link #generateImplicitUid()},
|
||||
*
|
||||
* A unique suffix may be added to the unique ID for an existing {@link QuerySpace}.
|
||||
* In this case, it is the caller's responsibility to ensure uniqueness.
|
||||
*
|
||||
* @param uid The unique ID for the root collection query space.
|
||||
* @param collectionPersister The collection persister.
|
||||
* @return the {@link ExpandingCollectionQuerySpace} with the specified unique ID.
|
||||
* @throws IllegalStateException if there is already a query space with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.CollectionReturn
|
||||
*/
|
||||
public ExpandingCollectionQuerySpace makeRootCollectionQuerySpace(
|
||||
String uid,
|
||||
CollectionPersister collectionPersister);
|
||||
|
||||
/**
|
||||
* Create an {@link ExpandingCollectionQuerySpace} for a collection (that is not a "return")
|
||||
* with the specified unique ID.
|
||||
*
|
||||
* The unique ID should be generated using {@link #generateImplicitUid()},
|
||||
*
|
||||
* A unique suffix may be added to the unique ID for an existing {@link QuerySpace}.
|
||||
* In this case, it is the caller's responsibility to ensure uniqueness.
|
||||
*
|
||||
* @param uid The unique ID for the collection query space.
|
||||
* @param collectionPersister The collection persister.
|
||||
* @param canJoinsBeRequired <code>true</code> if joins added to the returned value
|
||||
* can be required joins; <code>false</code>, otherwise.
|
||||
*
|
||||
* @return the {@link ExpandingCollectionQuerySpace} with the specified unique ID.
|
||||
* @throws IllegalStateException if there is already a query space with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* @see Join
|
||||
*/
|
||||
public ExpandingCollectionQuerySpace makeCollectionQuerySpace(
|
||||
String uid,
|
||||
CollectionPersister collectionPersister,
|
||||
boolean canJoinsBeRequired);
|
||||
|
||||
/**
|
||||
* Create an {@link ExpandingCompositeQuerySpace} for a composite
|
||||
* with the specified unique ID.
|
||||
*
|
||||
* The unique ID should be generated using {@link #generateImplicitUid()},
|
||||
*
|
||||
* A unique suffix may be added to the unique ID for an existing {@link QuerySpace}.
|
||||
* In this case, it is the caller's responsibility to ensure uniqueness.
|
||||
*
|
||||
* @param uid The unique ID for the composite query space.
|
||||
* @param compositePropertyMapping The composite property mapping.
|
||||
* @param canJoinsBeRequired <code>true</code> if joins added to the returned value
|
||||
* can be required joins; <code>false</code>, otherwise.
|
||||
*
|
||||
* @return the {@link ExpandingCompositeQuerySpace} with the specified unique ID.
|
||||
* @throws IllegalStateException if there is already a query space with the
|
||||
* specified unique ID.
|
||||
*
|
||||
* @see Join
|
||||
*/
|
||||
public ExpandingCompositeQuerySpace makeCompositeQuerySpace(
|
||||
String uid,
|
||||
CompositePropertyMapping compositePropertyMapping,
|
||||
boolean canJoinsBeRequired);
|
||||
|
||||
/**
|
||||
* Gets the session factory.
|
||||
*
|
||||
* @return The session factory.
|
||||
*/
|
||||
public SessionFactoryImplementor getSessionFactory();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@ import org.hibernate.loader.plan.spi.Return;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Prints a {@link org.hibernate.loader.plan.spi.QuerySpaces} graph as a tree structure.
|
||||
* Prints a {@link org.hibernate.loader.plan.spi.LoadPlan} graph and its
|
||||
* {@link org.hibernate.loader.plan.spi.QuerySpaces} graph as tree structures.
|
||||
* <p/>
|
||||
* Intended for use in debugging, logging, etc.
|
||||
* <p/>
|
||||
|
@ -53,8 +54,22 @@ public class LoadPlanTreePrinter {
|
|||
*/
|
||||
public static final LoadPlanTreePrinter INSTANCE = new LoadPlanTreePrinter();
|
||||
|
||||
private String toString(LoadPlan loadPlan) {
|
||||
return toString( loadPlan, null );
|
||||
private LoadPlanTreePrinter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the specified {@link org.hibernate.loader.plan.spi.LoadPlan} graph and its
|
||||
* {@link org.hibernate.loader.plan.spi.QuerySpaces} graph as tree structures.
|
||||
*
|
||||
* @param loadPlan The load plan.
|
||||
* @param aliasResolutionContext The context for resolving table and column aliases/
|
||||
*/
|
||||
public void logTree(LoadPlan loadPlan, AliasResolutionContext aliasResolutionContext) {
|
||||
if ( ! log.isDebugEnabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug( toString( loadPlan, aliasResolutionContext ) );
|
||||
}
|
||||
|
||||
private String toString(LoadPlan loadPlan, AliasResolutionContext aliasResolutionContext) {
|
||||
|
@ -70,22 +85,6 @@ public class LoadPlanTreePrinter {
|
|||
return new String( byteArrayOutputStream.toByteArray() );
|
||||
}
|
||||
|
||||
public void logTree(LoadPlan loadPlan, AliasResolutionContext aliasResolutionContext) {
|
||||
if ( ! log.isDebugEnabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
final PrintStream printStream = new PrintStream( byteArrayOutputStream );
|
||||
final PrintWriter printWriter = new PrintWriter( printStream );
|
||||
|
||||
logTree( loadPlan, aliasResolutionContext, printWriter );
|
||||
|
||||
printWriter.flush();
|
||||
printStream.flush();
|
||||
log.debug( new String( byteArrayOutputStream.toByteArray() ) );
|
||||
}
|
||||
|
||||
private void logTree(
|
||||
LoadPlan loadPlan,
|
||||
AliasResolutionContext aliasResolutionContext,
|
||||
|
|
|
@ -53,10 +53,39 @@ public class QuerySpaceTreePrinter {
|
|||
*/
|
||||
public static final QuerySpaceTreePrinter INSTANCE = new QuerySpaceTreePrinter();
|
||||
|
||||
private QuerySpaceTreePrinter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String containing the {@link QuerySpaces} graph as a tree structure.
|
||||
*
|
||||
* @param spaces The {@link QuerySpaces} object.
|
||||
* @param aliasResolutionContext The context for resolving table and column aliases
|
||||
* for the {@link QuerySpace} references in <code>spaces</code>; if null,
|
||||
* table and column aliases are not included in returned value..
|
||||
* @return the String containing the {@link QuerySpaces} graph as a tree structure.
|
||||
*/
|
||||
public String asString(QuerySpaces spaces, AliasResolutionContext aliasResolutionContext) {
|
||||
return asString( spaces, 0, aliasResolutionContext );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String containing the {@link QuerySpaces} graph as a tree structure, starting
|
||||
* at a particular depth.
|
||||
*
|
||||
* The value for depth indicates the number of indentations that will
|
||||
* prefix all lines in the returned String. Root query spaces will be written with depth + 1
|
||||
* and the depth will be further incremented as joined query spaces are traversed.
|
||||
*
|
||||
* An indentation is defined as the number of characters defined by {@link TreePrinterHelper#INDENTATION}.
|
||||
*
|
||||
* @param spaces The {@link QuerySpaces} object.
|
||||
* @param depth The intial number of indentations
|
||||
* @param aliasResolutionContext The context for resolving table and column aliases
|
||||
* for the {@link QuerySpace} references in <code>spaces</code>; if null,
|
||||
* table and column aliases are not included in returned value..
|
||||
* @return the String containing the {@link QuerySpaces} graph as a tree structure.
|
||||
*/
|
||||
public String asString(QuerySpaces spaces, int depth, AliasResolutionContext aliasResolutionContext) {
|
||||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
final PrintStream printStream = new PrintStream( byteArrayOutputStream );
|
||||
|
@ -65,6 +94,23 @@ public class QuerySpaceTreePrinter {
|
|||
return new String( byteArrayOutputStream.toByteArray() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String containing the {@link QuerySpaces} graph as a tree structure, starting
|
||||
* at a particular depth.
|
||||
*
|
||||
* The value for depth indicates the number of indentations that will
|
||||
* prefix all lines in the returned String. Root query spaces will be written with depth + 1
|
||||
* and the depth will be further incremented as joined query spaces are traversed.
|
||||
*
|
||||
* An indentation is defined as the number of characters defined by {@link TreePrinterHelper#INDENTATION}.
|
||||
*
|
||||
* @param spaces The {@link QuerySpaces} object.
|
||||
* @param depth The intial number of indentations
|
||||
* @param aliasResolutionContext The context for resolving table and column aliases
|
||||
* for the {@link QuerySpace} references in <code>spaces</code>; if null,
|
||||
* table and column aliases are not included in returned value.
|
||||
* @param printStream The print stream for writing.
|
||||
*/
|
||||
public void write(
|
||||
QuerySpaces spaces,
|
||||
int depth,
|
||||
|
@ -73,6 +119,23 @@ public class QuerySpaceTreePrinter {
|
|||
write( spaces, depth, aliasResolutionContext, new PrintWriter( printStream ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String containing the {@link QuerySpaces} graph as a tree structure, starting
|
||||
* at a particular depth.
|
||||
*
|
||||
* The value for depth indicates the number of indentations that will
|
||||
* prefix all lines in the returned String. Root query spaces will be written with depth + 1
|
||||
* and the depth will be further incremented as joined query spaces are traversed.
|
||||
*
|
||||
* An indentation is defined as the number of characters defined by {@link TreePrinterHelper#INDENTATION}.
|
||||
*
|
||||
* @param spaces The {@link QuerySpaces} object.
|
||||
* @param depth The intial number of indentations
|
||||
* @param aliasResolutionContext The context for resolving table and column aliases
|
||||
* for the {@link QuerySpace} references in <code>spaces</code>; if null,
|
||||
* table and column aliases are not included in returned value.
|
||||
* @param printWriter The print writer for writing.
|
||||
*/
|
||||
public void write(
|
||||
QuerySpaces spaces,
|
||||
int depth,
|
||||
|
@ -182,6 +245,17 @@ public class QuerySpaceTreePrinter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String containing high-level details about the {@link QuerySpace}, such as:
|
||||
* <ul>
|
||||
* <li>query space class name</li>
|
||||
* <li>unique ID</li>
|
||||
* <li>entity name (for {@link EntityQuerySpace}</li>
|
||||
* <li>collection role (for {@link CollectionQuerySpace}</li> *
|
||||
* </ul>
|
||||
* @param space The query space
|
||||
* @return a String containing details about the {@link QuerySpace}
|
||||
*/
|
||||
public String extractDetails(QuerySpace space) {
|
||||
if ( EntityQuerySpace.class.isInstance( space ) ) {
|
||||
final EntityQuerySpace entityQuerySpace = (EntityQuerySpace) space;
|
||||
|
|
|
@ -26,9 +26,14 @@ package org.hibernate.loader.plan.build.spi;
|
|||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* A singleton helper class for printing tree structures using indentation.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TreePrinterHelper {
|
||||
/**
|
||||
* The number of characters to indent.
|
||||
*/
|
||||
public static final int INDENTATION = 3;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +41,18 @@ public class TreePrinterHelper {
|
|||
*/
|
||||
public static final TreePrinterHelper INSTANCE = new TreePrinterHelper();
|
||||
|
||||
public String generateNodePrefix(int depth) {
|
||||
return StringHelper.repeat( ' ', depth * INDENTATION ) + " - ";
|
||||
private TreePrinterHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the specified number of indentations, where
|
||||
* each indentation contains {@link #INDENTATION} blank characters.
|
||||
*
|
||||
*
|
||||
* @param nIndentations the number of indentations in the returned String.
|
||||
* @return the String containing the specified number of indentations.
|
||||
*/
|
||||
public String generateNodePrefix(int nIndentations) {
|
||||
return StringHelper.repeat( ' ', nIndentations * INDENTATION ) + " - ";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.sql.SelectFragment;
|
||||
|
||||
/**
|
||||
* Largely a copy of the {@link org.hibernate.sql.Select} class, but changed up slightly to better meet needs
|
||||
|
@ -52,6 +51,11 @@ public class SelectStatementBuilder {
|
|||
|
||||
private int guesstimatedBufferSize = 20;
|
||||
|
||||
/**
|
||||
* Constructs a select statement builder object.
|
||||
*
|
||||
* @param dialect The dialect.
|
||||
*/
|
||||
public SelectStatementBuilder(Dialect dialect) {
|
||||
this.dialect = dialect;
|
||||
}
|
||||
|
@ -70,10 +74,11 @@ public class SelectStatementBuilder {
|
|||
this.guesstimatedBufferSize += selection.length();
|
||||
}
|
||||
|
||||
public void appendSelectClauseFragment(SelectFragment selectFragment) {
|
||||
appendSelectClauseFragment( selectFragment.toFragmentString().substring( 2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the from clause fragment.
|
||||
*
|
||||
* @param fragment The from cause fragment.
|
||||
*/
|
||||
public void appendFromClauseFragment(String fragment) {
|
||||
if ( this.fromClause.length() > 0 ) {
|
||||
this.fromClause.append( ", " );
|
||||
|
@ -83,10 +88,24 @@ public class SelectStatementBuilder {
|
|||
this.guesstimatedBufferSize += fragment.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified table name and alias as a from clause fragment.
|
||||
*
|
||||
* @param tableName The table name.
|
||||
* @param alias The table alias.
|
||||
*/
|
||||
public void appendFromClauseFragment(String tableName, String alias) {
|
||||
appendFromClauseFragment( tableName + ' ' + alias );
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified restrictions after "cleaning" the specified value
|
||||
* (by trimming and removing 'and ' from beginning and ' and' from the end).
|
||||
* If the where clause already exists, this method ensure that ' and '
|
||||
* prefixes the cleaned restrictions.
|
||||
*
|
||||
* @param restrictions The restrictions.
|
||||
*/
|
||||
public void appendRestrictions(String restrictions) {
|
||||
final String cleaned = cleanRestrictions( restrictions );
|
||||
if ( StringHelper.isEmpty( cleaned ) ) {
|
||||
|
@ -116,34 +135,12 @@ public class SelectStatementBuilder {
|
|||
return restrictions;
|
||||
}
|
||||
|
||||
// public void appendOuterJoins(String outerJoinsAfterFrom, String outerJoinsAfterWhere) {
|
||||
// appendOuterJoinsAfterFrom( outerJoinsAfterFrom );
|
||||
// appendOuterJoinsAfterWhere( outerJoinsAfterWhere );
|
||||
// }
|
||||
//
|
||||
// private void appendOuterJoinsAfterFrom(String outerJoinsAfterFrom) {
|
||||
// if ( this.outerJoinsAfterFrom == null ) {
|
||||
// this.outerJoinsAfterFrom = new StringBuilder( outerJoinsAfterFrom );
|
||||
// }
|
||||
// else {
|
||||
// this.outerJoinsAfterFrom.append( ' ' ).append( outerJoinsAfterFrom );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void appendOuterJoinsAfterWhere(String outerJoinsAfterWhere) {
|
||||
// final String cleaned = cleanRestrictions( outerJoinsAfterWhere );
|
||||
//
|
||||
// if ( this.outerJoinsAfterWhere == null ) {
|
||||
// this.outerJoinsAfterWhere = new StringBuilder( cleaned );
|
||||
// }
|
||||
// else {
|
||||
// this.outerJoinsAfterWhere.append( " and " ).append( cleaned );
|
||||
// this.guesstimatedBufferSize += 5;
|
||||
// }
|
||||
//
|
||||
// this.guesstimatedBufferSize += cleaned.length();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Sets the outer join fragments to be added to the "from" and "where" clauses.
|
||||
*
|
||||
* @param outerJoinsAfterFrom The outer join fragment to be appended to the "from" clause.
|
||||
* @param outerJoinsAfterWhere The outer join fragment to be appended to the "where" clause.
|
||||
*/
|
||||
public void setOuterJoins(String outerJoinsAfterFrom, String outerJoinsAfterWhere) {
|
||||
this.outerJoinsAfterFrom = outerJoinsAfterFrom;
|
||||
|
||||
|
@ -153,6 +150,12 @@ public class SelectStatementBuilder {
|
|||
this.guesstimatedBufferSize += outerJoinsAfterFrom.length() + cleanRestrictions.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the "order by" fragment, prefixed by a comma if the "order by" fragment already
|
||||
* exists.
|
||||
*
|
||||
* @param ordering The "order by" fragment to append.
|
||||
*/
|
||||
public void appendOrderByFragment(String ordering) {
|
||||
if ( this.orderByClause == null ) {
|
||||
this.orderByClause = new StringBuilder();
|
||||
|
@ -164,21 +167,38 @@ public class SelectStatementBuilder {
|
|||
this.orderByClause.append( ordering );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment for the select statement.
|
||||
*
|
||||
* @param comment The comment.
|
||||
*/
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
this.guesstimatedBufferSize += comment.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lock mode for the select statement.
|
||||
*
|
||||
* @param lockMode The lock mode.
|
||||
*/
|
||||
public void setLockMode(LockMode lockMode) {
|
||||
this.lockOptions.setLockMode( lockMode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lock options for the select statement.
|
||||
*
|
||||
* @param lockOptions The lock options.
|
||||
*/
|
||||
public void setLockOptions(LockOptions lockOptions) {
|
||||
LockOptions.copy( lockOptions, this.lockOptions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an SQL <tt>SELECT</tt> statement from the given clauses
|
||||
* Construct an SQL <tt>SELECT</tt> statement from the given clauses.
|
||||
*
|
||||
* @return the SQL <tt>SELECT</tt> statement.
|
||||
*/
|
||||
public String toStatementString() {
|
||||
final StringBuilder buf = new StringBuilder( guesstimatedBufferSize );
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the internal implementation for generating the load query for the LoadPlan.
|
||||
*/
|
||||
package org.hibernate.loader.plan.exec.query.internal;
|
|
@ -23,6 +23,6 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Defines support for build a query (SQL string specifically for now) based on a LoadPlan.
|
||||
* Defines support for building a query (SQL string specifically for now) based on a LoadPlan.
|
||||
*/
|
||||
package org.hibernate.loader.plan.exec.query;
|
||||
|
|
|
@ -32,5 +32,12 @@ package org.hibernate.loader.plan.exec.query.spi;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface NamedParameterContext {
|
||||
/**
|
||||
* Returns the locations of all occurrences of the named parameter.
|
||||
*
|
||||
* @param name The named parameter.
|
||||
*
|
||||
* @return the array of locations.
|
||||
*/
|
||||
public int[] getNamedParameterLocations(String name);
|
||||
}
|
||||
|
|
|
@ -28,13 +28,41 @@ import org.hibernate.LockOptions;
|
|||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
|
||||
/**
|
||||
* Provides values for all options that impact the built query.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface QueryBuildingParameters {
|
||||
|
||||
/**
|
||||
* Provides data for options which can influence the SQL query needed to load an
|
||||
* entity.
|
||||
*
|
||||
* @return the load query influencers
|
||||
*
|
||||
* @see LoadQueryInfluencers
|
||||
*/
|
||||
public LoadQueryInfluencers getQueryInfluencers();
|
||||
|
||||
/**
|
||||
* Gets the batch size.
|
||||
*
|
||||
* @return The batch size.
|
||||
*/
|
||||
public int getBatchSize();
|
||||
|
||||
// ultimately it would be better to have a way to resolve the LockMode for a given Return/Fetch...
|
||||
|
||||
/**
|
||||
* Gets the lock mode.
|
||||
* @return The lock mode.
|
||||
*/
|
||||
public LockMode getLockMode();
|
||||
|
||||
/**
|
||||
* Gets the lock options.
|
||||
*
|
||||
* @return The lock options.
|
||||
*/
|
||||
public LockOptions getLockOptions();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the SPI for obtaining values for options that impact the load query.
|
||||
*/
|
||||
package org.hibernate.loader.plan.exec.query.spi;
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the SPI for the building blocks that make up a LoadPlan.
|
||||
*/
|
||||
package org.hibernate.loader.plan.spi;
|
|
@ -56,7 +56,6 @@ import org.hibernate.loader.JoinWalker;
|
|||
import org.hibernate.loader.entity.EntityJoinWalker;
|
||||
import org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor;
|
||||
import org.hibernate.loader.plan.exec.query.spi.NamedParameterContext;
|
||||
import org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails;
|
||||
import org.hibernate.loader.plan.exec.spi.LoadQueryDetails;
|
||||
import org.hibernate.loader.plan.spi.LoadPlan;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
|
Loading…
Reference in New Issue