<- ReadMe.html  ||  <- ../Functionality.html

goodViberations: Data Layer

Introduction

This document describes:

Data structures

The data structures used by the app are based on a map of entries. The key to the map is the name field of DataEntry converted to lower case. This ensures case insensitive uniqueness of names used in the app.

Each entry is a master, with a fixed set of fields and a detail that is a list of detail fields. The class name is DataEntry. The package is com.j3t.dataentryapp.datalayer.

The fields of the DataEntry are kept in a class called DataField. The package is com.j3t.dataentryapp.datalayer.

The DataEntry class has the following fixed set of fields

The DataEntry class also has a list of DataField fields, the detail fields, as described below.

DataField fields

DataField field instances relate to a specific DataEntry entry instance. DataField fields can be considered to be a set of text fields, each field has a name and a value. The name must be unique to the master entry instance.

Some field values reflect a data type, and so have a syntax associated with them. For example, email must be a valid email address syntax, url must be a valid http url syntax.

Data storage and retrieval

The map of DataEntry instances are saved and loaded from a file in the context.filesDir, as xml.
A class called DataLayer in the package com.j3t.dataentryapp.datalayer has the methods all other classes in the app use.

The following methods are present in the DataLayer class:

MethodparametersDescription
createStore data: map of DataEntry instances The following operations are carried out by this method:
  1. checks how many files exist in the context.filesDir, if there are 5 or more files, the oldest file is deleted.
  2. a new file whose name is made of "info" + ddmmyyyyhhmmss + random integer between 0 and 100 + ".xml" is created in the context.filesDir.
  3. The data is written to the file as xml. The DataEntry map instance, sorted by the key (name) field.The sorted map is returned by the method.
saveStore data: map of DataEntry instances calls the createStore method. Returns the value returned by the createStore method.
loadStore no parameter if there are no files in the context.filesDir, the method returns a new map of DataEntry instances.

if there are files in the context.filesDir: the contents of the latest xml file in the context.filesDir are loaded into a new map of DataEntry instances. The method returns the map of DataEntry instances, sorted by the key (name) field.
listEntryNames no parameter calls the loadStore method. Returns a list of the names of the entries, sorted by the key (name)
loadEntry name: the name of the entry calls the loadStore method. If the returned map contains an entry with the given name, returns the DataEntry instance with the given name. Otherwise returns a new DataEntry instance with the name "entry " + name + " not found".
deleteStore no parameter Deletes all the files in the context.filesDir.
storeExists no parameter Boolean method returns true if a store exists, false otherwise.