01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.synth.sql;
07:
08: /**
09: * Represents an index.
10: */
11: public class Index {
12: Table table;
13: String name;
14: Column[] columns;
15: boolean unique;
16:
17: Index(Table table, String name, Column[] columns, boolean unique) {
18: this .table = table;
19: this .name = name;
20: this .columns = columns;
21: this .unique = unique;
22: }
23:
24: public String getName() {
25: return name;
26: }
27:
28: public String getCreateSQL() {
29: String sql = "CREATE ";
30: if (unique) {
31: sql += "UNIQUE ";
32: }
33: sql += "INDEX " + name + " ON " + table.getName() + "(";
34: for (int i = 0; i < columns.length; i++) {
35: if (i > 0) {
36: sql += ", ";
37: }
38: sql += columns[i].getName();
39: }
40: sql += ")";
41: return sql;
42: }
43:
44: public String getDropSQL() {
45: return "DROP INDEX " + name;
46: }
47:
48: public Table getTable() {
49: return table;
50: }
51:
52: }
|