Java Code Examples for org.hibernate.engine.spi.QueryParameters#getNamedParameters()

The following examples show how to use org.hibernate.engine.spi.QueryParameters#getNamedParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactiveSubselectOneToManyLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ReactiveSubselectOneToManyLoader(
		QueryableCollection persister,
		String subquery,
		Collection entityKeys,
		QueryParameters queryParameters,
		Map<String, int[]> namedParameterLocMap,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, 1, subquery, factory, loadQueryInfluencers );

	keys = new Serializable[ entityKeys.size() ];
	Iterator iter = entityKeys.iterator();
	int i=0;
	while ( iter.hasNext() ) {
		keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
	}

	this.namedParameters = queryParameters.getNamedParameters();
	this.types = queryParameters.getFilteredPositionalParameterTypes();
	this.values = queryParameters.getFilteredPositionalParameterValues();
	this.namedParameterLocMap = namedParameterLocMap;
}
 
Example 2
Source File: SubselectOneToManyLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public SubselectOneToManyLoader(
		QueryableCollection persister, 
		String subquery,
		Collection entityKeys,
		QueryParameters queryParameters,
		Map<String, int[]> namedParameterLocMap,
		SessionFactoryImplementor factory, 
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, 1, subquery, factory, loadQueryInfluencers );

	keys = new Serializable[ entityKeys.size() ];
	Iterator iter = entityKeys.iterator();
	int i=0;
	while ( iter.hasNext() ) {
		keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
	}
	
	this.namedParameters = queryParameters.getNamedParameters();
	this.types = queryParameters.getFilteredPositionalParameterTypes();
	this.values = queryParameters.getFilteredPositionalParameterValues();
	this.namedParameterLocMap = namedParameterLocMap;
}
 
Example 3
Source File: SubselectCollectionLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public SubselectCollectionLoader(
		QueryableCollection persister, 
		String subquery,
		Collection entityKeys,
		QueryParameters queryParameters,
		Map<String, int[]> namedParameterLocMap,
		SessionFactoryImplementor factory, 
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, 1, subquery, factory, loadQueryInfluencers );

	keys = new Serializable[ entityKeys.size() ];
	Iterator iter = entityKeys.iterator();
	int i=0;
	while ( iter.hasNext() ) {
		keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
	}
	
	this.namedParameters = queryParameters.getNamedParameters();
	this.types = queryParameters.getFilteredPositionalParameterTypes();
	this.values = queryParameters.getFilteredPositionalParameterValues();
	this.namedParameterLocMap = namedParameterLocMap;
	
}
 
Example 4
Source File: ResultSetProcessorHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static Map<String, int[]> buildNamedParameterLocMap(
		QueryParameters queryParameters,
		NamedParameterContext namedParameterContext) {
	if ( queryParameters.getNamedParameters() == null || queryParameters.getNamedParameters().isEmpty() ) {
		return null;
	}

	final Map<String, int[]> namedParameterLocMap = new HashMap<>();
	for ( String name : queryParameters.getNamedParameters().keySet() ) {
		namedParameterLocMap.put(
				name,
				namedParameterContext.getNamedParameterLocations( name )
		);
	}
	return namedParameterLocMap;
}
 
Example 5
Source File: Loader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Map buildNamedParameterLocMap(QueryParameters queryParameters) {
	if ( queryParameters.getNamedParameters() != null ) {
		final Map namedParameterLocMap = new HashMap();
		for ( String name : queryParameters.getNamedParameters().keySet() ) {
			namedParameterLocMap.put(
					name,
					getNamedParameterLocs( name )
			);
		}
		return namedParameterLocMap;
	}
	else {
		return null;
	}
}
 
Example 6
Source File: QueryKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generates a QueryKey.
 *
 * @param queryString The sql query string.
 * @param queryParameters The query parameters
 * @param filterKeys The keys of any enabled filters.
 * @param session The current session.
 * @param customTransformer The result transformer; should be null if data is not transformed before being cached.
 *
 * @return The generate query cache key.
 */
public static QueryKey generateQueryKey(
		String queryString,
		QueryParameters queryParameters,
		Set filterKeys,
		SharedSessionContractImplementor session,
		CacheableResultTransformer customTransformer) {
	// disassemble positional parameters
	final int positionalParameterCount = queryParameters.getPositionalParameterTypes().length;
	final Type[] types = new Type[positionalParameterCount];
	final Object[] values = new Object[positionalParameterCount];
	for ( int i = 0; i < positionalParameterCount; i++ ) {
		types[i] = queryParameters.getPositionalParameterTypes()[i];
		values[i] = types[i].disassemble( queryParameters.getPositionalParameterValues()[i], session, null );
	}

	// disassemble named parameters
	final Map<String,TypedValue> namedParameters;
	if ( queryParameters.getNamedParameters() == null ) {
		namedParameters = null;
	}
	else {
		namedParameters = CollectionHelper.mapOfSize( queryParameters.getNamedParameters().size() );
		for ( Map.Entry<String,TypedValue> namedParameterEntry : queryParameters.getNamedParameters().entrySet() ) {
			namedParameters.put(
					namedParameterEntry.getKey(),
					new TypedValue(
							namedParameterEntry.getValue().getType(),
							namedParameterEntry.getValue().getType().disassemble(
									namedParameterEntry.getValue().getValue(),
									session,
									null
							)
					)
			);
		}
	}

	// decode row selection...
	final RowSelection selection = queryParameters.getRowSelection();
	final Integer firstRow;
	final Integer maxRows;
	if ( selection != null ) {
		firstRow = selection.getFirstRow();
		maxRows = selection.getMaxRows();
	}
	else {
		firstRow = null;
		maxRows = null;
	}

	return new QueryKey(
			queryString,
			types,
			values,
			namedParameters,
			firstRow,
			maxRows,
			filterKeys,
			session.getTenantIdentifier(),
			customTransformer
	);
}