1 19 20 package org.netbeans.modules.dbschema; 21 22 import java.util.ResourceBundle ; 23 24 26 public final class IndexElement extends DBMemberElement implements ColumnElementHolder { 27 29 public IndexElement() { 30 this(new Memory(), null); 31 } 32 33 38 public IndexElement(Impl impl, TableElement declaringTable) { 39 super(impl, declaringTable); 40 } 41 42 45 final Impl getIndexImpl() { 46 return (Impl)getElementImpl(); 47 } 48 49 52 public boolean isUnique() { 53 return getIndexImpl().isUnique(); 54 } 55 56 60 public void setUnique(boolean flag) throws DBException { 61 getIndexImpl().setUnique(flag); 62 } 63 64 66 70 public void addColumn(ColumnElement el) throws DBException { 71 addColumns(new ColumnElement[]{el}); 72 } 73 74 78 public void addColumns(final ColumnElement[] els) throws DBException { 79 for (int i = 0; i < els.length; i++) 80 if (getColumn(els[i].getName()) != null) 81 throwAddException("FMT_EXC_AddColumn", els[i]); 83 getIndexImpl().changeColumns(els, TableElement.Impl.ADD); 84 } 85 86 90 public void removeColumn (ColumnElement el) throws DBException { 91 removeColumns(new ColumnElement[]{el}); 92 } 93 94 98 public void removeColumns (final ColumnElement[] els) throws DBException { 99 getIndexImpl().changeColumns(els, TableElement.Impl.REMOVE); 100 } 101 102 107 public void setColumns (ColumnElement[] els) throws DBException { 108 if (els == null) 109 throw new NullPointerException (ResourceBundle.getBundle("org.netbeans.modules.dbschema.resources.Bundle").getString("NulIndexes")); 111 getIndexImpl().changeColumns(els, TableElement.Impl.SET); 112 } 113 114 117 public ColumnElement[] getColumns () { 118 return getIndexImpl().getColumns(); 119 } 120 121 125 public ColumnElement getColumn (DBIdentifier name) { 126 return getIndexImpl().getColumn(name); 127 } 128 129 135 private void throwAddException (String formatKey, ColumnElement element) throws DBException { 136 String msg = element.getName().getName(); throw new DBException(msg); 139 } 140 141 144 public interface Impl extends DBMemberElement.Impl { 145 148 public boolean isUnique (); 149 150 154 public void setUnique (boolean flag) throws DBException; 155 156 161 public void changeColumns (ColumnElement[] elems, int action) throws DBException; 162 163 166 public ColumnElement[] getColumns (); 167 168 172 public ColumnElement getColumn (DBIdentifier name); 173 } 174 175 static class Memory extends DBMemberElement.Memory implements Impl { 176 177 private boolean _unique; 178 179 180 private DBMemoryCollection.Column columns; 181 182 184 Memory() { 185 super(); 186 _unique = true; 187 } 188 189 192 Memory(IndexElement index) { 193 super(index); 194 _unique = index.isUnique(); 195 } 196 197 200 public boolean isUnique() { 201 return _unique; 202 } 203 204 207 public void setUnique(boolean flag) { 208 boolean old = _unique; 209 210 _unique = flag; 211 firePropertyChange(PROP_UNIQUE, Boolean.valueOf(old), Boolean.valueOf(flag)); 212 } 213 214 218 public synchronized void changeColumns(ColumnElement[] elems, int action) { 219 initColumns(); 220 columns.change(elems, action); 221 } 222 223 226 public synchronized ColumnElement[] getColumns() { 227 initColumns(); 228 return (ColumnElement[])columns.getElements(); 229 } 230 231 235 public synchronized ColumnElement getColumn(DBIdentifier name) { 236 initColumns(); 237 return (ColumnElement)columns.getElement(name); 238 } 239 240 242 void initColumns() { 243 if (columns == null) 244 columns = new DBMemoryCollection.Column(this); 245 } 246 } 247 } 248 | Popular Tags |