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; } } });
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... }
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... }
List<OProperty<?>> keyProperties = new ArrayList<OProperty<?>>(entityKey.asComplexProperties()); BoolCommonExpression keyPredicate = null; for (int i = 0; i < keyProperties.size(); i++) {
List<OProperty<?>> keyProperties = new ArrayList<OProperty<?>>(entityKey.asComplexProperties()); BoolCommonExpression keyPredicate = null;
static Object typeSafeEntityKey( EntityManager em, EntityType<?> jpaEntityType, OEntityKey entityKey) { if (entityKey != null && jpaEntityType.getIdType().getPersistenceType() == PersistenceType.EMBEDDABLE) { Object id = newInstance(jpaEntityType.getIdType().getJavaType()); applyOProperties( em, em.getMetamodel().embeddable( jpaEntityType.getIdType().getJavaType()), entityKey.asComplexProperties(), id); return id; } Class<?> javaType = jpaEntityType.getIdType().getJavaType(); try { return TypeConverter.convert(entityKey == null ? null : entityKey.asSingleValue(), javaType); } catch (UnsupportedOperationException e) { throw new BadRequestException("Invalid key type", e); } catch (IllegalArgumentException e) { throw new BadRequestException("Invalid key value", e); } }
OEntity newEntity = c.createEntity(tableName).properties(rowKey1.asComplexProperties()).properties( OProperties.string("foo", "bar")) .execute();