2 Replies Latest reply: Oct 25, 2010 2:14 PM by aksarben RSS

    Instantiating a List of objects containing list fields

    843793
      I have two data objects TableBean and Column.The TableBean has a list of Column objects. I want to instantiate a TableBean on the fly. I am attaching the three classes TableBean, Column and main class. I am having difficulty instantiatng

      Instanting Class
      public class MetadataSessionBean implements MetadataSession,
      MetadataSessionLocal {
      @Resource(name="jdbc/DWDS")
      private DataSource dataSource; 
      private Connection connection; 
      private List<TableBean> tables = new ArrayList<TableBean>();
      private List<Column> columns = new ArrayList<Column>();
      private DatabaseMetaData dmd;
      public MetadataSessionBean() {
      }
      
      public List<TableBean> getTables(){
      try{ connection = dataSource.getConnection();
      DatabaseMetaData dmd;
      dmd = connection.getMetaData(); 
      if (dmd ==null){
      //Not available
      }else{
      ResultSet rs = dmd.getSchemas();
      ResultSet rs1 = null;
      ResultSet rsColumns = null;
      while(rs.next()) {
      if (rs.getString(1).equalsIgnoreCase("AV_DATA")){
      rs1 = dmd.getTables(null,rs.getString(1),"%",null);
      while(rs1.next()) {
      //PROBLEM instantiating Table Bean and add the column list to the new created TableBean
      tables.add(new TableBean(rs1.getString(3)));
      rsColumns = dmd.getColumns("", rs.getString(1), rs1.getString(3), null);
      while(rsColumns.next()){
      //How do I add the below columns to the Table created using new operator
      columns.add(new Column(rsColumns.getString(4))); 
      
      }
      }
      }
      }
      }
      }catch (SQLException sqle){
      sqle.printStackTrace();
      
      }
      return tables;
      }
      
      
      }
      TableBean Class
      package domain;
      
      import java.io.Serializable;
      
      import java.util.List;
      
      public class TableBean implements Serializable{
      private String name;
      private List<Column> columns;
      
      
      public TableBean(String name){
      this.name=name;
      } 
      
      
      public void setName(String name) {
      this.name = name;
      }
      
      public String getName() {
      return name;
      }
      
      
      public void setColumns(List<Column> columns) {
      this.columns = columns;
      }
      
      public List<Column> getColumns() {
      return columns;
      }
      }
      Column Class
      package domain;
      
      import java.io.Serializable;
      
      public class Column implements Serializable{
      private String name;
      private String description;
      
      public Column(String name){
      this.name = name; 
      }
      
      public void setName(String name) {
      this.name = name;
      }
      
      public String getName() {
      return name;
      }
      
      public void setDescription(String description) {
      this.description = description;
      }
      
      public String getDescription() {
      return description;
      }
      }
      Edited by: jthomas1 on Aug 30, 2010 6:08 PM