001package springdao;
002
003import java.lang.annotation.Documented;
004import java.lang.annotation.ElementType;
005import java.lang.annotation.Inherited;
006import java.lang.annotation.Retention;
007import java.lang.annotation.RetentionPolicy;
008import java.lang.annotation.Target;
009import javax.persistence.EntityManagerFactory;
010
011/**
012 * Inject a {@link Dao} implemention  into {@link RepositoryManager}.<br/>
013 * 將{@link Dao}注入{@link RepositoryManager}.<br/>
014 * Usage(用法):<br/>
015 * Initializate a {@link DaoAnnotationBeanPostProcessor} bean in your spring context.<br/>
016 * 在您的Spring環境內建立一個{@link DaoAnnotationBeanPostProcessor} bean 就可以了.<br/>
017 * <pre style="color:blue">
018 *     &#64;Dao(value = Entity.class, name = "customDao")
019 *     public DaoRepository&lt;Entity&gt; entityDao;
020 * </pre>
021 * <dl>
022 * <dt style="color:red">Note(備註):</dt>
023 * <dd>It's not recommend to use this annotation,
024 * because of {@link DaoManager} may also create  the same name {@link DaoRepository}, and &#64;Dao can't  assure instantiation order 
025 * of {@link DaoRepository}, please use carefully.<br/>
026 *我建議不要使用此標記, 因為{@link DaoManager}也有可能建立同名的{@link DaoRepository},而&#64;Dao並無法保證其建立順序,所以要用時,
027 * 請自求多福。</dd>
028 * </dl>
029 * @author Kent Yeh
030 */
031@Retention(RetentionPolicy.RUNTIME)
032@Target({ElementType.FIELD, ElementType.METHOD})
033@Documented
034@Inherited
035public @interface Dao {
036
037    /**
038     * Class assoicated with {@link DaoRepository}.<br/>
039     * {@link DaoRepository} 相關的一般化類別
040     * @return taget entity class
041     */
042    Class value() default Object.class;
043
044    /**
045     * Deinfe {@link EntityManagerFactory} bean's name.<br/>
046     * 設定 {@link EntityManagerFactory}  bean的名稱.
047     * @return {@link EntityManagerFactory} bean's name, default is &quot;entityManagerFactory&quot;
048     */
049    String factory() default "entityManagerFactory";
050
051    /**
052     * Naming object to be turned into a Spring bean in case of an autodetected component.<br/>
053     * Spring beand 的名稱., 若已存在則取用,若不存在則建立
054     * @return spring bean's name
055     */
056    String name() default "";
057
058    /**
059     * Auto register bean with ${@link #value() value}'s simple class name suffix with &quot;Dao&quot if not assigned ${@link #name() name}.<br/>
060     * 如果沒有指定${@link #name() name},則自動以${@link #value() value}的類別名稱加上&quot;Dao&quot;註冊
061     * @return spring bean's name
062     */
063    boolean autoRegister() default true;
064
065}