src/java.sql/share/classes/java/sql2/SqlRef.java
branchJDK-8188051-branch
changeset 56380 f06946e00a26
parent 56373 1f76a5f8e999
child 56381 653b066f4a88
equal deleted inserted replaced
56373:1f76a5f8e999 56380:f06946e00a26
     1 /*
       
     2  * Copyright (c)  2017, 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 java.sql2;
       
    26 
       
    27 import java.util.concurrent.CompletionStage;
       
    28 
       
    29 /**
       
    30  *
       
    31  * @param <T>
       
    32  */
       
    33 public interface SqlRef<T> {
       
    34   
       
    35   /**
       
    36    * Return the name of SQL type of the referent of this SQL REF.
       
    37    * 
       
    38    * ISSUE: Oracle Database JDBC driver may do a round trip for this. Is this
       
    39    * that heavy in other databases?
       
    40    * 
       
    41    * @return
       
    42    */
       
    43   public String getReferentTypeName();
       
    44   
       
    45   /**
       
    46    * Create and return an Operation that will fetch the value of the REF from
       
    47    * the database. The value of the Operation is the value of the REF.
       
    48    *
       
    49    * @return an Operation that will fetch the referent of this SqlRef
       
    50    */
       
    51   public Operation<T> fetchOperation();
       
    52   
       
    53   /**
       
    54    * Submit an Operation that will fetch the value of the REF in the database.
       
    55    *
       
    56    * @return a Future that will complete when the submitted Operation completes.
       
    57    * The value of the Future is the value of the REF.
       
    58    */
       
    59   public default CompletionStage<T> fetch() {
       
    60     return fetchOperation().submit().getCompletionStage();
       
    61   }
       
    62   
       
    63   /**
       
    64    * Create and return an Operation that will set the value of the REF in the
       
    65    * database.
       
    66    *
       
    67    * @param value
       
    68    * @return an Operation that will store the new referent into the REF
       
    69    */
       
    70   public Operation<Void> storeOperation(T value);
       
    71   
       
    72   /**
       
    73    * Submit an Operation that will store the new value of the referent into
       
    74    * the REF in the database.
       
    75    *
       
    76    * @param value
       
    77    * @return a Future that will complete when the submitted Operation completes.
       
    78    */
       
    79   public default CompletionStage<Void> store(T value) {
       
    80     return storeOperation(value).submit().getCompletionStage();
       
    81   }
       
    82 }