public boolean isImmutable() {
    Properties properties;

    if (tableConfiguration.getProperties().containsKey(PropertyRegistry.ANY_IMMUTABLE)) {
      properties = tableConfiguration.getProperties();
    } else {
      properties = context.getJavaModelGeneratorConfiguration().getProperties();
    }

    return isTrue(properties.getProperty(PropertyRegistry.ANY_IMMUTABLE));
  }
  public boolean isConstructorBased() {
    if (isImmutable()) {
      return true;
    }

    Properties properties;

    if (tableConfiguration.getProperties().containsKey(PropertyRegistry.ANY_CONSTRUCTOR_BASED)) {
      properties = tableConfiguration.getProperties();
    } else {
      properties = context.getJavaModelGeneratorConfiguration().getProperties();
    }

    return isTrue(properties.getProperty(PropertyRegistry.ANY_CONSTRUCTOR_BASED));
  }
  public void initialize() {
    calculateJavaClientAttributes();
    calculateModelAttributes();
    calculateExtjsAttributes();
    calculateXmlAttributes();

    if (tableConfiguration.getModelType() == ModelType.HIERARCHICAL) {
      rules = new HierarchicalModelRules(this);
    } else if (tableConfiguration.getModelType() == ModelType.FLAT) {
      rules = new FlatModelRules(this);
    } else {
      rules = new ConditionalModelRules(this);
    }

    context.getPlugins().initialized(this);
  }
 public String getTableConfigurationProperty(String property) {
   return tableConfiguration.getProperty(property);
 }
 public GeneratedKey getGeneratedKey() {
   return tableConfiguration.getGeneratedKey();
 }
 public String getSelectByPrimaryKeyQueryId() {
   return tableConfiguration.getSelectByPrimaryKeyQueryId();
 }
 public String getSelectByExampleQueryId() {
   return tableConfiguration.getSelectByExampleQueryId();
 }
Example #8
0
  public List<Table> queryFields(DBConfig config) {
    List<Table> tableInfoList = new ArrayList<Table>();
    Connection conn = null;
    try {
      List<TableConfiguration> tableList = (List<TableConfiguration>) config.getTableList();
      if (tableList == null || tableList.size() <= 0) return tableInfoList;

      conn = ConnectionFactory.getInstance().getConnection(config);
      DatabaseMetaData databaseMetaData = conn.getMetaData();
      for (TableConfiguration table : tableList) {
        Table tableInfo = new Table();

        String localCatalog = table.getCatalog();
        String localSchema = table.getSchema();
        String localTableName = table.getTableName();
        if (databaseMetaData.storesLowerCaseIdentifiers()) {
          localCatalog = localCatalog == null ? null : localCatalog.toLowerCase();
          localSchema = localSchema == null ? null : localSchema.toLowerCase();
          localTableName = localTableName == null ? null : localTableName.toLowerCase();
        } else if (databaseMetaData.storesUpperCaseIdentifiers()) {
          localCatalog = localCatalog == null ? null : localCatalog.toUpperCase();
          localSchema = localSchema == null ? null : localSchema.toUpperCase();
          localTableName = localTableName == null ? null : localTableName.toUpperCase();
        }

        Statement stmt = conn.createStatement();
        ResultSet tableRs = stmt.executeQuery("SHOW CREATE TABLE " + localTableName);
        if (tableRs != null && tableRs.next()) {
          String create = tableRs.getString(2);
          String comment = parse(create);
          tableInfo.setComment(comment);
        }

        ResultSet rs = databaseMetaData.getColumns(localCatalog, localSchema, localTableName, null);
        tableInfo.setSerialVersionUID(System.nanoTime() + "L");
        while (rs.next()) {
          tableInfo.setCatalog(rs.getString("TABLE_CAT"));
          tableInfo.setSchema(rs.getString("TABLE_SCHEM"));
          tableInfo.setName(rs.getString("TABLE_NAME"));
          tableInfo.setCode(rs.getString("TABLE_NAME"));

          Column introspectedColumn = new Column();
          introspectedColumn.setTableAlias(table.getTableName());
          introspectedColumn.setName(rs.getString("COLUMN_NAME"));
          introspectedColumn.setJdbcType(rs.getInt("DATA_TYPE"));
          introspectedColumn.setDataType(
              JdbcTypeNameTranslator.getJdbcTypeName(rs.getInt("DATA_TYPE"))); // $NON-NLS-1$
          introspectedColumn.setLength(rs.getInt("COLUMN_SIZE")); // $NON-NLS-1$
          introspectedColumn.setCode(rs.getString("COLUMN_NAME"));
          /*introspectedColumn.setActualColumnName(rs
          .getString("COLUMN_NAME"));*/
          //$NON-NLS-1$
          introspectedColumn.setNullable(
              rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable); // $NON-NLS-1$
          introspectedColumn.setScale(rs.getInt("DECIMAL_DIGITS")); // $NON-NLS-1$
          introspectedColumn.setComment(rs.getString("REMARKS"));

          tableInfo.addColumn(introspectedColumn);

          PropertyBean pb = new PropertyBean();

          pb.setName(convertFirstUpper(getFieldName(rs.getString("COLUMN_NAME"))));
          pb.setType(JdbcType2Java.calculateJavaType(introspectedColumn));
          String importType = JdbcType2Java.importJavaType(introspectedColumn);
          if (importType != null && !importType.equals("")) {
            if (importType.indexOf("java.lang") < 0
                && !tableInfo.getImportList().contains(importType))
              tableInfo.getImportList().add(importType);
          }
          tableInfo.getPropertyBeanList().add(pb);
        }
        closeResultSet(rs);

        rs = databaseMetaData.getPrimaryKeys(localCatalog, localSchema, localTableName);
        while (rs.next()) {
          tableInfo.addPrimaryKeyColumn(rs.getString("COLUMN_NAME"));
        }
        closeResultSet(rs);
        tableInfoList.add(tableInfo);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return tableInfoList;
  }