56380
|
1 |
/*
|
56797
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
56380
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.incubator.sql2;
|
|
27 |
|
|
28 |
import java.lang.annotation.Target;
|
|
29 |
import static java.lang.annotation.ElementType.CONSTRUCTOR;
|
|
30 |
import static java.lang.annotation.ElementType.METHOD;
|
|
31 |
import java.lang.annotation.Retention;
|
|
32 |
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
33 |
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Identifies a constructor or static factory method that can be used to construct
|
56832
|
37 |
* an instance of the containing type when the type is passed to {@link Result.Column#get}.
|
56380
|
38 |
* The method or constructor must be public.
|
|
39 |
*
|
|
40 |
* An instance of this type will be constructed by calling the factory method or
|
|
41 |
* constructor. Each element in the value of this annotation is used as a column
|
|
42 |
* identifier. The value of that column is passed to the corresponding parameter
|
56832
|
43 |
* of the annotated method or constructor. The id argument to {@link Result.Column#get} is
|
56380
|
44 |
* prefixed to the column identifiers.
|
|
45 |
*
|
|
46 |
* The following pseudo-code describes how an instance is constructed.
|
|
47 |
*
|
|
48 |
* {@code
|
|
49 |
* <pre> int i = 0;
|
|
50 |
* String[] columns = methodOrConstructor.getAnnotation(SqlColumns.class).value();
|
|
51 |
* Object[] args = new Object[columns.length];
|
|
52 |
* for (String columnName : columns)
|
56832
|
53 |
* args[i] = colum.at(prefix + columnName).get(parameterTypes[i++]);
|
56380
|
54 |
* instance = methodOrConstructor.invoke(null, args);</pre>}
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
@Retention(RUNTIME)
|
|
58 |
@Target({CONSTRUCTOR, METHOD})
|
|
59 |
public @interface SqlColumns {
|
|
60 |
|
|
61 |
/**
|
|
62 |
* The column names corresponding to the parameters of the factory method or
|
|
63 |
* constructor to construct an instance of this type. There must be exactly one
|
|
64 |
* column name for each parameter of the annotated method or constructor.
|
|
65 |
*
|
|
66 |
* @return the column names in the order returned by the database
|
|
67 |
*/
|
|
68 |
public String[] value();
|
|
69 |
}
|