/** * PUBLIC: * Return a Map.Entry containing the key and the value from a mapping that maps to a java.util.Map * This expression can only be used as a return value in a ReportQuery and cannot be used as part of * the WHERE clause in any query * * EclipseLink: eb.get("mapAttribute").mapEntry() * @return */ public Expression mapEntry(){ MapEntryExpression expression = new MapEntryExpression(this); expression.returnMapEntry(); return expression; }
/** * INTERNAL: * Used to print a debug form of the expression tree. */ @Override public void writeDescriptionOn(BufferedWriter writer) throws IOException { writer.write(descriptionOfNodeType()); }
/** * INTERNAL: */ @Override public List<DatabaseField> getSelectionFields(ReadQuery query) { ArrayList<DatabaseField> result = new ArrayList<DatabaseField>(); InterfaceContainerPolicy icp = getInterfaceContainerPolicy(); // if this is a map entry get all the fields for both the key and the value if (returnMapEntry || !icp.isMappedKeyMapPolicy()){ result.addAll(getBaseExpression().getSelectionFields(query)); } else if (isAttribute()) { DatabaseField field = getField(); if (field != null) { result.add(field); } } else { result.addAll(getInterfaceContainerPolicy().getAdditionalFieldsForJoin(getMapping())); } return result; }
/** * INTERNAL: */ @Override public DatabaseField getField() { if (!isAttribute()) { return null; } DatabaseField field = getInterfaceContainerPolicy().getDirectKeyField(getMapping()); return field; }
/** * Do any required validation for this node. Throw an exception if it's incorrect. */ @Override public void validateNode() { if ((getQueryKeyOrNull() == null) && (getMapping() == null)) { throw QueryException.invalidQueryKeyInExpression(getName()); } if (!getMapping().isCollectionMapping()) { throw QueryException.mapEntryExpressionForNonCollection(getBaseExpression(), getMapping()); } ContainerPolicy cp = getMapping().getContainerPolicy(); if ((cp == null) || !cp.isMapPolicy()) { throw QueryException.mapEntryExpressionForNonMap(getBaseExpression(), getMapping()); } }
@Override public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = getSession().getDescriptor(queryKey.getReferenceClass()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getContainerPolicy().getDescriptorForMapKey(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } } return descriptor; }
/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree * @Override */ public Expression rebuildOn(Expression newBase) { Expression newLocalBase = getBaseExpression().rebuildOn(newBase); Expression result = null; if (returnMapEntry){ result = newLocalBase.mapEntry(); } else { result = newLocalBase.mapKey(); } result.setSelectIfOrderedBy(selectIfOrderedBy()); return result; }
if (item.getMapping() != null) { if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) { if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) { returnQuery.getReturnTypes().add(Map.Entry.class.getSimpleName()); } else {
QueryKeyExpression baseExpression = (QueryKeyExpression)mapEntryExpression.getBaseExpression(); if (mapEntryExpression.shouldReturnMapEntry()) { return mapping;
private InterfaceContainerPolicy getInterfaceContainerPolicy(){ DatabaseMapping mapping = getMapping(); if (mapping == null) { throw QueryException.noMappingForMapEntryExpression(getBaseExpression()); } if (!mapping.isCollectionMapping()){ throw QueryException.mapEntryExpressionForNonCollection(getBaseExpression(), getMapping()); } InterfaceContainerPolicy cp = null; try{ cp = (InterfaceContainerPolicy)getMapping().getContainerPolicy(); } catch (ClassCastException e){ throw QueryException.mapEntryExpressionForNonMap(getBaseExpression(), getMapping()); } return cp; }
/** * PUBLIC: * Return the key from a mapping that maps to a java.util.Map * This expression can be used either in as a return value in a ReportQuery or in the WHERE clause in a query * * TopLink: eb.get("mapAttribute").mapKey() * @return */ public Expression mapKey(){ return new MapEntryExpression(this); }
/** * INTERNAL: * Find the alias for a given table. A TableEntry is a place holder and its base expression holds * all the relevant information. Get the alias from the baseExpression */ @Override public DatabaseTable aliasForTable(DatabaseTable table) { return ((DataExpression)getBaseExpression()).aliasForTable(table); }
public QueryKey getQueryKeyOrNull() { if (!hasQueryKey) { return null; } InterfaceContainerPolicy cp = getInterfaceContainerPolicy(); if (queryKey == null) { if (returnMapEntry){ return null; } else { queryKey = cp.createQueryKeyForMapKey(); } } return queryKey; }
/** * Do any required validation for this node. Throw an exception if it's incorrect. */ @Override public void validateNode() { if ((getQueryKeyOrNull() == null) && (getMapping() == null)) { throw QueryException.invalidQueryKeyInExpression(getName()); } if (!getMapping().isCollectionMapping()) { throw QueryException.mapEntryExpressionForNonCollection(getBaseExpression(), getMapping()); } ContainerPolicy cp = getMapping().getContainerPolicy(); if ((cp == null) || !cp.isMapPolicy()) { throw QueryException.mapEntryExpressionForNonMap(getBaseExpression(), getMapping()); } }
public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = getSession().getDescriptor(queryKey.getReferenceClass()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getContainerPolicy().getDescriptorForMapKey(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } } return descriptor; }
/** * INTERNAL: */ @Override public DatabaseField getField() { if (!isAttribute()) { return null; } DatabaseField field = getInterfaceContainerPolicy().getDirectKeyField(getMapping()); return field; }
/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree */ @Override public Expression rebuildOn(Expression newBase) { Expression newLocalBase = getBaseExpression().rebuildOn(newBase); Expression result = null; if (returnMapEntry){ result = newLocalBase.mapEntry(); } else { result = newLocalBase.mapKey(); } result.setSelectIfOrderedBy(selectIfOrderedBy()); return result; }
if (item.getMapping() != null) { if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) { if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) { returnQuery.getReturnTypes().add(Map.Entry.class.getSimpleName()); } else {
QueryKeyExpression baseExpression = (QueryKeyExpression)mapEntryExpression.getBaseExpression(); if (mapEntryExpression.shouldReturnMapEntry()) { return mapping;
private InterfaceContainerPolicy getInterfaceContainerPolicy(){ DatabaseMapping mapping = getMapping(); if (mapping == null) { throw QueryException.noMappingForMapEntryExpression(getBaseExpression()); } if (!mapping.isCollectionMapping()){ throw QueryException.mapEntryExpressionForNonCollection(getBaseExpression(), getMapping()); } InterfaceContainerPolicy cp = null; try{ cp = (InterfaceContainerPolicy)((CollectionMapping)getMapping()).getContainerPolicy(); } catch (ClassCastException e){ throw QueryException.mapEntryExpressionForNonMap(getBaseExpression(), getMapping()); } return cp; }