X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java new file mode 100644 index 0000000..0b70c9d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/subset/EntitySubset.java @@ -0,0 +1,86 @@ +package com.quantum.view.subset; + +import java.sql.SQLException; + +import com.quantum.model.Bookmark; +import com.quantum.model.BookmarkCollection; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.model.Index; +import com.quantum.model.Schema; + +/** + * @author BC + */ +public class EntitySubset implements Entity { + + private String name; + private String schema; + private String bookmarkName; + + public EntitySubset(String name, String schema, String bookmarkName) { + this.name = name; + this.schema = schema; + this.bookmarkName = bookmarkName; + } + + public String getName() { + return this.name; + } + + public String getSchema() { + return schema; + } + + public String getType() { + return null; + } + + public Column[] getColumns() { + // TODO: limit the columns + Entity relatedEntity = getEntityFromBookmark(); + if (relatedEntity != null) { + Column[] columns = relatedEntity.getColumns(); + return columns; + } else { + return null; + } + } + + public Index[] getIndexes() { + return new Index[0]; + } + + public Column getColumn(String columnName) { + Entity relatedEntity = getEntityFromBookmark(); + return relatedEntity == null + ? null : relatedEntity.getColumn(columnName); + } + + public String getCondQualifiedName() { + return this.schema + "." + this.name; + } + + public Boolean exists() { + return null; + } + + public Bookmark getBookmark() { + return BookmarkCollection.getInstance().find(this.bookmarkName); + } + + private Entity getEntityFromBookmark() { + try { + return getBookmark().getEntity( + new Schema(schema), name); + } catch (SQLException e) { + return null; + } + } + /** + * @see com.quantum.model.Entity#getQuotedTableName() + */ + public String getQuotedTableName() { + return getBookmark().getAdapter().filterTableName(getCondQualifiedName()); + } +}