/** * Creates an entity-key from a map of names and values. * * @param values the map of names and values * @return a newly-created entity-key */ public static OEntityKey create(Map<String, Object> values) { return create(NamedValues.fromMap(values)); }
/** * Gets the values of a complex entity-key. * * @return the key values as a set of named-values */ @SuppressWarnings("unchecked") public Set<NamedValue<?>> asComplexValue() { assertComplex(); return (Set<NamedValue<?>>) (Object) toSortedSet(Enumerable.create(values).cast(NamedValue.class), OComparators.namedValueByNameRaw()); }
private OEntityKey(Object[] values) { this.values = values; this.keyString = keyString(values); }
public String apply(String input) { String keyString = targetKeyValues == null || targetKeyValues.length == 0 ? "" : OEntityKey.create(targetKeyValues).toKeyString(); return input + "/$links/" + targetNavProp + keyString; } };
OEntityKey entityKey = OEntityKey.parse(skipToken.substring(start)); if (entityKey.getKeyType() == KeyType.SINGLE) { LiteralExpression entityKeyValue = Expression.literal(entityKey.asSingleValue()); List<OProperty<?>> keyProperties = new ArrayList<OProperty<?>>(entityKey.asComplexProperties()); BoolCommonExpression keyPredicate = null; for (int i = 0; i < keyProperties.size(); i++) {
public static OEntityKey create(Object... values) { if (values != null && values.length == 1 && values[0] instanceof Iterable<?>) return create(Enumerable.create((Iterable<Object>) values[0]).toArray(Object.class)); if (values != null && values.length == 1 && values[0] instanceof OEntityKey) return (OEntityKey) values[0]; rt.put(name, value); return create(rt); Object[] v = validate(values); return new OEntityKey(v);
for (int i = 0; i < v.length; i++) { String keyPropertyName = keys.get(i); v[i] = getProp(props, keyPropertyName); v = validate(v); return new OEntityKey(v);
public static OEntityKey parseEntityKey(String atomEntryId) { Matcher m = ENTITY_SET_NAME.matcher(atomEntryId); if (!m.find()) throw new RuntimeException("Unable to parse the entity-key from atom entry id: " + atomEntryId); return OEntityKey.parse(atomEntryId.substring(m.end() - 1)); }
@Override public String toString() { return this.segment + (key == null ? "" : key.toKeyString()); }
public boolean apply(Object input) { HashMap<String, Object> idObjectMap = ei.id.apply(input); if (keyList.length == 1) { Object idValue = rc.getEntityKey().asSingleValue(); return idObjectMap.get(keyList[0]).equals(idValue); } else if (keyList.length > 1) { for (String key : keyList) { Object curValue = null; Iterator<OProperty<?>> keyProps = rc.getEntityKey().asComplexProperties().iterator(); while (keyProps.hasNext()) { OProperty<?> keyProp = keyProps.next(); if (keyProp.getName().equalsIgnoreCase(key)) { curValue = keyProp.getValue(); } } if (curValue == null) { return false; } else if (!idObjectMap.get(key).equals(curValue)) { return false; } } return true; } else { return false; } } });
OEntityKey rowKey1 = OEntityKey.create("PartitionKey", "", "RowKey", "1"); OEntity newEntity = c.createEntity(tableName).properties(rowKey1.asComplexProperties()).properties( OProperties.string("foo", "bar")) .execute();
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; }
protected void findSchema(Context c) { EdmDataServices ds = dataProducer.getMetadata(); String nm = (String) c.entityKey.asSingleValue(); for (EdmSchema s : ds.getSchemas()) { if (nm.equals(s.getNamespace())) { c.entities.add(this.getSchema(c, s)); } } }
protected void findStructuralType(Context c, boolean isEntity, boolean root) { EdmDataServices ds = dataProducer.getMetadata(); Iterable<?> candidates = isEntity ? ds.getEntityTypes() : ds.getComplexTypes(); for (Object eto : candidates) { EdmStructuralType st = (EdmStructuralType) eto; if (root && st.getBaseType() != null) { continue; } boolean matchedAll = true; for (OProperty<?> keyprop : c.entityKey.asComplexProperties()) { String val = null; if (keyprop.getName().equals(Edm.EntityType.Namespace)) { val = st.getNamespace(); } else if (keyprop.getName().equals(Edm.EntityType.Name)) { val = st.getName(); } else { throw new RuntimeException(keyprop.getName() + " is not a key property of " + c.entitySet.getName()); } if (!keyprop.getValue().toString().equals(val)) { matchedAll = false; break; } } if (matchedAll) { c.entities.add(this.getStructuralType(c, st)); } } // didn't find it... }
/** * returns the value for a named value in a complex key. * @param name * @return the value */ public Object getComplexKeyValue(String name) { assertComplex(); for (Object o : this.values) { NamedValue<?> nv = (NamedValue<?>) o; if (nv.getName().equals(name)) { return nv.getValue(); } } return null; }
if (o instanceof NamedValue) o = ((NamedValue<?>) o).getValue(); assertSimple(o); return new Object[] { o }; throw new IllegalArgumentException( "Complex key values cannot be null"); assertSimple(nv.getValue()); v[i] = NamedValues.copy(nv);
*/ OEntityKey entityKey = OEntityKey.parse(skipToken.substring(start), names); if (entityKey.getKeyType() == KeyType.SINGLE) { LiteralExpression entityKeyValue = Expression.literal(entityKey.asSingleValue()); List<OProperty<?>> keyProperties = new ArrayList<OProperty<?>>(entityKey.asComplexProperties()); BoolCommonExpression keyPredicate = null;
public static OEntityKey create(Object... values) { if (values != null && values.length == 1 && values[0] instanceof Iterable<?>) return create(Enumerable.create((Iterable<Object>) values[0]).toArray(Object.class)); if (values != null && values.length == 1 && values[0] instanceof OEntityKey) return (OEntityKey) values[0]; rt.put(name, value); return create(rt); Object[] v = validate(values); return new OEntityKey(v);
public String apply(String input) { String keyString = targetKeyValues == null || targetKeyValues.length == 0 ? "" : OEntityKey.create(targetKeyValues).toKeyString(); return input + "/$links/" + targetNavProp + keyString; } };
for (int i = 0; i < v.length; i++) { String keyPropertyName = keys.get(i); v[i] = getProp(props, keyPropertyName); v = validate(v); return new OEntityKey(v);