001 package com.sptci.prevayler.annotations;
002
003 import java.lang.annotation.*;
004
005 /**
006 * Annotation used to indicate a foreign key (direct reference to another
007 * prevalent object). Foreign keys are automatically indexed, hence it
008 * is not necessary to declare single field indices for fields that are also
009 * marked as foreign keys. Delete actions are also configured using this
010 * annotation.
011 *
012 * <p>© Copyright 2008 <a href='http://sptci.com/' target='_top'>Sans Pareil Technologies, Inc.</a></p>
013 * @author Rakesh Vidyadharan 2008-05-23
014 * @version $Id: ForeignKey.java 11 2008-06-30 21:33:41Z sptrakesh $
015 */
016 @Documented
017 @Inherited
018 @Retention( RetentionPolicy.RUNTIME )
019 @Target( { ElementType.TYPE, ElementType.FIELD } )
020 public @interface ForeignKey
021 {
022 /** The default value for {@link #member} indicating a null value. */
023 static String NULL = "";
024
025 /** Enumeration for the delete actions supported. */
026 enum DeleteAction { CASCADE, NULL, EXCEPTION }
027
028 /**
029 * The name of the field in the prevalent object. This is necessary only
030 * when the prevalent class is annotated. Defaults to {@link #NULL}.
031 *
032 * @return The name of the field that is a foreign key.
033 */
034 String member() default NULL;
035
036 /**
037 * Indicate whether the referenced prevalent object should be unique within
038 * the extent of the prevalent object being annotated. Defaults to
039 * <code>false</code>.
040 *
041 * @return Return <code>true</code> if the referenced prevalent object
042 * should be unique.
043 */
044 boolean unique() default false;
045
046 /**
047 * The action to perform when the referenced prevalent object is deleted
048 * from the prevalent system. Defaults to {@link DeleteAction#EXCEPTION}.
049 *
050 * @return The delete action to apply.
051 */
052 DeleteAction deleteAction() default DeleteAction.EXCEPTION;
053
054 /**
055 * The fully qualified name of the prevalent object stored in collection
056 * fields. This is necessary only for collection fields since it is
057 * difficult to infer the type of objects stored in them.
058 *
059 * @return The fully qualified class name stored in the collection.
060 */
061 String collectionEntry() default NULL;
062 }