<commit_before>package org.grails.plugin.hibernate.filter

import grails.util.Metadata

import org.codehaus.groovy.grails.commons.GrailsDomainClass
import org.hibernate.cfg.Mappings
import org.hibernate.engine.spi.FilterDefinition
import org.hibernate.mapping.Collection
import org.hibernate.type.TypeFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * Add the filters from the domain closure.
 */
class HibernateFilterBuilder {

	private Logger log = LoggerFactory.getLogger(getClass())
	private boolean grails1 = Metadata.current.getGrailsVersion().startsWith('1')
	private Mappings mappings

	HibernateFilterDomainConfiguration configuration
	GrailsDomainClass domainClass

	HibernateFilterBuilder(HibernateFilterDomainConfiguration configuration, GrailsDomainClass domainClass) {
		this.configuration = configuration
		this.domainClass = domainClass
		mappings = configuration.createMappings()

		Closure filtersClosure = domainClass.getPropertyValue('hibernateFilters')
		filtersClosure.delegate = this
		filtersClosure.resolveStrategy = Closure.DELEGATE_ONLY
		filtersClosure()
	}

	def methodMissing(String name, args) {
		args = [name] + args.collect { it }
		def filterMethod = metaClass.getMetaMethod('addFilter', args.collect { it.getClass() } as Object[])
		if (filterMethod) {
			return filterMethod.invoke(this, args as Object[])
		}

		throw new HibernateFilterException(
			"Invalid arguments in hibernateFilters closure [class:$domainClass.name, name:$name]")
	}

	// Add a previously registered filter
	private void addFilter(String name, Map options = [:]) {
		// Use supplied condition if there is one, otherwise take the condition<commit_msg>equivalent changes to those proposed in PR #4<commit_after>package org.grails.plugin.hibernate.filter

import grails.util.Metadata

import org.codehaus.groovy.grails.commons.GrailsDomainClass
import org.hibernate.cfg.Mappings
import org.hibernate.cfg.Configuration
import org.hibernate.engine.spi.FilterDefinition
import org.hibernate.mapping.Collection
import org.hibernate.type.TypeFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * Add the filters from the domain closure.
 */
class HibernateFilterBuilder {

	private Logger log = LoggerFactory.getLogger(getClass())
	private boolean grails1 = Metadata.current.getGrailsVersion().startsWith('1')
	private Mappings mappings

	Configuration configuration
	GrailsDomainClass domainClass

	HibernateFilterBuilder(Configuration configuration, GrailsDomainClass domainClass) {
		this.configuration = configuration
		this.domainClass = domainClass
		mappings = configuration.createMappings()

		Closure filtersClosure = domainClass.getPropertyValue('hibernateFilters')
		filtersClosure.delegate = this
		filtersClosure.resolveStrategy = Closure.DELEGATE_ONLY
		filtersClosure()
	}

	def methodMissing(String name, args) {
		args = [name] + args.collect { it }
		def filterMethod = metaClass.getMetaMethod('addFilter', args.collect { it.getClass() } as Object[])
		if (filterMethod) {
			return filterMethod.invoke(this, args as Object[])
		}

		throw new HibernateFilterException(
			"Invalid arguments in hibernateFilters closure [class:$domainClass.name, name:$name]")
	}

	// Add a previously registered filter
	private void addFilter(String name, Map options = [:]) {
		// Use supplied condition if there is one, otherwise take the condition
{'fraction_non_alphanumeric': 0.08547008547008547, 'fraction_numerical': 0.002652519893899204, 'mean_word_length': 5.615984405458089, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4266637', 'n_tokens_mistral': 1015, 'n_tokens_neox': 915, 'n_words': 236}