Android Open Source - webots-remote-control Data Source






From Project

Back to project page webots-remote-control.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project webots-remote-control 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.black_mesa.webots_remote_control.database;
/*from   w  w w  .ja  v  a  2 s .  c  om*/
import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DataSource {

  private SQLiteDatabase mDatabase;
  private DataBaseHelper mDbHelper;
  private static final String[] ALL_SERVER_COLUMNS = { DataBaseContract.ServerTable._ID,
      DataBaseContract.ServerTable.NAME, DataBaseContract.ServerTable.ADRESS, DataBaseContract.ServerTable.PORT };

  public DataSource(Context context) {
    mDbHelper = new DataBaseHelper(context);
  }

  /**
   * Opens the database or throws an exception.
   * 
   * @throws SQLException
   */
  public void open() {
    mDatabase = mDbHelper.getWritableDatabase();
  }

  /**
   * Closes the database.
   */
  public void close() {
    mDbHelper.close();
  }

  /**
   * Creates a new Server and inserts it into the database.
   * 
   * @param name
   *            of the Server
   * @param adress
   *            of the Server
   * @param port
   *            of the Server
   * @return created Server
   */
  public Server createServer(String name, String adress, int port) {
    ContentValues values = new ContentValues();
    values.put(DataBaseContract.ServerTable.NAME, name);
    values.put(DataBaseContract.ServerTable.ADRESS, adress);
    values.put(DataBaseContract.ServerTable.PORT, port);
    long insertId = mDatabase.insert(DataBaseContract.ServerTable.TABLE_NAME, null, values);
    Cursor cursor =
        mDatabase.query(DataBaseContract.ServerTable.TABLE_NAME, ALL_SERVER_COLUMNS,
            DataBaseContract.ServerTable._ID + " = " + insertId, null, null, null, null);
    cursor.moveToFirst();
    Server newServer = cursorToServer(cursor);
    cursor.close();
    return newServer;

  }

  /**
   * Deletes the Server from the database.
   * 
   * @param Server
   *            to delete
   */
  public void deleteServer(Server server) {
    long id = server.getId();
    mDatabase.delete(DataBaseContract.ServerTable.TABLE_NAME, DataBaseContract.ServerTable._ID + " = " + id, null);
  }

  /**
   * Retrieves all the servers from the database.
   * 
   * @return List of Server
   */
  public List<Server> getAllServers() {
    List<Server> servers = new ArrayList<Server>();
    Cursor cursor =
        mDatabase.query(DataBaseContract.ServerTable.TABLE_NAME, ALL_SERVER_COLUMNS, null, null, null, null,
            null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      Server server = cursorToServer(cursor);
      servers.add(server);
      cursor.moveToNext();
    }
    cursor.close();
    return servers;
  }

  /**
   * Updates the server in the database.
   * 
   * @param server
   *            to update
   */
  public void updateServer(Server server) {
    String strFilter = DataBaseContract.ServerTable._ID + "=" + server.getId();
    ContentValues values = new ContentValues();
    values.put(DataBaseContract.ServerTable.NAME, server.getName());
    values.put(DataBaseContract.ServerTable.ADRESS, server.getAdress());
    values.put(DataBaseContract.ServerTable.PORT, server.getPort());
    mDatabase.update(DataBaseContract.ServerTable.TABLE_NAME, values, strFilter, null);
  }

  private Server cursorToServer(Cursor cursor) {
    return new Server(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3));
  }
}




Java Source Code List

org.black_mesa.webots_remote_control.activities.AboutFragment.java
org.black_mesa.webots_remote_control.activities.AddServerActivity.java
org.black_mesa.webots_remote_control.activities.CameraFragment.java
org.black_mesa.webots_remote_control.activities.ConnectionFragment.java
org.black_mesa.webots_remote_control.activities.MainActivity.java
org.black_mesa.webots_remote_control.client.CamerasManager.java
org.black_mesa.webots_remote_control.client.Client.java
org.black_mesa.webots_remote_control.client.ConnectionManager.java
org.black_mesa.webots_remote_control.client.ConnectionState.java
org.black_mesa.webots_remote_control.client.package-info.java
org.black_mesa.webots_remote_control.communication_structures.CameraInstructionQueue.java
org.black_mesa.webots_remote_control.communication_structures.CameraInstruction.java
org.black_mesa.webots_remote_control.communication_structures.CommunicationStructure.java
org.black_mesa.webots_remote_control.communication_structures.package-info.java
org.black_mesa.webots_remote_control.database.DataBaseContract.java
org.black_mesa.webots_remote_control.database.DataBaseHelper.java
org.black_mesa.webots_remote_control.database.DataSource.java
org.black_mesa.webots_remote_control.database.ServerListAdapter.java
org.black_mesa.webots_remote_control.database.Server.java
org.black_mesa.webots_remote_control.listeners.CameraJoysticksViewListener.java
org.black_mesa.webots_remote_control.listeners.CameraTouchListenerV1.java
org.black_mesa.webots_remote_control.listeners.CameraTouchListenerV2.java
org.black_mesa.webots_remote_control.listeners.CameraTouchListenerV3.java
org.black_mesa.webots_remote_control.listeners.CameraTouchListenerV4.java
org.black_mesa.webots_remote_control.listeners.CameraTouchListenerV5.java
org.black_mesa.webots_remote_control.listeners.ClientListener.java
org.black_mesa.webots_remote_control.listeners.ConnectionManagerListener.java
org.black_mesa.webots_remote_control.listeners.OnListEventsListener.java
org.black_mesa.webots_remote_control.listeners.package-info.java
org.black_mesa.webots_remote_control.utils.CameraTouchHandlerV1.java
org.black_mesa.webots_remote_control.utils.CameraTouchHandlerV2.java
org.black_mesa.webots_remote_control.utils.CameraTouchHandlerV3.java
org.black_mesa.webots_remote_control.utils.CameraTouchHandlerV4.java
org.black_mesa.webots_remote_control.utils.CameraTouchHandlerV5.java
org.black_mesa.webots_remote_control.utils.package-info.java
org.black_mesa.webots_remote_control.views.CameraJoysticksView.java
org.black_mesa.webots_remote_control.views.CameraView.java