1 22 23 package org.xquark.mapper.dbms; 24 25 26 30 public class ConstraintSpec 31 { 32 private static final String RCSRevision = "$Revision: 1.1 $"; 33 private static final String RCSName = "$Name: $"; 34 35 36 public static final byte CONSTRAINT_UNIQUE = 0; 37 38 private static final String uniqueString = "unique"; 39 40 protected byte type; 41 protected ColumnSpec[] columns = null; 42 43 protected ConstraintSpec() {} 47 48 public ConstraintSpec(String type) 49 { 50 this.type = parseType(type); 51 } 52 53 public String generateConstraintClause() 54 { 55 StringBuffer clause = new StringBuffer (); 56 clause.append("UNIQUE"); 57 clause.append(generateColumnList()); 58 return clause.toString(); 59 } 60 61 public String generateColumnList() 62 { 63 StringBuffer clause = new StringBuffer (); 64 clause.append('('); 65 for (int i = 0; i < columns.length; i++) 66 { 67 clause.append(columns[i].getName()); 68 clause.append(","); 69 } 70 clause.setCharAt(clause.length() - 1, ')'); 71 return clause.toString(); 72 } 73 74 public byte getType() 78 { 79 return type; 80 } 81 82 public void setColumns(ColumnSpec[] columns) 83 { 84 this.columns = columns; 85 } 86 87 private byte parseType(String type) 88 { 89 if (!type.equals(uniqueString)) 90 throw new RuntimeException ("The DBMS table type" + type + " used in tableSpec.xml is unknown."); 91 return CONSTRAINT_UNIQUE; 92 } 93 } 94 | Popular Tags |