1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.agile.db.model;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.xml.bind.annotation.XmlAttribute;
22 import javax.xml.bind.annotation.XmlRootElement;
23 import javax.xml.bind.annotation.XmlTransient;
24
25 import org.javagen.agile.core.model.AbstractModel;
26 import org.javagen.agile.core.model.Model;
27 import org.javagen.agile.core.util.ModelUtil;
28
29 @XmlRootElement(name="database")
30 public class Database extends AbstractModel {
31
32 public static final String DEFAULT_MODEL_TYPE = "DATABASE";
33
34 protected String catalog;
35 protected String schema;
36
37 public Database() {
38 super();
39 this.setModelType(DEFAULT_MODEL_TYPE);
40 }
41
42 public Database(String name) {
43 this();
44 setName(name);
45 }
46
47 @Override
48 public void copyTo(Model targetModel) {
49 super.copyTo(targetModel);
50 Database target = (Database)targetModel;
51 if (this.getCatalog()!=null)
52 target.setCatalog(this.getCatalog());
53 if (this.getSchema()!=null)
54 target.setSchema(this.getSchema());
55 }
56
57
58
59
60
61 public Table createTable() {
62 return new Table(this);
63 }
64
65 public Table addTable(String name, Boolean linkTable) {
66 Table table = createTable();
67 table.setName(name);
68 table.setLinkTable(linkTable);
69 this.addTable(table);
70 return table;
71 }
72
73 public Table lookupTable(String name) {
74 return (Table)ModelUtil.lookupChildByName(this, name, Table.class, false);
75 }
76
77 @XmlTransient
78 public List<Table> getTables() {
79 List<Table> list = new ArrayList<Table>(getChildModels().size());
80 for(Model child : getChildModels())
81 list.add((Table)child);
82 return list;
83 }
84
85 public void addTable(Table table) {
86 addChildModel(table);
87 }
88
89
90
91
92
93 @XmlAttribute
94 public String getSchema() {
95 return schema;
96 }
97
98 public void setSchema(String schema) {
99 this.schema = schema;
100 }
101
102 @XmlAttribute
103 public String getCatalog() {
104 return catalog;
105 }
106
107 public void setCatalog(String catalog) {
108 this.catalog = catalog;
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122 }