When discussing data access, people typically talk about  CRUD  or
CRUD -Q (“Q”  is  for  query)  and indicate the operation to be executed.
( Que ry  is  a kind  of  Read  operation and therefore the “Q”  isn’t  always
mentioned explicitly.)  As  already described in Section  2.1.1,  OData uses
the  REST  commands P OS T,  GET ,  PU T, or  DELE TE , which map to  CRUD.  The OData protocol defines conventions for all  of  these  CRUD  operations,
but  it’s  not  mandatory for every OData service  to  support  all four oper-
ations.  In  this section, we’ll explain each operation and give some con-
text for their use.

操作时,使用POST提交 业务参数,提交后,
操作成功HTTP状态返回:201(CREATE),                       类的代码可参考:基于gateway实现odata(9)–Create Methods

The  Create  operation is used  whenever  you  want  to create data  on  the  POST
backend server. This  is  data  that  wasn’t  present before, for exampl e,  a
new sales  order  or  a  new  business partner. The related  HTTP  method  is
P OST .  If  the  Create  operation is successful,  you  receive the  H TTP  20  1  (cre-
ated) response code, along with t he  entity  that  was created. Via the
metadata,  you  can specify  whether  an  entity set is creatable  or  not . This
information  is  reflected in the metadata  document  and allows the con-
sumer  to act accordingly (e.g.,  if  the application is  of  the type  Pl aye r).
Bu t there is  no  default handling  of  this annotation by the framework;
instead, the service  imp lementation has  to  handle it according to the
metadata definition (see Chapter 5 and Chapter 6 for more details  about
service implementation).

            读取成功后HTTP状态返回200 (OK),

The  Read  operation  is  the  most  frequently used operation. Typically,  GET
applications primarily read data instead  of  updating  data- for example,
a lunch  menu  application  that  doesn’t  include any option  to  provide
feedback  about  the  menu  provided. This data can be  of  any kind, such  as
customizing, master data, transaction data,  and  so on. The related  HTTP
method for the  Read  operation is  G ET .  A successful  Read  operation has
the  HTTP  200  ( OK status code.
Read  operations can be classified  into  two different kinds:  Query  and
Si ngl e  Read .


操作成功后HTTP状态返回HTTP  204 (no  content  )

The  Update  operation  is  used whenever you  want  to change an existing
entity.  As  such,  you  have to provide the same key information  as  in  the
Si ngl e  Read  operation, explained earlier, to uniquely identify the entity
you  want  to  update.
The  HTTP  method for the  Update  operation  is  PUT .  If  the  U pdate  opera-
tion  is  successful,  you  receive the  HTTP  204 (no  content  l status. You’re
intentionally  not  getting the entity back as part  of  the  HTTP  request
because the consumer typically knows the current state  of  the entity,
and therefore the  SAP  Gateway server  doesn’t  need to send it back.
Instead  of  P UT ,  it’s possible to leverage the  PATCH  operation that allows
you  to perform a partial update. The  ATCH  meth od  is  supported by the
framework and first calls the  GETDE TAIL  method to r etr ieve all properties
that  won ‘t be updated, then merges those values  with  the ones that are
sent  via the  PATC H  request, and finally performs  an  update using the
standard update method  of  an entity set.

操作成功后HTTP状态返回HTTP  204 (no  content  )

Finally, the  De l ete  operation  is  used whenever  you  want to delete an
entity. Equal to the  Update  operation,  you  have to provide the primary
key  of  the entity  you  want  to erase. The related  HTTP  method is  DELETE .
A successful  De l ete  operation has  the  HTTP  204  (no content) status code.
Via  the  sap:de leta b le  annotation,  you  can specify  whether  entities  of
an entity set can be deleted  or  not.  As  before, the service implementa-
tion has to make sure that the actual operations are  in  line with the

metadata definition (see Chapter 5 and Chapter 6 for more details  about

service implementation).



twenty − 6 =