Android Open Source - LitePal Lite Pal Attr






From Project

Back to project page LitePal.

License

The source code is released under:

Apache License

If you think the Android project LitePal 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 (C)  Tony Green, Litepal Framework Open Source Project
 *//www.  jav a  2 s.  c  o  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 org.litepal.parser;

import java.util.ArrayList;
import java.util.List;

import org.litepal.exceptions.InvalidAttributesException;
import org.litepal.util.Const;
import org.litepal.util.SharedUtil;

import android.text.TextUtils;

/**
 * The object model for the litepal.xml file. Once database connection happens,
 * LitePal will try to analysis the litepal.xml, and read all the attribute into
 * the LitePalAttr model for further usage.
 * 
 * @author Tony Green
 * @since 1.0
 */
public final class LitePalAttr {

  /**
   * Static litePalAttr object.
   */
  private static LitePalAttr litePalAttr;

  /**
   * The version of database.
   */
  private int version;

  /**
   * The name of database.
   */
  private String dbName;

  /**
   * The case of table names and column names and SQL.
   */
  private String cases;

  /**
   * All the model classes that want to map in the database. Each class should
   * be given the full name including package name.
   */
  private List<String> classNames;

  /**
   * Do not allow new a LitePalAttr object. Makes it a singleton class.
   */
  private LitePalAttr() {
  }

  /**
   * Provide a way to get the object of LitePalAttr class.
   * 
   * @return the singleton object of LitePalAttr
   */
  public static LitePalAttr getInstance() {
    if (litePalAttr == null) {
      synchronized (LitePalAttr.class) {
        if (litePalAttr == null) {
          litePalAttr = new LitePalAttr();
        }
      }
    }
    return litePalAttr;
  }

  public int getVersion() {
    return version;
  }

  void setVersion(int version) {
    this.version = version;
  }

  public String getDbName() {
    return dbName;
  }

  void setDbName(String dbName) {
    this.dbName = dbName;
  }

  /**
   * Get the class name list. Always add table_schema as a value.
   * 
   * @return The class name list.
   */
  public List<String> getClassNames() {
    if (classNames == null) {
      classNames = new ArrayList<String>();
      classNames.add("org.litepal.model.Table_Schema");
    } else if (classNames.isEmpty()) {
      classNames.add("org.litepal.model.Table_Schema");
    }
    return classNames;
  }

  /**
   * Add a class name into the current mapping model list.
   * 
   * @param className
   *            Full package class name.
   */
  void addClassName(String className) {
    getClassNames().add(className);
  }

  public String getCases() {
    return cases;
  }

  void setCases(String cases) {
    this.cases = cases;
  }

  /**
   * Before application build the connection with database, check the fields
   * in LitePalAttr. If all of the fields are passed, the connection will be
   * continued.If anyone of them doesn't pass, an exception will be thrown.
   * 
   * @return If all of the fields are passed, return true. If dbname is
   *         undefined, or version is less than 1, or version is earlier than
   *         current version, throw InvalidAttributesException
   * 
   * @throws InvalidAttributesException
   */
  public boolean checkSelfValid() {
    if (TextUtils.isEmpty(dbName)) {
      throw new InvalidAttributesException(
          InvalidAttributesException.DBNAME_IS_EMPTY_OR_NOT_DEFINED);
    }
    if (!dbName.endsWith(Const.LitePal.DB_NAME_SUFFIX)) {
      dbName = dbName + Const.LitePal.DB_NAME_SUFFIX;
    }
    if (version < 1) {
      throw new InvalidAttributesException(
          InvalidAttributesException.VERSION_OF_DATABASE_LESS_THAN_ONE);
    }
    if (version < SharedUtil.getLastVersion()) {
      throw new InvalidAttributesException(
          InvalidAttributesException.VERSION_IS_EARLIER_THAN_CURRENT);
    }
    if (TextUtils.isEmpty(cases)) {
      cases = Const.LitePal.CASES_LOWER;
    } else {
      if (!cases.equals(Const.LitePal.CASES_UPPER)
          && !cases.equals(Const.LitePal.CASES_LOWER)
          && !cases.equals(Const.LitePal.CASES_KEEP)) {
        throw new InvalidAttributesException(cases
            + InvalidAttributesException.CASES_VALUE_IS_INVALID);
      }
    }
    return true;
  }

}




Java Source Code List

org.litepal.LitePalApplication.java
org.litepal.LitePalBase.java
org.litepal.crud.AssociationsAnalyzer.java
org.litepal.crud.ClusterQuery.java
org.litepal.crud.DataHandler.java
org.litepal.crud.DataSupport.java
org.litepal.crud.DeleteHandler.java
org.litepal.crud.DynamicExecutor.java
org.litepal.crud.Many2ManyAnalyzer.java
org.litepal.crud.Many2OneAnalyzer.java
org.litepal.crud.One2OneAnalyzer.java
org.litepal.crud.QueryHandler.java
org.litepal.crud.SaveHandler.java
org.litepal.crud.UpdateHandler.java
org.litepal.crud.model.AssociationsInfo.java
org.litepal.exceptions.DataSupportException.java
org.litepal.exceptions.DatabaseGenerateException.java
org.litepal.exceptions.GlobalException.java
org.litepal.exceptions.InvalidAttributesException.java
org.litepal.exceptions.ParseConfigurationFileException.java
org.litepal.litepalsample.activity.AggregateActivity.java
org.litepal.litepalsample.activity.AverageSampleActivity.java
org.litepal.litepalsample.activity.CRUDActivity.java
org.litepal.litepalsample.activity.CountSampleActivity.java
org.litepal.litepalsample.activity.DeleteSampleActivity.java
org.litepal.litepalsample.activity.MainActivity.java
org.litepal.litepalsample.activity.ManageTablesActivity.java
org.litepal.litepalsample.activity.MaxSampleActivity.java
org.litepal.litepalsample.activity.MinSampleActivity.java
org.litepal.litepalsample.activity.ModelListActivity.java
org.litepal.litepalsample.activity.ModelStructureActivity.java
org.litepal.litepalsample.activity.QuerySampleActivity.java
org.litepal.litepalsample.activity.SaveSampleActivity.java
org.litepal.litepalsample.activity.SumSampleActivity.java
org.litepal.litepalsample.activity.TableListActivity.java
org.litepal.litepalsample.activity.TableStructureActivity.java
org.litepal.litepalsample.activity.UpdateSampleActivity.java
org.litepal.litepalsample.adapter.DataArrayAdapter.java
org.litepal.litepalsample.adapter.StringArrayAdapter.java
org.litepal.litepalsample.model.Album.java
org.litepal.litepalsample.model.Singer.java
org.litepal.litepalsample.model.Song.java
org.litepal.litepalsample.util.Utility.java
org.litepal.model.Table_Schema.java
org.litepal.parser.LitePalAttr.java
org.litepal.parser.LitePalContentHandler.java
org.litepal.parser.LitePalParser.java
org.litepal.tablemanager.AssociationCreator.java
org.litepal.tablemanager.AssociationUpdater.java
org.litepal.tablemanager.Connector.java
org.litepal.tablemanager.Creator.java
org.litepal.tablemanager.Dropper.java
org.litepal.tablemanager.Generator.java
org.litepal.tablemanager.LitePalOpenHelper.java
org.litepal.tablemanager.Upgrader.java
org.litepal.tablemanager.model.AssociationsModel.java
org.litepal.tablemanager.model.TableModel.java
org.litepal.tablemanager.typechange.BooleanOrm.java
org.litepal.tablemanager.typechange.DateOrm.java
org.litepal.tablemanager.typechange.DecimalOrm.java
org.litepal.tablemanager.typechange.NumericOrm.java
org.litepal.tablemanager.typechange.OrmChange.java
org.litepal.tablemanager.typechange.TextOrm.java
org.litepal.util.BaseUtility.java
org.litepal.util.Const.java
org.litepal.util.DBUtility.java
org.litepal.util.LogUtil.java
org.litepal.util.SharedUtil.java