Android Open Source - SimpleAndroidChat D B Connection






From Project

Back to project page SimpleAndroidChat.

License

The source code is released under:

GNU General Public License

If you think the Android project SimpleAndroidChat 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 com.anderscore.simpleandroidchat;
//from ww  w .  j av  a 2  s . c  o  m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

class DBConnection extends SQLiteOpenHelper{

  private static DBConnection db  = null;
  
  /**  Das initiieren dieses Contructors erzeugt ein Object, dass eine Schnittstelle zur DB bereithlt.
   *   
   *   @param context - der Context, indem die Datenbank gebraucht wird.
   */
  private DBConnection(Context context) {
    super(context, Constants.DB.DB_NAME, null, Constants.DB.DB_VERSION);
  }
  
  static DBConnection getDBConnection(Context context){
    if(db==null) db = new DBConnection(context);
    return db;
  }
  

/* ------- SQLiteOpenHelper ------- */
  
  @Override
  public void onCreate(SQLiteDatabase db) {
    String sql = "CREATE TABLE " +
        Constants.DB.Contacts.TABLE_NAME + " (" +
        Constants.DB.Contacts.ID +" INTEGER PRIMARY KEY, " +
        Constants.DB.Contacts.USER + " TEXT, " +
        Constants.DB.Contacts.ONLINE + " INTEGER " +
        ")";
    db.execSQL(sql);
    
    sql = "CREATE TABLE " +
        Constants.DB.Messages.TABLE_NAME + " (" +
        Constants.DB.Messages.ID +" INTEGER PRIMARY KEY, " +
        Constants.DB.Messages.USER_ID + " INTEGER, " +
        Constants.DB.Messages.INCOMMING + " INTEGER, " +
        Constants.DB.Messages.TEXT_MSG + " TEXT " +
        ")";
    db.execSQL(sql);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + Constants.DB.Contacts.TABLE_NAME);
    db.execSQL("DROP TABLE IF EXISTS " + Constants.DB.Messages.TABLE_NAME);
    onCreate(db);  
  }
}




Java Source Code List

com.anderscore.simpleandroidchat.AbstractActivity.java
com.anderscore.simpleandroidchat.ChatActivity.java
com.anderscore.simpleandroidchat.ChatListAdapter.java
com.anderscore.simpleandroidchat.ChatMsg.java
com.anderscore.simpleandroidchat.ConnectionAdapterEventbus.java
com.anderscore.simpleandroidchat.ConnectionAdapter.java
com.anderscore.simpleandroidchat.Constants.java
com.anderscore.simpleandroidchat.ContactListActivity.java
com.anderscore.simpleandroidchat.ContactListAdapter.java
com.anderscore.simpleandroidchat.Contact.java
com.anderscore.simpleandroidchat.DBConnection.java
com.anderscore.simpleandroidchat.DBModel.java
com.anderscore.simpleandroidchat.MessengerService.java
com.anderscore.simpleandroidchat.NotificationBuilder.java