1 10 11 package com.triactive.jdo.store; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import javax.jdo.JDOFatalInternalException; 19 20 21 abstract class Key 22 { 23 protected BaseTable table; 24 protected ArrayList columns = new ArrayList (); 25 26 27 protected Key(BaseTable table) 28 { 29 this.table = table; 30 } 31 32 33 protected void assertSameTable(Column col) 34 { 35 if (!table.equals(col.getTable())) 36 throw new JDOFatalInternalException("Cannot add " + col + " as key column for " + table); 37 } 38 39 40 public BaseTable getTable() 41 { 42 return table; 43 } 44 45 46 public List getColumns() 47 { 48 return Collections.unmodifiableList(columns); 49 } 50 51 52 public String getColumnList() 53 { 54 return getColumnList(columns); 55 } 56 57 58 public boolean startsWith(Key k) 59 { 60 int kSize = k.columns.size(); 61 62 return kSize <= columns.size() && k.columns.equals(columns.subList(0, kSize)); 63 } 64 65 66 protected static void setMinSize(List list, int size) 67 { 68 while (list.size() < size) 69 list.add(null); 70 } 71 72 73 public static String getColumnList(Collection cols) 74 { 75 StringBuffer s = new StringBuffer ("("); 76 Iterator i = cols.iterator(); 77 78 while (i.hasNext()) 79 { 80 Column col = (Column)i.next(); 81 82 if (col == null) 83 s.append('?'); 84 else 85 s.append(col.getName()); 86 87 if (i.hasNext()) 88 s.append(','); 89 } 90 91 s.append(')'); 92 93 return s.toString(); 94 } 95 } 96 | Popular Tags |