类org.hibernate.Filter源码实例Demo

下面列出了怎么用org.hibernate.Filter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: QueryPlanCache.java
/**
 * Get the query plan for the given HQL query, creating it and caching it if not already cached
 *
 * @param queryString The HQL query string
 * @param shallow Whether the execution will be shallow
 * @param enabledFilters The filters enabled on the Session
 *
 * @return The query plan
 *
 * @throws QueryException Indicates a problem translating the query
 * @throws MappingException Indicates a problem translating the query
 */
@SuppressWarnings("unchecked")
public HQLQueryPlan getHQLQueryPlan(String queryString, boolean shallow, Map<String,Filter> enabledFilters)
		throws QueryException, MappingException {
	final HQLQueryPlanKey key = new HQLQueryPlanKey( queryString, shallow, enabledFilters );
	HQLQueryPlan value = (HQLQueryPlan) queryPlanCache.get( key );
	if ( value == null ) {
		LOG.tracev( "Unable to locate HQL query plan in cache; generating ({0})", queryString );
		value = new HQLQueryPlan( queryString, shallow, enabledFilters, factory );
		queryPlanCache.putIfAbsent( key, value );
	}
	else {
		LOG.tracev( "Located HQL query plan in cache ({0})", queryString );
	}
	return value;
}
 
源代码2 项目: lams   文件: QueryPlanCache.java
/**
 * Get the query plan for the given collection HQL filter fragment, creating it and caching it if not already cached
 *
 * @param filterString The HQL filter fragment
 * @param collectionRole The collection being filtered
 * @param shallow Whether the execution will be shallow
 * @param enabledFilters The filters enabled on the Session
 *
 * @return The query plan
 *
 * @throws QueryException Indicates a problem translating the query
 * @throws MappingException Indicates a problem translating the query
 */
@SuppressWarnings("unchecked")
public FilterQueryPlan getFilterQueryPlan(
		String filterString,
		String collectionRole,
		boolean shallow,
		Map<String,Filter> enabledFilters) throws QueryException, MappingException {
	final FilterQueryPlanKey key =  new FilterQueryPlanKey( filterString, collectionRole, shallow, enabledFilters );
	FilterQueryPlan value = (FilterQueryPlan) queryPlanCache.get( key );
	if ( value == null ) {
		LOG.tracev(
				"Unable to locate collection-filter query plan in cache; generating ({0} : {1} )",
				collectionRole,
				filterString
		);
		value = new FilterQueryPlan( filterString, collectionRole, shallow, enabledFilters,factory );
		queryPlanCache.putIfAbsent( key, value );
	}
	else {
		LOG.tracev( "Located collection-filter query plan in cache ({0} : {1})", collectionRole, filterString );
	}
	return value;
}
 
源代码3 项目: lams   文件: FilterImpl.java
/**
 * Set the named parameter's value list for this filter.  Used
 * in conjunction with IN-style filter criteria.
 *
 * @param name   The parameter's name.
 * @param values The values to be expanded into an SQL IN list.
 * @return This FilterImpl instance (for method chaining).
 */
public Filter setParameterList(String name, Collection values) throws HibernateException  {
	// Make sure this is a defined parameter and check the incoming value type
	if ( values == null ) {
		throw new IllegalArgumentException( "Collection must be not null!" );
	}
	Type type = definition.getParameterType( name );
	if ( type == null ) {
		throw new HibernateException( "Undefined filter parameter [" + name + "]" );
	}
	if ( !values.isEmpty() ) {
		Class elementClass = values.iterator().next().getClass();
		if ( !type.getReturnedClass().isAssignableFrom( elementClass ) ) {
			throw new HibernateException( "Incorrect type for parameter [" + name + "]" );
		}
	}
	parameters.put( name, values );
	return this;
}
 
源代码4 项目: lams   文件: FilterKey.java
/**
 * Constructs a number of FilterKey instances, given the currently enabled filters
 *
 * @param enabledFilters The currently enabled filters
 *
 * @return The filter keys, one per enabled filter
 */
public static Set<FilterKey> createFilterKeys(Map<String,Filter> enabledFilters) {
	if ( enabledFilters.size() == 0 ) {
		return null;
	}
	final Set<FilterKey> result = new HashSet<FilterKey>();
	for ( Filter filter : enabledFilters.values() ) {
		final FilterKey key = new FilterKey(
				filter.getName(),
				( (FilterImpl) filter ).getParameters(),
				filter.getFilterDefinition().getParameterTypes()
		);
		result.add( key );
	}
	return result;
}
 
@Test
public void testExecuteWithThreadBoundAndParameterizedFilter() {
	Filter filter = mock(Filter.class);
	given(session.isOpen()).willReturn(true);
	given(session.enableFilter("myFilter")).willReturn(filter);
	hibernateTemplate.setAllowCreate(false);
	hibernateTemplate.setFilterName("myFilter");

	TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
	try {
		final List l = new ArrayList();
		l.add("test");
		Filter f = hibernateTemplate.enableFilter("myFilter");
		assertTrue("Correct filter", f == filter);
	}
	finally {
		TransactionSynchronizationManager.unbindResource(sessionFactory);
	}
	InOrder ordered = inOrder(session);
	ordered.verify(session).getEnabledFilter("myFilter");
	ordered.verify(session).enableFilter("myFilter");
}
 
@Test
public void testExecuteWithThreadBoundAndParameterizedExistingFilter() {
	Filter filter = mock(Filter.class);
	given(session.isOpen()).willReturn(true);
	given(session.enableFilter("myFilter")).willReturn(filter);
	hibernateTemplate.setAllowCreate(false);
	hibernateTemplate.setFilterName("myFilter");

	TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
	try {
		final List l = new ArrayList();
		l.add("test");
		Filter f = hibernateTemplate.enableFilter("myFilter");
		assertTrue("Correct filter", f == filter);
	}
	finally {
		TransactionSynchronizationManager.unbindResource(sessionFactory);
	}
	verify(session).getEnabledFilter("myFilter");
}
 
源代码7 项目: cacheonix-core   文件: FilterImpl.java
/**
 * Set the named parameter's value list for this filter.  Used
 * in conjunction with IN-style filter criteria.
 *
 * @param name   The parameter's name.
 * @param values The values to be expanded into an SQL IN list.
 * @return This FilterImpl instance (for method chaining).
 */
public Filter setParameterList(String name, Collection values) throws HibernateException  {
	// Make sure this is a defined parameter and check the incoming value type
	if ( values == null ) {
		throw new IllegalArgumentException( "Collection must be not null!" );
	}
	Type type = definition.getParameterType( name );
	if ( type == null ) {
		throw new HibernateException( "Undefined filter parameter [" + name + "]" );
	}
	if ( values.size() > 0 ) {
		Class elementClass = values.iterator().next().getClass();
		if ( !type.getReturnedClass().isAssignableFrom( elementClass ) ) {
			throw new HibernateException( "Incorrect type for parameter [" + name + "]" );
		}
	}
	parameters.put( name, values );
	return this;
}
 
源代码8 项目: spring-analysis-note   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = obtainSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码9 项目: hibernate-reactive   文件: ReactiveHQLQueryPlan.java
public ReactiveHQLQueryPlan(
		String hql,
		boolean shallow,
		Map<String, Filter> enabledFilters,
		SessionFactoryImplementor factory) {
	super( hql, shallow, enabledFilters, factory );
}
 
源代码10 项目: hibernate-reactive   文件: ReactiveHQLQueryPlan.java
public ReactiveHQLQueryPlan(
		String hql,
		boolean shallow,
		Map<String, Filter> enabledFilters,
		SessionFactoryImplementor factory, EntityGraphQueryHint entityGraphQueryHint) {
	super( hql, shallow, enabledFilters, factory, entityGraphQueryHint );
}
 
源代码11 项目: hibernate-reactive   文件: ReactiveHQLQueryPlan.java
public ReactiveHQLQueryPlan(
		String hql,
		String collectionRole,
		boolean shallow,
		Map<String, Filter> enabledFilters,
		SessionFactoryImplementor factory,
		EntityGraphQueryHint entityGraphQueryHint) {
	super( hql, collectionRole, shallow, enabledFilters, factory, entityGraphQueryHint );
}
 
源代码12 项目: java-technology-stack   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = obtainSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码13 项目: lams   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = getSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码14 项目: lams   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = getSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码15 项目: lams   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码16 项目: lams   文件: LoadQueryInfluencers.java
public Map<String,Filter> getEnabledFilters() {
	// First, validate all the enabled filters...
	//TODO: this implementation has bad performance
	for ( Filter filter : enabledFilters.values() ) {
		filter.validate();
	}
	return enabledFilters;
}
 
源代码17 项目: lams   文件: FilterImpl.java
/**
 * Set the named parameter's value for this filter.
 *
 * @param name The parameter's name.
 * @param value The value to be applied.
 * @return This FilterImpl instance (for method chaining).
 * @throws IllegalArgumentException Indicates that either the parameter was undefined or that the type
 * of the passed value did not match the configured type.
 */
public Filter setParameter(String name, Object value) throws IllegalArgumentException {
	// Make sure this is a defined parameter and check the incoming value type
	// TODO: what should be the actual exception type here?
	Type type = definition.getParameterType( name );
	if ( type == null ) {
		throw new IllegalArgumentException( "Undefined filter parameter [" + name + "]" );
	}
	if ( value != null && !type.getReturnedClass().isAssignableFrom( value.getClass() ) ) {
		throw new IllegalArgumentException( "Incorrect type for parameter [" + name + "]" );
	}
	parameters.put( name, value );
	return this;
}
 
源代码18 项目: hibernate-types   文件: SQLExtractor.java
/**
 * Get the underlying SQL generated by the provided JPA query.
 *
 * @param query JPA query
 * @return the underlying SQL generated by the provided JPA query
 */
public static String from(Query query) {
    AbstractQueryImpl abstractQuery = query.unwrap(AbstractQueryImpl.class);
    SessionImplementor session = ReflectionUtils.getFieldValue(abstractQuery, "session");
    String[] sqls = session.getFactory()
        .getQueryPlanCache()
        .getHQLQueryPlan(abstractQuery.getQueryString(), false, Collections.<String, Filter>emptyMap())
        .getSqlStrings();

    return sqls.length > 0 ? sqls[0] : null;
}
 
源代码19 项目: hibernate-types   文件: SQLExtractor.java
/**
 * Get the underlying SQL generated by the provided JPA query.
 *
 * @param query JPA query
 * @return the underlying SQL generated by the provided JPA query
 */
public static String from(Query query) {
    AbstractQueryImpl abstractQuery = query.unwrap(AbstractQueryImpl.class);
    SessionImplementor session = ReflectionUtils.getFieldValue(abstractQuery, "session");
    String[] sqls = session.getFactory()
        .getQueryPlanCache()
        .getHQLQueryPlan(abstractQuery.getQueryString(), false, Collections.<String, Filter>emptyMap())
        .getSqlStrings();

    return sqls.length > 0 ? sqls[0] : null;
}
 
源代码20 项目: hibernate-types   文件: SQLExtractor.java
/**
 * Get the underlying SQL generated by the provided JPA query.
 *
 * @param query JPA query
 * @return the underlying SQL generated by the provided JPA query
 */
public static String from(Query query) {
    AbstractQueryImpl abstractQuery = query.unwrap(AbstractQueryImpl.class);
    SessionImplementor session = ReflectionUtils.getFieldValue(abstractQuery, "session");
    String[] sqls = session.getFactory()
        .getQueryPlanCache()
        .getHQLQueryPlan(abstractQuery.getQueryString(), false, Collections.<String, Filter>emptyMap())
        .getSqlStrings();

    return sqls.length > 0 ? sqls[0] : null;
}
 
源代码21 项目: spring4-understanding   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码22 项目: spring4-understanding   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = getSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
源代码23 项目: spring4-understanding   文件: HibernateTemplate.java
@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
	Session session = getSessionFactory().getCurrentSession();
	Filter filter = session.getEnabledFilter(filterName);
	if (filter == null) {
		filter = session.enableFilter(filterName);
	}
	return filter;
}
 
@Test
public void testExecuteWithThreadBoundAndParameterizedFilter() {
	Filter filter = mock(Filter.class);
	given(session.enableFilter("myFilter")).willReturn(filter);
	hibernateTemplate.setFilterNames("myFilter");

	final List l = new ArrayList();
	l.add("test");
	Filter f = hibernateTemplate.enableFilter("myFilter");
	assertTrue("Correct filter", f == filter);

	InOrder ordered = inOrder(session);
	ordered.verify(session).getEnabledFilter("myFilter");
	ordered.verify(session).enableFilter("myFilter");
}
 
@Test
public void testExecuteWithThreadBoundAndParameterizedExistingFilter() {
	Filter filter = mock(Filter.class);
	given(session.enableFilter("myFilter")).willReturn(filter);
	hibernateTemplate.setFilterNames("myFilter");

	final List l = new ArrayList();
	l.add("test");
	Filter f = hibernateTemplate.enableFilter("myFilter");
	assertTrue("Correct filter", f == filter);

	verify(session).getEnabledFilter("myFilter");
}
 
源代码26 项目: cacheonix-core   文件: SessionImpl.java
public Filter enableFilter(String filterName) {
	errorIfClosed();
	checkTransactionSynchStatus();
	FilterImpl filter = new FilterImpl( factory.getFilterDefinition(filterName) );
	enabledFilters.put(filterName, filter);
	return filter;
}
 
源代码27 项目: cacheonix-core   文件: SessionImpl.java
public Map getEnabledFilters() {
	errorIfClosed();
	checkTransactionSynchStatus();
	// First, validate all the enabled filters...
	//TODO: this implementation has bad performance
	Iterator itr = enabledFilters.values().iterator();
	while ( itr.hasNext() ) {
		final Filter filter = (Filter) itr.next();
		filter.validate();
	}
	return enabledFilters;
}
 
源代码28 项目: cacheonix-core   文件: FilterImpl.java
/**
 * Set the named parameter's value for this filter.
 *
 * @param name The parameter's name.
 * @param value The value to be applied.
 * @return This FilterImpl instance (for method chaining).
 * @throws IllegalArgumentException Indicates that either the parameter was undefined or that the type
 * of the passed value did not match the configured type.
 */
public Filter setParameter(String name, Object value) throws IllegalArgumentException {
	// Make sure this is a defined parameter and check the incoming value type
	// TODO: what should be the actual exception type here?
	Type type = definition.getParameterType( name );
	if ( type == null ) {
		throw new IllegalArgumentException( "Undefined filter parameter [" + name + "]" );
	}
	if ( value != null && !type.getReturnedClass().isAssignableFrom( value.getClass() ) ) {
		throw new IllegalArgumentException( "Incorrect type for parameter [" + name + "]" );
	}
	parameters.put( name, value );
	return this;
}
 
源代码29 项目: hibernate-reactive   文件: MutinySessionImpl.java
@Override
public Filter enableFilter(String filterName) {
	return delegate.enableFilter(filterName);
}
 
源代码30 项目: hibernate-reactive   文件: MutinySessionImpl.java
@Override
public Filter getEnabledFilter(String filterName) {
	return delegate.getEnabledFilter(filterName);
}
 
 类所在包
 类方法
 同包方法