FileDocCategorySizeDatePackage
ForeignKeyConstraint.javaAPI DocGlassfish v2 API6090Tue May 22 16:54:54 BST 2007oracle.toplink.essentials.tools.schemaframework

ForeignKeyConstraint

public class ForeignKeyConstraint extends Object implements Serializable

Purpose: Define a foreign key from one table to another. This support composite foreign keys can constraint options.

Fields Summary
protected String
name
protected Vector
sourceFields
protected Vector
targetFields
protected String
targetTable
protected boolean
shouldCascadeOnDelete
Constructors Summary
public ForeignKeyConstraint()

        this.name = "";
        this.sourceFields = new Vector();
        this.targetFields = new Vector();
        this.targetTable = "";
        this.shouldCascadeOnDelete = false;
    
public ForeignKeyConstraint(String name, String sourceField, String targetField, String targetTable)

        this();
        this.name = name;
        sourceFields.addElement(sourceField);
        targetFields.addElement(targetField);
        this.targetTable = targetTable;
    
Methods Summary
public voidaddSourceField(java.lang.String sourceField)

        getSourceFields().addElement(sourceField);
    
public voidaddTargetField(java.lang.String targetField)

        getTargetFields().addElement(targetField);
    
public voidappendDBString(java.io.Writer writer, oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Append the database field definition string to the table creation statement.

        try {
            writer.write("FOREIGN KEY (");
            for (Enumeration sourceEnum = getSourceFields().elements();
                     sourceEnum.hasMoreElements();) {
                writer.write((String)sourceEnum.nextElement());
                if (sourceEnum.hasMoreElements()) {
                    writer.write(", ");
                }
            }
            writer.write(") REFERENCES ");
            writer.write(getTargetTable());
            writer.write(" (");
            for (Enumeration targetEnum = getTargetFields().elements();
                     targetEnum.hasMoreElements();) {
                writer.write((String)targetEnum.nextElement());
                if (targetEnum.hasMoreElements()) {
                    writer.write(", ");
                }
            }
            writer.write(")");
            if (shouldCascadeOnDelete()) {
                writer.write(" ON DELETE CASCADE");
            }
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
    
public voidcascadeOnDelete()
PUBLIC: Enables delete cascading on the database. This must be used carefully, i.e. only private relationships.

        setShouldCascadeOnDelete(true);
    
public voiddontCascadeOnDelete()
PUBLIC: Disables delete cascading on the database, this is the default.

        setShouldCascadeOnDelete(false);
    
public java.lang.StringgetName()

        return name;
    
public java.util.VectorgetSourceFields()

        return sourceFields;
    
public java.util.VectorgetTargetFields()

        return targetFields;
    
public java.lang.StringgetTargetTable()

        return targetTable;
    
public voidsetName(java.lang.String name)

        this.name = name;
    
public voidsetShouldCascadeOnDelete(boolean shouldCascadeOnDelete)
PUBLIC: Enables delete cascading on the database. This must be used carefully, i.e. only private relationships.

        this.shouldCascadeOnDelete = shouldCascadeOnDelete;
    
public voidsetSourceFields(java.util.Vector sourceFields)

        this.sourceFields = sourceFields;
    
public voidsetTargetFields(java.util.Vector targetFields)

        this.targetFields = targetFields;
    
public voidsetTargetTable(java.lang.String targetTable)

        this.targetTable = targetTable;
    
public booleanshouldCascadeOnDelete()

        return shouldCascadeOnDelete;