View Javadoc
1   /*
2    * AutoDAO - Generic DAO on steroids implementation for Java.
3    *
4    * Copyright 2008-2012  Marat Radchenko <slonopotamus@users.sourceforge.net>
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package net.sf.autodao;
19  
20  import java.lang.annotation.Documented;
21  import java.lang.annotation.ElementType;
22  import java.lang.annotation.Retention;
23  import java.lang.annotation.RetentionPolicy;
24  import java.lang.annotation.Target;
25  import java.util.Collection;
26  import java.util.List;
27  
28  import org.intellij.lang.annotations.Language;
29  
30  /**
31   * Annotation for DAO finder methods.
32   *
33   * @since AutoDAO 0.5
34   */
35  @Documented
36  @Retention(RetentionPolicy.RUNTIME)
37  @Target(ElementType.METHOD)
38  public @interface Finder {
39    /**
40     * Use this parameter to specify named query name.
41     *
42     * @return named query name.
43     */
44    String queryName() default "";
45  
46    /**
47     * Use this parameter to specify HQL query.
48     *
49     * @return HQL query.
50     */
51    String query() default "";
52  
53    /**
54     * Use this parameter to specify SQL native query name.
55     *
56     * @return SQL query name.
57     * @since AutoDAO 0.9
58     */
59    String sqlQueryName() default "";
60  
61    /**
62     * Use this parameter to specify SQL native query.
63     *
64     * @return SQL query.
65     * @since AutoDAO 0.9
66     */
67    @Language("SQL") String sqlQuery() default "";
68  
69    /**
70     * Use this parameter if finder method wants to return custom collection type.
71     *
72     * <p>The only requirements for specified type are: no-arg constructor and implemented {@link
73     * Collection#addAll(java.util.Collection)} method.
74     *
75     * <p>Example:
76     * <pre>
77     * &#64;Finder(query = "from Book where id in (:ids)", returnAs = HashSet.class)
78     * Set&lt;Book&gt; findByIds(@Named("ids") Set&lt;Long&gt; ids);
79     * </pre>
80     *
81     * @return result collection type.
82     */
83    @SuppressWarnings("rawtypes") Class<? extends Collection> returnAs() default List.class;
84  }