Menu

#28 How can we go from a repo object to a kind-label string?

FAQ
pending
None
2014-07-24
2014-06-30
No

Discussion

  • John Haley

    John Haley - 2014-07-24

    By kind-label string I assume you mean a unique name uri.

    Repo objects implement various interfaces:

    • They are Aggregates (Composite, Listing, Mapping).
      Listing is an extension of java.util.List
      Mapping is an extension of java.util.Map
      Composite is like a Mapping but specifically models a tuple similar to a RDBMS row tuple; i.e. the elements in the tuple are keyed to a string name and not an integer index). The generated bean interfaces are Composites with getters and setters decorating the Composite.
    • They are Resources. Note that the generated bean interfaces don't explicitly extend from Resource.

    The repository objects can be worked with like they are Pojos - using the generated interfaces. They can also be worked with as generic Resources.

    To answer the question, here are possible ways:

    1. When defining a Transaction, you can declare "T" to be of a specific Resource type, e.g.:
      Transaction<Resource<?>>
      Transaction<resource\<object>>
      Transaction<resource\<person>>
      Transaction<resource\<aggregate\<object,object>>>
      Then you can perform things like:
      Transaction<resource\<person>> tx = myPackage.connect("anonymous");
      Resource<person> res = myTx.create("Person");
      Person person = res.value();
      String version = res.version().toString();
      String uri = res.id().getUniqueName();</person></resource\<person></resource\<aggregate\<object,object></resource\<person></resource\<object>

    2. Simply cast the bean to Resource:
      Transaction<person> tx = myPackage.connect("anonymous");
      Person person = myTx.create("Person");
      String uri = ((Resource<?>)person).getUniqueName();</person>

    3. I believe you can generate your bean interfaces extending an Interface. So have "Person" extend "Named" or "Resource<person>" (depending on how much "information hiding" you want). If the generation doesn't do it/work/or more infomation is needed, let me know.</person>

     
  • John Haley

    John Haley - 2014-07-24
    • summary: Question for John --> How can we go from a repo object to a kind-label string?
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +0,0 @@
    -How can we go from a repo object to a kind-label string?
    
    • status: open --> pending
     

Log in to post a comment.

MongoDB Logo MongoDB