protected OEntity toOEntity(JdbcMetadataMapping mapping, EdmEntitySet entitySet, ResultSet results) throws SQLException { List<OProperty<?>> properties = new ArrayList<OProperty<?>>(); for (EdmProperty edmProperty : entitySet.getType().getProperties()) { JdbcColumn column = mapping.getMappedColumn(edmProperty); Object value = results.getObject(column.columnName); OProperty<?> property = OProperties.simple(edmProperty.getName(), value); properties.add(property); } OEntityKey entityKey = OEntityKey.infer(entitySet, properties); return OEntities.create(entitySet, entityKey, properties, Collections.<OLink> emptyList()); }
? (dsae.id.endsWith(")") ? parseEntityKey(dsae.id) : OEntityKey.infer(entitySet, props)) : null;
? (dsae.id.endsWith(")") ? parseEntityKey(dsae.id) : OEntityKey.infer(entitySet, props)) : null;
@Override public CommandResult execute(CreateEntityCommandContext context) throws Exception { JdbcProducerCommandContext jdbcContext = (JdbcProducerCommandContext) context; String entitySetName = context.getEntitySetName(); final JdbcMetadataMapping mapping = jdbcContext.getBackend().getMetadataMapping(); final EdmEntitySet entitySet = mapping.getMetadata().findEdmEntitySet(entitySetName); if (entitySet == null) throw new NotFoundException(); GenerateSqlInsert insertGen = jdbcContext.get(GenerateSqlInsert.class); final SqlStatement sqlStatement = insertGen.generate(mapping, entitySet, context.getEntity()); jdbcContext.getJdbc().execute(new ThrowingFunc1<Connection, Void>() { @Override public Void apply(Connection conn) throws Exception { PreparedStatement stmt = sqlStatement.asPreparedStatement(conn); int updated = stmt.executeUpdate(); if (updated == 0) throw new BadRequestException("Entity not inserted"); return null; } }); // now re-query for inserted entity OEntityKey entityKey = OEntityKey.infer(entitySet, context.getEntity().getProperties()); GetEntityCommandContext getEntityCommandContext = jdbcContext.getBackend().newGetEntityCommandContext(entitySetName, entityKey, null); jdbcContext.getBackend().getCommand(GetEntityCommandContext.class).execute(getEntityCommandContext); OEntity newEntity = getEntityCommandContext.getResult().getEntity(); EntityResponse response = Responses.entity(newEntity); context.setResult(response); return CommandResult.CONTINUE; }