src/jdk.incubator.adba/share/classes/jdk/incubator/sql2/SessionProperty.java
author lancea
Sat, 20 Oct 2018 08:17:38 -0400
branchJDK-8188051-branch
changeset 56997 c9cbac2979fb
parent 56832 4f7713e6a308
permissions -rw-r--r--
JDK-8188051-branch October 20 ABDA updates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     1
/*
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     2
 * Copyright (c)  2017, 2018, Oracle and/or its affiliates. All rights reserved.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     4
 *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    10
 *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    15
 * accompanied this code).
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    16
 *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    20
 *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    23
 * questions.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    24
 */
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    25
package jdk.incubator.sql2;
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    26
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    27
import java.io.Serializable;
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    28
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    29
/**
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    30
 * An attribute of a {@link Session} that can be configured to influence its
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    31
 * behavior. implementers of this interface define the properties of
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    32
 * {@link Session}s. The {@link Session.Builder#property} method is used to set
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    33
 * the values of {@link Session} properties.
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    34
 *
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    35
 * Implementations must be thread safe.
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    36
 *
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    37
 */
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    38
public interface SessionProperty extends Serializable {
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    39
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    40
  /**
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    41
   * Return the name of this {@code SessionProperty}.
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    42
   *
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    43
   * @return the name of this {@code SessionProperty}
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    44
   */
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    45
  public String name();
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    46
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    47
  /**
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    48
   * Return the type of the value of this {@code SessionProperty}. Any value set
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    49
   * for this property must be assignable to this type.
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    50
   *
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    51
   * @return the type of the values of this {@code SessionProperty}
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    52
   */
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    53
  public Class<?> range();
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    54
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    55
  /**
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    56
   * Determine whether a value is valid for this {@code SessionProperty}.
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    57
   * Returns {@code true} if {@code value} is valid and {@code false} otherwise.
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    58
   *
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    59
   * @param value a value for this {@code SessionProperty}
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    60
   * @return {@code true} iff {@code value} is valid for this
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    61
   * {@code SessionProperty}
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    62
   */
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    63
  public default boolean validate(Object value) {
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    64
    return (value == null && this.range() == Void.class) || this.range().isInstance(value);
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    65
  }
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    66
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    67
  /**
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    68
   * Return the value for this property to use if no other value is set. For
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    69
   * this to have any meaning for a user defined property the property must be
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    70
   * registered with the {@link DataSource} by calling
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    71
   * {@link DataSource.Builder#registerSessionProperty}.
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    72
   *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    73
   * @return the default value or {@code null} if there is no default value
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    74
   */
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    75
  public Object defaultValue();
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    76
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    77
  /**
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    78
   * Returns true if this {@code SessionProperty} contains sensitive information
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    79
   * such as a password or encryption key.
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    80
   *
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    81
   * @return true iff this is sensitive
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    82
   */
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    83
  public boolean isSensitive();
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    84
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    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
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    89
   *
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    90
   * Potentially called when an attach {@link Operation} is executed to
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    91
   * configure a {@link Session} as specified in the
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    92
   * {@link Session.Builder#property} method. SessionProperties known to the
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    93
   * implementation may return {@code false} and rely on the implementation to
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    94
   * do the right thing.
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
    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
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    98
   * @param value the value to which the property is to be set. May be
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56832
diff changeset
    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
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   101
   * @throws IllegalStateException if it is not possible to configure the
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   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
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   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
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   107
    if (validate(value)) {
56828
64304e37e9b1 JDK-8188051-branch javadoc updates and added TransactionCompletion.java
lancea
parents: 56824
diff changeset
   108
      return false;
56824
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   109
    }
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   110
    else {
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   111
      throw new IllegalArgumentException(value.toString() + " is invalid");
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   112
    }
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   113
  }
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   114
62e92191354d JDK-8188051-branch latest updates
lancea
parents:
diff changeset
   115
}