Data management

Many apps that you create will need to manipulate data in some way. A contacts list app might need to load existing contacts from a data file and save new contacts in the file. A sports app might track team statistics in a data file and update these statistics after each game.

The BlackBerry 10 Native SDK supports a wide range of libraries that you can use to manipulate data, like SQLite, JSON_parser, and libxml2. Cascades also provides its own set of data management APIs to help remove some of the complexity of storing and modeling data.

JSON data

When it comes to JSON data, the BlackBerry 10 Native SDK supports a couple different open source libraries you can use in addition to Cascades: JSON_parser and CouchDB. JSON_parser is a C-based parser that you can use in your apps to parse text formatted in JSON. CouchDB allows you to store and access JSON documents using HTTP and query, combine, and transform your documents with JavaScript.

Additionally, Cascades provides its own set of APIs that you can use to parse and store JSON data.

SQL data

For SQL data, the SQLite library provides a serverless, transactional SQL database engine that you can include in your apps.

To remove some of the complexity of creating a SQLite database, you can use the Cascades APIs. To learn more about using SQL in Cascades, see SQL data.

XML data

To parse and store XML data in your app, you can use either libxml2 or Expat. The libxml2 library is a portable XML C parsing toolkit, while Expat is a stream-oriented XML C parser.

As with the other types of data mentioned above, Cascades provides its own set of APIs to make managing the data type easier. For more information about managing XML data with Cascades, see XML data

File system access

Before you can store or retrieve data from the device, you should first make yourself familiar with the architecture of the device file system. Applications have access to their own working directories as well as a shared directory that all apps can access. For more information about the file system, see File system access.

Cascades data management APIs

The Cascades framework uses a modular approach to store, access, and display data in your apps. This approach makes it easy for you to store different types of data, organize and model the data in different ways, and display the data with different visual styles.

The following diagram illustrates the different components that interact when you manipulate data in your app:

Diagram showing component interaction when data is manipulated.

External data

This component represents the raw data for your app. The data could be a list of contact entries, a set of financial records, or a group of game objects. You can access data that you package with your app, but you can also create new data dynamically as your app runs. The format of this data can vary depending on your needs, and Cascades provides classes that help you manage three common data formats: JSON, SQL, and XML.

Data access

This component lets you access the external data and manipulate it in your app. You can load data files, create new files and save data in them, and handle any errors that might occur during these operations. Then, you can add the data to a data model to organize it before it's displayed. You can use the JsonDataAccess, SqlDataAccess, and XmlDataAccess classes to load and save data in JSON, SQL, and XML format, respectively. You can also access SQL data asynchronously using an SqlConnection. Supporting classes, such as DataAccessError, give you more information about errors so you can handle them appropriately.

Data source

This component is designed specifically as an easy-to-use adapter in QML between external data and UI components. You can use the DataSource  class to declare the properties of the external data that you want to access. This data can be SQL, JSON, or XML data that's stored locally, or it can be JSON or XML data feeds that are accessed remotely. You can also use the DataSource class to control when and where the data is loaded.

Data model

This component lets you organize and sort your data, and then provide the data to a list view to display it. For example, you can use a  GroupDataModel  to sort a list of employees by last name or employee number. Then, you can associate this data model with a list view, and your data is organized and displayed in the way you specified.

To learn more about data models, see Data models .

List view

This component determines how the data from the data model is most often displayed in your app. Each entry in the data model becomes an item in the list, and you can specify how each item should appear visually. You might represent each item using a simple  Label, or you might represent each item using multiple controls that you define yourself. A  ListView lets you handle all visual aspects of the list, and is separate from the data and the data model that's used to provide the data to display.

To learn more about list views, see Lists.

Screen showing a list view.

Large data sets

If you're using a ListView to display information from a data source, you must consider how the performance of your app is affected by the amount of data. Small amounts of data can be loaded as a complete set during initialization with little to no performance impact. Large sets of data must be managed differently to avoid start-up delays, slow scrolling, and other indicators of poor performance. For more information about managing large amounts of data, see Large data sets.

Persistent data

Persistent data allows you to save app settings to the persistent store and load them when they are needed. The persistent store lets you save objects to persistent memory, and these objects are retained in memory after a device is restarted. For more information about the persistent store, see Persistent data.

Last modified: 2015-07-24

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus