01: package jimm.datavision.testdata.mysql;
02:
03: import jimm.datavision.testdata.SchemaGen;
04:
05: public class MySQLSchemaGen extends SchemaGen {
06:
07: /** Max MySQL varchar length. */
08: protected static final int MAX_VARCHAR_LEN = 255;
09:
10: protected String printableName(String name) {
11: if (name.indexOf(' ') >= 0 || !name.toLowerCase().equals(name))
12: return "`" + name + "`";
13: return name;
14: }
15:
16: protected void makeTable(String tableName) {
17: String name = printableName(tableName);
18: System.out.println("drop table if exists " + name + ";");
19: System.out.print("create table " + name + " (");
20: }
21:
22: protected void endTable() {
23: System.out.println();
24: System.out.println(");");
25: }
26:
27: protected void printType(String type, int size) {
28: System.out.print(" ");
29: if ("integer".equals(type))
30: System.out.print("int");
31: else if ("date".equals(type))
32: System.out.print("date");
33: else if ("boolean".equals(type))
34: System.out.print("enum('F','T') default 'F'");
35: else if ("string".equals(type)) {
36: if (size > MAX_VARCHAR_LEN)
37: size = MAX_VARCHAR_LEN;
38: System.out.print("varchar(" + size + ")");
39: }
40: }
41:
42: protected void printNotNull() {
43: System.out.print(" not null");
44: }
45:
46: protected void printPrimaryKey() {
47: System.out.print(" primary key");
48: }
49:
50: public static void main(String[] args) {
51: new MySQLSchemaGen().run("../schema.xml");
52: }
53: }
|