Android Open Source - SQLKing S Q L Initialise






From Project

Back to project page SQLKing.

License

The source code is released under:

Apache License

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

/**
 * Copyright 2013-present memtrip./*from  w  w w  . j a  v a2 s  .  co  m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.memtrip.sqlking;

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

import com.memtrip.sqlking.base.IModel;
import com.memtrip.sqlking.helper.DatabaseHelper;
import com.memtrip.sqlking.helper.ReflectionHelper;
import com.memtrip.sqlking.helper.StringHelper;
import com.memtrip.sqlking.schema.Column;

/**
 * Build the SQL database based on the provided models
 * @author  memtrip
 */
public class SQLInitialise {
  private SQLiteDatabase mDatabase;
  
  public SQLiteDatabase getDatabase() {
      return mDatabase;
  }
  
  public SQLInitialise(String name, int version, Context context, IModel[] baseModelArray) {
    String[] schemaArray = new String[baseModelArray.length];
    String[] tableNameArray = new String[baseModelArray.length];
    for (int i = 0; i < baseModelArray.length; i++) {
      IModel baseModel = baseModelArray[i];
      schemaArray[i] = buildSchemaFromBaseModel(baseModel);
      tableNameArray[i] = baseModel.getClass().getSimpleName();
    }
    
    SQLOpen sqlOpen = new SQLOpen(context, name, version, schemaArray, tableNameArray, baseModelArray);
    mDatabase = sqlOpen.getDatabase();
  }
  
  /**
   * Build a schema from the provided base model
   * @param  baseModel  The baseModel to build the schema from
   * @return  A schema string built on the provided baseModel
   */
  private String buildSchemaFromBaseModel(IModel baseModel) {
    String tableName = ReflectionHelper.getClassName(baseModel);
    Column[] columns = DatabaseHelper.getSQLColumnFromBaseModel(baseModel);
    return StringHelper.buildCreateTableStatement(tableName, columns);
  }
}




Java Source Code List

com.memtrip.sqlking.SQLInitialise.java
com.memtrip.sqlking.SQLOpen.java
com.memtrip.sqlking.SQLProvider.java
com.memtrip.sqlking.base.IModel.java
com.memtrip.sqlking.helper.DatabaseHelper.java
com.memtrip.sqlking.helper.ReflectionHelper.java
com.memtrip.sqlking.helper.StringHelper.java
com.memtrip.sqlking.schema.Column.java
com.memtrip.sqlking.schema.ORMDataType.java
com.memtrip.sqlking.schema.SQLDataType.java