Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Saving and gaining datas whith one-to-many relation

1 reply [Last post]
  • Login or register to post comments
Tue, 02/26/2013 - 03:06
kenhome
Offline
Joined: 12/20/2012
Groups: None

Hi all,
Here are my java-client code:
/** save data **/
client.set(getKey(cls, id), 0, Object);

/** gain data **/

public static T getData(long id, Class<? extends BasePlayerModule> cls)
throws IllegalArgumentException, IllegalAccessException, UnKnowTypeException, InstantiationException,
ClassNotFoundException {
return getCouchBaseData(cls, getKey(cls, id));
}

@SuppressWarnings("unchecked")
private static T getCouchBaseData(Class<? extends BasePlayerModule> cls, String keyName)
throws InstantiationException, IllegalAccessException, ClassNotFoundException, UnKnowTypeException {
String data = (String) client.get(keyName);
...
...

As you can see, the gain method only contain one-one data, I wonder how can i gain datas with one-many relation?
In other words, How do I design this function?
Thanks!

Top
  • Login or register to post comments
Wed, 02/27/2013 - 11:49
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

It depends how you want to do it and what do you use to do the JSON<->Java part. Which library are you using? (GSon, Jackson, ....)

At the end it is you that make the decision to either embed the document in the parent (1) or create a child document and use the is in the children. (2)

Case 1:
id: person:001
{
"name" : "John",
"children" : [ {"name":"Jane"}, {"name":"David"} ]
}

Chase 2:
id: person:001
{
"name" : "John"
}

id:person:002
{
"name":"Jane",
"parent_id" : "person:001"
}

id:person:003
{
"name":"David",
"parent_id" : "person:001"
}

So you can do it yourself in Java, I am currently working on developing small frameworks such as:
- https://github.com/tgrall/couchbase-document-api (not complete at all but can give you some idea)
- https://github.com/tgrall/hibernate-ogm/tree/couchbase-support to work with JPA (60% done)

regards

__________________

Tug
@tgrall

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker