FileDocCategorySizeDatePackage
SyncableContentProvider.javaAPI DocAndroid 1.5 API8829Wed May 06 22:41:54 BST 2009android.content

SyncableContentProvider

public abstract class SyncableContentProvider extends ContentProvider
A specialization of the ContentProvider that centralizes functionality used by ContentProviders that are syncable. It also wraps calls to the ContentProvider inside of database transactions.
hide

Fields Summary
Constructors Summary
Methods Summary
protected abstract voidbootstrapDatabase(android.database.sqlite.SQLiteDatabase db)
Override to create your schema and do anything else you need to do with a new database. This is run inside a transaction (so you don't need to use one). This method may not use getDatabase(), or call content provider methods, it must only use the database handle passed to it.

public abstract booleanchangeRequiresLocalSync(android.net.Uri uri)
Check if changes to this URI can be syncable changes.

param
uri the URI of the resource that was changed
return
true if changes to this URI can be syncable changes, false otherwise

public abstract voidclose()
Close resources that must be closed. You must call this to properly release the resources used by the SyncableContentProvider.

protected abstract intdeleteInternal(android.net.Uri url, java.lang.String selection, java.lang.String[] selectionArgs)
Subclasses should override this instead of delete(). See delete() for details.

This method is called within a acquireDbLock()/releaseDbLock() block, which means a database transaction will be active during the call;

protected abstract voiddeleteRowsForRemovedAccounts(java.util.Map accounts, java.lang.String table, java.lang.String accountColumnName)
A helper method to delete all rows whose account is not in the accounts map. The accountColumnName is the name of the column that is expected to hold the account. If a row has an empty account it is never deleted.

param
accounts a map of existing accounts
param
table the table to delete from
param
accountColumnName the name of the column that is expected to hold the account.

public abstract booleangetContainsDiffs()

public abstract android.database.sqlite.SQLiteDatabasegetDatabase()

protected abstract java.lang.IterablegetMergers()
Each subclass of this class should define a subclass of {@link AbstractTableMerger} for each table they wish to merge. It should then override this method and return one instance of each merger, in sequence. Their {@link AbstractTableMerger#merge merge} methods will be called, one at a time, in the order supplied.

The default implementation returns an empty list, so that no merging will occur.

return
A sequence of subclasses of {@link AbstractTableMerger}, one for each table that should be merged.

public abstract java.lang.StringgetSyncingAccount()
The account of the most recent call to onSyncStart()

return
the account

public abstract android.content.SyncableContentProvidergetTemporaryInstance()
Get a non-persistent instance of this content provider. You must call {@link #close} on the returned SyncableContentProvider when you are done with it.

return
a non-persistent content provider with the same layout as this provider.

protected abstract android.net.UriinsertInternal(android.net.Uri url, ContentValues values)
Subclasses should override this instead of insert(). See insert() for details.

This method is called within a acquireDbLock()/releaseDbLock() block, which means a database transaction will be active during the call;

public abstract booleanisMergeCancelled()

protected abstract booleanisTemporary()

public abstract voidmerge(SyncContext context, android.content.SyncableContentProvider diffs, TempProviderSyncResult result, SyncResult syncResult)
Merge diffs from a sync source with this content provider.

param
context the SyncContext within which this merge is taking place
param
diffs A temporary content provider containing diffs from a sync source.
param
result a MergeResult that contains information about the merge, including a temporary content provider with the same layout as this provider containing
param
syncResult

protected abstract voidonAccountsChanged(java.lang.String[] accountsArray)
Make sure that there are no entries for accounts that no longer exist

param
accountsArray the array of currently-existing accounts

protected abstract voidonDatabaseOpened(android.database.sqlite.SQLiteDatabase db)
Override to do anything (like cleanups or checks) you need to do after opening a database. Does nothing by default. This is run inside a transaction (so you don't need to use one). This method may not use getDatabase(), or call content provider methods, it must only use the database handle passed to it.

public abstract voidonSyncCanceled()
Invoked when the active sync has been canceled. The default implementation doesn't do anything (except ensure that this provider is syncable). Subclasses of ContentProvider that support canceling of sync should override this.

public abstract voidonSyncStart(SyncContext context, java.lang.String account)
Called right before a sync is started.

param
context the sync context for the operation
param
account

public abstract voidonSyncStop(SyncContext context, boolean success)
Called right after a sync is completed

param
context the sync context for the operation
param
success true if the sync succeeded, false if an error occurred

protected abstract android.database.CursorqueryInternal(android.net.Uri url, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)
Subclasses should override this instead of query(). See query() for details.

This method is *not* called within a acquireDbLock()/releaseDbLock() block for performance reasons. If an implementation needs atomic access to the database the lock can be acquired then.

public abstract byte[]readSyncDataBytes(java.lang.String account)
Retrieves the SyncData bytes for the given account. The byte array returned may be null.

public abstract voidsetContainsDiffs(boolean containsDiffs)

protected abstract intupdateInternal(android.net.Uri url, ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)
Subclasses should override this instead of update(). See update() for details.

This method is called within a acquireDbLock()/releaseDbLock() block, which means a database transaction will be active during the call;

protected abstract booleanupgradeDatabase(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
Override to upgrade your database from an old version to the version you specified. Don't set the DB version, this will automatically be done after the method returns. This method may not use getDatabase(), or call content provider methods, it must only use the database handle passed to it.

param
oldVersion version of the existing database
param
newVersion current version to upgrade to
return
true if the upgrade was lossless, false if it was lossy

public abstract voidwipeAccount(java.lang.String account)
Called when the sync system determines that this provider should no longer contain records for the specified account.

public abstract voidwriteSyncDataBytes(java.lang.String account, byte[] data)
Sets the SyncData bytes for the given account. The bytes array may be null.