author | lancea |
Wed, 11 Jul 2018 19:36:23 -0400 | |
branch | JDK-8188051-branch |
changeset 56828 | 64304e37e9b1 |
parent 56824 | 62e92191354d |
child 56832 | 4f7713e6a308 |
permissions | -rw-r--r-- |
56824 | 1 |
/* |
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
|
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 |
/** |
|
29 |
* An attribute of a {@link Session} that can be configured to influence its |
|
30 |
* behavior. Implementors of this interface define the properties of |
|
31 |
* {@link Session}s. The {@link Session.Builder#property} method is used to set the values |
|
32 |
* of {@link Session} properties. |
|
33 |
* |
|
34 |
* Implementations must be thread safe. |
|
35 |
* |
|
36 |
*/ |
|
37 |
public interface SessionProperty { |
|
38 |
||
39 |
/** |
|
40 |
* Return the name of this {@link SessionProperty}. |
|
41 |
* |
|
42 |
* @return the name of this {@link SessionProperty} |
|
43 |
*/ |
|
44 |
public String name(); |
|
45 |
||
46 |
/** |
|
47 |
* Return the type of the value of this {@link SessionProperty}. Any value |
|
48 |
* set for this property must be assignable to this type. |
|
49 |
* |
|
50 |
* @return the type of the values of this {@link SessionProperty} |
|
51 |
*/ |
|
52 |
public Class<?> range(); |
|
53 |
||
54 |
/** |
|
55 |
* Determine whether a value is valid for this {@link SessionProperty}. Returns |
|
56 |
* {@code true} if {@code value} is valid and {@code false} otherwise. |
|
57 |
* |
|
58 |
* @param value a value for this {@link SessionProperty} |
|
59 |
* @return {@code true} iff {@code value} is valid for this {@link SessionProperty} |
|
60 |
*/ |
|
61 |
public default boolean validate(Object value) { |
|
62 |
return (value == null && this.range() == Void.class) || this.range().isInstance(value); |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* Return the value for this property to use if no other value is set. For |
|
67 |
* this to have any meaning for a user defined property the property must be |
|
68 |
* registered with the {@link DataSource} by calling |
|
69 |
* {@link DataSource.Builder#registerSessionProperty}. |
|
70 |
* |
|
71 |
* @return the default value or {@code null} if there is no default value |
|
72 |
*/ |
|
73 |
public Object defaultValue(); |
|
74 |
||
75 |
/** |
|
76 |
* Returns true if this {@link SessionProperty} is contains sensitive information |
|
77 |
* such as a password or encryption key. |
|
78 |
* |
|
79 |
* @return true iff this is sensitive |
|
80 |
*/ |
|
81 |
public boolean isSensitive(); |
|
82 |
||
83 |
/** |
|
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
84 |
* Creates and submits zero or more {@link Operation}s that will configure the |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
85 |
* {@link Session} to have the specified property value. Returns {@code true} |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
86 |
* if any {@link Operation}s were submitted. {@code false} otherwise. |
56824 | 87 |
* |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
88 |
* Called by {@link Session.Builder#build()} to configure a {@link Session} as |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
89 |
* specified in the {@link Session.Builder#property} method. SessionProperties |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
90 |
* known to the implementation may return {@code false} and rely on the |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
91 |
* implementation to do the right thing. |
56824 | 92 |
* |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
93 |
* @param group an {@link OperationGroup} which will be the container of the |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
94 |
* submitted {@link Operation}s, if any |
56824 | 95 |
* @param value the value to which the property is to be set. May be null if |
96 |
* {@link range()} is {@link Void}. |
|
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
97 |
* @return true if any {@link Operation}s were submitted, false otherwise |
56824 | 98 |
* @throws IllegalStateException if it is not possible to configure the |
99 |
* {@link Session} as specified. |
|
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
100 |
* @throws IllegalArgumentException if {@code this.validate(value)} returns |
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
101 |
* {@code false} |
56824 | 102 |
*/ |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
103 |
public default boolean configureOperation(OperationGroup<?, ?> group, Object value) { |
56824 | 104 |
if (validate(value)) { |
56828
64304e37e9b1
JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents:
56824
diff
changeset
|
105 |
return false; |
56824 | 106 |
} |
107 |
else { |
|
108 |
throw new IllegalArgumentException(value.toString() + " is invalid"); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
} |