@@ -0,0 +1,2677 @@
+/* Copyright 2004-2005 the original author or authors.%0D%0A *%0D%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A * you may not use this file except in compliance with the License.%0D%0A * You may obtain a copy of the License at%0D%0A *%0D%0A *      http://www.apache.org/licenses/LICENSE-2.0%0D%0A *%0D%0A * Unless required by applicable law or agreed to in writing, software%0D%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A * See the License for the specific language governing permissions and%0D%0A * limitations under the License.%0D%0A */%0D%0Apackage grails.orm;%0D%0A%0D%0Aimport org.hibernate.Criteria;%0D%0Aimport org.hibernate.HibernateException;%0D%0Aimport org.hibernate.criterion.CriteriaQuery;%0D%0Aimport org.hibernate.criterion.Criterion;%0D%0Aimport org.hibernate.criterion.MatchMode;%0D%0Aimport org.hibernate.dialect.*;%0D%0Aimport org.hibernate.engine.TypedValue;%0D%0A%0D%0A/**%0D%0A * %0D%0A * Adds support for rlike to Hibernate in supported dialects%0D%0A *%0D%0A * @author Graeme Rocher%0D%0A * @since 1.1.1%0D%0A */%0D%0Apublic class RlikeExpression implements Criterion%0D%0A%7B%0D%0A    private final String propertyName;%0D%0A    private final Object value;%0D%0A%0D%0A    public RlikeExpression(String propertyName, Object value) %7B%0D%0A        this.propertyName = propertyName;%0D%0A        this.value = value;%0D%0A    %7D%0D%0A%0D%0A    public RlikeExpression(String propertyName, String value, MatchMode matchMode) %7B%0D%0A        this( propertyName, matchMode.toMatchString(value) );%0D%0A    %7D%0D%0A%0D%0A    public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)%0D%0A    throws HibernateException %7B%0D%0A        Dialect dialect = criteriaQuery.getFactory().getDialect();%0D%0A        String%5B%5D columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);%0D%0A        if (columns.length!=1) throw new HibernateException(%22ilike may only be used with single-column properties%22);%0D%0A        if ( dialect instanceof MySQLDialect) %7B%0D%0A            return columns%5B0%5D + %22 rlike ?%22;%0D%0A%0D%0A        %7D%0D%0A        else if (isOracleDialect(dialect))%0D%0A        %7B%0D%0A            return %22 REGEXP_LIKE ( %22 + columns%5B0%5D + %22, ? )%22;%0D%0A        %7D%0D%0A        else%0D%0A        %7B%0D%0A            return columns%5B0%5D + %22 like ?%22;%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    private boolean isOracleDialect(Dialect dialect) %7B%0D%0A        return (dialect instanceof Oracle8iDialect);%0D%0A    %7D%0D%0A%0D%0A    public TypedValue%5B%5D getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)%0D%0A    throws HibernateException %7B%0D%0A        return new TypedValue%5B%5D %7B criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() ) %7D;%0D%0A    %7D%0D%0A%0D%0A    public String toString() %7B%0D%0A        return propertyName + %22 rlike %22 + value;%0D%0A    %7D%0D%0A%0D%0A%7D%0D%0A

fix for GRAILS-3481. rlike expression support in Grails on MySQL and Oracle