@Override public boolean apply(OEntity input) { Object pv = input.getProperty(propName).getValue(); return (value == null) ? pv == null : value.equals(pv); } };
public SqlStatement generate(JdbcMetadataMapping mapping, EdmEntitySet entitySet, OEntity entity) { JdbcTable table = mapping.getMappedTable(entitySet); StringBuilder sql = new StringBuilder("INSERT INTO " + table.tableName + "("); StringBuilder columns = new StringBuilder(); StringBuilder values = new StringBuilder(); List<SqlParameter> params = new ArrayList<SqlParameter>(); for (OProperty<?> prop : entity.getProperties()) { if (columns.length() > 0) columns.append(", "); if (values.length() > 0) values.append(", "); EdmProperty edmProp = entitySet.getType().findProperty(prop.getName()); JdbcColumn column = mapping.getMappedColumn(edmProp); columns.append(column.columnName); values.append("?"); params.add(new SqlParameter(prop.getValue(), null)); } sql.append(columns); sql.append(") VALUES ("); sql.append(values); sql.append(")"); return new SqlStatement(sql.toString(), ImmutableList.copyOf(params)); }
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; } } });
public TProperty apply(OEntity input) { return input.getProperty(propName, propClass).getValue(); } };
isComplex = false; Object value = entity.getProperty(colName).getValue(); if (isComplex) { List<OProperty<?>> embeddedProperties = (List<OProperty<?>>)value; for (OProperty prop:embeddedProperties) { if (prop.getName().equals(columns[i].getSourceName())) { value = prop.getValue(); break; while(this.complexValues.hasNext()) { OProperty prop = this.complexValues.next(); values.put(prop.getName(), prop.getValue());
@Override public boolean apply(OEntity input) { Object pv = input.getProperty(propName).getValue(); return (value == null) ? pv == null : value.equals(pv); } };
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... }
@Override public boolean apply(OEntity input) { Object pv = input.getProperty(propName).getValue(); return (value == null) ? pv == null : value.equals(pv); } };
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... }
static Object coercePropertyValue(OProperty<?> prop, Class<?> javaType) { Object value = prop.getValue(); try { return TypeConverter.convert(value, javaType); } catch (UnsupportedOperationException ex) { // let java complain return value; } }
private void run(String[] args) { ODataConsumer c = ODataConsumers.create(ODataEndpoints.NETFLIX); // locate the netflix id for Morgan Spurlock int morganSpurlockId = c.getEntities("People").filter("substringof('Spurlock',Name)").execute().first().getProperty("Id", Integer.class).getValue(); // lookup and print all titles he's acted in List<OEntity> titlesActedIn = c.getEntities("People").nav(morganSpurlockId, "TitlesActedIn").execute().toList(); for (OEntity title : titlesActedIn) { for (OProperty<?> p : title.getProperties()) { report("%s: %s", p.getName(), p.getValue()); } report("\n"); } report("count: " + titlesActedIn.size()); }