public Expression equal(char theChar) { return equal(new Character(theChar)); }
public Expression equal(double theValue) { return equal(new Double(theValue)); }
public Expression equal(float theValue) { return equal(new Float(theValue)); }
public Expression equal(int theValue) { return equal(new Integer(theValue)); }
public Expression equal(long theValue) { return equal(new Long(theValue)); }
public Expression equal(boolean theBoolean) { return equal(new Boolean(theBoolean)); }
public Expression equal(byte theValue) { return equal(new Byte(theValue)); }
public Expression equal(short theValue) { return equal(new Short(theValue)); }
/** * PUBLIC: * Return an expression that compares if the receiver's value is equal to the other value, ignoring case. * This is equivalent to the Java "equalsIgnoreCase" method. * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").equalsIgnoreCase("Bob") * Java: employee.getFirstName().equalsIgnoreCase("Bob") * SQL: UPPER(F_NAME) = 'BOB' * </blockquote></pre> */ public Expression equalsIgnoreCase(String theValue) { return toUpperCase().equal(theValue.toUpperCase()); }
/** * PUBLIC: A logical expression for the collection <code>attributeName</code> * being empty. * Equivalent to <code>size(attributeName).equal(0)</code> * <p>Example: * <pre><blockquote> * TopLink: employee.isEmpty("phoneNumbers") * Java: employee.getPhoneNumbers().size() == 0 * SQL: SELECT ... FROM EMP t0 WHERE ( * (SELECT COUNT(*) FROM PHONE t1 WHERE (t0.EMP_ID = t1.EMP_ID)) = 0) * </blockquote></pre> * This is a case where a fast operation in java does not translate to an * equally fast operation in SQL, requiring a correlated subselect. * @see #size(java.lang.String) */ public Expression isEmpty(String attributeName) { return size(attributeName).equal(0); }
/** * PUBLIC: * Return an expression that compares if the receiver's value is equal to the other value, ignoring case. * This is equivalent to the Java "equalsIgnoreCase" method. * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").equalsIgnoreCase("Bob") * Java: employee.getFirstName().equalsIgnoreCase("Bob") * SQL: UPPER(F_NAME) = 'BOB' * </blockquote></pre> */ public Expression equalsIgnoreCase(Expression theValue) { return toUpperCase().equal(theValue.toUpperCase()); }
/** * Iterate the set of variables declared in an outer scope and * connect the inner varaible expression with the outer one. */ public Expression joinVariables(Set variables) { if ((outer == null) || (variables == null) || variables.isEmpty()) { // not an inner query or no variables to join return null; } Expression expr = null; for (Iterator i = variables.iterator(); i.hasNext(); ) { String name = (String)i.next(); VariableNode var = new VariableNode(name); Expression innerExpr = var.generateExpression(this); Expression outerExpr = var.generateExpression(outer); Expression join = innerExpr.equal(outerExpr); expr = var.appendExpression(expr, join); } return expr; } }
/** * Delete all criteria is created with target foreign keys and source keys. * This criteria is then used to delete target records from the table. */ protected Expression getDeleteAllCriteria(AbstractSession session) { Expression expression; Expression criteria = null; Expression builder = new ExpressionBuilder(); for (Iterator keys = getTargetForeignKeyToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = (DatabaseField)getTargetForeignKeyToSourceKeys().get(targetForeignKey); expression = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); criteria = expression.and(criteria); } return criteria; }
/** * Build the primary key expression from the specified primary key values. */ public Expression buildPrimaryKeyExpressionFromKeys(Vector primaryKeyValues, AbstractSession session) { Expression expression = null; Expression subExpression; Expression builder = new ExpressionBuilder(); List primaryKeyFields = getDescriptor().getPrimaryKeyFields(); for (int index = 0; index < primaryKeyFields.size(); index++) { Object value = primaryKeyValues.get(index); DatabaseField field = (DatabaseField)primaryKeyFields.get(index); if (value != null) { subExpression = builder.getField(field).equal(value); expression = subExpression.and(expression); } } return expression; }
/** * INTERNAL: * Selection criteria is created with target foreign keys and source keys. * This criteria is then used to read records from the target table. */ protected void initializeSelectionCriteria(AbstractSession session) { Expression expression; Expression criteria; Expression builder = new ExpressionBuilder(); for (Iterator keys = getTargetForeignKeyToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = (DatabaseField)getTargetForeignKeyToSourceKeys().get(targetForeignKey); expression = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); criteria = expression.and(getSelectionCriteria()); setSelectionCriteria(criteria); } }
/** * Resolve the expression. The steps are: * 1. Set the expressionBuilder for the left and right nodes * 2. Generate the expression for the left node * 3. Add the .equals to the where clause returned from step 2 * 4. Generate the expression for the right side and use it as the parameter for the .equals() * 5. Return the completed where clause to the caller */ public Expression generateExpression(GenerationContext context) { Expression whereClause = getLeft().generateExpression(context); whereClause = whereClause.equal(getRight().generateExpression(context)); return whereClause; }
/** * INTERNAL: * Selection criteria is created with source foreign keys and target keys. * This criteria is then used to read target records from the table. * * CR#3922 - This method is almost the same as buildSelectionCriteria() the difference * is that getSelectionCriteria() is called */ protected void initializeSelectionCriteria(AbstractSession session) { if (getSourceToTargetKeyFields().isEmpty()) { throw DescriptorException.noForeignKeysAreSpecified(this); } Expression criteria; Expression builder = new ExpressionBuilder(); for (Iterator entries = getSourceToTargetKeyFields().entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Map.Entry) entries.next(); DatabaseField foreignKey = (DatabaseField)entry.getKey(); DatabaseField targetKey = (DatabaseField)entry.getValue(); Expression expression = builder.getField(targetKey).equal(builder.getParameter(foreignKey)); criteria = expression.and(getSelectionCriteria()); setSelectionCriteria(criteria); } }
/** * INTERNAL: * Used to allow object level comparisons. */ public Expression buildObjectJoinExpression(Expression expression, Expression argument, AbstractSession session) { Expression attributeByAttributeComparison = null; //Enumeration mappingsEnum = getSourceToTargetKeyFields().elements(); Enumeration mappingsEnum = getReferenceDescriptor().getMappings().elements(); for (; mappingsEnum.hasMoreElements();) { DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement(); String attributeName = mapping.getAttributeName(); Expression join = expression.get(attributeName).equal(argument.get(attributeName)); if (attributeByAttributeComparison == null) { attributeByAttributeComparison = join; } else { attributeByAttributeComparison = attributeByAttributeComparison.and(join); } } return attributeByAttributeComparison; }
/** * Build the primary key expression for the secondary table. */ public Expression buildPrimaryKeyExpression(DatabaseTable table) throws DescriptorException { if (getDescriptor().getTables().firstElement().equals(table)) { return getPrimaryKeyExpression(); } Map keyMapping = (Map)getDescriptor().getAdditionalTablePrimaryKeyFields().get(table); if (keyMapping == null) { throw DescriptorException.multipleTablePrimaryKeyNotSpecified(getDescriptor()); } ExpressionBuilder builder = new ExpressionBuilder(); Expression expression = null; for (Iterator primaryKeyEnum = keyMapping.values().iterator(); primaryKeyEnum.hasNext();) { DatabaseField field = (DatabaseField)primaryKeyEnum.next(); expression = (builder.getField(field).equal(builder.getParameter(field))).and(expression); } return expression; }
/** * INTERNAL: * Returns an expression that will be used for both the update and * delete where clause */ protected Expression buildExpression() { ExpressionBuilder builder = new ExpressionBuilder(); return builder.getField(getWriteLockField()).equal(builder.getParameter(getWriteLockField())); }