Android Open Source - android-sqlite-server My Activity






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.sample;
/*from   ww  w.ja  v  a 2s  .  com*/
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import org.devtcg.sqliteserver.SQLiteServerConnection;
import org.devtcg.sqliteserver.SQLiteServerConnectionManager;

import java.util.ArrayList;

public class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        new Thread() {
            public void run() {
                smokeTest();
            }
        }.start();
    }

    private abstract class AbstractConnectionProvider {
        protected SQLiteServerConnectionManager createConnectionManager() {
            return new SQLiteServerConnectionManager(getApplicationContext());
        }

        public abstract SQLiteServerConnection openConnection();
    }

    private class ServiceConnectionProvider extends AbstractConnectionProvider {
        @Override
        public SQLiteServerConnection openConnection() {
            Intent serviceIntent = new Intent(MyActivity.this, TestService.class);
            System.out.println("Opening Service connection to: " + serviceIntent.getComponent());
            return createConnectionManager().openConnectionToService(serviceIntent);
        }
    }

    private class ContentProviderConnectionProvider extends AbstractConnectionProvider {
        @Override
        public SQLiteServerConnection openConnection() {
            String authority = TestContentProvider.AUTHORITY;
            System.out.println("Opening ContentProvider connection to: " + authority);
            return createConnectionManager().openConnectionToContentProvider(authority);
        }
    }

    private void smokeTest() {
        ArrayList<AbstractConnectionProvider> providers =
                new ArrayList<AbstractConnectionProvider>();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            providers.add(new ContentProviderConnectionProvider());
        }
        providers.add(new ServiceConnectionProvider());
        for (AbstractConnectionProvider provider : providers) {
            SQLiteServerConnection conn = provider.openConnection();
            try {
                doSmokeTest(conn);
            } finally {
                conn.close();
            }
        }
    }

    private void doSmokeTest(SQLiteServerConnection conn) {
        conn.beginTransaction();
        try {
            System.out.println("Deleting all records...");
            conn.delete("test", null, null);

            System.out.println("Inserting records...");
            ContentValues values = new ContentValues();
            values.put("test1", "foo");
            values.put("test2", "bar");
            conn.insert("test", values);
            values.put("test2", "baz");
            conn.insert("test", values);
            values.put("test1", "bla");
            conn.insert("test", values);
            conn.setTransactionSuccessful();
        } finally {
            conn.endTransaction();
        }

        System.out.println("Querying...");
        Cursor foo = conn.rawQuery("SELECT * FROM test", new String[] {});
        try {
            dumpCursor(foo);
        } finally {
            foo.close();
        }
    }

    private static void dumpCursor(Cursor cursor) {
        int columnCount = cursor.getColumnCount();
        System.out.println("count=" + cursor.getCount() + "; columnCount=" + columnCount);
        int rowNum = 0;
        while (cursor.moveToNext()) {
            System.out.println("Row #" + (++rowNum) + ":");
            for (int i = 0; i < columnCount; i++) {
                System.out.println("\t" + cursor.getColumnName(i) + ": " +
                        cursor.getString(i));
            }
        }
    }

}




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