src/jdk.incubator.adba/share/classes/jdk/incubator/sql2/Result.java
branchJDK-8188051-branch
changeset 56380 f06946e00a26
child 56397 729f80d0cf31
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 
       
    26 package jdk.incubator.sql2;
       
    27 
       
    28 import java.util.concurrent.CompletionStage;
       
    29 
       
    30 /**
       
    31  * All or part of the result of a database operation (lower case).
       
    32  *
       
    33  * A {@link Result} is valid only for the duration of the call it is passed to. Once
       
    34  * that call has returned, the {@link Result} passed to that call is invalid and any
       
    35  * calls to it throw {@link IllegalStateException}. {@link Result}s are not required to be
       
    36  * thread-safe.
       
    37  *
       
    38  */
       
    39 public interface Result {
       
    40 
       
    41   /**
       
    42    * A {@link Result} that is just a number of rows modified, a {@link Long}.
       
    43    *
       
    44    * Note: It is certainly true that this is not needed; {@link Long} could be used
       
    45    * instead. Seems like there might be a documentational advantage to having
       
    46    * this type. If you don't like it, just mentally replace it with {@link Long}
       
    47    * everywhere it appears.
       
    48    */
       
    49   public static interface Count extends Result {
       
    50 
       
    51     /**
       
    52      *
       
    53      * @return
       
    54      */
       
    55     public long getCount();
       
    56   }
       
    57 
       
    58   /**
       
    59    * A {@link Result} where the components can be retrieved by name. What 
       
    60    * constitutes a name is implementation dependent.
       
    61    *
       
    62    */
       
    63   public static interface ResultMap extends Result {
       
    64 
       
    65     /**
       
    66      * Return the value indicated by the {@code id}. The {@code id} may be either the id for an
       
    67      * OUT parameter marker or for a column. See {@link OutOperation} and
       
    68      * {@link RowOperation}.
       
    69      *
       
    70      * @param <T> the type of the returned value
       
    71      * @param id the name of the column or OUT parameter marker
       
    72      * @param type the value indicated by {@code id} is converted to this type
       
    73      * @return a value of type {@code T}
       
    74      * @throws IllegalArgumentException if id is not the identifier of a value
       
    75      * in this {@link ResultMap}
       
    76      * @throws IllegalStateException if the call that was passed this {@link ResultMap} has
       
    77      * ended
       
    78      * @throws ClassCastException if the returned value cannot be converted to the 
       
    79      * specified type -- ISSUE: Not really a class cast. Maybe a new unchecked exception.
       
    80      */
       
    81     public <T> T get(String id, Class<T> type);
       
    82 
       
    83     /**
       
    84      * Returns a {@code {@link String}[]} that contains the identifiers that reference the
       
    85      * values of this {@link ResultMap} in the same order these values are returned by the
       
    86      * database. A {@code null} value in the array means there is a returned value for
       
    87      * which no identifier was defined. There is no way to retrieve such a
       
    88      * value.
       
    89      *
       
    90      * By default the values in the array are the identifier portion of the out
       
    91      * parameter markers in the SQL. Alternatively the implementation may assign
       
    92      * other identifiers, typically column names or aliases. If there
       
    93      * are values that have no associated identifier the corresponding value in
       
    94      * the array will be null.
       
    95      *
       
    96      * @return an array containing the value identifiers. Not {@code null}.
       
    97      * @throws IllegalStateException if the call that was passed this {@link ResultMap} has
       
    98      * ended
       
    99      */
       
   100     public String[] getIdentifiers();
       
   101   }
       
   102 
       
   103   /**
       
   104    * Used by {@link OutOperation} to expose the out parameters of a call.
       
   105    */
       
   106   public static interface OutParameterMap extends ResultMap {
       
   107   }
       
   108 
       
   109   /**
       
   110    * Used by {@link RowOperation} to expose each row of a row sequence.
       
   111    */
       
   112   public static interface Row extends ResultMap {
       
   113 
       
   114     /**
       
   115      * The count of {@link Row}s in the {@link Row} sequence preceeding this {@link Row}. For the first
       
   116      * row in the Row sequence the {@link rowNumber} is 0.
       
   117      *
       
   118      * @return the count of {@link Row}s in the {@link Row} sequence preceeding this {@link Row}
       
   119      * @throws IllegalStateException if the call that was passed this {@link Result} has
       
   120      * ended
       
   121      */
       
   122     public long rowNumber();
       
   123 
       
   124     /**
       
   125      * Is this the last {@link Row} of the row sequence. If true then the result of the
       
   126      * call that was passed this {@link Row} is the result of the {@link Operation}.
       
   127      * 
       
   128      * @return a {@link java.util.concurrent.CompletionStage} the value of which
       
   129      * will be true iff this the last {@link Row} of a row sequence and false otherwise
       
   130      * @throws IllegalStateException if the call that was passed this {@link Result} has
       
   131      * ended
       
   132      */
       
   133     public CompletionStage<Boolean> isLast();
       
   134 
       
   135     /**
       
   136      * Terminate processing of the rows in this {@link RowOperation}. The result of the
       
   137      * call that was passed this {@link Row} will be the result of the {@link Operation}. No
       
   138      * further rows in the row sequence will be processed. All subsequent rows,
       
   139      * if any, will be ignored. Any rows already fetched will not be processed.
       
   140      * Any rows not yet fetched may or may not be fetched. If fetched they will
       
   141      * not be processed.
       
   142      *
       
   143      * @throws IllegalStateException if the call that was passed this {@link Result} has
       
   144      * ended
       
   145      */
       
   146     public void cancel();
       
   147 
       
   148   }
       
   149 
       
   150 }