Concept : Understanding Datasources
Contents |
[edit] Description
Datasources (part of the Model) are abstractions that enable you to persist a data construct, or object instance, anywhere in your Bungee project for later reuse, such as application data.
For example, consider creating a library's catalog. You could create a class structure called Book the has three fields: name, author,and call number. Then you could create multiple instances of this Book class, filling in the name, author, and call number appropriately, and store these instances in a datasource. After deploying your application, users of your application could then access all the data in your datasource (in this case, see all the books in your library).
Caution Datasources have no concurrency controls. Consequently, if two people edit the datasource simultaneously, the results are undefined.
Scope of Datasource Storage
When you add a datasource, one of the options is Storage Scope. Choose either Design Time or User Application.
- Design Time—If a datasource is populated by the developer during the design of the application, then, when the application is posted and run by a user, the user has access to the data at run time (the datasource is posted with the application).
- User Application—A datasource with this scope is accessible and private to each authenticated user of an application. If the application is marked for anonymous access, a datasource with this scope will retain data. This type of datasource is ideal for storing information about a user specific to the application, such as preferences.
[edit] Setting the Is Persistent Property
When using datasources, you must use the Is Persistent property for every field you want saved in the datasource. This includes the contained members of complex objects. For example, assume you have a class Foo that has a member called Bar, and Bar has two fields: name and date. If you want to make a persistent collection of Foo, and have all the fields of Bar persistent as well, then Bar's name and date fields must be marked Is Persistent as well as the collection of Foo.
Note You can set a field's Is Persistent property after the datasource has been created. The datasource will then start storing data for the field and records entered previously will have empty data for the newly persisted field.
[edit] Creating and Using
When you right-click on a class and select Add Datasource, you are specifying that this class is going to be saved to disk and all the fields inside that class that have Is Persistent enabled will also be saved. Assume that you create a datasource of type NoteBook and the datasource is called NoteBookDatasource. You can later use this saved NoteBook object by creating a field (for example, named Foo) of the same type as the datasource type (in this case, type NoteBook), and then setting the default value of field Foo to point to NoteBookDatasource. When the application is run, Foo will load NoteBookDatasource and manipulate the data.
[edit] See Also
[edit] Tags