protected BoolCommonExpression prependPrimaryKeyFilter(JdbcMetadataMapping mapping, EdmEntityType entityType, OEntityKey entityKey, BoolCommonExpression filter) { List<BoolCommonExpression> filters = new ArrayList<BoolCommonExpression>(); if (entityType.getKeys().size() == 1) { String key = entityType.getKeys().iterator().next(); filters.add(Expression.eq(Expression.simpleProperty(key), Expression.literal(entityKey.asSingleValue()))); } else { Map<String, NamedValue<?>> complexKey = Enumerable.create(entityKey.asComplexValue()).toMap(new Func1<NamedValue<?>, String>() { @Override public String apply(NamedValue<?> nv) { return nv.getName(); } }); for (String key : entityType.getKeys()) { filters.add(Expression.eq(Expression.simpleProperty(key), Expression.literal(complexKey.get(key).getValue()))); } } if (filter != null) filters.add(filter); BoolCommonExpression newFilter = null; for (BoolCommonExpression f : filters) newFilter = newFilter == null ? f : Expression.and(f, newFilter); return newFilter; }