Couchbase lite java api with scala - retrieving document properties after reopening database yields different result

Retrieving document properties after reopening database yields different result. I am using the Java API in scala (don’t be put off by it - code is still easy to read). Details - http://stackoverflow.com/questions/43315540/couchbase-lite-retrieving-document-properties-after-reopening-database-yields

Could someone help me understand and fix the problem?

@hideki, could you take a look since this is Java?

Hi @vishvas.vasuki

I read your code in the stackoverflow’s post. Your code looks fine. First of all, we’d like to confirm that the data is stored correctly in the database file. If you are using Mac OS X, can you open the database file with Couchbase Lite Viewer (https://github.com/couchbaselabs/CouchbaseLiteViewer)? If not, could you switch storage engine to SQLite instead of ForestDB. To check the data, you could use SQLite command or tools.

Thanks,
Hideki

Hi @hideki, Thanks for taking a look!
Despite switching to sqlite, I get the same output:

Library not found: /native/linux/amd64/libsqlcipher.so
Apr 14, 2017 11:12:52 AM com.couchbase.lite.util.SystemLogger e
SEVERE: CBLite: Cannot find library: sqlcipher
JavaSQLiteStorageEngine
Library not found: /native/linux/amd64/libsqlcipher.so
Apr 14, 2017 11:12:52 AM com.couchbase.lite.util.SystemLogger e
SEVERE: CBLite: Cannot find library: sqlcipher
11:12:53 subhAShitaDb.QuoteInfoDb 62 --- {scriptRenderings=List(Map(text -> दण्डः शास्ति प्रजाः सर्वाः दण्ड एवाभिरक्षति। दण्डः सुप्तेषु जागर्ति दण्डं धर्मं विदुर्बुधाः।।, scheme -> dev, startLetter -> द)), jsonClass=QuoteText, language=Map(code -> sa), key=damDaHshaastiprajaaHsarvaaHdamDaevaabhiraxatidamDaHsupteShujaagartidamDamdharmamvidurbudhaaH}
11:12:53 subhAShitaDb.QuoteInfoDb 136 --- {scriptRenderings=List(Map(text -> दण्डः शास्ति प्रजाः सर्वाः दण्ड एवाभिरक्षति। दण्डः सुप्तेषु जागर्ति दण्डं धर्मं विदुर्बुधाः।।, scheme -> dev, startLetter -> द)), jsonClass=QuoteText, language=Map(code -> sa), key=damDaHshaastiprajaaHsarvaaHdamDaevaabhiraxatidamDaHsupteShujaagartidamDamdharmamvidurbudhaaH}
11:12:53 subhAShitaDb.QuoteInfoDb 136 --- {scriptRenderings={empty=false, traversableAgain=true}, jsonClass=QuoteText, language={traversableAgain=true, empty=false}, key=damDaHshaastiprajaaHsarvaaHdamDaevaabhiraxatidamDaHsupteShujaagartidamDamdharmamvidurbudhaaH}
11:12:53 subhAShitaDb.QuoteInfoDb 136 --- {scriptRenderings={empty=false, traversableAgain=true}, jsonClass=QuoteText, language={traversableAgain=true, empty=false}, key=damDaHshaastiprajaaHsarvaaHdamDaevaabhiraxatidamDaHsupteShujaagartidamDamdharmamvidurbudhaaH}

Process finished with exit code 0

I could not figure out how to make sense of the resulting sqlite database (I am on Ubuntu 14.10) by looking using the sqlitebrowser client. But I’ve checked in the database here so that you can take a look.

The data is not stored in the database correctly.

I am not familiar with Scala. It seems that the generating the nested Java Map/List could have the problem. Can you check if jsonMap.asJava generates appropriate Java Map instance with nested Java Map/List instancies?

     val jsonMap =Map("scriptRenderings"-> List(Map("text"-> "दण्डः शास्ति प्रजाः सर्वाः दण्ड एवाभिरक्षति। दण्डः सुप्तेषु जागर्ति दण्डं धर्मं विदुर्बुधाः।।", "scheme" -> "dev", "startLetter" -> "द")),
      "jsonClass"->"QuoteText",
      "language"->Map("code" -> "sa"),
      "key"->"damDaHshaastiprajaaHsarvaaHdamDaevaabhiraxatidamDaHsupteShujaagartidamDamdharmamvidurbudhaaH"
    )
properties.putAll(jsonMap.asJava)

Ah! That was indeed it. I was able to fix the code by recursively converting the scala map to a java map (using this tip) while writing to the database. Thanks very much for unblocking me, @hideki !

1 Like