Android Open Source - storm-gen Database Model






From Project

Back to project page storm-gen.

License

The source code is released under:

Apache License

If you think the Android project storm-gen 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 2012 Google, Inc.//from  ww  w . j ava 2  s .com
 *
 * 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.turbomanage.storm.apt.database;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.turbomanage.storm.apt.ClassModel;
import com.turbomanage.storm.apt.ProcessorLogger;
import com.turbomanage.storm.apt.StormEnvironment;
import com.turbomanage.storm.apt.entity.EntityModel;
import com.turbomanage.storm.csv.CsvUtils;

public class DatabaseModel extends ClassModel {

  private String dbName;
  private int dbVersion;
  private List<EntityModel> entities = new ArrayList<EntityModel>();
  private List<String> tableHelpers = new ArrayList<String>();

  public DatabaseModel(String dbName, int dbVersion, String helperClass) {
    super();
    this.setDbName(dbName);
    this.setDbVersion(dbVersion);
    parseQualifiedClassName(helperClass);
  }

  public String getDbName() {
    return dbName;
  }

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

  public int getDbVersion() {
    return dbVersion;
  }

  void setDbVersion(int dbVersion) {
    this.dbVersion = dbVersion;
  }

  public String getDbHelperClass() {
    return getQualifiedClassName();
  }

  public String getFactoryName() {
    return capFirst(this.getDbName()) + "Factory";
  }

  public String getFactoryClass() {
    String pkg = this.getPackage();
    if (pkg == null || pkg.length() < 1)
      return getFactoryName();
    return this.getPackage() + "." + getFactoryName();
  }

  public List<String> getDaoClasses() {
    List<String> daoClasses = new ArrayList<String>();
    for (EntityModel em : entities) {
      daoClasses.add(em.getDaoPackage() + "." + em.getDaoName());
    }
    return daoClasses;
  }

  public void addEntity(EntityModel daoModel) {
    this.entities.add(daoModel);
    // Duplicate TableHelper info for use by index writer
    String thClassName = daoModel.getTableHelperClass();
    if (!this.tableHelpers.contains(thClassName)) {
      // Skip it if it's already in the list
      // TODO use a Set instead?
      this.tableHelpers.add(daoModel.getTableHelperClass());
    }
  }

  public String[] getTableHelpers() {
    return tableHelpers.toArray(new String[]{});
  }

  /**
   * Populate the model of a database and its associated tables from
   * a file in support of incremental compilation.
   *
   * @param reader
   * @param logger
   * @return DatabaseModel
   * @throws IOException
   */
  public static DatabaseModel readFromIndex(BufferedReader reader, ProcessorLogger logger) throws IOException {
    String dbInfo = reader.readLine();
    logger.info(dbInfo);
    Map<String, String> props = CsvUtils.getAsMap(dbInfo);
    String dbName = props.get("dbName");
    int dbVersion = Integer.parseInt(props.get("dbVersion"));
    String helperClass = props.get("helperClass");
    DatabaseModel dbModel = new DatabaseModel(dbName, dbVersion, helperClass);
    // read TableHelpers
    List<String> tables = new ArrayList<String>();
    String th = reader.readLine();
    while (th != null && !th.equals(StormEnvironment.END_DATABASE)) {
      tables.add(th);
      th = reader.readLine();
    }
    dbModel.tableHelpers = tables;
    return dbModel;
  }

  /**
   * Write the database info and associated tables to a file
   * in support of incremental compilation.
   *
   * @param out PrintWriter
   */
  public void writeToIndex(PrintWriter out) {
    out.println(StormEnvironment.BEGIN_DATABASE);
    Map<String,String> dbMap = new HashMap<String,String>();
    dbMap.put("dbName", this.getDbName());
    dbMap.put("dbVersion", String.valueOf(this.getDbVersion()));
    dbMap.put("helperClass", this.getQualifiedClassName());
    String dbInfo = CsvUtils  .mapToCsv(dbMap);
    out.println(dbInfo);
    // write TableHelpers
    for (String th: this.tableHelpers) {
      out.println(th);
    }
    out.println(StormEnvironment.END_DATABASE);
  }

}




Java Source Code List

com.turbomanage.storm.DatabaseHelper.java
com.turbomanage.storm.ModelBase.java
com.turbomanage.storm.SQLiteDao.java
com.turbomanage.storm.TableHelper.java
com.turbomanage.storm.api.Converter.java
com.turbomanage.storm.api.DatabaseFactory.java
com.turbomanage.storm.api.Database.java
com.turbomanage.storm.api.Entity.java
com.turbomanage.storm.api.Id.java
com.turbomanage.storm.api.Syncable.java
com.turbomanage.storm.api.package-info.java
com.turbomanage.storm.apt.BaseDaoModel.java
com.turbomanage.storm.apt.ClassModel.java
com.turbomanage.storm.apt.ClassProcessor.java
com.turbomanage.storm.apt.ClassTemplate.java
com.turbomanage.storm.apt.MainProcessor.java
com.turbomanage.storm.apt.ProcessorLogger.java
com.turbomanage.storm.apt.SqlUtil.java
com.turbomanage.storm.apt.StormAnnotationException.java
com.turbomanage.storm.apt.StormEnvironment.java
com.turbomanage.storm.apt.converter.ConverterModel.java
com.turbomanage.storm.apt.converter.ConverterProcessor.java
com.turbomanage.storm.apt.converter.ConverterTypeAnnotationValueVisitor.java
com.turbomanage.storm.apt.converter.ConverterTypeAnnotationValuesVisitor.java
com.turbomanage.storm.apt.converter.package-info.java
com.turbomanage.storm.apt.database.DatabaseFactoryTemplate.java
com.turbomanage.storm.apt.database.DatabaseModel.java
com.turbomanage.storm.apt.database.DatabaseProcessor.java
com.turbomanage.storm.apt.database.package-info.java
com.turbomanage.storm.apt.entity.EntityDaoTemplate.java
com.turbomanage.storm.apt.entity.EntityModel.java
com.turbomanage.storm.apt.entity.EntityProcessor.java
com.turbomanage.storm.apt.entity.FieldModel.java
com.turbomanage.storm.apt.entity.TableHelperTemplate.java
com.turbomanage.storm.apt.entity.package-info.java
com.turbomanage.storm.csv.CsvTableReader.java
com.turbomanage.storm.csv.CsvTableWriter.java
com.turbomanage.storm.csv.CsvUtils.java
com.turbomanage.storm.csv.package-info.java
com.turbomanage.storm.exception.TooManyResultsException.java
com.turbomanage.storm.exception.TypeNotSupportedException.java
com.turbomanage.storm.exception.package-info.java
com.turbomanage.storm.query.Query.java
com.turbomanage.storm.query.package-info.java
com.turbomanage.storm.sample.activity.ContactActivity.java
com.turbomanage.storm.sample.activity.NewContactActivity.java
com.turbomanage.storm.sample.adapter.ContactAdapter.java
com.turbomanage.storm.sample.database.SampleDatabaseHelper.java
com.turbomanage.storm.sample.loader.AbstractAsyncTaskLoader.java
com.turbomanage.storm.sample.loader.ContactLoader.java
com.turbomanage.storm.sample.model.Contact.java
com.turbomanage.storm.types.BlobConverter.java
com.turbomanage.storm.types.BooleanConverter.java
com.turbomanage.storm.types.ByteConverter.java
com.turbomanage.storm.types.CharConverter.java
com.turbomanage.storm.types.DateConverter.java
com.turbomanage.storm.types.DoubleConverter.java
com.turbomanage.storm.types.EnumConverter.java
com.turbomanage.storm.types.FloatConverter.java
com.turbomanage.storm.types.IntegerConverter.java
com.turbomanage.storm.types.LongConverter.java
com.turbomanage.storm.types.PrimitiveConverter.java
com.turbomanage.storm.types.ShortConverter.java
com.turbomanage.storm.types.StringConverter.java
com.turbomanage.storm.types.TypeConverter.java
com.turbomanage.storm.types.package-info.java
com.turbomanage.storm.package-info.java