ActiveAndroid set instance id - android
Is it possible to set ID of certain record? I'm importing multi table database into my application database, that is mapped to ActiveAndroid model. I get it over http in json.
It would save a lot of work to preserver those server-side ids on records to have same relations id<>id as on the server.
I planned on deserialisating json to objects using gson and then to save them using activeandroid .save()
Or what is the simplest way to accomplish something like that. Get rid of the the json and do some SQL import?
Not possible. Importing data is to be done by calling SQL inserts directly.
Related
How to store data offline in android database after parsing it from json through URL?
I want to store data locally in the phone after parsing it from JSON API and then make a button to synchronize that data whenever I need to so that the content can be used offline.
If you want to store data object locally, then you can make use of Realm DB. Below link explains how to use Realm DB https://www.androidhive.info/2016/05/android-working-with-realm-database-replacing-sqlite-core-data/
Right now, the best option to store bunch of data locally is using sqlite. You can search for it. There is a bunch of tutorials for it. Also, you can also use Room library which makes it really easy to create sqlite databases and interact with it.
How to relate individual json data that I am getting in my android app?
In my android app I am accessing external PostgreSQL database, I am able to get json data but here I am accessing three tables which are related through there id's.I am getting those tables json data individually. Now my question is how to get data from three tables that I want through there relation in my app?In my app I am using Spring Rest API. With this link I am accessing first table, http://localhost:443/seis/productTemplateController/getproductTemplate and I am getting json data like this. [{"name":"Mobile","id":31,"state":null,"type":"consu","description":null,"active":true,"create_uid":1,"create_date":1466549730430,"write_date":1466549730430,"write_uid":1,"warranty":0.0,"uos_id":null,"list_price":12000.00,"color":null,"image":null,"mes_type":"fixed","uom_id":1,"uos_coeff":1.000,"sale_ok":false,"categ_id":1,"company_id":1,"uom_po_id":1,"weight":0.00,"weight_net":0.00,"volume":0.0,"rental":false,"image_medium":null,"image_small":null,"track_all":false,"loc_rack":null,"loc_case":null,"loc_row":null,"sale_delay":7.0,"purchase_ok":true,"project_id":null,"avail_scheme":null,"product_id":"M001","product_cat":null,"message_last_post":null,"description_purchase":null,"product_manager":null,"description_sale":null,"track_outgoing":false,"track_incoming":false,"auto_create_task":false,"product_brande":null,"product_serial":null,"product_sub_subcategory":null,"product_subcategory":null,"product_modele":null}] With this link I am accessing second table, http://localhost:443/seis/productAccount/getAccount and I am getting json data like this. [{"name":null,"id":32,"state":"paid","type":"in_invoice","number":"EXJ/2016/0003","origin":null,"comment":null,"reference":null,"message_last_post":null,"commercial_partner_id":29,"fiscal_position":null,"amount_untaxed":0.00,"partner_bank_id":null,"supplier_invoice_number":"123","reference_type":"none","internal_number":"EXJ/2016/0003","installation_date":null,"create_uid":1,"create_date":1466557180185,"write_date":1466557192973,"write_uid":1,"company_id":1,"user_id":1,"section_id":null,"amount_tax":0.00,"date_due":"2016-06-22","check_total":0.00,"payment_term":null,"currency_id":21,"partner_id":29,"journal_id":2,"move_id":47,"account_id":37,"reconciled":true,"residual":0.00,"move_name":"/","date_invoice":"2016-06-22","period_id":7,"amount_total":0.00,"sent":false,"service3_date":null,"service2_date":null,"delivery_date":null,"service1_date":null}] With this link I am accessing third table, http://localhost:443/seis/resPartnerController/getPartner and I am getting json data like this. [{"name":"Varenya","id":39,"type":"contact","ref":null,"comment":null,"date":null,"message_last_post":null,"use_parent_address":false,"commercial_partner_id":39,"signup_expiration":null,"calendar_last_notif_ack":null,"last_reconciliation_date":null,"tax_identification_no":null,"ean13":null,"active":true,"create_uid":1,"create_date":1466548847830,"write_date":1466548847830,"write_uid":1,"color":0,"image":null,"company_id":1,"image_medium":null,"image_small":null,"street":null,"city":null,"display_name":"Varenya","zip":null,"title":null,"function":null,"country_id":null,"parent_id":null,"supplier":true,"email":null,"is_company":false,"website":null,"customer":false,"fax":null,"street2":null,"credit_limit":null,"employee":false,"tz":"Asia/Kolkata","lang":"en_US","phone":null,"mobile":null,"user_id":null,"birthdate":null,"vat":null,"state_id":null,"notify_email":"always","opt_out":false,"section_id":null,"signup_type":null,"signup_token":null,"debit_limit":null,"vat_subjected":false,"exercise_no":null,"swift":null,"msme_no":null,"micr":null,"service_tax":null,"cst":null},{"name":"swathi","id":31,"type":"contact","ref":null,"comment":"Customer of varenya","date":"2016-06-21","message_last_post":null,"use_parent_address":false,"commercial_partner_id":30,"signup_expiration":null,"calendar_last_notif_ack":null,"last_reconciliation_date":1466479345000,"tax_identification_no":null,"ean13":null,"active":true,"create_uid":1,"create_date":1466055326322,"write_date":1466479344558,"write_uid":1,"color":0,"image":null,"company_id":1,"image_medium":null,"image_small":null,"street":null,"city":null,"display_name":"Hcl, swathi","zip":null,"title":null,"function":null,"country_id":null,"parent_id":30,"supplier":false,"email":null,"is_company":false,"website":null,"customer":true,"fax":null,"street2":null,"credit_limit":0.0,"employee":false,"tz":"Asia/Kolkata","lang":"en_US","phone":null,"mobile":null,"user_id":null,"birthdate":null,"vat":null,"state_id":null,"notify_email":"always","opt_out":false,"section_id":null,"signup_type":null,"signup_token":null,"debit_limit":0.0,"vat_subjected":false,"exercise_no":null,"swift":null,"msme_no":null,"micr":null,"service_tax":null,"cst":null}]
Well first I would suggest you use Gson to parse the Json into ProductTemplate, Account, Partner classes. Then you would have id-fields to establish the connection between them?
How do you choose your database type based on the criteria (SQL, JSON, etc.) and how do you ensure its integrity?
Implementing and managing remote or cloud databases in Android Applications is new to me. I am currently making an app that would take in thousands of "entries" to a form, think of it as an attendance app. Right now I've decided to use JSON as my database type and Parse as my BaaS. I need some tips on my decision. I don't actually see JSON suitable for this because it is a "text" file that can easily be modified or if I somehow accidentally append an extra bracket it would render the whole database corrupt whereas SQL use queries like INSERT which I think is more secure. I just picked JSON because it works well with Parse. Do you think this is a good idea? Another is what if the JSON file will accumulate tens of thousands of entries, how do you manage this huge database? Do you split it into several files (eg. every 1k entries make another JSON file) or is it enough to just dump all the data in that one JSON database file? When using BaaS do you just sync the data in that server or do you also make backups of some sort (I don't really know how to put this)? Thanks in advance!
JSON is not a database, but a data interchange format. You can have a database that uses JSON for communication, for internal representation, etc. but that does not make JSON a database in itself. Parse itself manages the organization of the data. You communicate using JSON but don't have to care about how it's stored, updated, etc. internally. So in your app, you should use SQLite for storing such amounts of information, or, depending on the app, just send it to the Parse server and execute the queries against it. You can see how it's done in the Parse Android documentation.
Whether to use Sqlite database or Json format for database insertion
Hi I am newbie in android . I am retrieving data using json parsin and i want to insert the data in my database.So suggest me whether i should in xml/json form or directly in sqlite. I am good at sqlite but i am dont know to insert in json format please suggest me to insert in to Json Object.
The most useful solution is such a case will be to use libraries like GSON or Jackson for converting JSON response to POJO (btw, you can use nice site http://www.jsonschema2pojo.org/, which will help you to create the needed POJO automatically from your response). After that you can use ORM helpers to link these objects with SQLite database, like greenDAO or ORMLite. All these libs are well-documented, so you will dive inside them easily.
How to create database using Db4o in android?
I am developing an App in which now i have to create database for more better user experience. Then i came to know about DB4o which is many times faster tool for creating database than other like SQLite, MySql etc, but the problem is i am not able to find any single example that explains about DB4o and how to create database using Db4o. If anybody has used it, please post an example or send me link.
To store the object in database use db().store(exercise); To retrieve All records from database, use db().query(Object); To retrieve particular record from database, use db().queryByExample(Object); If you need example, Try My blog example using db4o. In this example, simple student object will be stored in database using db4o. Student object will contain student name, register number, and his age. Thank you.