/** * Return if the expression is by primary key. */ public boolean isPrimaryKeyExpression(boolean requiresExactMatch, Expression expression, AbstractSession session) { expression.getBuilder().setSession(session.getRootSession(null)); List<DatabaseField> keyFields = this.descriptor.getPrimaryKeyFields(); int size = keyFields.size(); Set<DatabaseField> fields = new HashSet(size); boolean isValid = expression.extractFields(requiresExactMatch, true, this.descriptor, keyFields, fields); if (requiresExactMatch && (!isValid)) { return false; } // Check that the sizes match. if (fields.size() != size) { return false; } return true; }
/** * Return if the expression is by primary key. */ public boolean isPrimaryKeyExpression(boolean requiresExactMatch, Expression expression, AbstractSession session) { expression.getBuilder().setSession(session.getRootSession(null)); List<DatabaseField> keyFields = this.descriptor.getPrimaryKeyFields(); int size = keyFields.size(); Set<DatabaseField> fields = new HashSet(size); boolean isValid = expression.extractFields(requiresExactMatch, true, this.descriptor, keyFields, fields); if (requiresExactMatch && (!isValid)) { return false; } // Check that the sizes match. if (fields.size() != size) { return false; } return true; }
/** * Return the row from the given expression. */ public AbstractRecord extractRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord record = createRecord(session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractValues(false, false, this.descriptor, record, translationRow); if (!isValid) { return null; } return record; }
/** * Return the row from the given expression. */ public AbstractRecord extractRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord record = createRecord(session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractValues(false, false, this.descriptor, record, translationRow); if (!isValid) { return null; } return record; }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * INTERNAL: * Iterate through a list of joined expressions and add the fields they represent to a list * of fields. */ protected void addSelectionFieldsForJoinedExpressions(List fields, List joinedExpressions) { for (int index = 0; index < joinedExpressions.size(); index++) { ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index); // Expression may not have been initialized. ExpressionBuilder builder = objectExpression.getBuilder(); builder.setSession(getSession().getRootSession(null)); builder.setQueryClass(getReferenceClass()); ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor(); fields.addAll(descriptor.getAllFields()); } }
/** * Return the row with primary keys and their values from the given expression. */ public Vector extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { if (translationRow != null && translationRow.hasSopObject()) { return translationRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, getDescriptor(), primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, getDescriptor(), primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { if (translationRow != null && translationRow.hasSopObject()) { return translationRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Return the row with primary keys and their values from the given expression. */ public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } Object primaryKey = extractPrimaryKeyFromRow(primaryKeyRow, session); if ((primaryKey == null) && isValid) { return InvalidObject.instance; } return primaryKey; }
/** * Return the row with primary keys and their values from the given expression. */ public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } Object primaryKey = extractPrimaryKeyFromRow(primaryKeyRow, session); if ((primaryKey == null) && isValid) { return InvalidObject.instance; } return primaryKey; }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, getDescriptor(), primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ @Override public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, getDescriptor(), primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ public Vector extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, getDescriptor(), primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
/** * Override method in superclass in order to set the session on the record. * Return the row with primary keys and their values from the given expression. */ @Override public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, getDescriptor(), primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
/** * INTERNAL: * Return if the expression is not a valid primary key expression and add all primary key fields to the set. */ @Override public boolean extractFields(boolean requireExactMatch, boolean primaryKey, ClassDescriptor descriptor, List<DatabaseField> searchFields, Set<DatabaseField> foundFields) { // If this is a primary key expression then it can only have and/or relationships. if (this.operator.getSelector() != ExpressionOperator.And) { // If this is an exact primary key expression it can not have ors. // After fixing bug 2782991 this must now work correctly. if (requireExactMatch || (this.operator.getSelector() != ExpressionOperator.Or)) { return false; } } // Ensure that both sides of the expression tree have a session, for correct descriptor, field resolution if (this.secondChild.getSession() == null && this.firstChild.getSession() != null) { this.secondChild.getBuilder().setSession(this.firstChild.getSession()); } else if (this.firstChild.getSession() == null && this.secondChild.getSession() != null) { this.firstChild.getBuilder().setSession(this.secondChild.getSession()); } boolean validExpression = this.firstChild.extractFields(requireExactMatch, primaryKey, descriptor, searchFields, foundFields); if (requireExactMatch && (!validExpression)) { return false; } return this.secondChild.extractFields(requireExactMatch, primaryKey, descriptor, searchFields, foundFields); }
/** * INTERNAL: * If the alias is for a query key item, then return its descriptor. * If it is for a function, then it has no descriptor. */ @Override public ClassDescriptor getContainingDescriptor() { AbstractSession session = getBuilder().getSession(); if (this.containingDescriptor == null) { Expression expression = getItem().getAttributeExpression(); if (expression.isQueryKeyExpression()) { // Need to ensure expression has a session before getting its descriptor. if (expression.getBuilder().getSession() == null) { expression.getBuilder().setSession(session); } this.containingDescriptor = ((QueryKeyExpression)expression).getContainingDescriptor(); return this.containingDescriptor; } return null; } return containingDescriptor; }
/** * INTERNAL: * If the alias is for a query key item, then return its descriptor. * If it is for a function, then it has no descriptor. */ @Override public ClassDescriptor getContainingDescriptor() { AbstractSession session = getBuilder().getSession(); if (this.containingDescriptor == null) { Expression expression = getItem().getAttributeExpression(); if (expression.isQueryKeyExpression()) { // Need to ensure expression has a session before getting its descriptor. if (expression.getBuilder().getSession() == null) { expression.getBuilder().setSession(session); } this.containingDescriptor = ((QueryKeyExpression)expression).getContainingDescriptor(); return this.containingDescriptor; } return null; } return containingDescriptor; }