1 2 12 package com.versant.core.jdbc.metadata; 13 14 import com.versant.core.jdbc.sql.JdbcNameGenerator; 15 16 import java.io.Serializable ; 17 import java.util.ArrayList ; 18 import java.util.Collections ; 19 import java.util.List ; 20 import java.util.Arrays ; 21 22 27 public final class JdbcConstraint implements Serializable { 28 29 public String name; 30 33 public JdbcTable src; 34 38 public JdbcColumn[] srcCols; 39 42 public JdbcTable dest; 43 44 public JdbcConstraint() { 45 } 46 47 public String toString() { 48 StringBuffer s = new StringBuffer (); 49 s.append(name); 50 s.append('('); 51 s.append(JdbcColumn.toNameString(srcCols)); 52 s.append(") references "); 53 s.append(dest.name); 54 s.append('('); 55 s.append(JdbcColumn.toNameString(dest.pk)); 56 s.append(')'); 57 return s.toString(); 58 } 59 60 63 public void generateName(JdbcNameGenerator namegen) { 64 name = namegen.generateRefConstraintName(src.name, dest.name, JdbcColumn.getColumnNames( 65 srcCols), 66 dest.getPkNames()); 67 } 68 69 public List getColumnList() { 70 if (srcCols == null) { 71 return Collections.EMPTY_LIST; 72 } 73 ArrayList list = new ArrayList (srcCols.length); 74 for (int i = 0; i < srcCols.length; i++) { 75 JdbcColumn col = srcCols[i]; 76 list.add(col); 77 } 78 return list; 79 } 80 81 public boolean isSameConstraint(JdbcConstraint constraint) { 82 return false; 83 } 84 85 public boolean equals(Object o) { 86 if (this == o) return true; 87 if (!(o instanceof JdbcConstraint)) return false; 88 89 final JdbcConstraint jdbcConstraint = (JdbcConstraint)o; 90 91 if (dest != null ? !dest.equals(jdbcConstraint.dest) : jdbcConstraint.dest != null) return false; 92 if (src != null ? !src.equals(jdbcConstraint.src) : jdbcConstraint.src != null) return false; 93 if (!Arrays.equals(srcCols, jdbcConstraint.srcCols)) return false; 94 95 return true; 96 } 97 98 public int hashCode() { 99 int result; 100 result = (src != null ? src.hashCode() : 0); 101 if (srcCols != null) { 102 for (int i = 0; i < srcCols.length; i++) { 103 JdbcColumn srcCol = srcCols[i]; 104 result = 29 * result + (srcCol != null ? srcCol.hashCode() : 0); 105 } 106 } 107 result = 29 * result + (dest != null ? dest.hashCode() : 0); 108 return result; 109 } 110 } 111 112 113 | Popular Tags |