src/jdk.incubator.adba/share/classes/jdk/incubator/sql2/DataSourceProperty.java
branchJDK-8188051-branch
changeset 56824 62e92191354d
child 56832 4f7713e6a308
equal deleted inserted replaced
56823:6ba0dbf6a75f 56824:62e92191354d
       
     1 /*
       
     2  * Copyright (c)  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 package jdk.incubator.sql2;
       
    26 
       
    27 /**
       
    28  * An attribute of a {@link DataSource} that can be configured to influence its
       
    29  * behavior. Implementors of this interface define the properties of
       
    30  * {@link DataSource}s. The {@link DataSource.Builder#property} method is used
       
    31  * to set the values of {@link DataSource} properties.
       
    32  *
       
    33  * Implementations must be thread safe.
       
    34  *
       
    35  */
       
    36 public interface DataSourceProperty {
       
    37 
       
    38   /**
       
    39    * Return the name of this {@link DataSourceProperty}.
       
    40    *
       
    41    * @return the name of this {@link DataSourceProperty}
       
    42    */
       
    43   public String name();
       
    44 
       
    45   /**
       
    46    * Return the type of the value of this {@link DataSourceProperty}. Any value
       
    47    * set for this property must be assignable to this type.
       
    48    *
       
    49    * @return the type of the values of this {@link DataSourceProperty}
       
    50    */
       
    51   public Class<?> range();
       
    52 
       
    53   /**
       
    54    * Determine whether a value is valid for this {@link DataSourceProperty}.
       
    55    * Returns {@code true} if {@code value} is valid and {@code false} otherwise.
       
    56    *
       
    57    * @param value a value for this {@link DataSourceProperty}
       
    58    * @return {@code true} iff {@code value} is valid for this
       
    59    * {@link DataSourceProperty}
       
    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. This
       
    67    * has no meaning for user defined properties as the implementation is not
       
    68    * aware of the the existence of the property. Default values are used for
       
    69    * standard and implementation defined properties.
       
    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 DataSourceProperty} is contains sensitive
       
    77    * information such as a password or encryption key.
       
    78    *
       
    79    * @return true iff this is sensitive
       
    80    */
       
    81   public boolean isSensitive();
       
    82 
       
    83   /**
       
    84    * Configure the {@link DataSource as appropriate for the given {@code value} 
       
    85    * of this {@link DataSourceProperty}. This is primarily for the use of user 
       
    86    * defined properties.
       
    87    *
       
    88    * @param ds the {@link DataSource} to configure
       
    89    * @param value the value of this property
       
    90    */
       
    91   public default void configure(DataSource ds, Object value) {
       
    92     // nothing
       
    93   }
       
    94   
       
    95 }