5

package jp.co.test.logic;

import java.io.File;
import java.io.IOException;
import java.util.List;

import jp.co.test.common.Common;
import jp.co.test.common.Constant;

/**
 * モデル作成の基本処理クラス
 */
public class ModelCreate {

 public static void modelCreate(File file, List<List<List<Object>>> dataList, String folder) throws IOException {
  
  // モデルクラスの作成処理
  for (int i = 0;i < dataList.size();i++) {
   
   // 共通情報を取得する
   // テーブルIDを取得する
   String fName = dataList.get(i).get(6).get(4).toString();
   // テーブル名称を取得する
   String tName = dataList.get(i).get(6).get(16).toString();
   
   // 属性文字列の定義
   StringBuilder strBuilder = new StringBuilder();
   // メソッド文字列の定義
   StringBuilder strMethod = new StringBuilder();
   // Model属性情報出力
   for (int k = 8;k < dataList.get(i).size(); k++) {
    
    // フィールドの情報を取得する
    // 属性IDを取得する
    String attrId = Common.attrFormat(dataList.get(i).get(k).get(1).toString(), Constant.SEP_LINE);
    // 属性名称を取得する
    String attrName = dataList.get(i).get(k).get(11).toString();
    // 属性のデータタイプを取得する
    String dataType = dataList.get(i).get(k).get(29).toString();
    
    // ファイルの末尾に到達する場合、サイクル終了
    if (dataList.get(i).get(k).get(0) == null
      || Constant.EMPTY.equals(dataList.get(i).get(k).get(0).toString())) {
     // 処理終了
     break;
    }
    
    ModelCreate.modelCommon(k, dataList.get(i).size(), fName, tName, attrId,
      attrName, dataType, strBuilder, strMethod);
   }
   
   strBuilder.append(strMethod.toString());
   // ファイルの新規
   file = Common.createFile(file, folder, fName + "_Model.java", strBuilder.toString());
  }
 }
 
 /**
  * Modelファイルの作成処理
  *
  * @param fName          ファイル名称
  * @param tName          テーブル名称
  * @param strBuilder     文字列変数
  */
 private static void modelCommon(int k,int m, String fName, String tName, String attrId,
   String attrName, String dataType, StringBuilder strBuilder, StringBuilder strMethod) {
  
  if (k == 8) {
   
   String pkgName = "jp.co.nssol";
   
   strBuilder.append("package " + pkgName + ".model;\n\n");
   strBuilder.append("import java.util.*;\n\n");
   strBuilder.append("/**\n *\n *" + tName + "のDTO\n *\n *@param fName       ファイル名称\n *@param tName");
   strBuilder.append("       テーブル名称\n *@param strBuilder  文字列変数\n */\n");
   strBuilder.append("public class ");
   strBuilder.append(fName + "_Model");
   strBuilder.append(" {" + "\n" + " " + "\n" + " ");
  }
  // フィールドのコメント
  strBuilder.append("// " + attrName + "\n" + " ");
  // フィールドの属性は大文字を小文字に変更する
  dataType = dataType.toLowerCase();
  // フィールドの定義
  if (Constant.TYPE_BOOLEAN.equals(dataType)) {
   
   strBuilder.append("public Boolean " + attrId + ";\n\n ");
  } else if (Constant.TYPE_CHAR.equals(dataType)
    || Constant.TYPE_NCHAR.equals(dataType)) {
   
   strBuilder.append("public String " + attrId + ";\n\n ");
  } else if (Constant.TYPE_DATETIME.equals(dataType)
    || Constant.TYPE_DATETIME2.equals(dataType)) {
   
   strBuilder.append("public Date " + attrId + ";\n\n ");
  } else if (Constant.TYPE_INT.equals(dataType)) {
   
   strBuilder.append("public Integer " + attrId + ";\n\n ");
  } else if (Constant.TYPE_DECIMAL.equals(dataType)) {
   
   strBuilder.append("public Double " + attrId + ";\n\n ");
  }
  
  // DTO属性ゲットとセットメソッドを作成する
  strMethod.append("/**\n  * @param " + attrId + " セットする  " + attrName + "\n  */\n ");
  
  // 属性の先頭文字を大文字に変換する
  String upperAttrId = Common.firstLowerToUpper(attrId);
  // セットメソッド
  if (Constant.TYPE_BOOLEAN.equals(dataType)) {
   
   strMethod.append("public void set" + upperAttrId + "() {\n  ");
  } else if (Constant.TYPE_CHAR.equals(dataType)
    || Constant.TYPE_NCHAR.equals(dataType)) {
   
   strMethod.append("public void set" + upperAttrId + "(String " + attrId + ") {\n  ");
  } else if (Constant.TYPE_DATETIME.equals(dataType)
    || Constant.TYPE_DATETIME2.equals(dataType)) {
   
   strMethod.append("public void set" + upperAttrId + "(Date " + attrId + ") {\n  ");
  } else if (Constant.TYPE_INT.equals(dataType)) {
   
   strMethod.append("public void set" + upperAttrId + "(Integer " + attrId + ") {\n  ");
  } else if (Constant.TYPE_DECIMAL.equals(dataType)) {
   
   strMethod.append("public void set" + upperAttrId + "(Double " + attrId + ") {\n  ");
  }
  strMethod.append("this." + attrId + " = " + attrId +";\n }\n\n ");
  
  // ゲットメソッド
  strMethod.append("/**\n  * @return " + attrId + "      " + attrName + "\n  */\n ");
  if (Constant.TYPE_BOOLEAN.equals(dataType)) {
   
   strMethod.append("public boolean is" + upperAttrId + "() {\n  ");
  } else if (Constant.TYPE_CHAR.equals(dataType)
    || Constant.TYPE_NCHAR.equals(dataType)) {
   
   strMethod.append("public String get" + upperAttrId + "() {\n  ");
  } else if (Constant.TYPE_DATETIME.equals(dataType)
    || Constant.TYPE_DATETIME2.equals(dataType)) {
   
   strMethod.append("public Date get" + upperAttrId + "() {\n  ");
  } else if (Constant.TYPE_INT.equals(dataType)) {
   
   strMethod.append("public Integer get" + upperAttrId + "() {\n  ");
  } else if (Constant.TYPE_DECIMAL.equals(dataType)) {
   
   strMethod.append("public double get" + upperAttrId + "() {\n  ");
  }
  strMethod.append("return " + attrId +";\n }\n");
  
  if (k != m - 1) {
   strMethod.append("\n ");
  } else {
   strMethod.append("\n}");
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值