latest quantum sources 2.3.2
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / subset / EntitySubset.java
1 package com.quantum.view.subset;
2
3 import java.sql.SQLException;
4
5 import com.quantum.model.Bookmark;
6 import com.quantum.model.BookmarkCollection;
7 import com.quantum.model.Column;
8 import com.quantum.model.Entity;
9 import com.quantum.model.ForeignKey;
10 import com.quantum.model.Index;
11 import com.quantum.model.NotConnectedException;
12 import com.quantum.model.Schema;
13
14 /**
15  * @author BC
16  */
17 public class EntitySubset implements Entity {
18     
19     private String name;
20     private String schema;
21     private String bookmarkName;
22     
23     public EntitySubset(String name, String schema, String bookmarkName) {
24         this.name = name;
25         this.schema = schema;
26         this.bookmarkName = bookmarkName;
27     }
28
29     public String getName() {
30         return this.name;
31     }
32
33     public String getSchema() {
34         return schema;
35     }
36
37     public String getType() {
38         return null;
39     }
40
41     public Column[] getColumns() {
42         // TODO: limit the columns
43         Entity relatedEntity = getEntityFromBookmark();
44         if (relatedEntity != null) {
45                 try {
46                     Column[] columns = relatedEntity.getColumns();
47                     return columns;
48                 } catch (NotConnectedException e) {
49                         return new Column[0];
50                 } catch (SQLException e) {
51                         return new Column[0];
52                 }
53         } else {
54             return null;
55         }
56     }
57
58     public Index[] getIndexes() {
59         return new Index[0];
60     }
61
62     public Column getColumn(String columnName) throws NotConnectedException, SQLException {
63         Entity relatedEntity = getEntityFromBookmark();
64         return relatedEntity == null 
65             ? null : relatedEntity.getColumn(columnName);
66     }
67
68     public String getQualifiedName() {
69         return this.schema + "." + this.name;
70     }
71
72     public Boolean exists() {
73         return null;
74     }
75
76     public Bookmark getBookmark() {
77         return BookmarkCollection.getInstance().find(this.bookmarkName);
78     }
79     
80     private Entity getEntityFromBookmark() {
81         try {
82             return getBookmark().getEntity(
83                 new Schema(schema), name);
84         } catch (SQLException e) {
85             return null;
86         }
87     }
88     /**
89      * @see com.quantum.model.Entity#getQuotedTableName()
90      */
91     public String getQuotedTableName() {
92         return getBookmark().getAdapter().filterTableName(getQualifiedName());
93     }
94
95         /* (non-Javadoc)
96          * @see java.lang.Comparable#compareTo(java.lang.Object)
97          */
98         public int compareTo(Object arg0) {
99                 // TODO Auto-generated method stub
100                 return 0;
101         }
102
103         /* (non-Javadoc)
104          * @see com.quantum.model.Entity#getExportedKeys()
105          */
106         public ForeignKey[] getExportedKeys() throws NotConnectedException, SQLException {
107                 // TODO Auto-generated method stub
108                 return null;
109         }
110
111         /* (non-Javadoc)
112          * @see com.quantum.model.Entity#getImportedKeys()
113          */
114         public ForeignKey[] getImportedKeys() throws NotConnectedException, SQLException {
115                 // TODO Auto-generated method stub
116                 return null;
117         }
118
119         /* (non-Javadoc)
120          * @see com.quantum.model.Entity#getReferences()
121          */
122         public ForeignKey[] getReferences() throws NotConnectedException, SQLException {
123                 // TODO Auto-generated method stub
124                 return null;
125         }
126 }