org.hibernate.engine.spi.FilterDefinition Java Examples

The following examples show how to use org.hibernate.engine.spi.FilterDefinition. 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: GrailsDomainBinder.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
/**
 * Add a Hibernate filter for multitenancy if the persistent class is multitenant
 *
 * @param entity target persistent entity for get tenant information
 * @param persistentClass persistent class for add the filter and get tenant property info
 * @param mappings mappings to add the filter
 * @param sessionFactoryBeanName the session factory bean name
 */
protected void addMultiTenantFilterIfNecessary(
        HibernatePersistentEntity entity, PersistentClass persistentClass,
        InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
    if (entity.isMultiTenant()) {
        TenantId tenantId = entity.getTenantId();

        if (tenantId != null) {
            String filterCondition = getMultiTenantFilterCondition(sessionFactoryBeanName, entity);

            persistentClass.addFilter(
                    GormProperties.TENANT_IDENTITY,
                    filterCondition,
                    true,
                    Collections.emptyMap(),
                    Collections.emptyMap()
            );

            mappings.addFilterDefinition(new FilterDefinition(
                    GormProperties.TENANT_IDENTITY,
                    filterCondition,
                    Collections.singletonMap(GormProperties.TENANT_IDENTITY, persistentClass.getProperty(tenantId.getName()).getType())
            ));
        }
    }
}
 
Example #2
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
	FilterDefinition def = filters.get( filterName );
	if ( def == null ) {
		throw new HibernateException( "No such filter configured [" + filterName + "]" );
	}
	return def;
}
 
Example #3
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addFilterDefinition(FilterDefinition filterDefinition) {
	if ( filterDefinition == null || filterDefinition.getFilterName() == null ) {
		throw new IllegalArgumentException( "Filter definition object or name is null: "  + filterDefinition );
	}
	filterDefinitionMap.put( filterDefinition.getFilterName(), filterDefinition );
}
 
Example #4
Source File: FilterDefinitionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handling for a {@code <filter-def/>} declaration.
 *
 * @param context Access to information relative to the mapping document containing this binding
 * @param jaxbFilterDefinitionMapping The {@code <filter-def/>} JAXB mapping
 */
@SuppressWarnings("unchecked")
public static void processFilterDefinition(
		HbmLocalMetadataBuildingContext context,
		JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) {
	Map<String,Type> parameterMap = null;
	String condition = jaxbFilterDefinitionMapping.getCondition();

	for ( Serializable content : jaxbFilterDefinitionMapping.getContent() ) {
		if ( String.class.isInstance( content ) ) {
			final String contentString = content.toString().trim();
			if ( StringHelper.isNotEmpty( contentString ) ) {
				if ( condition != null ) {
					log.debugf(
							"filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one",
							jaxbFilterDefinitionMapping.getName(),
							context.getOrigin().toString()
					);
				}
			}
		}
		else {
			final JaxbHbmFilterParameterType jaxbParameterMapping;
			if ( JaxbHbmFilterParameterType.class.isInstance( content ) ) {
				jaxbParameterMapping = (JaxbHbmFilterParameterType) content;
			}
			else if ( JAXBElement.class.isInstance( content ) ) {
				final JAXBElement<JaxbHbmFilterParameterType> jaxbElement = (JAXBElement<JaxbHbmFilterParameterType>) content;
				jaxbParameterMapping = jaxbElement.getValue();
			}
			else {
				throw new MappingException(
						"Unable to decipher filter-def content type [" + content.getClass().getName() + "]",
						context.getOrigin()
				);
			}

			if ( parameterMap == null ) {
				parameterMap = new HashMap<String, Type>();
			}

			parameterMap.put(
					jaxbParameterMapping.getParameterName(),
					context.getMetadataCollector().getTypeResolver().heuristicType( jaxbParameterMapping.getParameterValueTypeName() )
			);
		}
	}

	context.getMetadataCollector().addFilterDefinition(
			new FilterDefinition(
					jaxbFilterDefinitionMapping.getName(),
					condition,
					parameterMap
			)
	);

	log.debugf( "Processed filter definition : %s", jaxbFilterDefinitionMapping.getName() );
}
 
Example #5
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public FilterDefinition getFilterDefinition(String filterName)
        throws HibernateException {
    return sessionFactoryImplementor.getFilterDefinition(filterName);
}
 
Example #6
Source File: CacheHibernateStoreFactorySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
    return null;
}
 
Example #7
Source File: CacheHibernateStoreFactorySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
    return null;
}
 
Example #8
Source File: CacheHibernateStoreFactorySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
    return null;
}
 
Example #9
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FilterDefinition getFilterDefinition(String name) {
	return filterDefinitionMap.get( name );
}
 
Example #10
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Map<String, FilterDefinition> getFilterDefinitions() {
	return filterDefinitionMap;
}
 
Example #11
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
MetadataImpl(
		UUID uuid,
		MetadataBuildingOptions metadataBuildingOptions,
		MutableIdentifierGeneratorFactory identifierGeneratorFactory,
		Map<String, PersistentClass> entityBindingMap,
		Map<Class, MappedSuperclass> mappedSuperclassMap,
		Map<String, Collection> collectionBindingMap,
		Map<String, TypeDefinition> typeDefinitionMap,
		Map<String, FilterDefinition> filterDefinitionMap,
		Map<String, FetchProfile> fetchProfileMap,
		Map<String, String> imports,
		Map<String, IdentifierGeneratorDefinition> idGeneratorDefinitionMap,
		Map<String, NamedQueryDefinition> namedQueryMap,
		Map<String, NamedSQLQueryDefinition> namedNativeQueryMap,
		Map<String, NamedProcedureCallDefinition> namedProcedureCallMap,
		Map<String, ResultSetMappingDefinition> sqlResultSetMappingMap,
		Map<String, NamedEntityGraphDefinition> namedEntityGraphMap,
		Map<String, SQLFunction> sqlFunctionMap,
		java.util.Collection<DomainDataRegionConfigImpl.Builder> cacheRegionConfigBuilders,
		Database database,
		BootstrapContext bootstrapContext) {
	this.uuid = uuid;
	this.metadataBuildingOptions = metadataBuildingOptions;
	this.identifierGeneratorFactory = identifierGeneratorFactory;
	this.entityBindingMap = entityBindingMap;
	this.mappedSuperclassMap = mappedSuperclassMap;
	this.collectionBindingMap = collectionBindingMap;
	this.typeDefinitionMap = typeDefinitionMap;
	this.filterDefinitionMap = filterDefinitionMap;
	this.fetchProfileMap = fetchProfileMap;
	this.imports = imports;
	this.idGeneratorDefinitionMap = idGeneratorDefinitionMap;
	this.namedQueryMap = namedQueryMap;
	this.namedNativeQueryMap = namedNativeQueryMap;
	this.namedProcedureCallMap = namedProcedureCallMap;
	this.sqlResultSetMappingMap = sqlResultSetMappingMap;
	this.namedEntityGraphMap = namedEntityGraphMap;
	this.sqlFunctionMap = sqlFunctionMap;
	this.cacheRegionConfigBuilders = cacheRegionConfigBuilders;
	this.database = database;
	this.bootstrapContext = bootstrapContext;
}
 
Example #12
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FilterDefinition getFilterDefinition(String name) {
	return filterDefinitionMap.get( name );
}
 
Example #13
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Map<String, FilterDefinition> getFilterDefinitions() {
	return filterDefinitionMap;
}
 
Example #14
Source File: LegacySessionFactory.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
    return null;
}
 
Example #15
Source File: AbstractDelegatingMetadata.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FilterDefinition getFilterDefinition(String name) {
	return delegate.getFilterDefinition( name );
}
 
Example #16
Source File: AbstractDelegatingMetadata.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Map<String, FilterDefinition> getFilterDefinitions() {
	return delegate.getFilterDefinitions();
}
 
Example #17
Source File: FilterImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public FilterDefinition getFilterDefinition() {
	return definition;
}
 
Example #18
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static void bindFilterDef(FilterDef defAnn, MetadataBuildingContext context) {
	Map<String, org.hibernate.type.Type> params = new HashMap<>();
	for ( ParamDef param : defAnn.parameters() ) {
		params.put( param.name(), context.getMetadataCollector().getTypeResolver().heuristicType( param.type() ) );
	}
	FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params );
	LOG.debugf( "Binding filter definition: %s", def.getFilterName() );
	context.getMetadataCollector().addFilterDefinition( def );
}
 
Example #19
Source File: PrevalidatedQuarkusMetadata.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public FilterDefinition getFilterDefinition(final String name) {
    return metadata.getFilterDefinition(name);
}
 
Example #20
Source File: PrevalidatedQuarkusMetadata.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, FilterDefinition> getFilterDefinitions() {
    return metadata.getFilterDefinitions();
}
 
Example #21
Source File: InFlightMetadataCollector.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adds a filter definition to this repository.
 *
 * @param definition The filter definition to add.
 *
 * @throws DuplicateMappingException If a FilterDefinition already exists with that name.
 */
void addFilterDefinition(FilterDefinition definition);
 
Example #22
Source File: Metadata.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieves a filter definition by name.
 *
 * @param name The name of the filter definition to retrieve
 * .
 * @return The filter definition, or {@code null}.
 */
FilterDefinition getFilterDefinition(String name);
 
Example #23
Source File: Metadata.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieves the complete map of filter definitions.
 *
 * Returned map is immutable
 *
 * @return The filter definition map.
 */
Map<String,FilterDefinition> getFilterDefinitions();
 
Example #24
Source File: SessionFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Obtain the definition of a filter by name.
 *
 * @param filterName The name of the filter for which to obtain the definition.
 * @return The filter definition.
 * @throws HibernateException If no filter defined with the given name.
 */
FilterDefinition getFilterDefinition(String filterName) throws HibernateException;
 
Example #25
Source File: FilterImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs a new FilterImpl.
 *
 * @param configuration The filter's global configuration.
 */
public FilterImpl(FilterDefinition configuration) {
	this.definition = configuration;
	filterName = definition.getFilterName();
}
 
Example #26
Source File: Filter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the filter definition containing additional information about the
 * filter (such as default-condition and expected parameter names/types).
 *
 * @return The filter definition
 */
public FilterDefinition getFilterDefinition();