Class ObjectExpression

java.lang.Object
org.datanucleus.store.rdbms.sql.expression.SQLExpression
org.datanucleus.store.rdbms.sql.expression.ObjectExpression
Direct Known Subclasses:
ObjectLiteral, TypeConverterMultiExpression

public class ObjectExpression extends SQLExpression
Representation of an Object expression in a Query. Typically represents a persistable object, and so its identity, though could be used to represent any Object.

Let's take an example. We have classes A and B, and A contains a reference to B "b". If we do a JDOQL query for class A of "b == value" then "b" is interpreted first and an ObjectExpression is created to represent that object (of type B).

  • Constructor Details

    • ObjectExpression

      public ObjectExpression(SQLStatement stmt, SQLTable table, JavaTypeMapping mapping)
      Constructor for an SQL expression for a (field) mapping in a specified table.
      Parameters:
      stmt - The statement
      table - The table in the statement
      mapping - The mapping for the field
    • ObjectExpression

      public ObjectExpression(SQLStatement stmt, JavaTypeMapping mapping, String functionName, List<SQLExpression> args)
      Generates statement as "FUNCTION_NAME(arg [,argN])".
      Parameters:
      stmt - The statement
      mapping - Mapping to use
      functionName - Name of function
      args - SQLExpression list
    • ObjectExpression

      public ObjectExpression(SQLStatement stmt, JavaTypeMapping mapping, String functionName, List<SQLExpression> args, List<Object> types)
      Generates statement as "FUNCTION_NAME(arg [AS type] [,argN [AS typeN]])".
      Parameters:
      stmt - The statement
      mapping - Mapping to use
      functionName - Name of function
      args - SQLExpression list
      types - Optional String/SQLExpression list of types for the args
  • Method Details

    • useFirstColumnOnly

      public void useFirstColumnOnly()
      Method to change the expression to use only the first column. This is used where we want to use the expression with COUNT(...) and that only allows 1 column.
    • eq

      public BooleanExpression eq(SQLExpression expr)
      Equals operator. Called when the query contains "obj == value" where "obj" is this object.
      Overrides:
      eq in class SQLExpression
      Parameters:
      expr - The expression we compare with (the right-hand-side in the query)
      Returns:
      Boolean expression representing the comparison.
    • processComparisonOfImplementationWithReference

      protected BooleanExpression processComparisonOfImplementationWithReference(SQLExpression refExpr, SQLExpression implExpr, boolean negate)
    • ne

      public BooleanExpression ne(SQLExpression expr)
      Not equals operator. Called when the query contains "obj != value" where "obj" is this object.
      Overrides:
      ne in class SQLExpression
      Parameters:
      expr - The expression we compare with (the right-hand-side in the query)
      Returns:
      Boolean expression representing the comparison.
    • addSubexpressionsToRelatedExpression

      protected void addSubexpressionsToRelatedExpression(SQLExpression expr)
      Updates the supplied expression with sub-expressions of consistent types to this expression. This is called when we have some comparison expression (e.g this == expr) and where the other expression has no sub-expressions currently.
      Parameters:
      expr - The expression
    • literalIsValidForSimpleComparison

      private boolean literalIsValidForSimpleComparison(SQLExpression expr)
      Convenience method to return if this object is valid for simple comparison with the passed expression. Performs a type comparison of the object and the expression for compatibility. The expression must be a literal of a suitable type for simple comparison (e.g where this object is a String, and the literal is a StringLiteral).
      Parameters:
      expr - The expression
      Returns:
      Whether a simple comparison is valid
    • in

      public BooleanExpression in(SQLExpression expr, boolean not)
      Description copied from class: SQLExpression
      In expression. Return true if this is contained by expr
      Overrides:
      in in class SQLExpression
      Parameters:
      expr - the right-hand expression
      not - Whether we really want "not in"
      Returns:
      true if the left-hand expression is contained by the right-hand expression. Otherwise the result is false.
    • lt

      public BooleanExpression lt(SQLExpression expr)
      Description copied from class: SQLExpression
      Relational operator (lower than)
      Overrides:
      lt in class SQLExpression
      Parameters:
      expr - the right-hand operand
      Returns:
      true if the value of the left-hand operand is less than the value of the right-hand operand, and otherwise is false.
    • le

      public BooleanExpression le(SQLExpression expr)
      Description copied from class: SQLExpression
      Relational operator (lower than or equals)
      Overrides:
      le in class SQLExpression
      Parameters:
      expr - the right-hand operand
      Returns:
      true if the value of the left-hand operand is less than or equal to the value of the right-hand operand, and otherwise is false.
    • gt

      public BooleanExpression gt(SQLExpression expr)
      Description copied from class: SQLExpression
      Relational operator (greater than)
      Overrides:
      gt in class SQLExpression
      Parameters:
      expr - the right-hand operand
      Returns:
      true if the value of the left-hand operand is greater than the value of the right-hand operand, and otherwise is false.
    • ge

      public BooleanExpression ge(SQLExpression expr)
      Description copied from class: SQLExpression
      Relational operator (greater than or equals)
      Overrides:
      ge in class SQLExpression
      Parameters:
      expr - the right-hand operand
      Returns:
      true if the value of the left-hand operand is greater than or equal the value of the right-hand operand, and otherwise is false.
    • cast

      public SQLExpression cast(SQLExpression expr)
      Cast operator. Called when the query contains "(type)obj" where "obj" is this object.
      Overrides:
      cast in class SQLExpression
      Parameters:
      expr - Expression representing the type to cast to
      Returns:
      Scalar expression representing the cast object.
    • is

      public BooleanExpression is(SQLExpression expr, boolean not)
      An "is" (instanceOf) expression, providing a BooleanExpression whether this expression is an instanceof the provided type.
      Overrides:
      is in class SQLExpression
      Parameters:
      expr - The expression representing the type
      not - Whether the operator is "!instanceof"
      Returns:
      Whether this expression is an instance of the provided type
    • invoke

      public SQLExpression invoke(String methodName, List<SQLExpression> args)
      Description copied from class: SQLExpression
      Invocation of a method on this expression.
      Overrides:
      invoke in class SQLExpression
      Parameters:
      methodName - name of the method to invoke
      args - Args to this method (if any)
      Returns:
      the converted value