Class Filters

java.lang.Object
org.apache.openjpa.kernel.Filters

public class Filters extends Object
Helper methods for dealing with query filters.
Author:
Abe White
  • Constructor Details

    • Filters

      public Filters()
  • Method Details

    • wrap

      public static Class<?> wrap(Class<?> c)
      Return the correct wrapper type for the given class.
    • unwrap

      public static Class<?> unwrap(Class<?> c)
      Return the correct primitive type for the given class, if it is a wrapper.
    • promote

      public static Class<?> promote(Class<?> c1, Class<?> c2)
      Given two types, return type they should both be converted to before performing any operations between them.
    • promoteArithmetic

      public static Class<?> promoteArithmetic(Class<?> c1, Class<?> c2)
      Given the types of the two operands of an arithmetic operation, return the type of its result, which both operands are converted to before the operation. This is promote(Class, Class), except that, as the numeric promotion rules of the specification require, an operation on a BigDecimal or BigInteger and a Double or Float has the floating point type: Double if an operand is Double, else Float, BigDecimal, BigInteger, Long and Integer, in that order.
    • promoteForComparison

      public static Class<?> promoteForComparison(Class<?> c1, Class<?> c2)
      Given the types of two values that are compared, return the type they should both be converted to before the comparison. This is promote(Class, Class), except that a java.time value compared to a java.util.Date is compared as the java.time type, and two different java.util.Date types are compared as timestamps if one of them is a timestamp and as plain dates otherwise.
    • canConvert

      public static boolean canConvert(Class<?> c1, Class<?> c2, boolean strict)
      Return whether an instance of the first class can be converted to an instance of the second.
    • convertToMatchMethodArgument

      public static Object convertToMatchMethodArgument(Object o, Method method)
      Convert the given value to match the given (presumably a setter) method argument type.
      Parameters:
      o - given value
      method - a presumably setter method
      Returns:
      the same value if the method does not have one and only one input argument.
    • convert

      public static Object convert(Object o, Class<?> type)
    • convert

      public static Object convert(Object o, Class<?> type, boolean strictNumericConversion)
      Convert the given value to the given type.
      Parameters:
      o - the given value
      type - the target type
    • toSqlDate

      public static Date toSqlDate(Date date)
      The Date of the day of the given date in the default time zone, normalized to the start of that day as JDBC requires. new java.sql.Date(millis) keeps the time of day, which drivers such as Oracle's bind as part of a DATE value.
    • add

      public static Object add(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Add the given values.
    • subtract

      public static Object subtract(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Subtract the given values.
    • multiply

      public static Object multiply(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Multiply the given values.
    • divide

      public static Object divide(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Divide the given values.
    • mod

      public static Object mod(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Mod the given values.
    • power

      public static Object power(Object o1, Class<?> c1, Object o2, Class<?> c2)
      Power the base to the exponent
    • round

      public static Object round(Object o1, Class<?> c1, Object o2, Class<?> c2)
    • parseDeclaration

      public static List<String> parseDeclaration(String dec, char split, String decType)
      Parses the given declarations into a list of type, name, type, name... Returns null if no declarations. Assumes declaration is not an empty string and is already trimmed (valid assumptions given the checks made in our setters).
      Parameters:
      decType - the type of declaration being parsed, for use in error messages
    • splitExpressions

      public static List<String> splitExpressions(String str, char split, int expected)
      Split the given expression list into distinct expressions. Assumes the given string is not null or of zero length and is already trimmed (valid assumptions given the checks in our setters and before this method call).
    • addAccessPathMetaDatas

      public static List<ClassMetaData> addAccessPathMetaDatas(List<ClassMetaData> metas, ClassMetaData[] path)
      Add the given access path metadatas to the full path list, making sure to maintain only base metadatas in the list. The given list may be null.
    • hintToAggregateListener

      public static AggregateListener hintToAggregateListener(Object hint, ClassLoader loader)
      Convert the user-given hint value to an aggregate listener. The hint can be an aggregate listener instance or class name.
    • hintToAggregateListeners

      public static AggregateListener[] hintToAggregateListeners(Object hint, ClassLoader loader)
      Convert the user-given hint value to an array of aggregate listeners. The hint can be an aggregate listener, aggregate listener array, collection, or comma-separated class names.
    • hintToFilterListener

      public static FilterListener hintToFilterListener(Object hint, ClassLoader loader)
      Convert the user-given hint value to a filter listener. The hint can be a filter listener instance or class name.
    • hintToFilterListeners

      public static FilterListener[] hintToFilterListeners(Object hint, ClassLoader loader)
      Convert the user-given hint value to an array of filter listeners. The hint can be a filter listener, filter listener array, collection, or comma-separated class names.
    • hintToGetter

      public static Object hintToGetter(Object target, String hintKey)
      Return the value of the property named by the hint key.
    • hintToSetter

      public static void hintToSetter(Object target, String hintKey, Object value)
      Set the value of the property named by the hint key.
    • parseJDBCTemporalSyntax

      public static Object parseJDBCTemporalSyntax(String s)
      Parses the given string assuming it is a JDBC key expression. Extracts the data portion and based on the key, calls static java.sql.Date/Time/Timestamp.valueOf(String) method to convert to a java.sql.Date/Time/Timestamp instance.
    • isJDBCTemporalSyntax

      public static boolean isJDBCTemporalSyntax(String s)
      Affirms if the given String is enclosed in {}.
    • clip

      public static String clip(String s, String first, String last, boolean fail)
      Removes the first and last string if they are the terminal sequence in the given string.
      Parameters:
      s - a string to be examined
      first - the characters in the beginning of the given string
      last - the characters in the end of the given string
      fail - if true throws exception if the given string does not have the given terminal sequences.
      Returns:
      the string with terminal sequences removed.
    • isTemporalType

      public static boolean isTemporalType(Class<?> c)
      Affirms if the given class is Data, Time or Timestamp.
    • getDefaultForNull

      public static Object getDefaultForNull(Class<?> nType)