1 19 20 package org.netbeans.modules.dbschema.jdbcimpl; 21 22 import java.sql.*; 23 import java.util.*; 24 25 import org.netbeans.modules.dbschema.*; 26 import org.netbeans.modules.dbschema.util.*; 27 28 public class IndexElementImpl extends DBMemberElementImpl implements IndexElement.Impl { 29 30 private DBElementsCollection columns; 31 private TableElementImpl tei; 32 private boolean _unique; 33 34 35 public IndexElementImpl() { 36 this(null, null, false); 37 } 38 39 public IndexElementImpl(TableElementImpl tei, String name, boolean unique) { 40 super(name); 41 columns = new DBElementsCollection(tei, new ColumnElement[0]); 42 43 Object hc = String.valueOf(columns.hashCode()); 46 while (DBElementsCollection.instances.contains(hc)) { 47 columns = new DBElementsCollection(tei, new ColumnElement[0]); 48 hc = String.valueOf(columns.hashCode()); 49 } 50 DBElementsCollection.instances.add(hc); 51 52 this.tei = tei; 53 _unique = unique; 54 } 55 56 59 public boolean isUnique() { 60 return _unique; 61 } 62 63 67 public void setUnique(boolean unique) throws DBException { 68 _unique = unique; 69 } 70 71 76 public void changeColumns(ColumnElement[] elems,int action) throws DBException { 77 columns.changeElements(elems, action); 78 } 79 80 83 public ColumnElement[] getColumns() { 84 DBElement[] dbe = columns.getElements(); 85 return (ColumnElement[]) Arrays.asList(dbe).toArray(new ColumnElement[dbe.length]); 86 } 87 88 92 public ColumnElement getColumn(DBIdentifier name) { 93 return (ColumnElement) columns.find(name); 94 } 95 96 protected void initColumns(LinkedList idxs) { 97 LinkedList columnsList = new LinkedList(); 98 String name, info; 99 int start, end; 100 101 try { 102 for (int i = 0; i < idxs.size(); i++) { 103 info = idxs.get(i).toString(); 104 start = info.indexOf('.'); 105 end = info.lastIndexOf('.'); 106 107 name = info.substring(0, start); 108 if (name.equals(this.getName().getName())) 109 columnsList.add(info.substring(start + 1, end)); 110 } 111 112 for (int i = 0; i < columnsList.size(); i++) { 113 ColumnElement c = ((IndexElement) element).getDeclaringTable().getColumn(DBIdentifier.create(columnsList.get(i).toString())); 114 if (c != null) 115 changeColumns(new ColumnElement[] {c}, DBElement.Impl.ADD); 116 } 117 } catch (Exception exc) { 118 exc.printStackTrace(); 119 } 120 } 121 122 126 public DBElementsCollection getColumnCollection () { 127 return columns; 128 } 129 130 135 public void setColumnCollection (DBElementsCollection collection) { 136 columns = collection; 137 } 138 139 } 140 | Popular Tags |