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