Android Open Source - BaseAndroid Sample D A O






From Project

Back to project page BaseAndroid.

License

The source code is released under:

MIT License

If you think the Android project BaseAndroid 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

/**
 * File: SampleDAO//from w ww .  j av a 2 s  .  c  o  m
 * CreationDate: 31/07/13
 * Author: "M. en C. Javier Silva Perez (JSP)"
 * Description: 
 * Data Access Object implementation for State table, will contain all the function that access to the data base
 * table in order to modify or retrieve information
 *
 */
package com.cmovil.baseandroid.dao.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

import com.cmovil.baseandroid.dao.db.helper.SampleOpenHelper;
import com.cmovil.baseandroid.model.db.State;

/**
 * Data Access Object implementation for State table, will contain all the function that access to the data base table
 * in order to modify or retrieve information
 *
 * @author "M. en C. Javier Silva Perez (JSP)"
 * @version 1.0
 * @since 31/07/13
 */
public class SampleDAO extends BaseDBDAO<State> {

  /**
   * Constructor
   *
   * @param context
   *   The Context within which to work, used to create the DB
   */
  public SampleDAO(Context context) {
    super(DatabaseDictionary.State.NAME, new SampleOpenHelper(context));
  }

  /**
   * Fill up a map for the values to be inserted or updated into the data base
   *
   * @param state
   *   Object to be get the table values
   * @return A ContentValues object filled up with the corresponding Patient values
   */
  @Override
  protected ContentValues fillMapValues(State state) {
    // Create a new map of values, where column base_dictionary are the keys
    ContentValues values = new ContentValues();
    values.put(DatabaseDictionary.State.COLUMN_NAME_NAME, state.getName());
    values.put(DatabaseDictionary.State.COLUMN_NAME_ID_SERVER, state.getIdServer());
    return values;
  }

  /**
   * Gets all the states with the selected server id
   *
   * @param idServer
   *   Server Id that will be searched in the database
   * @param columns
   *   The columns to include, if null then all are included
   * @return Cursor positioned to matching word, or null if not found.
   *
   * @throws DBException
   *   if something goes wrong during SQL statements execution
   */
  public Cursor getByServerId(Integer idServer, String[] columns) throws DBException {
    String selection = DatabaseDictionary.State.FILTER_ID_SERVER;
    String[] selectionArgs = new String[]{String.valueOf(idServer)};
    try {
      return query(DatabaseDictionary.State.NAME, selection, selectionArgs, columns, null);
    } catch (SQLException e) {
      throw new DBException(e.getMessage(), e);
    }
  }
}




Java Source Code List

com.cmovil.baseandroid.controller.BaseDBController.java
com.cmovil.baseandroid.controller.SampleController.java
com.cmovil.baseandroid.dao.db.BaseDBDAO.java
com.cmovil.baseandroid.dao.db.DBException.java
com.cmovil.baseandroid.dao.db.DatabaseDictionary.java
com.cmovil.baseandroid.dao.db.SampleDAO.java
com.cmovil.baseandroid.dao.db.helper.BaseDatabaseOpenHelper.java
com.cmovil.baseandroid.dao.db.helper.SampleOpenHelper.java
com.cmovil.baseandroid.dao.ws.BaseMessageWS.java
com.cmovil.baseandroid.dao.ws.InvalidResponseException.java
com.cmovil.baseandroid.dao.ws.WSClient.java
com.cmovil.baseandroid.model.db.BaseModel.java
com.cmovil.baseandroid.model.db.State.java
com.cmovil.baseandroid.model.ws.MessageErrorCode.java
com.cmovil.baseandroid.model.ws.Parser.java
com.cmovil.baseandroid.util.CMUtils.java
com.cmovil.baseandroid.util.CustomCatalogComparator.java
com.cmovil.baseandroid.util.KeyDictionary.java
com.cmovil.baseandroid.view.BaseActionBarActivity.java
com.cmovil.baseandroid.view.BaseDrawerActivity.java
com.cmovil.baseandroid.view.SplashActivity.java