Android Open Source - android-sqlite-server Raw Query Command






From Project

Back to project page android-sqlite-server.

License

The source code is released under:

Apache License

If you think the Android project android-sqlite-server listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.devtcg.sqliteserver.impl.binder.protocol;
/*w  w  w  .  j a  va  2 s. c  om*/
import android.database.Cursor;
import android.os.Bundle;
import aosp.android.database.BulkCursorDescriptor;
import aosp.android.database.BulkCursorToCursorAdaptor;
import aosp.android.database.CursorToBulkCursorAdaptor;
import org.devtcg.sqliteserver.impl.binder.ClientTransactor;
import org.devtcg.sqliteserver.impl.binder.ContentObserverProxy;
import org.devtcg.sqliteserver.impl.binder.ServerImpl;

public class RawQueryCommand {
    private static final String KEY_QUERY = "query";
    private static final String KEY_SELECTION_ARGS = "selection_args";
    private static final String KEY_CONTENT_OBSERVER = "content_observer";
    private static final String KEY_CURSOR_DESCRIPTOR = "cursor_descriptor";

    public static class RawQueryMessage extends AbstractCommandMessage {
        private final String mQuery;
        private final String[] mSelectionArgs;

        private final BulkCursorToCursorAdaptor mCursorAdaptor;

        private Cursor mCursor;

        public RawQueryMessage(
                ClientTransactor transactor,
                String query,
                String[] selectionArgs) {
            super(transactor, MethodName.RAW_QUERY);
            mQuery = query;
            mSelectionArgs = selectionArgs;

            // XXX: Serious gotcha here.  The ContentProviderNative code that implements this
            // class expects to be able to catch RuntimeException at any point during
            // processing and invoke close() on this instance if it does.  Our design
            // doesn't allow this, so we have no way of cleaning up whatever resources
            // are being used underneath on error!
            mCursorAdaptor = new BulkCursorToCursorAdaptor();
        }

        @Override
        protected Bundle onBuildRequest(Bundle request) {
            request.putString(KEY_QUERY, mQuery);
            request.putStringArray(KEY_SELECTION_ARGS, mSelectionArgs);
            request.putParcelable(KEY_CONTENT_OBSERVER,
                    new ContentObserverProxy(mCursorAdaptor.getObserver()));
            return request;
        }

        @Override
        protected void onParseResponse(Bundle response) {
            try {
                BulkCursorDescriptor descriptor = response.getParcelable(KEY_CURSOR_DESCRIPTOR);
                if (descriptor != null) {
                    mCursorAdaptor.initialize(descriptor);
                    mCursor = mCursorAdaptor;
                    return;
                }
            } catch (RuntimeException e) {
                // Fall through...
            }
            mCursorAdaptor.close();
            mCursor = null;
        }

        public Cursor getCursor() {
            return mCursor;
        }
    }

    public static class RawQueryHandler extends AbstractCommandHandler {
        private final String mServerName;

        public RawQueryHandler(ServerImpl serverImpl, String serverName) {
            super(serverImpl);
            mServerName = serverName;
        }

        @Override
        protected Bundle onHandle(Bundle request) {
            String query = request.getString(KEY_QUERY);
            String[] selectionArgs = request.getStringArray(KEY_SELECTION_ARGS);
            ContentObserverProxy contentObserver = request.getParcelable(KEY_CONTENT_OBSERVER);
            Cursor cursor = getExecutor().rawQuery(query, selectionArgs);
            Bundle ret = new Bundle();
            if (cursor != null) {
                CursorToBulkCursorAdaptor adaptor = new CursorToBulkCursorAdaptor(
                        cursor, contentObserver, mServerName);
                BulkCursorDescriptor descriptor = adaptor.getBulkCursorDescriptor();
                ret.putParcelable(KEY_CURSOR_DESCRIPTOR, descriptor);
            } else {
                ret.putParcelable(KEY_CURSOR_DESCRIPTOR, null);
            }
            return ret;
        }
    }
}




Java Source Code List

aosp.android.database.BulkCursorDescriptor.java
aosp.android.database.BulkCursorNative.java
aosp.android.database.BulkCursorToCursorAdaptor.java
aosp.android.database.CrossProcessCursorWrapper.java
aosp.android.database.CursorToBulkCursorAdaptor.java
aosp.android.database.IBulkCursor.java
aosp.android.database.MoreDatabaseUtils.java
org.devtcg.sqliteserver.SQLiteContentProviderServer.java
org.devtcg.sqliteserver.SQLiteServerConnectionManager.java
org.devtcg.sqliteserver.SQLiteServerConnection.java
org.devtcg.sqliteserver.SQLiteServer.java
org.devtcg.sqliteserver.SQLiteServiceServer.java
org.devtcg.sqliteserver.exception.SQLiteServerException.java
org.devtcg.sqliteserver.impl.ExecutorHelper.java
org.devtcg.sqliteserver.impl.SQLiteExecutor.java
org.devtcg.sqliteserver.impl.ServerImplProvider.java
org.devtcg.sqliteserver.impl.binder.AbstractBinderClient.java
org.devtcg.sqliteserver.impl.binder.BinderHandle.java
org.devtcg.sqliteserver.impl.binder.BundleUtils.java
org.devtcg.sqliteserver.impl.binder.ClientTransactor.java
org.devtcg.sqliteserver.impl.binder.ContentObserverProxy.java
org.devtcg.sqliteserver.impl.binder.ContentProviderClient.java
org.devtcg.sqliteserver.impl.binder.SQLiteServerProtocolException.java
org.devtcg.sqliteserver.impl.binder.ServerImpl.java
org.devtcg.sqliteserver.impl.binder.ServerState.java
org.devtcg.sqliteserver.impl.binder.ServiceClient.java
org.devtcg.sqliteserver.impl.binder.ThreadAffinityExecutor.java
org.devtcg.sqliteserver.impl.binder.protocol.AbstractCommandHandler.java
org.devtcg.sqliteserver.impl.binder.protocol.AbstractCommandMessage.java
org.devtcg.sqliteserver.impl.binder.protocol.AcquireCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.BeginTransactionCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.DeleteCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.EndTransactionCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.ExceptionTransportHelper.java
org.devtcg.sqliteserver.impl.binder.protocol.ExecSQLCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.InsertCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.MethodName.java
org.devtcg.sqliteserver.impl.binder.protocol.RawQueryCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.ReleaseCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.SetTransactionSuccessfulCommand.java
org.devtcg.sqliteserver.impl.binder.protocol.UpdateCommand.java
org.devtcg.sqliteserver.sample.MyActivity.java
org.devtcg.sqliteserver.sample.MyOpenHelper.java
org.devtcg.sqliteserver.sample.TestContentProvider.java
org.devtcg.sqliteserver.sample.TestService.java