<commit_before>package com.radiadesign.relationalscope.comparison

import org.hibernate.criterion.*
import com.radiadesign.relationalscope.RelationalScope
import com.radiadesign.relationalscope.expression.*

class ScopeComparisonBase {
  
  def lhsValue
  def rhsValue
  
  ScopeComparisonBase() {
    
  }
  
  ScopeComparisonBase(_lhsValue, _rhsValue) {
    lhsValue = _lhsValue
    rhsValue = _rhsValue
  }
  
  
  // --------------------------------------------------------------------------
  // Standard RelationalScope criterion creation implementation
  // --------------------------------------------------------------------------
  
  Criterion toCriterion(options) {
    _dispatchToCriterion_(lhsValue, rhsValue, options)
  }
  
  
  // --------------------------------------------------------------------------
  // Criterion creation methods to override in an extending comparison class
  // --------------------------------------------------------------------------
  
  Criterion criterionForPropertyAndProperty(lhs, rhs, options) {
    throw new RuntimeException("Property-to-Property comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForPropertyAndValue(property, value, options) {
    throw new RuntimeException("Property-to-Value comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForPropertyAndSubquery(property, criteria, options) {
    throw new RuntimeException("Property-to-Subquery comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForValueAndSubquery(value, criteria, options) {
    throw new RuntimeException("Value-to-Subquery comparator not implemented on ${this.class.simpleName}.")
  }
  
  
  // --------------------------------------------------------------------------
  // Semi-private API: supports subquery comparisons
  // --------------------------------------------------------------------------
  
  DetachedCriteria detachedCriteriaFor(RelationalScope scope, options) {
    options.incrementDetachedCriteriaCount()
    
    def rootAlias = "sqrt_${options.getDetachedCriteriaCount()}"
    def detachedCriteria = DetachedCriteria.forClass(scope.domainKlass, rootAlias)
    
    this.detachedCriteriaCallback(scope, detachedCriteria)
    
    def newOptions = options + [ criteria: detachedCriteria,
                                 associationPath: scope.associationName,
                                 associationAliases: [:],
                                 isDetachedCriteria: true,
                                 currentRootAlias: rootAlias ]
    
    prepareCriteria(detachedCriteria, newOptions)
    
    return detachedCriteria
  }
  
  def detachedCriteriaCallback(RelationalScope scope, criteria) {
    // Override in child class if desired...
  }
  
  
  // --------------------------------------------------------------------------
  // Private: these strongly typed methods support the standardization of the
  //          criterion creation methods.
  // --------------------------------------------------------------------------
  
  Criterion _dispatchToCriterion_(AbstractPropertyExpression prop1, AbstractPropertyExpression prop2, options ) {<commit_msg>Nasty typo...<commit_after>package com.radiadesign.relationalscope.comparison

import org.hibernate.criterion.*
import com.radiadesign.relationalscope.RelationalScope
import com.radiadesign.relationalscope.expression.*

class ScopeComparisonBase {
  
  def lhsValue
  def rhsValue
  
  ScopeComparisonBase() {
    
  }
  
  ScopeComparisonBase(_lhsValue, _rhsValue) {
    lhsValue = _lhsValue
    rhsValue = _rhsValue
  }
  
  
  // --------------------------------------------------------------------------
  // Standard RelationalScope criterion creation implementation
  // --------------------------------------------------------------------------
  
  Criterion toCriterion(options) {
    _dispatchToCriterion_(lhsValue, rhsValue, options)
  }
  
  
  // --------------------------------------------------------------------------
  // Criterion creation methods to override in an extending comparison class
  // --------------------------------------------------------------------------
  
  Criterion criterionForPropertyAndProperty(lhs, rhs, options) {
    throw new RuntimeException("Property-to-Property comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForPropertyAndValue(property, value, options) {
    throw new RuntimeException("Property-to-Value comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForPropertyAndSubquery(property, criteria, options) {
    throw new RuntimeException("Property-to-Subquery comparator not implemented on ${this.class.simpleName}.")
  }
  
  Criterion criterionForValueAndSubquery(value, criteria, options) {
    throw new RuntimeException("Value-to-Subquery comparator not implemented on ${this.class.simpleName}.")
  }
  
  
  // --------------------------------------------------------------------------
  // Semi-private API: supports subquery comparisons
  // --------------------------------------------------------------------------
  
  DetachedCriteria detachedCriteriaFor(RelationalScope scope, options) {
    options.incrementDetachedCriteriaCount()
    
    def rootAlias = "sqrt_${options.getDetachedCriteriaCount()}"
    def detachedCriteria = DetachedCriteria.forClass(scope.domainKlass, rootAlias)
    
    this.detachedCriteriaCallback(scope, detachedCriteria)
    
    def newOptions = options + [ criteria: detachedCriteria,
                                 associationPath: scope.associationName,
                                 associationAliases: [:],
                                 isDetachedCriteria: true,
                                 currentRootAlias: rootAlias ]
    
    scope.prepareCriteria(detachedCriteria, newOptions)
    
    return detachedCriteria
  }
  
  def detachedCriteriaCallback(RelationalScope scope, criteria) {
    // Override in child class if desired...
  }
  
  
  // --------------------------------------------------------------------------
  // Private: these strongly typed methods support the standardization of the
  //          criterion creation methods.
  // --------------------------------------------------------------------------
  
  Criterion _dispatchToCriterion_(AbstractPropertyExpression prop1, AbstractPropertyExpression prop2, options ) {
{'fraction_non_alphanumeric': 0.2466687325689495, 'fraction_numerical': 0.0006197706848466068, 'mean_word_length': 1.6261187957689178, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5530938', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1418, 'n_words': 307}