001: package org.dbbrowser.db.engine.model;
002:
003: import java.util.ArrayList;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: /**
008: * Represents the data in the table
009: * @author amangat
010: */
011: public class DBTable {
012: private List listOfRows = null;
013: private List listOfcolumnInfos = null;
014: private String schemaName = null;
015: private String tableName = null;
016: private Integer offset = null;
017: private Integer numberOfRowsToReturn = null;
018: private Integer numberOfRowsInTable = null;
019:
020: /**
021: * Constructer
022: * @param schemaName
023: * @param tableName
024: * @param listOfRows
025: * @param offset
026: * @param numberOfRowsToReturn
027: * @param numberOfRowsInTable
028: */
029: public DBTable(String schemaName, String tableName,
030: List listOfRows, Integer offset,
031: Integer numberOfRowsToReturn, Integer numberOfRowsInTable) {
032: this .schemaName = schemaName;
033: this .tableName = tableName;
034: this .listOfRows = listOfRows;
035: this .offset = offset;
036: this .numberOfRowsToReturn = numberOfRowsToReturn;
037: this .numberOfRowsInTable = numberOfRowsInTable;
038: }
039:
040: /**
041: * Constructer
042: * @param schemaName
043: * @param tableName
044: * @param listOfRows
045: * @param offset
046: * @param numberOfRowsToReturn
047: * @param listOfcolumnInfos
048: * @param numberOfRowsInTable
049: */
050: public DBTable(String schemaName, String tableName,
051: List listOfRows, Integer offset,
052: Integer numberOfRowsToReturn, List listOfcolumnInfos) {
053: this .schemaName = schemaName;
054: this .tableName = tableName;
055: this .listOfRows = listOfRows;
056: this .listOfcolumnInfos = listOfcolumnInfos;
057: this .offset = offset;
058: this .numberOfRowsToReturn = numberOfRowsToReturn;
059: this .numberOfRowsInTable = new Integer(0);
060: }
061:
062: /**
063: * Returns the name of the schema
064: * @return
065: */
066: public String getSchemaName() {
067: return this .schemaName;
068: }
069:
070: /**
071: * Returns the name of the table
072: * @return
073: */
074: public String getTableName() {
075: return this .tableName;
076: }
077:
078: /**
079: * Returns the offset for the data
080: * @return
081: */
082: public Integer getOffset() {
083: return this .offset;
084: }
085:
086: /**
087: * Returns the number of rows to return
088: * @return
089: */
090: public Integer getNumberOfRowsToReturn() {
091: return this .numberOfRowsToReturn;
092: }
093:
094: /**
095: * Returns the list of column info objects. Each column info describes a column in the db table
096: * @return - a list of columnInfo objects
097: */
098: public List getListOfColumnInfos() {
099: //If there are no db rows and local list of column infos was set, then use the local list
100: if (this .listOfcolumnInfos != null) {
101: return this .listOfcolumnInfos;
102: }
103:
104: Iterator i = this .listOfRows.iterator();
105: List listOfColumnInfos = new ArrayList();
106:
107: //Only process the first row
108: if (i.hasNext()) {
109: DBRow dbRow = (DBRow) i.next();
110: List listOfTableCells = dbRow.getListOFDBTableCells();
111: Iterator j = listOfTableCells.iterator();
112: while (j.hasNext()) {
113: DBTableCell dbTableCell = (DBTableCell) j.next();
114: ColumnInfo ci = dbTableCell.getColumnInfo();
115: listOfColumnInfos.add(ci);
116: }
117: }
118: return listOfColumnInfos;
119: }
120:
121: /**
122: * Get the number of rows in the table
123: * @return
124: */
125: public Integer getNumberOfRowsInTable() {
126: return numberOfRowsInTable;
127: }
128:
129: /**
130: * Returns the list of rows in the db table
131: * @return - a list of DBRow objects
132: */
133: public List getListOfRows() {
134: return this.listOfRows;
135: }
136: }
|