All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nz.co.gregs.dbvolution.annotations.DBForeignKey Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nz.co.gregs.dbvolution.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import nz.co.gregs.dbvolution.DBRow;

/**
 *
 * Indicates that this field is a Foreign Key to another database table and
 * specifies the table.
 * 
 * 
* public class MyTable extends DBRow {
*
* @DBColumn("other_table_fk")
* @DBForeignKey(OtherTable.class)
* public DBInteger otherTableFK = new DBInteger();
* }
*
*
*

* The class reference is to another DBRow class that represents the table of * the foreign key. * *

* Multiple foreign keys to the same table can be handled by subclassing the * original DBRow subclass. For instance Manager might be a trivial extension of * the Employee class but it will be treated as a separate relation by * DBvolution. * *

* DBForeignKey works with DBPrimaryKey and DBQuery to make Natural Joins happen * automatically. * *

* DBForeignKey does not require a foreign key relationship to exist within the * database and does not enforce referential integrity. * *

* DBForeignKey is generated automatically by DBTableClassGenerator if the * foreign key is specified within the database. * *

Support DBvolution at * Patreon

* * @author Gregory Graham * @see DBPrimaryKey * @see DBColumn */ @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface DBForeignKey { /** * Identifies the foreign table by its {@code DBRow} implementation class. * *

Support DBvolution at * Patreon

* * @return the DBRow subclass that this foreign key references. */ Class value(); /** * Identifies the foreign column by column name. This must be a column in the * foreign class. * *

* If not specified, and the foreign class as exactly one primary key column, * the primary key of the foreign class is used. *

* Must be specified if the foreign class has no primary key, or if it has * multiple primary key columns (not supported yet). * *

Support DBvolution at * Patreon

* * @return the name of the column this foreign key references. */ String column() default ""; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy