jdk/src/share/classes/javax/sql/rowset/spi/SyncResolver.java
author lancea
Thu, 27 Jun 2013 15:07:56 -0400
changeset 18564 f9db68ff2cbb
parent 18156 edb590d448c5
child 20880 1b610151b316
permissions -rw-r--r--
8017471: Fix JDBC -Xdoclint public errors Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sql.rowset.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.sql.RowSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Defines a framework that allows applications to use a manual decision tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * to decide what should be done when a synchronization conflict occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Although it is not mandatory for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * applications to resolve synchronization conflicts manually, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * framework provides the means to delegate to the application when conflicts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * arise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Note that a conflict is a situation where the <code>RowSet</code> object's original
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * values for a row do not match the values in the data source, which indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * the data source row has been modified since the last synchronization. Note also that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a <code>RowSet</code> object's original values are the values it had just prior to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the last synchronization, which are not necessarily its initial values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <H2>Description of a <code>SyncResolver</code> Object</H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A <code>SyncResolver</code> object is a specialized <code>RowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * that implements the <code>SyncResolver</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * It <b>may</b> operate as either a connected <code>RowSet</code> object (an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * implementation of the <code>JdbcRowSet</code> interface) or a connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>RowSet</code> object (an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>CachedRowSet</code> interface or one of its subinterfaces). For information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * on the subinterfaces, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <a href="../package-summary.html"><code>javax.sql.rowset</code></a> package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * description. The reference implementation for <code>SyncResolver</code> implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the <code>CachedRowSet</code> interface, but other implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * may choose to implement the <code>JdbcRowSet</code> interface to satisfy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * particular needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * After an application has attempted to synchronize a <code>RowSet</code> object with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the data source (by calling the <code>CachedRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * method <code>acceptChanges</code>), and one or more conflicts have been found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * a rowset's <code>SyncProvider</code> object creates an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>SyncResolver</code>. This new <code>SyncResolver</code> object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * the same number of rows and columns as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>RowSet</code> object that was attempting the synchronization. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <code>SyncResolver</code> object contains the values from the data source that caused
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the conflict(s) and <code>null</code> for all other values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * In addition, it contains information about each conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <H2>Getting and Using a <code>SyncResolver</code> Object</H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * When the method <code>acceptChanges</code> encounters conflicts, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <code>SyncProvider</code> object creates a <code>SyncProviderException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * object and sets it with the new <code>SyncResolver</code> object. The method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>acceptChanges</code> will throw this exception, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the application can then catch and use to retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>SyncResolver</code> object it contains. The following code snippet uses the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <code>SyncProviderException</code> method <code>getSyncResolver</code> to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the <code>SyncResolver</code> object <i>resolver</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <PRE>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
    84
 * {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *     } catch (SyncProviderException spe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *         SyncResolver resolver = spe.getSyncResolver();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *     ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *     }
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
    89
 *
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
    90
 * }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * With <i>resolver</i> in hand, an application can use it to get the information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * it contains about the conflict or conflicts.  A <code>SyncResolver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * such as <i>resolver</i> keeps
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * track of the conflicts for each row in which there is a conflict.  It also places a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * lock on the table or tables affected by the rowset's command so that no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * conflicts can occur while the current conflicts are being resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * The following kinds of information can be obtained from a <code>SyncResolver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <P>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   103
 *    <h3>What operation was being attempted when a conflict occurred</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * The <code>SyncProvider</code> interface defines four constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * describing states that may occur. Three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * constants describe the type of operation (update, delete, or insert) that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <code>RowSet</code> object was attempting to perform when a conflict was discovered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * and the fourth indicates that there is no conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * These constants are the possible return values when a <code>SyncResolver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * calls the method <code>getStatus</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <PRE>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   112
 *     {@code int operation = resolver.getStatus(); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <P>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   115
 *    <h3>The value in the data source that caused a conflict</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * A conflict exists when a value that a <code>RowSet</code> object has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * and is attempting to write to the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * has also been changed in the data source since the last synchronization.  An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * application can call the <code>SyncResolver</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <code>getConflictValue</code > to retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * value in the data source that is the cause of the conflict because the values in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <code>SyncResolver</code> object are the conflict values from the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *     java.lang.Object conflictValue = resolver.getConflictValue(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * Note that the column in <i>resolver</i> can be designated by the column number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * as is done in the preceding line of code, or by the column name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * With the information retrieved from the methods <code>getStatus</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <code>getConflictValue</code>, the application may make a determination as to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * which value should be persisted in the data source. The application then calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <code>SyncResolver</code> method <code>setResolvedValue</code>, which sets the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * to be persisted in the <code>RowSet</code> object and also in the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *     resolver.setResolvedValue("DEPT", 8390426);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * In the preceding line of code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * the column name designates the column in the <code>RowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * that is to be set with the given value. The column number can also be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * designate the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * An application calls the method <code>setResolvedValue</code> after it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * resolved all of the conflicts in the current conflict row and repeats this process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * for each conflict row in the <code>SyncResolver</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <H2>Navigating a <code>SyncResolver</code> Object</H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * Because a <code>SyncResolver</code> object is a <code>RowSet</code> object, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * application can use all of the <code>RowSet</code> methods for moving the cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * to navigate a <code>SyncResolver</code> object. For example, an application can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * use the <code>RowSet</code> method <code>next</code> to get to each row and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * call the <code>SyncResolver</code> method <code>getStatus</code> to see if the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * contains a conflict.  In a row with one or more conflicts, the application can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * iterate through the columns to find any non-null values, which will be the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * from the data source that are in conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * To make it easier to navigate a <code>SyncResolver</code> object, especially when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * there are large numbers of rows with no conflicts, the <code>SyncResolver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * interface defines the methods <code>nextConflict</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <code>previousConflict</code>, which move only to rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * that contain at least one conflict value. Then an application can call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <code>SyncResolver</code> method <code>getConflictValue</code>, supplying it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * with the column number, to get the conflict value itself. The code fragment in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * next section gives an example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * <H2>Code Example</H2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * The following code fragment demonstrates how a disconnected <code>RowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * object <i>crs</i> might attempt to synchronize itself with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * underlying data source and then resolve the conflicts. In the <code>try</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * block, <i>crs</i> calls the method <code>acceptChanges</code>, passing it the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <code>Connection</code> object <i>con</i>.  If there are no conflicts, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * changes in <i>crs</i> are simply written to the data source.  However, if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * is a conflict, the method <code>acceptChanges</code> throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <code>SyncProviderException</code> object, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <code>catch</code> block takes effect.  In this example, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * illustrates one of the many ways a <code>SyncResolver</code> object can be used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * the <code>SyncResolver</code> method <code>nextConflict</code> is used in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * <code>while</code> loop. The loop will end when <code>nextConflict</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <code>false</code>, which will occur when there are no more conflict rows in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <code>SyncResolver</code> object <i>resolver</i>. In This particular code fragment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * <i>resolver</i> looks for rows that have update conflicts (rows with the status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * <code>SyncResolver.UPDATE_ROW_CONFLICT</code>), and the rest of this code fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * executes only for rows where conflicts occurred because <i>crs</i> was attempting an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * After the cursor for <i>resolver</i> has moved to the next conflict row that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * has an update conflict, the method <code>getRow</code> indicates the number of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * current row, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * the cursor for the <code>CachedRowSet</code> object <i>crs</i> is moved to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * the comparable row in <i>crs</i>. By iterating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * through the columns of that row in both <i>resolver</i> and <i>crs</i>, the conflicting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * values can be retrieved and compared to decide which one should be persisted. In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * code fragment, the value in <i>crs</i> is the one set as the resolved value, which means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * that it will be used to overwrite the conflict value in the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   198
 * <PRE>
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   199
 * {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *         crs.acceptChanges(con);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *     } catch (SyncProviderException spe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *         SyncResolver resolver = spe.getSyncResolver();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   208
 *         Object crsValue;  // value in the RowSet object
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   209
 *         Object resolverValue:  // value in the SyncResolver object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *         Object resolvedValue:  // value to be persisted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *         while(resolver.nextConflict())  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *             if(resolver.getStatus() == SyncResolver.UPDATE_ROW_CONFLICT)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *                 int row = resolver.getRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *                 crs.absolute(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *                 int colCount = crs.getMetaData().getColumnCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *                 for(int j = 1; j <= colCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *                     if (resolver.getConflictValue(j) != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *                         crsValue = crs.getObject(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 *                         resolverValue = resolver.getConflictValue(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 *                         . . .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 *                         // compare crsValue and resolverValue to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *                         // which should be the resolved value (the value to persist)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 *                         resolvedValue = crsValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 *                         resolver.setResolvedValue(j, resolvedValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 *              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *      }
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
   233
 * }</PRE>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * @author  Jonathan Bruce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
public interface SyncResolver extends RowSet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Indicates that a conflict occurred while the <code>RowSet</code> object was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * attempting to update a row in the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The values in the data source row to be updated differ from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>RowSet</code> object's original values for that row, which means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the row in the data source has been updated or deleted since the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     public static int UPDATE_ROW_CONFLICT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Indicates that a conflict occurred while the <code>RowSet</code> object was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * attempting to delete a row in the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * The values in the data source row to be updated differ from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <code>RowSet</code> object's original values for that row, which means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * the row in the data source has been updated or deleted since the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public static int DELETE_ROW_CONFLICT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    * Indicates that a conflict occurred while the <code>RowSet</code> object was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    * attempting to insert a row into the data source.  This means that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    * row with the same primary key as the row to be inserted has been inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    * into the data source since the last synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public static int INSERT_ROW_CONFLICT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Indicates that <b>no</b> conflict occured while the <code>RowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * was attempting to update, delete or insert a row in the data source. The values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the <code>SyncResolver</code> will contain <code>null</code> values only as an indication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * that no information in pertitent to the conflict resolution in this row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public static int NO_ROW_CONFLICT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Retrieves the conflict status of the current row of this <code>SyncResolver</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * which indicates the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * the <code>RowSet</code> object was attempting when the conflict occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return one of the following constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         <code>SyncResolver.UPDATE_ROW_CONFLICT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *         <code>SyncResolver.DELETE_ROW_CONFLICT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *         <code>SyncResolver.INSERT_ROW_CONFLICT</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *         <code>SyncResolver.NO_ROW_CONFLICT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public int getStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Retrieves the value in the designated column in the current row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <code>SyncResolver</code> object, which is the value in the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * that caused a conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param index an <code>int</code> designating the column in this row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *        <code>SyncResolver</code> object from which to retrieve the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *        causing a conflict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @return the value of the designated column in the current row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *         <code>SyncResolver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @throws SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public Object getConflictValue(int index) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Retrieves the value in the designated column in the current row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <code>SyncResolver</code> object, which is the value in the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * that caused a conflict.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param columnName a <code>String</code> object designating the column in this row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *        <code>SyncResolver</code> object from which to retrieve the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *        causing a conflict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return the value of the designated column in the current row of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *         <code>SyncResolver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public Object getConflictValue(String columnName) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Sets <i>obj</i> as the value in column <i>index</i> in the current row of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <code>RowSet</code> object that is being synchronized. <i>obj</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * is set as the value in the data source internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param index an <code>int</code> giving the number of the column into which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *        set the value to be persisted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param obj an <code>Object</code> that is the value to be set in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *        <code>RowSet</code> object and persisted in the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @throws SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void setResolvedValue(int index, Object obj) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Sets <i>obj</i> as the value in column <i>columnName</i> in the current row of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>RowSet</code> object that is being synchronized. <i>obj</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * is set as the value in the data source internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param columnName a <code>String</code> object giving the name of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *        into which to set the value to be persisted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param obj an <code>Object</code> that is the value to be set in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *        <code>RowSet</code> object and persisted in the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public void setResolvedValue(String columnName, Object obj) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Moves the cursor down from its current position to the next row that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * a conflict value. A <code>SyncResolver</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * cursor is initially positioned before the first conflict row; the first call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * method <code>nextConflict</code> makes the first conflict row the current row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * the second call makes the second conflict row the current row, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * A call to the method <code>nextConflict</code> will implicitly close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * an input stream if one is open and will clear the <code>SyncResolver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * object's warning chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return <code>true</code> if the new current row is valid; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *         if there are no more rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @throws SQLException if a database access error occurs or the result set type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *     is <code>TYPE_FORWARD_ONLY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public boolean nextConflict() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Moves the cursor up from its current position to the previous conflict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * row in this <code>SyncResolver</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * A call to the method <code>previousConflict</code> will implicitly close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * an input stream if one is open and will clear the <code>SyncResolver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * object's warning chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @return <code>true</code> if the cursor is on a valid row; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *     if it is off the result set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @throws SQLException if a database access error occurs or the result set type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *     is <code>TYPE_FORWARD_ONLY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public boolean previousConflict() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}