1 64 65 package com.jcorporate.expresso.core.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.i18n.Messages; 69 70 import java.io.IOException ; 71 import java.io.ObjectInputStream ; 72 import java.io.ObjectOutputStream ; 73 import java.io.Serializable ; 74 75 76 81 public class DBIndex 82 implements Serializable { 83 84 87 private String indexName; 88 89 92 private String fieldNames; 93 94 100 private boolean unique; 101 private String tableName; 102 103 106 public DBIndex() { 107 indexName = null; 108 fieldNames = null; 109 tableName = null; 110 unique = false; 111 } 112 113 122 public DBIndex(String theIndexName, String theTableName, 123 String theFieldNames, boolean isItUnique) { 124 indexName = theIndexName; 125 tableName = theTableName; 126 fieldNames = theFieldNames; 127 unique = isItUnique; 128 } 129 130 public String getIndexName() { 131 return indexName; 132 } 133 134 public void setIndexName(String newIndexName) { 135 indexName = newIndexName; 136 } 137 138 public String getFieldNames() { 139 return fieldNames; 140 } 141 142 public boolean isUnique() { 143 return unique; 144 } 145 146 public void setFieldNames(String newFieldNames) { 147 fieldNames = newFieldNames; 148 } 149 150 public void setUnique(boolean newUnique) { 151 unique = newUnique; 152 } 153 154 162 public String constructSQL() 163 throws DBException { 164 165 if (indexName == null) { 167 throw new DBException(Messages.getString("DBIndex_ConstructSQL_IllegalArgument")); 168 } 169 if (tableName == null) { 170 throw new DBException("DBIndex_ConstructSQL_IllegalArgument)"); 171 } 172 if (fieldNames == null) { 173 throw new DBException("DBIndex_ConstructSQL_IllegalArgument"); 174 } 175 176 StringBuffer statement = new StringBuffer (100); 177 statement.append("CREATE "); 178 179 if (isUnique() == true) { 180 statement.append("UNIQUE "); 181 } 182 183 statement.append("INDEX "); 184 statement.append(indexName); 185 statement.append(" ON "); 186 statement.append(tableName); 187 statement.append("("); 188 statement.append(fieldNames); 189 statement.append(")"); 190 191 return statement.toString(); 192 } 193 194 195 private void writeObject(ObjectOutputStream oos) 196 throws IOException { 197 oos.defaultWriteObject(); 198 } 199 200 private void readObject(ObjectInputStream ois) 201 throws ClassNotFoundException , IOException { 202 ois.defaultReadObject(); 203 } 204 205 public void setTableName(String newTableName) { 206 tableName = newTableName; 207 } 208 209 public String getTableName() { 210 return tableName; 211 } 212 } | Popular Tags |