1 package net.sourceforge.phpdt.sql.model;
3 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
4 import net.sourceforge.phpdt.sql.sql.DbElementsConstants;
5 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
6 import net.sourceforge.phpdt.sql.sql.SQLHelper;
13 public class EntityFactory {
15 public abstract class EntityImpl implements Entity {
16 private String schema;
19 private Bookmark bookmark;
21 public EntityImpl(Bookmark bookmark, String schema, String name, String type) {
25 this.bookmark = bookmark;
27 protected Bookmark getBookmark() {
30 public String getName() {
33 public String getSchema() {
36 public String getType() {
39 public String getQualifiedName() {
40 return (this.schema == null || this.schema.length() == 0) ?
41 this.name : this.schema + "." + this.name;
45 public class TableImpl extends EntityImpl implements Table {
46 public TableImpl(Bookmark bookmark, String schema, String name) {
47 super(bookmark, schema, name, DbElementsConstants.Table);
50 public int getSize() {
51 return SQLHelper.getSize(getBookmark(), getQualifiedName());
54 public void deleteAllRows() {
55 String sql = "DELETE FROM " + getQualifiedName();
56 MultiSQLServer.getInstance().execute(getBookmark().getConnection(), sql);
60 public class ViewImpl extends EntityImpl implements View {
61 public ViewImpl(Bookmark bookmark, String schema, String name) {
62 super(bookmark, schema, name, DbElementsConstants.View);
65 public int getSize() {
66 return SQLHelper.getSize(getBookmark(), getQualifiedName());
70 public class SequenceImpl extends EntityImpl implements Sequence {
71 public SequenceImpl(Bookmark bookmark, String schema, String name) {
72 super(bookmark, schema, name, DbElementsConstants.Sequence);
76 private static EntityFactory instance = new EntityFactory();
78 private EntityFactory() {
81 public static EntityFactory getInstance() {
82 return EntityFactory.instance;
85 public Entity create(Bookmark bookmark, String schema, String name, String type) {
90 if (DbElementsConstants.Table.equals(type)) {
91 return new TableImpl(bookmark, schema, name);
92 } else if (DbElementsConstants.View.equals(type)) {
93 return new ViewImpl(bookmark, schema, name);
94 } else if (DbElementsConstants.Sequence.equals(type)) {
95 return new SequenceImpl(bookmark, schema, name);
98 // throw new IllegalArgumentException("Unknown type: " + type);