001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package javax.persistence;
037:
038: import java.lang.annotation.Target;
039: import java.lang.annotation.Retention;
040: import static java.lang.annotation.ElementType.METHOD;
041: import static java.lang.annotation.ElementType.FIELD;
042: import static java.lang.annotation.RetentionPolicy.RUNTIME;
043:
044: /**
045: * This annotation specifies the ordering of the elements of a
046: * collection valued association at the point when the association
047: * is retrieved.
048: *
049: * <p> The syntax of the <code>value</code> ordering element is an
050: * <code>orderby_list</code>, as follows:
051: *
052: * <pre>
053: * orderby_list::= orderby_item [,orderby_item]*
054: * orderby_item::= property_or_field_name [ASC | DESC]
055: * </pre>
056: *
057: * <p> If <code>ASC</code> or <code>DESC</code> is not specified,
058: * <code>ASC</code> (ascending order) is assumed.
059: *
060: * <p> If the ordering element is not specified, ordering by
061: * the primary key of the associated entity is assumed.
062: *
063: * <p> The property or field name must correspond to that of a
064: * persistent property or field of the associated class. The
065: * properties or fields used in the ordering must correspond to
066: * columns for which comparison operators are supported.
067: *
068: * <pre>
069: * Example:
070: *
071: * @Entity public class Course {
072: * ...
073: * @ManyToMany
074: * @OrderBy("lastname ASC")
075: * public List<Student> getStudents() {...};
076: * ...
077: * }
078: *
079: * @Entity public class Student {
080: * ...
081: * @ManyToMany(mappedBy="students")
082: * @OrderBy // PK is assumed
083: * public List<Course> getCourses() {...};
084: * ...
085: * }
086: * </pre>
087: *
088: * @since Java Persistence 1.0
089: */
090: @Target({METHOD,FIELD})
091: @Retention(RUNTIME)
092: public @interface OrderBy {
093:
094: /**
095: * An <code>orderby_list</code>, specified as follows:
096: *
097: * <pre>
098: * orderby_list::= orderby_item [,orderby_item]*
099: * orderby_item::= property_or_field_name [ASC | DESC]
100: * </pre>
101: *
102: * <p> If <code>ASC</code> or <code>DESC</code> is not specified,
103: * <code>ASC</code> (ascending order) is assumed.
104: *
105: * <p> If the ordering element is not specified, ordering by
106: * the primary key of the associated entity is assumed.
107: */
108: String value() default "";
109: }
|