A delegate that implements the Loader part of QueryTranslator.
| Method from org.hibernate.loader.hql.QueryLoader Detail: |
protected String applyLocks(String sql,
Map lockModes,
Dialect dialect) throws QueryException {
if ( lockModes == null || lockModes.size() == 0 ) {
return sql;
}
// can't cache this stuff either (per-invocation)
// we are given a map of user-alias - > lock mode
// create a new map of sql-alias - > lock mode
final Map aliasedLockModes = new HashMap();
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
final Iterator iter = lockModes.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
final String userAlias = ( String ) me.getKey();
final String drivingSqlAlias = ( String ) sqlAliasByEntityAlias.get( userAlias );
if ( drivingSqlAlias == null ) {
throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
}
// at this point we have (drivingSqlAlias) the SQL alias of the driving table
// corresponding to the given user alias. However, the driving table is not
// (necessarily) the table against which we want to apply locks. Mainly,
// the exception case here is joined-subclass hierarchies where we instead
// want to apply the lock against the root table (for all other strategies,
// it just happens that driving and root are the same).
final QueryNode select = ( QueryNode ) queryTranslator.getSqlAST();
final Lockable drivingPersister = ( Lockable ) select.getFromClause().getFromElement( userAlias ).getQueryable();
final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
aliasedLockModes.put( sqlAlias, me.getValue() );
if ( keyColumnNames != null ) {
keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
return dialect.applyLocksToSql( sql, aliasedLockModes, keyColumnNames );
}
|
protected int bindParameterValues(PreparedStatement statement,
QueryParameters queryParameters,
int startIndex,
SessionImplementor session) throws SQLException {
int position = startIndex;
List parameterSpecs = queryTranslator.getCollectedParameterSpecifications();
Iterator itr = parameterSpecs.iterator();
while ( itr.hasNext() ) {
ParameterSpecification spec = ( ParameterSpecification ) itr.next();
position += spec.bind( statement, queryParameters, session, position );
}
return position - startIndex;
}
We specifically override this method here, because in general we know much more
about the parameters and their appropriate bind positions here then we do in
our super because we track them explciitly here through the ParameterSpecification
interface. |
public String[] getAliases() {
return sqlAliases;
}
|
protected int[] getCollectionOwners() {
return collectionOwners;
}
|
protected CollectionPersister[] getCollectionPersisters() {
return collectionPersisters;
}
An (optional) persister for a collection to be initialized; only collection loaders
return a non-null value |
public String[] getCollectionSuffixes() {
return collectionSuffixes;
}
|
protected boolean[] getEntityEagerPropertyFetches() {
return entityEagerPropertyFetches;
}
|
public Loadable[] getEntityPersisters() {
return entityPersisters;
}
|
protected LockMode[] getLockModes(Map lockModes) {
if ( lockModes==null || lockModes.size()==0 ) {
return defaultLockModes;
}
else {
// unfortunately this stuff can't be cached because
// it is per-invocation, not constant for the
// QueryTranslator instance
LockMode[] lockModeArray = new LockMode[entityAliases.length];
for ( int i = 0; i < entityAliases.length; i++ ) {
LockMode lockMode = (LockMode) lockModes.get( entityAliases[i] );
if ( lockMode == null ) {
//NONE, because its the requested lock mode, not the actual!
lockMode = LockMode.NONE;
}
lockModeArray[i] = lockMode;
}
return lockModeArray;
}
}
|
public int[] getNamedParameterLocs(String name) throws QueryException {
return queryTranslator.getParameterTranslations().getNamedParameterSqlLocations( name );
}
Returns the locations of all occurrences of the named parameter. |
protected EntityType[] getOwnerAssociationTypes() {
return ownerAssociationTypes;
}
|
protected int[] getOwners() {
return owners;
}
An array of indexes of the entity that owns a one-to-one association
to the entity at the given index (-1 if there is no "owner") |
protected String getQueryIdentifier() {
return queryTranslator.getQueryIdentifier();
}
|
protected Object getResultColumnOrRow(Object[] row,
ResultTransformer transformer,
ResultSet rs,
SessionImplementor session) throws SQLException, HibernateException {
row = toResultRow( row );
boolean hasTransform = hasSelectNew() || transformer!=null;
if ( hasScalars ) {
String[][] scalarColumns = scalarColumnNames;
int queryCols = queryReturnTypes.length;
if ( !hasTransform && queryCols == 1 ) {
return queryReturnTypes[0].nullSafeGet( rs, scalarColumns[0], session, null );
}
else {
row = new Object[queryCols];
for ( int i = 0; i < queryCols; i++ ) {
row[i] = queryReturnTypes[i].nullSafeGet( rs, scalarColumns[i], session, null );
}
return row;
}
}
else if ( !hasTransform ) {
return row.length == 1 ? row[0] : row;
}
else {
return row;
}
}
|
protected List getResultList(List results,
ResultTransformer resultTransformer) throws QueryException {
// meant to handle dynamic instantiation queries...
HolderInstantiator holderInstantiator = HolderInstantiator.getHolderInstantiator(selectNewTransformer, resultTransformer, queryReturnAliases);
if ( holderInstantiator.isRequired() ) {
for ( int i = 0; i < results.size(); i++ ) {
Object[] row = ( Object[] ) results.get( i );
Object result = holderInstantiator.instantiate(row);
results.set( i, result );
}
if(!hasSelectNew() && resultTransformer!=null) {
return resultTransformer.transformList(results);
} else {
return results;
}
} else {
return results;
}
}
|
protected String getSQLString() {
return queryTranslator.getSQLString();
}
The SQL query string to be called. |
public String[] getSqlAliasSuffixes() {
return sqlAliasSuffixes;
}
|
public String[] getSuffixes() {
return getSqlAliasSuffixes();
}
|
protected boolean isSubselectLoadingEnabled() {
return hasSubselectLoadableCollections();
}
|
public Iterator iterate(QueryParameters queryParameters,
EventSource session) throws HibernateException {
checkQuery( queryParameters );
final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
long startTime = 0;
if ( stats ) {
startTime = System.currentTimeMillis();
}
try {
final PreparedStatement st = prepareQueryStatement( queryParameters, false, session );
if(queryParameters.isCallable()) {
throw new QueryException("iterate() not supported for callable statements");
}
final ResultSet rs = getResultSet(st, queryParameters.hasAutoDiscoverScalarTypes(), false, queryParameters.getRowSelection(), session);
final Iterator result = new IteratorImpl(
rs,
st,
session,
queryReturnTypes,
queryTranslator.getColumnNames(),
HolderInstantiator.getHolderInstantiator(selectNewTransformer, queryParameters.getResultTransformer(), queryReturnAliases)
);
if ( stats ) {
session.getFactory().getStatisticsImplementor().queryExecuted(
// "HQL: " + queryTranslator.getQueryString(),
getQueryIdentifier(),
0,
System.currentTimeMillis() - startTime
);
}
return result;
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
getFactory().getSQLExceptionConverter(),
sqle,
"could not execute query using iterate",
getSQLString()
);
}
}
|
public List list(SessionImplementor session,
QueryParameters queryParameters) throws HibernateException {
checkQuery( queryParameters );
return list( session, queryParameters, queryTranslator.getQuerySpaces(), queryReturnTypes );
}
|
protected boolean needsFetchingScroll() {
return queryTranslator.containsCollectionFetches();
}
|
public ScrollableResults scroll(QueryParameters queryParameters,
SessionImplementor session) throws HibernateException {
checkQuery( queryParameters );
return scroll( queryParameters, queryReturnTypes, HolderInstantiator.getHolderInstantiator(selectNewTransformer, queryParameters.getResultTransformer(), queryReturnAliases), session );
}
|
protected boolean upgradeLocks() {
return true;
}
|
public final void validateScrollability() throws HibernateException {
queryTranslator.validateScrollability();
}
|