# Operators.java

    /*
    ** Module   : Operators.java
    ** Abstract : Dispatcher methods for Java language, server-side database
    **            functions which replace Progress comparison and math operators
    **
    ** Copyright (c) 2004-2019, Golden Code Development Corporation.
    **
    ** -#- -I- --Date-- --JPRM-- ----------------Description-----------------
    ** 001 ECF 20060811   @28585 Created initial version. Backing methods for
    **                           Progress comparison and math operators executed
    **                           within the database server as custom,
    **                           Java-language functions.
    ** 002 ECF 20060817   @28691 Removed numerous methods which were causing
    **                           ambiguity in server-side function resolution.
    **                           All binary operator methods which accepted mixed
    **                           lists of Integers and Doubles were eliminated.
    **                           Now we have only methods which accept two
    **                           Integers or two Doubles.
    ** 003 ECF 20060904   @29218 Added support for modulo operator.
    ** 004 ECF 20070608   @34015 Replaced all Double with BigDecimal. Reflects
    **                           new implementations of decimal and MathOps
    **                           classes.
    ** 005 ECF 20071210   @36495 Implemented error handling for CAN-FINDs.
    **                           Built-in functions/operators within converted
    **                           CAN-FIND statements must handle errors by
    **                           returning null instead of throwing an exception.
    **                           These are wrapped in the
    **                           ErrorHandler.checkError() function, which checks
    **                           pending error state and returns an appropriate
    **                           result.
    ** 006 ECF 20080313   @37512 Expanded API to provide variants with
    **                           exhaustive combinations of numeric parameter
    **                           types. This is necessary to enable "manual"
    **                           overloading user defined functions.
    ** 007 OM  20121222          Modulus operations for int64.
    ** 008 OM  20130502          Switch to 64-bit integer computing (Long/int64).
    ** 009 OM  20130527          Added support for datetime arithmetics.
    **                           At this moment I cannot tell how the signature for datetine-tz
    **                           should looks like (or even if it is possible to use
    **                           pl/java with multi-column values).
    ** 010 OM  20151130          Added HQLFunction annotation from methods exposed a UDFs.
    ** 011 GES 20160804          Javadoc update.
    ** 012 CA  20190722          Fixed datetimetz query arguments - they are treated like a ISO date,
    **                           in string representation. UDF are used to compare them.
    ** 013 AIL 20191111          Change initialization of ErrorHandler's static context.
    */
    /*
    ** This program is free software: you can redistribute it and/or modify
    ** it under the terms of the GNU Affero General Public License as
    ** published by the Free Software Foundation, either version 3 of the
    ** License, or (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU Affero General Public License for more details.
    **
    ** You may find a copy of the GNU Affero GPL version 3 at the following
    ** location: https://www.gnu.org/licenses/agpl-3.0.en.html
    **
    ** Additional terms under GNU Affero GPL version 3 section 7:
    **
    **   Under Section 7 of the GNU Affero GPL version 3, the following additional
    **   terms apply to the works covered under the License.  These additional terms
    **   are non-permissive additional terms allowed under Section 7 of the GNU
    **   Affero GPL version 3 and may not be removed by you.
    **
    **   0. Attribution Requirement.
    **
    **     You must preserve all legal notices or author attributions in the covered
    **     work or Appropriate Legal Notices displayed by works containing the covered
    **     work.  You may not remove from the covered work any author or developer
    **     credit already included within the covered work.
    **
    **   1. No License To Use Trademarks.
    **
    **     This license does not grant any license or rights to use the trademarks
    **     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
    **     of Golden Code Development Corporation. You are not authorized to use the
    **     name Golden Code, FWD, or the names of any author or contributor, for
    **     publicity purposes without written authorization.
    **
    **   2. No Misrepresentation of Affiliation.
    **
    **     You may not represent yourself as Golden Code Development Corporation or FWD.
    **
    **     You may not represent yourself for publicity purposes as associated with
    **     Golden Code Development Corporation, FWD, or any author or contributor to
    **     the covered work, without written authorization.
    **
    **   3. No Misrepresentation of Source or Origin.
    **
    **     You may not represent the covered work as solely your work.  All modified
    **     versions of the covered work must be marked in a reasonable way to make it
    **     clear that the modified work is not originating from Golden Code Development
    **     Corporation or FWD.  All modified versions must contain the notices of
    **     attribution required in this license.
    */

    package com.goldencode.p2j.persist.pl;

    import java.math.*;
    import java.sql.*;

    import com.goldencode.p2j.util.*;

    /**
     * A collection of static methods which provide the backing functionality for Progress-like
     * comparison and math operators, which are executed within the database server as custom,
     * Java-language functions.  This provides a much faster alternative to client-side where
     * clause processing. This mechanism (or client-side where clause processing) must be used
     * in cases where an operation converted from Progress code must retain semantics specific
     * to the Progress environment. Executing these operations on the server is much preferred,
     * since moving records across the network only to test them for inclusion in a result set
     * is prohibitively expensive.
     * <p>
     * This class serves primarily as a consolidation point and dispatcher for
     * worker methods located in diverse classes.  All method calls made by the
     * database server are redirected to those worker methods.  However, since
     * the database server knows nothing of the P2J wrapper types used by those
     * methods to represent primitives, this class also performs a transformation
     * to (on input) and from (on output) the P2J wrapper types.  Thus, all
     * parameters and return types for methods in this class are specified in
     * terms of the standard J2SE wrapper types or primitive types.
     * <p>
     * The transformation handles conversion between <code>null</code> J2SE
     * wrapper types and the implementation of <code>unknown value</code> in the
     * P2J wrapper types.  This is possible because unknown value maps to SQL
     * NULL in the backing database.  However, certain data can be lost in the
     * transformation, and if these data are necessary, this mechanism should be
     * avoided.  Instead, client-side where clause processing should be used in
     * these cases.  Specifically, the following data are not represented by J2SE
     * wrappers or primitives and thus cannot be preserved during transformation:
     * <ul>
     *   <li>non-default precision of a <code>decimal</code> value;
     *   <li>non-default case sensitivity of a <code>character</code> value;
     *   <li>non-default timezone of a <code>date</code> value.
     * </ul>
     *
     * @see  Functions
     */
    public final class Operators
    {
       static
       {
          // make sure static initialization take place before using operators
          try
          {
             Class.forName("com.goldencode.p2j.persist.pl.ErrorHandler");
          }
          catch (ClassNotFoundException e)
          {
             ErrorHandler.handleError(new RuntimeException(e));
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isEqual(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(String a, String b)
       {
          try
          {
             return CompareOps.isEqual(new character(a),
                                       new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Long a, Long b)
       {
          try
          {
             return CompareOps.isEqual(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Long a, Integer b)
       {
          return eq(a, toLong(b));
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Integer a, Long b)
       {
          return eq(toLong(a), b);
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Integer a, Integer b)
       {
          return eq(toLong(a), toLong(b));
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isEqual(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isEqual(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(BigDecimal a, Integer b)
       {
          return eq(a, toLong(b));
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isEqual(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Integer a, BigDecimal b)
       {
          return eq(toLong(a), b);
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isEqual(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for equality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean eq(Date a, Date b)
       {
          try
          {
             return CompareOps.isEqual(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isNotEqual(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(String a, String b)
       {
          try
          {
             return CompareOps.isNotEqual(new character(a), new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Long a, Long b)
       {
          try
          {
             return CompareOps.isNotEqual(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Long a, Integer b)
       {
          return ne(a, toLong(b));
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Integer a, Long b)
       {
          return ne(toLong(a), b);
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Integer a, Integer b)
       {
          return ne(toLong(a), toLong(b));
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isNotEqual(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isNotEqual(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(BigDecimal a, Integer b)
       {
          return ne(a, toLong(b));
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isNotEqual(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isNotEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Integer a, BigDecimal b)
       {
          return ne(toLong(a), b);
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isNotEqual(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test two values for inequality.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean ne(Date a, Date b)
       {
          try
          {
             return CompareOps.isNotEqual(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isGreaterThan(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(String a, String b)
       {
          try
          {
             return CompareOps.isGreaterThan(new character(a), new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Long a, Long b)
       {
          try
          {
             return CompareOps.isGreaterThan(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Long a, Integer b)
       {
          return gt(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Integer a, Long b)
       {
          return gt(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Integer a, Integer b)
       {
          return gt(toLong(a), toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isGreaterThan(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isGreaterThan(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(BigDecimal a, Integer b)
       {
          return gt(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isGreaterThan(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Integer a, BigDecimal b)
       {
          return gt(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isGreaterThan(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gt(Date a, Date b)
       {
          try
          {
             return CompareOps.isGreaterThan(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(String a, String b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(
                new character(a),
                new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Long a, Long b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Long a, Integer b)
       {
          return gte(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Integer a, Long b)
       {
          return gte(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Integer a, Integer b)
       {
          return gte(toLong(a), toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(BigDecimal a, Integer b)
       {
          return gte(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Integer a, BigDecimal b)
       {
          return gte(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &gt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean gte(Date a, Date b)
       {
          try
          {
             return CompareOps.isGreaterThanOrEqual(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isLessThan(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(String a, String b)
       {
          try
          {
             return CompareOps.isLessThan(new character(a), new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Long a, Long b)
       {
          try
          {
             return CompareOps.isLessThan(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Long a, Integer b)
       {
          return lt(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Integer a, Long b)
       {
          return lt(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Integer a, Integer b)
       {
          return lt(toLong(a), toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isLessThan(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isLessThan(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(BigDecimal a, Integer b)
       {
          return lt(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isLessThan(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThan(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Integer a, BigDecimal b)
       {
          return lt(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isLessThan(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt; <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lt(Date a, Date b)
       {
          try
          {
             return CompareOps.isLessThan(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Boolean a, Boolean b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new logical(a), new logical(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(String a, String b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new character(a), new character(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Long a, Long b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Long a, Integer b)
       {
          return lte(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Integer a, Long b)
       {
          return lte(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Integer a, Integer b)
       {
          return lte(toLong(a), toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(BigDecimal a, BigDecimal b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(BigDecimal a, Long b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(BigDecimal a, Integer b)
       {
          return lte(a, toLong(b));
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Long a, BigDecimal b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isLessThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Integer a, BigDecimal b)
       {
          return lte(toLong(a), b);
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Timestamp a, Timestamp b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new datetime(a), new datetime(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Test whether <code>a</code> &lt;= <code>b</code>.
        *
        * @see  com.goldencode.p2j.util.CompareOps#isGreaterThanOrEqual(
        *          com.goldencode.p2j.util.BaseDataType,
        *          com.goldencode.p2j.util.BaseDataType)
        */
       @HQLFunction
       public static Boolean lte(Date a, Date b)
       {
          try
          {
             return CompareOps.isLessThanOrEqual(new date(a), new date(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long plus(Long a, Long b)
       {
          try
          {
             return MathOps.plus(new int64(a), new int64(b)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long plus(Long a, Integer b)
       {
          return plus(a, toLong(b));
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long plus(Integer a, Long b)
       {
          return plus(toLong(a), b);
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long plus(Integer a, Integer b)
       {
          return plus(toLong(a), toLong(b));
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal plus(BigDecimal a, BigDecimal b)
       {
          try
          {
             return MathOps.plus(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal plus(BigDecimal a, Long b)
       {
          try
          {
             return MathOps.plus(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal plus(BigDecimal a, Integer b)
       {
          return plus(a, toLong(b));
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal plus(Long a, BigDecimal b)
       {
          try
          {
             return MathOps.plus(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#plus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal plus(Integer a, BigDecimal b)
       {
          return plus(toLong(a), b);
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(Date value, Long days)
       {
          try
          {
             java.util.Date d = date.plusDays(new date(value), new int64(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(Date value, Integer days)
       {
          return plus(value, toLong(days));
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(Date value, BigDecimal days)
       {
          try
          {
             java.util.Date d = date.plusDays(new date(value), new decimal(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(Long days, Date value)
       {
          try
          {
             java.util.Date d = date.plusDays(new date(value), new int64(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(Integer days, Date value)
       {
          return plus(toLong(days), value);
       }

       /**
        * Add a number of days to a date.
        *
        * @see  com.goldencode.p2j.util.date#plusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date plus(BigDecimal days, Date value)
       {
          try
          {
             java.util.Date d = date.plusDays(new date(value), new decimal(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of milliseconds to a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#plusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp plusMillis(BigDecimal millis, Timestamp value)
       {
          try
          {
             java.util.Date d = datetime.plusMillis(new datetime(value),
                                              new decimal(millis)).dateValue();

             return (d != null ? new Timestamp(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of milliseconds to a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#plusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp plusMillis(Timestamp value, BigDecimal millis)
       {
          try
          {
             java.util.Date d = datetime.plusMillis(new datetime(value),
                                              new decimal(millis)).dateValue();

             return (d != null ? new Timestamp(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of milliseconds to a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#plusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp plusMillis(Timestamp value, Long millis)
       {
          try
          {
             java.util.Date d = datetime.plusMillis(new datetime(value),
                                              new int64(millis)).dateValue();

             return (d != null ? new Timestamp(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Add a number of milliseconds to a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#plusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp plusMillis(Timestamp value, Integer millis)
       {
          return plusMillis(value, toLong(millis));
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long minus(Long a, Long b)
       {
          try
          {
             return MathOps.minus(new int64(a), new int64(b)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long minus(Long a, Integer b)
       {
          return minus(a, toLong(b));
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long minus(Integer a, Long b)
       {
          return minus(toLong(a), b);
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long minus(Integer a, Integer b)
       {
          return minus(toLong(a), toLong(b));
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal minus(BigDecimal a, BigDecimal b)
       {
          try
          {
             return MathOps.minus(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal minus(BigDecimal a, Long b)
       {
          try
          {
             return MathOps.minus(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal minus(BigDecimal a, Integer b)
       {
          return minus(a, toLong(b));
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal minus(Long a, BigDecimal b)
       {
          try
          {
             return MathOps.minus(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Subtract one number from another.
        *
        * @see  com.goldencode.p2j.util.MathOps#minus(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal minus(Integer a, BigDecimal b)
       {
          return minus(toLong(a), b);
       }

       /**
        * Calculate a date by subtracting a number of days from a date.
        *
        * @see  com.goldencode.p2j.util.date#minusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date minus(Date value, Long days)
       {
          try
          {
             java.util.Date d = date.minusDays(new date(value), new int64(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate a date by subtracting a number of days from a date.
        *
        * @see  com.goldencode.p2j.util.date#minusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date minus(Date value, Integer days)
       {
          return minus(value, toLong(days));
       }

       /**
        * Calculate a date by subtracting a number of days from a date.
        *
        * @see  com.goldencode.p2j.util.date#minusDays(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Date minus(Date value, BigDecimal days)
       {
          try
          {
             java.util.Date d = date.minusDays(new date(value), new decimal(days)).dateValue();

             return (d != null ? new Date(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate a timestamp by substracting a number of milliseconds from a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#minusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp minusMillis(Timestamp value, BigDecimal millis)
       {
          try
          {
             java.util.Date d = datetime.minusMillis(new datetime(value),
                                              new decimal(millis)).dateValue();

             return (d != null ? new Timestamp(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);
             return null;
          }
       }

       /**
        * Calculate a timestamp by substracting a number of milliseconds from a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#minusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp minusMillis(Timestamp value, Long millis)
       {
          try
          {
             java.util.Date d = datetime.minusMillis(new datetime(value),
                                              new int64(millis)).dateValue();

             return (d != null ? new Timestamp(d.getTime()) : null);
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);
             return null;
          }
       }

       /**
        * Calculate a timestamp by substracting a number of milliseconds from a datetime.
        *
        * @see  com.goldencode.p2j.util.datetime#minusMillis(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Timestamp minusMillis(Timestamp value, Integer millis)
       {
          return minusMillis(value, toLong(millis));
       }

       /**
        * Determine the number of days between two dates.
        *
        * @see  com.goldencode.p2j.util.date#differenceNum(
        *          com.goldencode.p2j.util.date,
        *          com.goldencode.p2j.util.date)
        */
       @HQLFunction
       public static Long dateSpan(Date d1, Date d2)
       {
          try
          {
             return date.differenceNum(new date(d1), new date(d2)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Determine the number of milliseconds between two timestamps.
        *
        * @see  com.goldencode.p2j.util.datetime#differenceNum(
        *          com.goldencode.p2j.util.datetime,
        *          com.goldencode.p2j.util.datetime)
        */
       @HQLFunction
       public static Long timeSpan(Timestamp d1, Timestamp d2)
       {
          try
          {
             return datetime.differenceNum(new datetime(d1), new datetime(d2)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long multiply(Long a, Long b)
       {
          try
          {
             return MathOps.multiply(new int64(a), new int64(b)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long multiply(Long a, Integer b)
       {
          return multiply(a, toLong(b));
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long multiply(Integer a, Long b)
       {
          return multiply(toLong(a), b);
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static Long multiply(Integer a, Integer b)
       {
          return multiply(toLong(a), toLong(b));
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal multiply(BigDecimal a, BigDecimal b)
       {
          try
          {
             return MathOps.multiply(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal multiply(BigDecimal a, Long b)
       {
          try
          {
             return MathOps.multiply(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal multiply(BigDecimal a, Integer b)
       {
          return multiply(a, toLong(b));
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal multiply(Long a, BigDecimal b)
       {
          try
          {
             return MathOps.multiply(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the product of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#multiply(
        *          com.goldencode.p2j.util.int64,
        *          com.goldencode.p2j.util.int64)
        */
       @HQLFunction
       public static BigDecimal multiply(Integer a, BigDecimal b)
       {
          return multiply(toLong(a), b);
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Long a, Long b)
       {
          try
          {
             return MathOps.divide(new int64(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Integer a, Long b)
       {
          return divide(toLong(a), b);
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Long a, Integer b)
       {
          return divide(a, toLong(b));
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Integer a, Integer b)
       {
          return divide(toLong(a), toLong(b));
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(BigDecimal a, BigDecimal b)
       {
          try
          {
             return MathOps.divide(new decimal(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(BigDecimal a, Long b)
       {
          try
          {
             return MathOps.divide(new decimal(a), new int64(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(BigDecimal a, Integer b)
       {
          return divide(a, toLong(b));
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Long a, BigDecimal b)
       {
          try
          {
             return MathOps.divide(new int64(a), new decimal(b)).toJavaType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the quotient of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#divide(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static BigDecimal divide(Integer a, BigDecimal b)
       {
          return divide(toLong(a), b);
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Long a, Long b)
       {
          try
          {
             return MathOps.modulo(new int64(a), new int64(b)).toJavaLongType();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Long a, Integer b)
       {
          return modulo(a, toLong(b));
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Integer a, Long b)
       {
          return modulo(toLong(a), b);
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Integer a, Integer b)
       {
          return modulo(toLong(a), toLong(b));
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(BigDecimal a, BigDecimal b)
       {
          try
          {
             int64 mod = MathOps.modulo(new decimal(a), new decimal(b));
             return mod.isUnknown() ? null : mod.longValue();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(BigDecimal a, Long b)
       {
          try
          {
             int64 mod = MathOps.modulo(new decimal(a), new int64(b));
             return mod.isUnknown() ? null : mod.longValue();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(BigDecimal a, Integer b)
       {
          return modulo(a, toLong(b));
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Long a, BigDecimal b)
       {
          try
          {
             int64 mod = MathOps.modulo(new int64(a), new decimal(b));
             return mod.isUnknown() ? null : mod.longValue();
          }
          catch (RuntimeException exc)
          {
             ErrorHandler.handleError(exc);

             return null;
          }
       }

       /**
        * Calculate the integer remainder resulting from the integer division of two numbers.
        *
        * @see  com.goldencode.p2j.util.MathOps#modulo(
        *          com.goldencode.p2j.util.NumberType,
        *          com.goldencode.p2j.util.NumberType)
        */
       @HQLFunction
       public static Long modulo(Integer a, BigDecimal b)
       {
          return modulo(toLong(a), b);
       }

       /**
        * Rewraps an <code>Integer</code> value into a <code>Long</code>.
        *
        * @param   i
        *          The <code>java.lang.Integer</code> to be rewrapped.
        *
        * @return  The <code>java.lang.Long</code> that wraps the passed integer value or
        *          <code>null</code> if the argument was <code>null</code>.
        */
       private static Long toLong(Integer i)
       {
          return i == null ? null : i.longValue();
       }
    }