Constructors Summary |
---|
SQLQueryImpl(org.hibernate.engine.NamedSQLQueryDefinition queryDef, org.hibernate.engine.SessionImplementor session, org.hibernate.engine.query.ParameterMetadata parameterMetadata)Constructs a SQLQueryImpl given a sql query defined in the mappings.
super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata );
if ( queryDef.getResultSetRef() != null ) {
ResultSetMappingDefinition definition = session.getFactory()
.getResultSetMapping( queryDef.getResultSetRef() );
if (definition == null) {
throw new MappingException(
"Unable to find resultset-ref definition: " +
queryDef.getResultSetRef()
);
}
this.queryReturns = Arrays.asList( definition.getQueryReturns() );
}
else {
this.queryReturns = Arrays.asList( queryDef.getQueryReturns() );
}
this.querySpaces = queryDef.getQuerySpaces();
this.callable = queryDef.isCallable();
|
SQLQueryImpl(String sql, List queryReturns, Collection querySpaces, org.hibernate.FlushMode flushMode, boolean callable, org.hibernate.engine.SessionImplementor session, org.hibernate.engine.query.ParameterMetadata parameterMetadata)
// TODO : absolutely no usages of this constructor form; can it go away?
super( sql, flushMode, session, parameterMetadata );
this.queryReturns = queryReturns;
this.querySpaces = querySpaces;
this.callable = callable;
|
SQLQueryImpl(String sql, String[] returnAliases, Class[] returnClasses, org.hibernate.LockMode[] lockModes, org.hibernate.engine.SessionImplementor session, Collection querySpaces, org.hibernate.FlushMode flushMode, org.hibernate.engine.query.ParameterMetadata parameterMetadata)
// TODO : this constructor form is *only* used from constructor directly below us; can it go away?
super( sql, flushMode, session, parameterMetadata );
queryReturns = new ArrayList(returnAliases.length);
for ( int i=0; i<returnAliases.length; i++ ) {
NativeSQLQueryRootReturn ret = new NativeSQLQueryRootReturn(
returnAliases[i],
returnClasses[i].getName(),
lockModes==null ? LockMode.NONE : lockModes[i]
);
queryReturns.add(ret);
}
this.querySpaces = querySpaces;
this.callable = false;
|
SQLQueryImpl(String sql, String[] returnAliases, Class[] returnClasses, org.hibernate.engine.SessionImplementor session, org.hibernate.engine.query.ParameterMetadata parameterMetadata)
this( sql, returnAliases, returnClasses, null, session, null, null, parameterMetadata );
|
SQLQueryImpl(String sql, org.hibernate.engine.SessionImplementor session, org.hibernate.engine.query.ParameterMetadata parameterMetadata)
super( sql, null, session, parameterMetadata );
queryReturns = new ArrayList();
querySpaces = null;
callable = false;
|
Methods Summary |
---|
public org.hibernate.SQLQuery | addEntity(java.lang.Class entityClass)
return addEntity( StringHelper.unqualify( entityClass.getName() ), entityClass );
|
public org.hibernate.SQLQuery | addEntity(java.lang.String entityName)
return addEntity( StringHelper.unqualify( entityName ), entityName );
|
public org.hibernate.SQLQuery | addEntity(java.lang.String alias, java.lang.String entityName)
return addEntity(alias, entityName, LockMode.READ);
|
public org.hibernate.SQLQuery | addEntity(java.lang.String alias, java.lang.Class entityClass)
return addEntity( alias, entityClass.getName() );
|
public org.hibernate.SQLQuery | addEntity(java.lang.String alias, java.lang.String entityName, org.hibernate.LockMode lockMode)
queryReturns.add( new NativeSQLQueryRootReturn(alias, entityName, lockMode) );
return this;
|
public org.hibernate.SQLQuery | addEntity(java.lang.String alias, java.lang.Class entityClass, org.hibernate.LockMode lockMode)
return addEntity( alias, entityClass.getName(), lockMode );
|
public org.hibernate.SQLQuery | addJoin(java.lang.String alias, java.lang.String path)
return addJoin(alias, path, LockMode.READ);
|
public org.hibernate.SQLQuery | addJoin(java.lang.String alias, java.lang.String path, org.hibernate.LockMode lockMode)
int loc = path.indexOf('.");
if ( loc < 0 ) {
throw new QueryException( "not a property path: " + path );
}
String ownerAlias = path.substring(0, loc);
String role = path.substring(loc+1);
queryReturns.add( new NativeSQLQueryJoinReturn(alias, ownerAlias, role, CollectionHelper.EMPTY_MAP, lockMode) );
return this;
|
private org.hibernate.SQLQuery | addQuerySpaces(java.io.Serializable[] spaces)
if ( spaces != null ) {
if ( querySpaces == null ) {
querySpaces = new ArrayList();
}
for ( int i = 0; i < spaces.length; i++ ) {
querySpaces.add( spaces[i] );
}
}
return this;
|
public org.hibernate.SQLQuery | addScalar(java.lang.String columnAlias, org.hibernate.type.Type type)
queryReturns.add( new NativeSQLQueryScalarReturn( columnAlias, type ) );
return this;
|
public org.hibernate.SQLQuery | addScalar(java.lang.String columnAlias)
autodiscovertypes = true;
queryReturns.add( new NativeSQLQueryScalarReturn( columnAlias, null ) );
return this;
|
public org.hibernate.SQLQuery | addSynchronizedEntityClass(java.lang.Class entityClass)
return addQuerySpaces( getSession().getFactory().getEntityPersister( entityClass.getName() ).getQuerySpaces() );
|
public org.hibernate.SQLQuery | addSynchronizedEntityName(java.lang.String entityName)
return addQuerySpaces( getSession().getFactory().getEntityPersister( entityName ).getQuerySpaces() );
|
public org.hibernate.SQLQuery | addSynchronizedQuerySpace(java.lang.String querySpace)
if ( querySpaces == null ) {
querySpaces = new ArrayList();
}
querySpaces.add( querySpace );
return this;
|
public int | executeUpdate()
Map namedParams = getNamedParams();
before();
try {
return getSession().executeNativeUpdate(
generateQuerySpecification( namedParams ),
getQueryParameters( namedParams )
);
}
finally {
after();
}
|
private org.hibernate.engine.query.sql.NativeSQLQuerySpecification | generateQuerySpecification(java.util.Map namedParams)
return new NativeSQLQuerySpecification(
expandParameterLists(namedParams),
getQueryReturns(),
querySpaces
);
|
protected java.util.Map | getLockModes()
//we never need to apply locks to the SQL
return CollectionHelper.EMPTY_MAP;
|
public org.hibernate.engine.QueryParameters | getQueryParameters(java.util.Map namedParams)
QueryParameters qp = super.getQueryParameters(namedParams);
qp.setCallable(callable);
qp.setAutoDiscoverScalarTypes(autodiscovertypes);
return qp;
|
private org.hibernate.engine.query.sql.NativeSQLQueryReturn[] | getQueryReturns()
return ( NativeSQLQueryReturn[] ) queryReturns.toArray( NO_SQL_RETURNS );
|
public java.lang.String[] | getReturnAliases()
throw new UnsupportedOperationException("SQL queries do not currently support returning aliases");
|
public org.hibernate.type.Type[] | getReturnTypes()
throw new UnsupportedOperationException("not yet implemented for SQL queries");
|
public java.util.Iterator | iterate()
throw new UnsupportedOperationException("SQL queries do not currently support iteration");
|
public java.util.List | list()
verifyParameters();
before();
Map namedParams = getNamedParams();
NativeSQLQuerySpecification spec = generateQuerySpecification( namedParams );
try {
return getSession().list( spec, getQueryParameters( namedParams ) );
}
finally {
after();
}
|
public org.hibernate.ScrollableResults | scroll()
return scroll(ScrollMode.SCROLL_INSENSITIVE);
|
public org.hibernate.ScrollableResults | scroll(org.hibernate.ScrollMode scrollMode)
verifyParameters();
before();
Map namedParams = getNamedParams();
NativeSQLQuerySpecification spec = generateQuerySpecification( namedParams );
QueryParameters qp = getQueryParameters( namedParams );
qp.setScrollMode( scrollMode );
try {
return getSession().scroll( spec, qp );
}
finally {
after();
}
|
public org.hibernate.Query | setLockMode(java.lang.String alias, org.hibernate.LockMode lockMode)
throw new UnsupportedOperationException("cannot set the lock mode for a native SQL query");
|
public org.hibernate.SQLQuery | setResultSetMapping(java.lang.String name)
ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name );
if ( mapping == null ) {
throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" );
}
NativeSQLQueryReturn[] returns = mapping.getQueryReturns();
int length = returns.length;
for ( int index = 0 ; index < length ; index++ ) {
queryReturns.add( returns[index] );
}
return this;
|
protected void | verifyParameters()
verifyParameters( callable );
boolean noReturns = queryReturns==null || queryReturns.isEmpty();
if ( noReturns ) {
this.autodiscovertypes = noReturns;
}
else {
Iterator itr = queryReturns.iterator();
while ( itr.hasNext() ) {
NativeSQLQueryReturn rtn = ( NativeSQLQueryReturn ) itr.next();
if ( rtn instanceof NativeSQLQueryScalarReturn ) {
NativeSQLQueryScalarReturn scalar = ( NativeSQLQueryScalarReturn ) rtn;
if ( scalar.getType() == null ) {
autodiscovertypes = true;
break;
}
}
}
}
|