Android Open Source - TwelveRules Assets Database






From Project

Back to project page TwelveRules.

License

The source code is released under:

Apache License

If you think the Android project TwelveRules 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.manuelpeinado.twelverules;
/*w  w  w  .java2  s. c  om*/

import android.database.sqlite.SQLiteDatabase;
import android.content.Context;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;


public abstract class AssetsDatabase extends SQLiteAssetHelper implements IDatabase {
  private SQLiteDatabase db;
  private DatabaseTable[] tables;
  private String name;

  protected AssetsDatabase(Context context, String name, int version) {
          super(context, name, null, version);
                this.name = name;
      }
  
  protected abstract DatabaseTable[] getTables(SQLiteDatabase db);
  
  @Override
  public DatabaseTable[] getTables() {
    if (tables == null) {
      tables = getTables(getDatabase());
    }
    return tables;
  }

  private SQLiteDatabase getDatabase() {
    if (db == null) {
      db = getWritableDatabase();
    }
    return db;
  }

  public void beginInsertTransaction() {
    db.beginTransaction();
  }

  public void endInsertTransaction(boolean success) {
    if (success) {
      db.setTransactionSuccessful();
    }
    db.endTransaction();
    for (DatabaseTable table : tables) {
      table.finishInsert();
    }
  }
  
  /**
   * Provoca que se sobreescriba la base de datos existente si su versin es inferior a la proporcionada
   * til cuando no necesitamos hacer una migracin mediante script, sino que queremos reemplazar todos 
   * los datos anteriores con datos nuevos
   */
  public void forceUpgrade(int version) {
    setForcedUpgradeVersion(version);
  }
  
  @Override
  public boolean copyToSdCard(Context context) {
    return DbUtils.copyDbToSdCard(context, this);
  }
  
  @Override
  public String getName() {
    return name;
  }
}




Java Source Code List

com.manuelpeinado.sql_dsl.Constants.java
com.manuelpeinado.sql_dsl.Criterion.java
com.manuelpeinado.sql_dsl.DBObject.java
com.manuelpeinado.sql_dsl.Field.java
com.manuelpeinado.sql_dsl.GroupBy.java
com.manuelpeinado.sql_dsl.JoinType.java
com.manuelpeinado.sql_dsl.Join.java
com.manuelpeinado.sql_dsl.Operator.java
com.manuelpeinado.sql_dsl.OrderType.java
com.manuelpeinado.sql_dsl.Order.java
com.manuelpeinado.sql_dsl.Query.java
com.manuelpeinado.sql_dsl.Table.java
com.manuelpeinado.sql_dsl.UnaryCriterion.java
com.manuelpeinado.twelverules.AssetsDatabase.java
com.manuelpeinado.twelverules.ColumnSet.java
com.manuelpeinado.twelverules.ContentValuesCreator.java
com.manuelpeinado.twelverules.DatabaseColumn.java
com.manuelpeinado.twelverules.DatabaseTable.java
com.manuelpeinado.twelverules.Database.java
com.manuelpeinado.twelverules.DbUtils.java
com.manuelpeinado.twelverules.IDatabase.java