KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > PrimaryKey


1 //$Id: PrimaryKey.java,v 1.5 2005/02/12 07:19:26 steveebersole Exp $
2
package org.hibernate.mapping;
3
4 import java.util.Iterator JavaDoc;
5
6 import org.hibernate.dialect.Dialect;
7
8 /**
9  * A primary key constraint
10  * @author Gavin King
11  */

12 public class PrimaryKey extends Constraint {
13
14     public String JavaDoc sqlConstraintString(Dialect dialect) {
15         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("primary key (");
16         Iterator JavaDoc iter = getColumnIterator();
17         while ( iter.hasNext() ) {
18             buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
19             if ( iter.hasNext() ) buf.append(", ");
20         }
21         return buf.append(')').toString();
22     }
23
24     public String JavaDoc sqlConstraintString(Dialect dialect, String JavaDoc constraintName, String JavaDoc defaultCatalog, String JavaDoc defaultSchema) {
25         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(
26             dialect.getAddPrimaryKeyConstraintString(constraintName)
27         ).append('(');
28         Iterator JavaDoc iter = getColumnIterator();
29         while ( iter.hasNext() ) {
30             buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
31             if ( iter.hasNext() ) buf.append(", ");
32         }
33         return buf.append(')').toString();
34     }
35 }
36
Popular Tags