Ejemplo n.º 1
0
  private Table _getTable(String catalog, String schema, String tableName) throws SQLException {
    if (tableName == null || tableName.trim().length() == 0)
      throw new IllegalArgumentException("tableName must be not empty");
    catalog = StringHelper.defaultIfEmpty(catalog, null);
    schema = StringHelper.defaultIfEmpty(schema, null);

    Connection conn = getConnection();
    DatabaseMetaData dbMetaData = conn.getMetaData();
    ResultSet rs = dbMetaData.getTables(catalog, schema, tableName, null);
    while (rs.next()) {
      Table table = createTable(conn, rs);
      return table;
    }
    return null;
  }
Ejemplo n.º 2
0
  private Table createTable(Connection conn, ResultSet rs) throws SQLException {
    String realTableName = null;
    try {
      ResultSetMetaData rsMetaData = rs.getMetaData();
      String schemaName = rs.getString("TABLE_SCHEM") == null ? "" : rs.getString("TABLE_SCHEM");
      realTableName = rs.getString("TABLE_NAME");
      String tableType = rs.getString("TABLE_TYPE");
      String remarks = rs.getString("REMARKS");
      if (remarks == null && dbHelper.isOracleDataBase()) {
        remarks = getOracleTableComments(realTableName);
      }

      Table table = new Table();
      table.setSqlName(realTableName);
      table.setRemarks(remarks);

      if ("SYNONYM".equals(tableType) && dbHelper.isOracleDataBase()) {
        table.setOwnerSynonymName(getSynonymOwner(realTableName));
      }

      retriveTableColumns(table);

      table.initExportedKeys(conn.getMetaData());
      table.initImportedKeys(conn.getMetaData());
      BeanHelper.copyProperties(
          table, TableOverrideValuesProvider.getTableOverrideValues(table.getSqlName()));
      return table;
    } catch (SQLException e) {
      throw new RuntimeException("create table object error,tableName:" + realTableName, e);
    }
  }
Ejemplo n.º 3
0
 private List getAllTables(Connection conn) throws SQLException {
   DatabaseMetaData dbMetaData = conn.getMetaData();
   ResultSet rs = dbMetaData.getTables(getCatalog(), getSchema(), null, null);
   List tables = new ArrayList();
   while (rs.next()) {
     tables.add(createTable(conn, rs));
   }
   return tables;
 }
Ejemplo n.º 4
0
 public Connection getConnection() {
   try {
     if (connection == null || connection.isClosed()) {
       loadJdbcDriver();
       connection =
           DriverManager.getConnection(
               GeneratorProperties.getRequiredProperty("jdbc.url"),
               GeneratorProperties.getRequiredProperty("jdbc.username"),
               GeneratorProperties.getProperty("jdbc.password"));
     }
     return connection;
   } catch (SQLException e) {
     throw new RuntimeException(e);
   }
 }