Jearil / SimpleNoSQL

A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.
387 stars 53 forks source link

How to Support List like HashMap? #28

Closed longtaoge closed 8 years ago

longtaoge commented 8 years ago

I want save a list in entify like HashMap

public void testSaveEntities2() throws Throwable {

    NoSQLEntity<SampleBean2> entity = new NoSQLEntity<SampleBean2>(
            "bucket", "entityId");
    SampleBean2 data = new SampleBean2();
    data.setField1("abc");
    data.setId(9);
    List<User> mUsers = new ArrayList<User>();
    for (int i = 0; i < 100; i++) {

        User mUser = new User();
        mUser.setAge("15" + i);
        mUser.setName("name" + i);
        mUsers.add(mUser);

    }

    data.setmUsers(mUsers);
    entity.setData(data);
    //NoSQL.with(context).using(SampleBean2.class).bucketId("bucket")
   // .entityId("entityId").delete();
    NoSQL.with( getInstrumentation().getTargetContext()).using(SampleBean2.class).save(entity);

}

but the result like this

image

link

How to Support List like HashMap?

Jearil commented 8 years ago

Unfortunately your image doesn't work so I'm not sure what your error is. By default, your data is Serialized using Gson. You will need to make sure your objects are serializable via that library. Alternatively you may create your own Serializer and Deserializer by implementing DataSerializer and DataDeserializer.

NoSQL.with(context)
  .withSerializer(serializer)
  .withDeserializer(deserializer)
  .using(SampleBean2.class)
  .save(entity);
longtaoge commented 8 years ago

the Serialized is ok and i am use the Gson also , my mean is if a entity contains a long list ,like SampleBean2 ' entity ,the entity will save as a long json String in DB ,eg : if the list 's size is big than 1000, sqlite will save the String failure.

Jearil commented 8 years ago

Ok. I'll work on changing the DB to store a byte array which would be better.

On Sun, Jan 17, 2016, 2:45 AM longtaoger notifications@github.com wrote:

the Serialized is ok and i am use the Gson also , my mean is if a entity contains a long list ,like SampleBean2 ' entity ,the entity will save as a long json String in db ,eg : if the list 's size is big than 1000, sqlite will save the String failure.

— Reply to this email directly or view it on GitHub https://github.com/Jearil/SimpleNoSQL/issues/28#issuecomment-172311634.

longtaoge commented 8 years ago

that may be good idea , i tested the hawk can saved more data on once I/O

Jearil commented 8 years ago

Saving as a byte[] is now in the github. You can build your own copy of the library and try that until I publish a new build to sonatype.