Package xgenerator.model

Examples of xgenerator.model.FieldMetadata


   * </p>
   * @author <a href="mailto:shushanlee@msn.com">liss</a>
   * @param rowIndex
   */
  private void insertRowEditable(int rowIndex) {
    FieldMetadata fieldMetadata = buildNewRowData();
    this.cellEditableVector.insertElementAt(mapRowEditableVector(fieldMetadata), rowIndex);
  }
View Full Code Here


   * </p>
   * @author <a href="mailto:shushanlee@msn.com">liss</a>
   * @return
   */
  private FieldMetadata buildNewRowData() {
    FieldMetadata fieldMetadata = new FieldMetadata();
   
    fieldMetadata.setNullable(true);
    fieldMetadata.setKeyField(false);
   
    return fieldMetadata;
  }
View Full Code Here

      /*
       * 获取表格数据
       */
      int rowCount = metadataTableModel.getRowCount();
      for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        final FieldMetadata oneFieldMetadata = new FieldMetadata();
       
        final Object columnName = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.COLUMN_NAME_INDEX);
        final Object propertyNameObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.PROPERTY_NAME_INDEX);
        final Object displayName = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DISPLAY_NAME_INDEX);
        final Object comments = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.COMMENTS_INDEX);
        final Object sqlDataTypeObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.SQL_DATA_TYPE_INDEX);
        final Object dataLengthObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DATA_LENGTH_INDEX);
        final Object dataPrecisionObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DATA_PRECISION_INDEX);
        final Object dataScaleObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DATA_SCALE_INDEX);
        final Object propertyTypeObj = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.PROPERTY_TYPE_INDEX);
        final Object nullable = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.NULLABLE_INDEX);
        final Object dataDefault = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DATA_DEFAULT_INDEX);
        final Object keyField = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.IS_KEY_FIELD_INDEX);
        final Object constraintType = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.CONSTRAINT_TYPE_INDEX);
        final Object referencingTable = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.REFERENCING_TABLE_INDEX);
        final Object referencingColumn = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.REFERENCING_COLUMN_INDEX);
        final Object deleteRule = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.DELETE_RULE_INDEX);
        final Object queryField = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.IS_QUERY_FIELD_INDEX);
        final Object queryMode = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.QUERY_MODE_INDEX);
        final Object componentType = metadataTableModel.getValueAt(rowIndex, MetadataTableModel.COMPONENT_TYPE_INDEX);
       
        oneFieldMetadata.setColumnName(StringUtils.toString(columnName));
        String propertyName = StringUtils.toString(propertyNameObj);
        oneFieldMetadata.setPropertyName(propertyName);
        oneFieldMetadata.setPropertyNameLowerCamelCase((NotationUtils.smallFirst(propertyName)));
        oneFieldMetadata.setPropertyNameUpperCamelCase((NotationUtils.capFirst(propertyName)));
        oneFieldMetadata.setPropertyNameUnderscore(NotationUtils.underscore(StringUtils.toString(columnName)));
        oneFieldMetadata.setPropertyNameStudlyCaps(NotationUtils.studlyCaps(propertyName));
        oneFieldMetadata.setDisplayName(StringUtils.toString(displayName));
        oneFieldMetadata.setComments(StringUtils.toString(comments));
        String sqlDataType = StringUtils.toString(sqlDataTypeObj);
        oneFieldMetadata.setSqlDataType(sqlDataType);
       
        if(null != dataLengthObj) {
          try {
            oneFieldMetadata.setDataLength(Integer.parseInt(StringUtils.toString(dataLengthObj)));
          } catch (Exception ex) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_LENGTH_INDEX] + "格式错误!");
          }
        }
        if(null != dataPrecisionObj) {
          try {
            oneFieldMetadata.setDataPrecision(Integer.parseInt(StringUtils.toString(dataPrecisionObj)));
          } catch (Exception ex) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_PRECISION_INDEX] + "格式错误!");
          }
        }
        if(null != dataScaleObj) {
          try {
            oneFieldMetadata.setDataScale(Integer.parseInt(StringUtils.toString(dataScaleObj)));
          } catch (Exception ex) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_SCALE_INDEX] + "格式错误!");
          }
        }

        oneFieldMetadata.setPropertyType(StringUtils.toString(propertyTypeObj));
        oneFieldMetadata.setNullable(Boolean.parseBoolean(StringUtils.toString(nullable)));
        oneFieldMetadata.setDataDefault(StringUtils.toString(dataDefault));
        oneFieldMetadata.setKeyField(Boolean.parseBoolean(StringUtils.toString(keyField)));
        oneFieldMetadata.setConstraintType(StringUtils.toString(constraintType));
        oneFieldMetadata.setReferencingTable(StringUtils.toString(referencingTable));
        oneFieldMetadata.setReferencingColumn(StringUtils.toString(referencingColumn));
        oneFieldMetadata.setDeleteRule(StringUtils.toString(deleteRule));
        oneFieldMetadata.setQueryField(Boolean.parseBoolean(StringUtils.toString(queryField)));
        oneFieldMetadata.setQueryMode(StringUtils.toString(queryMode));
        oneFieldMetadata.setComponentType(StringUtils.toString(componentType));
       
        fieldMetadatas.add(oneFieldMetadata);
      }
     
      /*
       * 2、验证表格数据
       */
      for (int rowIndex = 0; rowIndex < fieldMetadatas.size(); rowIndex++) {
        final FieldMetadata oneFieldMetadata = fieldMetadatas.get(rowIndex);
       
        //列名
        if(StringUtils.isBlank(oneFieldMetadata.getColumnName())) {
          throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.COLUMN_NAME_INDEX] + "不能为空!");
        }
        //属性名
        if(StringUtils.isBlank(oneFieldMetadata.getPropertyName())) {
          throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.PROPERTY_NAME_INDEX] + "不能为空!");
        }
        //列描述
        if(StringUtils.isBlank(oneFieldMetadata.getDisplayName())) {
          throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DISPLAY_NAME_INDEX] + "不能为空!");
        }
        //数据类型
        String columnType = oneFieldMetadata.getSqlDataType();
        if(StringUtils.isBlank(columnType)) {
          throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.SQL_DATA_TYPE_INDEX] + "不能为空!");
        }
        //数据类型长度、浮点长度
        if (SqlDataTypeComboBoxModel.DATE_TYPE.equalsIgnoreCase(columnType)) {
          /*
          if(null != oneFieldMetadata.getDataLength()) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行,DATE类型" + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_LENGTH_INDEX] + "必须为空!");
          }
          if(null != oneFieldMetadata.getDataScale()) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行,DATE类型" + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_PRECISION_INDEX] + "必须为空!");
          }
          */
        } else {
          if(null == oneFieldMetadata.getDataLength()) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DATA_LENGTH_INDEX] + "不能为空!");
          }
//          if(null == oneFieldMetadata.getFloatLength()) {
//            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行,浮点长度不能为空!");
//          }
        }
        if(oneFieldMetadata.isKeyField()) {
          if (StringUtils.isBlank(oneFieldMetadata.getConstraintType())) {
            throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.CONSTRAINT_TYPE_INDEX] + "不能为空!");
          }
          if(ConstraintTypeComboBoxModel.FK_TYPE.equalsIgnoreCase(oneFieldMetadata.getConstraintType())) {
            if (StringUtils.isBlank(oneFieldMetadata.getReferencingTable())) {
              throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.REFERENCING_TABLE_INDEX] + "不能为空!");
            }
            if (StringUtils.isBlank(oneFieldMetadata.getReferencingColumn())) {
              throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.REFERENCING_COLUMN_INDEX] + "不能为空!");
            }
            if (StringUtils.isBlank(oneFieldMetadata.getDeleteRule())) {
              throw new IllegalArgumentException("元数据第" + (rowIndex + 1) + "行," + MetadataTableModel.COLUMN_NAMES[MetadataTableModel.DELETE_RULE_INDEX] + "不能为空!");
            }
          }
        }
      }// end of for loop
View Full Code Here

          { "年龄", "AGE", "年龄", "NUMBER", new Integer(10), null, true, null, false, null },
          { "存款", "MONEY", "存款", "FLOAT", new Integer(10), new Integer(5), true, new Float(0.00000F), false, null },
          { "备注", "DESCRIPTION", "备注", "CLOB", new Integer(1000), null, true, null, false, null } };

      for (int i = 0; i < data.length; i++) {
        FieldMetadata oneFieldMetadata = new FieldMetadata();

        oneFieldMetadata.setDisplayName(String.valueOf(data[i][0]));
        String columnName = String.valueOf(data[i][1]);
        oneFieldMetadata.setColumnName(columnName);
        oneFieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(columnName));
        oneFieldMetadata.setComments(String.valueOf(data[i][2]));
        String dataType = String.valueOf(data[i][3]);
        int dataLength = null != data[i][4] ? (Integer) data[i][4] : 0;
        int dataPrecision = null != data[i][5] ? (Integer) data[i][5] : 0;
        int dataScale = 3;
        String sqlType = this.dataTypeConverter.convert(dataType, dataLength, dataPrecision, dataScale);
        oneFieldMetadata.setSqlDataType(sqlType);
        oneFieldMetadata.setDataLength(dataLength);
        oneFieldMetadata.setDataPrecision(dataPrecision);
        oneFieldMetadata.setDataScale(dataScale);
        String propertyType = this.getPropertyTypeConverter().convert(sqlType);
        oneFieldMetadata.setPropertyType(propertyType);
        oneFieldMetadata.setNullable((Boolean) data[i][6]);
        oneFieldMetadata.setDataDefault(null != data[i][7] ? "" + data[i][7] : null);
        oneFieldMetadata.setKeyField((Boolean) data[i][8]); // 是否为键
        oneFieldMetadata.setConstraintType(null != data[i][9] ? (String) data[i][9] : null); // 键类型

        fieldMetadatas.add(oneFieldMetadata);
      }
     
      return fieldMetadatas;
    }
   
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
      conn = JdbcContext.getJdbcContext(dataSourceName).currentConnection();
      stmt = conn.createStatement();
      //String sql = "SELECT A.*, B.* FROM (SELECT S.COMMENTS, T.COLUMN_ID, T.COLUMN_NAME, T.DATA_TYPE, T.DATA_LENGTH, T.DATA_PRECISION, T.DATA_SCALE, T.NULLABLE, T.DEFAULT_LENGTH, T.DATA_DEFAULT, T.CHAR_LENGTH FROM USER_COL_COMMENTS S, USER_TAB_COLUMNS T WHERE S.TABLE_NAME = T.TABLE_NAME AND S.COLUMN_NAME = T.COLUMN_NAME AND T.TABLE_NAME = '" + tableName + "') A, (SELECT U.COLUMN_NAME CONSTRAINT_COLUMN_NAME, U.POSITION, C.CONSTRAINT_NAME, C.CONSTRAINT_TYPE, C.TABLE_NAME, C.R_CONSTRAINT_NAME, C.DELETE_RULE, C.INDEX_NAME FROM USER_CONS_COLUMNS U, USER_CONSTRAINTS C WHERE U.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND U.OWNER = C.OWNER AND U.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE IN ('P', 'R') AND U.TABLE_NAME = '" + tableName + "') B WHERE A.COLUMN_NAME = B.CONSTRAINT_COLUMN_NAME(+) ORDER BY A.COLUMN_ID";
      String sql = "SELECT A.*, B.* FROM (SELECT S.COMMENTS, S.TABLE_NAME, T.COLUMN_ID, T.COLUMN_NAME, T.DATA_TYPE, T.DATA_LENGTH, T.DATA_PRECISION, T.DATA_SCALE, T.NULLABLE, T.DEFAULT_LENGTH, T.DATA_DEFAULT, T.CHAR_LENGTH FROM USER_COL_COMMENTS S, USER_TAB_COLUMNS T WHERE S.TABLE_NAME = T.TABLE_NAME AND S.COLUMN_NAME = T.COLUMN_NAME AND T.TABLE_NAME = '" + tableName + "') A, (SELECT U.COLUMN_NAME CONSTRAINT_COLUMN_NAME, U.POSITION, C.R_TABLE_NAME, C.R_COLUMN_NAME, C.CONSTRAINT_NAME, C.CONSTRAINT_TYPE, C.TABLE_NAME, C.R_CONSTRAINT_NAME, C.DELETE_RULE, C.INDEX_NAME FROM USER_CONS_COLUMNS U, (SELECT N.TABLE_NAME AS R_TABLE_NAME, N.CONSTRAINT_COLUMN_NAME AS R_COLUMN_NAME, M.* from (SELECT H.COLUMN_NAME AS CONSTRAINT_COLUMN_NAME, G.* from USER_CONSTRAINTS G, USER_CONS_COLUMNS H WHERE G.OWNER=H.OWNER AND G.TABLE_NAME=H.TABLE_NAME AND G.CONSTRAINT_NAME=H.CONSTRAINT_NAME AND G.CONSTRAINT_TYPE IN('P', 'R')) M, (SELECT H.COLUMN_NAME AS CONSTRAINT_COLUMN_NAME, G.* from USER_CONSTRAINTS G, USER_CONS_COLUMNS H WHERE G.OWNER=H.OWNER AND G.TABLE_NAME=H.TABLE_NAME AND G.CONSTRAINT_NAME=H.CONSTRAINT_NAME AND G.CONSTRAINT_TYPE IN('P', 'R')) N where M.R_CONSTRAINT_NAME=N.CONSTRAINT_NAME(+) AND M.TABLE_NAME='" + tableName + "' AND M.CONSTRAINT_TYPE IN('P', 'R')) C WHERE U.OWNER = C.OWNER AND U.TABLE_NAME = C.TABLE_NAME AND U.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND U.COLUMN_NAME = C.CONSTRAINT_COLUMN_NAME AND C.CONSTRAINT_TYPE IN ('P', 'R') AND U.TABLE_NAME = '" + tableName + "') B WHERE A.TABLE_NAME = B.TABLE_NAME(+) AND A.COLUMN_NAME = B.CONSTRAINT_COLUMN_NAME(+) ORDER BY A.COLUMN_ID";
//      System.out.println(sql);
      rs = stmt.executeQuery(sql);
     
      FieldMetadata oneFieldMetadata = null;
      while(rs.next()) {
        oneFieldMetadata = new FieldMetadata();
       
        oneFieldMetadata.setColumnName(rs.getString("COLUMN_NAME"));
        oneFieldMetadata.setComments(rs.getString("COMMENTS"));
        oneFieldMetadata.setDisplayName(rs.getString("COMMENTS"));
        String dataType = rs.getString("DATA_TYPE");
        int dataLength = rs.getInt("DATA_LENGTH");
        int dataPrecision = rs.getInt("DATA_PRECISION");
        int dataScale = rs.getInt("DATA_SCALE");
        String sqlType = this.dataTypeConverter.convert(dataType, dataLength, dataPrecision, dataScale);
        oneFieldMetadata.setSqlDataType(sqlType);
        oneFieldMetadata.setDataLength(dataLength);
        oneFieldMetadata.setDataPrecision(dataPrecision);
        oneFieldMetadata.setDataScale(dataScale);
        String nullableFlag = rs.getString("NULLABLE");
        if("Y".equals(nullableFlag)) {
          oneFieldMetadata.setNullable(true);
        } else {
          oneFieldMetadata.setNullable(false);
        }
        oneFieldMetadata.setDefaultLength(rs.getInt("DEFAULT_LENGTH"));
        oneFieldMetadata.setDataDefault(rs.getString("DATA_DEFAULT"));
        oneFieldMetadata.setCharLength(rs.getInt("CHAR_LENGTH"));
       
        oneFieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(rs.getString("COLUMN_NAME")));
        String propertyType = this.getPropertyTypeConverter().convert(sqlType);
        oneFieldMetadata.setPropertyType(propertyType);
       
        String constraintType = rs.getString("CONSTRAINT_TYPE")// 约束类型
        if(StringUtils.isNotBlank(constraintType)) {
          oneFieldMetadata.setKeyField(true); // 是否为键
        } else {
          oneFieldMetadata.setKeyField(false); // 是否为键
        }
        if("P".equals(constraintType)) {
          oneFieldMetadata.setConstraintType(ConstraintTypes.PK_TYPE);
        } else if("R".equals(constraintType)) {
          oneFieldMetadata.setConstraintType(ConstraintTypes.FK_TYPE);
          oneFieldMetadata.setReferencingTable(rs.getString("R_TABLE_NAME"));
          oneFieldMetadata.setReferencingColumn(rs.getString("R_COLUMN_NAME"));
          oneFieldMetadata.setDeleteRule(rs.getString("DELETE_RULE"));
        } else if("C".equals(constraintType)) {
          oneFieldMetadata.setConstraintType(ConstraintTypes.CHECK_TYPE);
        }
        fieldMetadatas.add(oneFieldMetadata);
      }
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
View Full Code Here

      conn = JdbcContext.getJdbcContext(dataSourceName).currentConnection();
      stmt = conn.createStatement();
      String sql = "SELECT T.COLUMN_ID, T.COLUMN_NAME, S.COMMENTS, T.DATA_TYPE, DATA_LENGTH, T.DATA_PRECISION, T.DATA_SCALE, T.NULLABLE, T.DEFAULT_LENGTH, T.DATA_DEFAULT, T.CHAR_LENGTH FROM USER_COL_COMMENTS S, USER_TAB_COLUMNS T WHERE S.COLUMN_NAME=T.COLUMN_NAME AND T.TABLE_NAME='" + tableName + "' ORDER BY T.COLUMN_ID";
      rs = stmt.executeQuery(sql);
     
      FieldMetadata fieldMetadata = null;
      while(rs.next()) {
        fieldMetadata = new FieldMetadata();
       
        fieldMetadata.setColumnName(rs.getString("COLUMN_NAME"));
        fieldMetadata.setComments(rs.getString("COMMENTS"));
        System.out.println(rs.getString("COMMENTS"));
        fieldMetadata.setDisplayName(rs.getString("COMMENTS"));
        String dataType = rs.getString("DATA_TYPE");
        int dataLength = rs.getInt("DATA_LENGTH");
        int dataPrecision = rs.getInt("DATA_PRECISION");
        int dataScale = rs.getInt("DATA_SCALE");
        fieldMetadata.setSqlDataType(dataType);
        fieldMetadata.setDataLength(dataLength);
        fieldMetadata.setDataPrecision(dataPrecision);
        fieldMetadata.setDataScale(dataScale);
        String nullableFlag = rs.getString("NULLABLE");
        if("Y".equals(nullableFlag)) {
          fieldMetadata.setNullable(true);
        } else {
          fieldMetadata.setNullable(false);
        }
        fieldMetadata.setDefaultLength(rs.getInt("DEFAULT_LENGTH"));
        fieldMetadata.setDataDefault(rs.getString("DATA_DEFAULT"));
        fieldMetadata.setCharLength(rs.getInt("CHAR_LENGTH"));
       
        fieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(rs.getString("COLUMN_NAME")));
        fieldMetadata.setKeyField(false); // 是否为键
        fieldMetadata.setConstraintType(""); // 键类型
       
        tableList.add(fieldMetadata);
      }
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
View Full Code Here

      conn = JdbcContext.getJdbcContext(dataSourceName).currentConnection();
      stmt = conn.createStatement();
      String sql = "SELECT T.COLUMN_ID, T.COLUMN_NAME, S.COMMENTS, T.DATA_TYPE, DATA_LENGTH, T.DATA_PRECISION, T.DATA_SCALE, T.NULLABLE, T.DEFAULT_LENGTH, T.DATA_DEFAULT, T.CHAR_LENGTH FROM USER_COL_COMMENTS S, USER_TAB_COLUMNS T WHERE S.COLUMN_NAME=T.COLUMN_NAME AND T.TABLE_NAME='" + tableName + "' ORDER BY T.COLUMN_ID";
      rs = stmt.executeQuery(sql);
     
      FieldMetadata fieldMetadata = null;
      while(rs.next()) {
        fieldMetadata = new FieldMetadata();
       
        fieldMetadata.setColumnName(rs.getString("COLUMN_NAME"));
        fieldMetadata.setComments(rs.getString("COMMENTS"));
        System.out.println(rs.getString("COMMENTS"));
        fieldMetadata.setDisplayName(rs.getString("COMMENTS"));
        String dataType = rs.getString("DATA_TYPE");
        int dataLength = rs.getInt("DATA_LENGTH");
        int dataPrecision = rs.getInt("DATA_PRECISION");
        int dataScale = rs.getInt("DATA_SCALE");
        fieldMetadata.setSqlDataType(dataType);
        fieldMetadata.setDataLength(dataLength);
        fieldMetadata.setDataPrecision(dataPrecision);
        fieldMetadata.setDataScale(dataScale);
        String nullableFlag = rs.getString("NULLABLE");
        if("Y".equals(nullableFlag)) {
          fieldMetadata.setNullable(true);
        } else {
          fieldMetadata.setNullable(false);
        }
        fieldMetadata.setDefaultLength(rs.getInt("DEFAULT_LENGTH"));
        fieldMetadata.setDataDefault(rs.getString("DATA_DEFAULT"));
        fieldMetadata.setCharLength(rs.getInt("CHAR_LENGTH"));
       
        fieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(rs.getString("COLUMN_NAME")));
        fieldMetadata.setKeyField(false); // 是否为键
        fieldMetadata.setConstraintType(""); // 键类型
       
        tableList.add(fieldMetadata);
      }
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
View Full Code Here

    List<FieldMetadata> fieldMetadatas = null;
    if (StringUtils.isBlank(dataSourceName) || StringUtils.isBlank(tableName)) {//初始界面数据
      tableComments = "";
      fieldMetadatas = new ArrayList<FieldMetadata>();
      for (int i = 0; i < INIT_ROWS_COUNT; i++) {
        FieldMetadata oneMetadata = new FieldMetadata();
        oneMetadata.setNullable(true);
        oneMetadata.setKeyField(false);
        fieldMetadatas.add(oneMetadata);
      }
    } else {
      String dbType = this.dataSourceConfigDao.getDbType(dataSourceName);
      if(StringUtils.isBlank(dbType)) {
View Full Code Here

      stmt = conn.createStatement();
      String sql = "SELECT T.ORDINAL_POSITION, T.COLUMN_NAME, T.COLUMN_COMMENT, T.COLUMN_DEFAULT, T.COLUMN_KEY, T.IS_NULLABLE, T.DATA_TYPE, T.CHARACTER_MAXIMUM_LENGTH, T.CHARACTER_OCTET_LENGTH, T.NUMERIC_PRECISION, T.NUMERIC_SCALE, T.COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS T WHERE T.TABLE_CATALOG='DEF' AND T.TABLE_SCHEMA='" + tableSchema + "' AND T.TABLE_NAME='" + tableName + "' ORDER BY T.ORDINAL_POSITION";
//      System.out.println(sql);
      rs = stmt.executeQuery(sql);
     
      FieldMetadata fieldMetadata = null;
      while(rs.next()) {
        fieldMetadata = new FieldMetadata();
       
        fieldMetadata.setColumnName(rs.getString("COLUMN_NAME"));
        fieldMetadata.setComments(rs.getString("COLUMN_COMMENT"));
        fieldMetadata.setDisplayName(rs.getString("COLUMN_COMMENT"));
        String dataType = rs.getString("DATA_TYPE");
        int dataLength = 0;
        int dataPrecision = 0;
        int dataScale = 0;
        if(MySqlDataTypes.INT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.SMALLINT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.MEDIUMINT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.INT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.BIGINT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.FLOAT_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.DOUBLE_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.NUMERIC_TYPE.equalsIgnoreCase(dataType)
             || MySqlDataTypes.DECIMAL_TYPE.equalsIgnoreCase(dataType)) {
          dataLength = 255//最大长度
          dataPrecision = rs.getInt("NUMERIC_PRECISION")//实际长度
          dataScale = rs.getInt("NUMERIC_SCALE");
        } else if(MySqlDataTypes.CHAR_TYPE.equalsIgnoreCase(dataType) || MySqlDataTypes.VARCHAR_TYPE.equalsIgnoreCase(dataType)) {
          dataLength = rs.getInt("CHARACTER_OCTET_LENGTH")//最大长度
          dataPrecision = rs.getInt("CHARACTER_MAXIMUM_LENGTH")//实际长度
        }
       
        String sqlType = this.dataTypeConverter.convert(dataType, dataLength, dataPrecision, dataScale);
        fieldMetadata.setSqlDataType(sqlType);
        fieldMetadata.setDataLength(dataLength);
        fieldMetadata.setDataPrecision(dataPrecision);
        fieldMetadata.setDataScale(dataScale);
        String nullableFlag = rs.getString("IS_NULLABLE");
        if("YES".equals(nullableFlag)) {
          fieldMetadata.setNullable(true);
        } else {
          fieldMetadata.setNullable(false);
        }
        fieldMetadata.setDefaultLength(rs.getInt("CHARACTER_OCTET_LENGTH"));
        fieldMetadata.setDataDefault(rs.getString("COLUMN_DEFAULT"));
        fieldMetadata.setCharLength(rs.getInt("CHARACTER_MAXIMUM_LENGTH"));
       
        fieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(rs.getString("COLUMN_NAME")));
        String propertyType = this.getPropertyTypeConverter().convert(sqlType);
        fieldMetadata.setPropertyType(propertyType);
       
        String constraintType = rs.getString("COLUMN_KEY")// 约束类型
        if(StringUtils.isNotBlank(constraintType)) {
          fieldMetadata.setKeyField(true); // 是否为键
        } else {
          fieldMetadata.setKeyField(false); // 是否为键
        }
        if("PRI".equals(constraintType)) {
          fieldMetadata.setConstraintType(ConstraintTypes.PK_TYPE);
        } else if("REF".equals(constraintType)) {
          fieldMetadata.setConstraintType(ConstraintTypes.FK_TYPE);
          fieldMetadata.setReferencingTable(rs.getString("R_TABLE_NAME"));
          fieldMetadata.setReferencingColumn(rs.getString("R_COLUMN_NAME"));
          fieldMetadata.setDeleteRule(rs.getString("DELETE_RULE"));
        } else if("CHK".equals(constraintType)) {
          fieldMetadata.setConstraintType(ConstraintTypes.CHECK_TYPE);
        }
       
        tableList.add(fieldMetadata);
      }
    } catch (Exception e) {
View Full Code Here

      conn = JdbcContext.getJdbcContext(dataSourceName).currentConnection();
      stmt = conn.createStatement();
      String sql = "SELECT T.COLUMN_ID, T.COLUMN_NAME, S.COMMENTS, T.DATA_TYPE, DATA_LENGTH, T.DATA_PRECISION, T.DATA_SCALE, T.NULLABLE, T.DEFAULT_LENGTH, T.DATA_DEFAULT, T.CHAR_LENGTH FROM USER_COL_COMMENTS S, USER_TAB_COLUMNS T WHERE S.COLUMN_NAME=T.COLUMN_NAME AND T.TABLE_NAME='" + tableName + "' ORDER BY T.COLUMN_ID";
      rs = stmt.executeQuery(sql);
     
      FieldMetadata oneFieldMetadata = null;
      while(rs.next()) {
        oneFieldMetadata = new FieldMetadata();
       
        oneFieldMetadata.setColumnName(rs.getString("COLUMN_NAME"));
        oneFieldMetadata.setComments(rs.getString("COMMENTS"));
        oneFieldMetadata.setDisplayName(rs.getString("COMMENTS"));
        String dataType = rs.getString("DATA_TYPE");
        int dataLength = rs.getInt("DATA_LENGTH");
        int dataPrecision = rs.getInt("DATA_PRECISION");
        int dataScale = rs.getInt("DATA_SCALE");
        String sqlType = dataTypeConverter.convert(dataType, dataLength, dataPrecision, dataScale);
        oneFieldMetadata.setSqlDataType(sqlType);
        oneFieldMetadata.setDataLength(dataLength);
        oneFieldMetadata.setDataPrecision(dataPrecision);
        oneFieldMetadata.setDataScale(dataScale);
        String nullableFlag = rs.getString("NULLABLE");
        if("Y".equals(nullableFlag)) {
          oneFieldMetadata.setNullable(true);
        } else {
          oneFieldMetadata.setNullable(false);
        }
        oneFieldMetadata.setDefaultLength(rs.getInt("DEFAULT_LENGTH"));
        oneFieldMetadata.setDataDefault(rs.getString("DATA_DEFAULT"));
        oneFieldMetadata.setCharLength(rs.getInt("CHAR_LENGTH"));
       
        oneFieldMetadata.setPropertyName(NotationUtils.lowerCamelCase(rs.getString("COLUMN_NAME")));
        String propertyType = propertyTypeConverter.convert(sqlType);
        oneFieldMetadata.setPropertyType(propertyType);
        oneFieldMetadata.setKeyField(false); // 是否为键
        oneFieldMetadata.setConstraintType(""); // 键类型
       
        tableList.add(oneFieldMetadata);
      }
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
View Full Code Here

TOP

Related Classes of xgenerator.model.FieldMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.