0b70c9d464227e47a5188717d60675e91970b8ea
[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.Index;
10 import com.quantum.model.Schema;
11
12 /**
13  * @author BC
14  */
15 public class EntitySubset implements Entity {
16     
17     private String name;
18     private String schema;
19     private String bookmarkName;
20     
21     public EntitySubset(String name, String schema, String bookmarkName) {
22         this.name = name;
23         this.schema = schema;
24         this.bookmarkName = bookmarkName;
25     }
26
27     public String getName() {
28         return this.name;
29     }
30
31     public String getSchema() {
32         return schema;
33     }
34
35     public String getType() {
36         return null;
37     }
38
39     public Column[] getColumns() {
40         // TODO: limit the columns
41         Entity relatedEntity = getEntityFromBookmark();
42         if (relatedEntity != null) {
43             Column[] columns = relatedEntity.getColumns();
44             return columns;
45         } else {
46             return null;
47         }
48     }
49
50     public Index[] getIndexes() {
51         return new Index[0];
52     }
53
54     public Column getColumn(String columnName) {
55         Entity relatedEntity = getEntityFromBookmark();
56         return relatedEntity == null 
57             ? null : relatedEntity.getColumn(columnName);
58     }
59
60     public String getCondQualifiedName() {
61         return this.schema + "." + this.name;
62     }
63
64     public Boolean exists() {
65         return null;
66     }
67
68     public Bookmark getBookmark() {
69         return BookmarkCollection.getInstance().find(this.bookmarkName);
70     }
71     
72     private Entity getEntityFromBookmark() {
73         try {
74             return getBookmark().getEntity(
75                 new Schema(schema), name);
76         } catch (SQLException e) {
77             return null;
78         }
79     }
80     /**
81      * @see com.quantum.model.Entity#getQuotedTableName()
82      */
83     public String getQuotedTableName() {
84         return getBookmark().getAdapter().filterTableName(getCondQualifiedName());
85     }
86 }