org.hermit.android.provider
Class TableSchema

java.lang.Object
  extended by org.hermit.android.provider.TableSchema

public abstract class TableSchema
extends java.lang.Object

Class encapsulating the schema for a table within a content provider. Applications must subclass this, and provide the necessary information in the call to this base class's constructor.

An application's subclass will typically provide the following:


Constructor Summary
protected TableSchema(java.lang.String name, java.lang.String type, Uri uri, java.lang.String sort, java.lang.String[][] fields)
          Create a table schema instance.
 
Method Summary
 Uri getContentUri()
          Get the table's content URI.
 java.lang.String getItemType()
          Get the MIME type for the items in the table.
 java.lang.String getTableName()
          Get the table name.
 java.lang.String getTableType()
          Get the MIME type for the table as a whole.
protected static java.lang.String[] makeProjection(java.lang.String[][] fields)
          This method creates a projection from a set of field definitions.
 void onInsert(ContentValues values)
          This method is called when a new row is added into this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSchema

protected TableSchema(java.lang.String name,
                      java.lang.String type,
                      Uri uri,
                      java.lang.String sort,
                      java.lang.String[][] fields)
Create a table schema instance.

Parameters:
name - Name for the table; e.g. "points".
type - Base MIME type identifying the content of this table; e.g. "vnd.hermit.org.passage.point".
uri - Content URI for this table.
sort - Default sort order for this table; e.g. "time ASC".
fields - List of field definitions. Each one is two strings, being the field name and type. E.g. { { "name", "TEXT" }, { "time", "INTEGER" }}. The standard ID field "_id" will be prepended automatically.
Method Detail

makeProjection

protected static java.lang.String[] makeProjection(java.lang.String[][] fields)
This method creates a projection from a set of field definitions. It can be used by subclasses to set up a default projection. The returned projection includes all fields, including the implicit "_id" field, which should not be in the supplied field list.

Parameters:
fields - List of field definitions. Each one is two strings, being the field name and type. E.g. { { "name", "TEXT" }, { "time", "INTEGER" }}. The standard ID field "_id" will be prepended automatically.
Returns:
An all-fields projection for the given fields list.

getTableName

public java.lang.String getTableName()
Get the table name.

Returns:
The table's name in the database.

getContentUri

public Uri getContentUri()
Get the table's content URI.

Returns:
The "content://" content URI for this table.

getTableType

public java.lang.String getTableType()
Get the MIME type for the table as a whole.

Returns:
The "vnd.android.cursor.dir/" MIME type for the table.

getItemType

public java.lang.String getItemType()
Get the MIME type for the items in the table.

Returns:
The "vnd.android.cursor.item/" MIME type for the items.

onInsert

public void onInsert(ContentValues values)
This method is called when a new row is added into this table. Subclasses can override this to fill in any missing values.

Parameters:
values - The fields being added.