diff options
author | Fred Quintana <fredq@google.com> | 2009-05-07 17:35:38 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-05-13 12:49:04 -0700 |
commit | 6a8d5332f00bdfade6674b312e7166940aa28348 (patch) | |
tree | c45f5e5bc0fb4918e3df45821c723845d64506d3 /core/java/android/content/ContentProviderNative.java | |
parent | 7dfc85f1199790a3c3dab701cec45045d100d7d3 (diff) | |
download | frameworks_base-6a8d5332f00bdfade6674b312e7166940aa28348.zip frameworks_base-6a8d5332f00bdfade6674b312e7166940aa28348.tar.gz frameworks_base-6a8d5332f00bdfade6674b312e7166940aa28348.tar.bz2 |
content provider entities
Diffstat (limited to 'core/java/android/content/ContentProviderNative.java')
-rw-r--r-- | core/java/android/content/ContentProviderNative.java | 165 |
1 files changed, 164 insertions, 1 deletions
diff --git a/core/java/android/content/ContentProviderNative.java b/core/java/android/content/ContentProviderNative.java index f9282e2..ac67076 100644 --- a/core/java/android/content/ContentProviderNative.java +++ b/core/java/android/content/ContentProviderNative.java @@ -105,6 +105,20 @@ abstract public class ContentProviderNative extends Binder implements IContentPr return true; } + case QUERY_ENTITIES_TRANSACTION: + { + data.enforceInterface(IContentProvider.descriptor); + Uri url = Uri.CREATOR.createFromParcel(data); + String selection = data.readString(); + String[] selectionArgs = data.readStringArray(); + String sortOrder = data.readString(); + EntityIterator entityIterator = queryEntities(url, selection, selectionArgs, + sortOrder); + reply.writeNoException(); + reply.writeStrongBinder(new IEntityIteratorImpl(entityIterator).asBinder()); + return true; + } + case GET_TYPE_TRANSACTION: { data.enforceInterface(IContentProvider.descriptor); @@ -140,6 +154,40 @@ abstract public class ContentProviderNative extends Binder implements IContentPr return true; } + case BULK_INSERT_ENTITIES_TRANSACTION: + { + data.enforceInterface(IContentProvider.descriptor); + Uri uri = Uri.CREATOR.createFromParcel(data); + String className = data.readString(); + Class entityClass = Class.forName(className); + int numEntities = data.readInt(); + Entity[] entities = new Entity[numEntities]; + for (int i = 0; i < numEntities; i++) { + entities[i] = (Entity) data.readParcelable(entityClass.getClassLoader()); + } + Uri[] uris = bulkInsertEntities(uri, entities); + reply.writeNoException(); + reply.writeTypedArray(uris, 0); + return true; + } + + case BULK_UPDATE_ENTITIES_TRANSACTION: + { + data.enforceInterface(IContentProvider.descriptor); + Uri uri = Uri.CREATOR.createFromParcel(data); + String className = data.readString(); + Class entityClass = Class.forName(className); + int numEntities = data.readInt(); + Entity[] entities = new Entity[numEntities]; + for (int i = 0; i < numEntities; i++) { + entities[i] = (Entity) data.readParcelable(entityClass.getClassLoader()); + } + int[] counts = bulkUpdateEntities(uri, entities); + reply.writeNoException(); + reply.writeIntArray(counts); + return true; + } + case DELETE_TRANSACTION: { data.enforceInterface(IContentProvider.descriptor); @@ -215,6 +263,25 @@ abstract public class ContentProviderNative extends Binder implements IContentPr return super.onTransact(code, data, reply, flags); } + private class IEntityIteratorImpl extends IEntityIterator.Stub { + private final EntityIterator mEntityIterator; + + IEntityIteratorImpl(EntityIterator iterator) { + mEntityIterator = iterator; + } + public boolean hasNext() throws RemoteException { + return mEntityIterator.hasNext(); + } + + public Entity next() throws RemoteException { + return mEntityIterator.next(); + } + + public void close() throws RemoteException { + mEntityIterator.close(); + } + } + public IBinder asBinder() { return this; @@ -288,7 +355,7 @@ final class ContentProviderProxy implements IContentProvider BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor(); IBulkCursor bulkCursor = bulkQuery(url, projection, selection, selectionArgs, sortOrder, adaptor.getObserver(), window); - + if (bulkCursor == null) { return null; } @@ -296,6 +363,54 @@ final class ContentProviderProxy implements IContentProvider return adaptor; } + public EntityIterator queryEntities(Uri url, String selection, String[] selectionArgs, + String sortOrder) + throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + + data.writeInterfaceToken(IContentProvider.descriptor); + + url.writeToParcel(data, 0); + data.writeString(selection); + data.writeStringArray(selectionArgs); + data.writeString(sortOrder); + + mRemote.transact(IContentProvider.QUERY_ENTITIES_TRANSACTION, data, reply, 0); + + DatabaseUtils.readExceptionFromParcel(reply); + + IBinder entityIteratorBinder = reply.readStrongBinder(); + + data.recycle(); + reply.recycle(); + + return new RemoteEntityIterator(IEntityIterator.Stub.asInterface(entityIteratorBinder)); + } + + static class RemoteEntityIterator implements EntityIterator { + private final IEntityIterator mEntityIterator; + RemoteEntityIterator(IEntityIterator entityIterator) { + mEntityIterator = entityIterator; + } + + public boolean hasNext() throws RemoteException { + return mEntityIterator.hasNext(); + } + + public Entity next() throws RemoteException { + return mEntityIterator.next(); + } + + public void close() { + try { + mEntityIterator.close(); + } catch (RemoteException e) { + // doesn't matter + } + } + } + public String getType(Uri url) throws RemoteException { Parcel data = Parcel.obtain(); @@ -357,6 +472,54 @@ final class ContentProviderProxy implements IContentProvider return count; } + public Uri[] bulkInsertEntities(Uri uri, Entity[] entities) throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + + data.writeInterfaceToken(IContentProvider.descriptor); + uri.writeToParcel(data, 0); + data.writeString(entities[0].getClass().getName()); + data.writeInt(entities.length); + for (Entity entity : entities) { + data.writeParcelable(entity, 0); + } + + mRemote.transact(IContentProvider.BULK_INSERT_ENTITIES_TRANSACTION, data, reply, 0); + + DatabaseUtils.readExceptionFromParcel(reply); + Uri[] results = new Uri[entities.length]; + reply.readTypedArray(results, Uri.CREATOR); + + data.recycle(); + reply.recycle(); + + return results; + } + + public int[] bulkUpdateEntities(Uri uri, Entity[] entities) throws RemoteException { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + + data.writeInterfaceToken(IContentProvider.descriptor); + uri.writeToParcel(data, 0); + data.writeString(entities[0].getClass().getName()); + data.writeInt(entities.length); + for (Entity entity : entities) { + data.writeParcelable(entity, 0); + } + + mRemote.transact(IContentProvider.BULK_UPDATE_ENTITIES_TRANSACTION, data, reply, 0); + + DatabaseUtils.readExceptionFromParcel(reply); + int[] results = new int[entities.length]; + reply.readIntArray(results); + + data.recycle(); + reply.recycle(); + + return results; + } + public int delete(Uri url, String selection, String[] selectionArgs) throws RemoteException { Parcel data = Parcel.obtain(); |