KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > index > IndexType


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.index;
6
7 /**
8  * @author Thomas
9  */

10 public class IndexType {
11     private boolean isPrimaryKey, isPersistent, isUnique, isHash, isScan;
12     private boolean belongsToConstraint;
13     
14     public static IndexType createPrimaryKey(boolean persistent, boolean hash) {
15         IndexType type = new IndexType();
16         type.isPrimaryKey = true;
17         type.isPersistent = persistent;
18         type.isHash = hash;
19         type.isUnique = true;
20         return type;
21     }
22     
23     public static IndexType createUnique(boolean persistent, boolean hash) {
24         IndexType type = new IndexType();
25         type.isUnique = true;
26         type.isPersistent = persistent;
27         type.isHash = hash;
28         return type;
29     }
30     
31     public static IndexType createNonUnique(boolean persistent) {
32         IndexType type = new IndexType();
33         type.isPersistent = persistent;
34         return type;
35     }
36     
37     public static IndexType createScan(boolean persistent) {
38         IndexType type = new IndexType();
39         type.isPersistent = persistent;
40         type.isScan = true;
41         return type;
42     }
43     
44     public void setBelongsToConstraint(boolean belongsToConstraint) {
45         this.belongsToConstraint = belongsToConstraint;
46     }
47     
48     public boolean belongsToConstraint() {
49         return belongsToConstraint;
50     }
51     
52     public boolean isHash() {
53         return isHash;
54     }
55     public boolean isPersistent() {
56         return isPersistent;
57     }
58     public boolean isPrimaryKey() {
59         return isPrimaryKey;
60     }
61     public boolean isUnique() {
62         return isUnique;
63     }
64     
65     public String JavaDoc getSQL() {
66         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
67         if (isPrimaryKey) {
68             buff.append("PRIMARY KEY");
69             if(isHash) {
70                 buff.append(" HASH");
71             }
72         } else {
73             if (isUnique) {
74                 buff.append("UNIQUE ");
75             }
76             if (isHash) {
77                 buff.append("HASH ");
78             }
79             buff.append("INDEX");
80         }
81         return buff.toString();
82     }
83
84     public boolean isScan() {
85         return isScan;
86     }
87
88 }
89
Popular Tags