Android Open Source - storm-gen Field 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  www .j av a 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.
 ******************************************************************************/
/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * 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.entity;

import com.turbomanage.storm.apt.converter.ConverterModel;
import com.turbomanage.storm.types.TypeConverter.SqlType;

/**
 * Model of a persisted field
 *
 * @author David M. Chandler
 */
public class FieldModel {

  private String fieldName, colName, javaType;
  private boolean isEnum, isEntityId;
  private ConverterModel converter;

  public FieldModel(String fieldName, String javaType, boolean isEnum, ConverterModel converter) {
    this.fieldName = fieldName;
    this.javaType = javaType;
    this.isEnum = isEnum;
    this.converter = converter;
    // TODO or @ColumnName
    this.colName = fieldName;
  }

  public String getFieldName() {
    return fieldName;
  }

  public String getColName() {
    // CursorAdapter requires lowercase _id col
    if (EntityModel.ID_COL.equals(colName)) {
      return EntityModel.ID_COL;
    } else {
      return colName.toUpperCase();
    }
  }
  
  void setColName(String colName) {
    this.colName = colName;
  }

  public String getJavaType() {
    return javaType;
  }

  private ConverterModel getConverter() {
    return this.converter;
  }

  /**
   * Convenience method for more compact Dao templates. Returns the name of
   * this field's converter class sans package name.
   *
   * @return
   */
  public String getConverterName() {
    return getConverter().getClassName();
  }

  /**
   * Fully-qualified name of the converter class for this field.
   *
   * @return String classname
   */
  public String getQualifiedConverterClass() {
    return getConverter().getQualifiedClassName();
  }

  /**
   * Morph bind type like INT ==> Int so it can be used in a Cursor getXxx
   * method name. Never called at runtime.
   *
   * @return
   */
  public String getBindType() {
    String bindType = getConverter().getBindType().name();
    return bindType.charAt(0) + bindType.toLowerCase().substring(1);
  }

  public String getSqlType() {
    if (this.isEntityId)
      return "INTEGER PRIMARY KEY AUTOINCREMENT";
    else if (isEnum) {
      return SqlType.TEXT.name();
    }
    return this.converter.getSqlType().name();
  }

  public String getSetter() {
    return "set" + capFirst(fieldName);
  }

  public String getGetter() {
    if ("boolean".equals(javaType))
      return "is" + capFirst(fieldName);
    else
      return "get" + capFirst(fieldName);
  }

  /**
   * Capitalizes the first letter to create a valid getter/setter name.
   *
   * @param String
   * @return String
   */
  private String capFirst(String anyName) {
    // obscure Java convention:
    // if second letter capitalized, leave it alone
    if (anyName.length() > 1)
      if (anyName.charAt(1) >= 'A' && anyName.charAt(1) <= 'Z')
        return anyName;
    String capFirstLetter = anyName.substring(0, 1).toUpperCase();
    return capFirstLetter + anyName.substring(1);
  }

  public boolean isNullable() {
    return javaType.contains(".") || javaType.contains("[]");
  }

  public boolean isEnum() {
    return isEnum;
  }

  boolean isEntityId() {
    return isEntityId;
  }

  void setEntityId(boolean isEntityId) {
    this.isEntityId = isEntityId;
  }
}




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