1 /* 2 * Copyright (c) 2003, 2019, 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 javax.sql.rowset.spi; 27 28 import javax.sql.*; 29 30 /** 31 * The synchronization mechanism that provides reader/writer capabilities for 32 * disconnected <code>RowSet</code> objects. 33 * A <code>SyncProvider</code> implementation is a class that extends the 34 * <code>SyncProvider</code> abstract class. 35 * <P> 36 * A <code>SyncProvider</code> implementation is 37 * identified by a unique ID, which is its fully qualified class name. 38 * This name must be registered with the 39 * <code>SyncFactory</code> SPI, thus making the implementation available to 40 * all <code>RowSet</code> implementations. 41 * The factory mechanism in the reference implementation uses this name to instantiate 42 * the implementation, which can then provide a <code>RowSet</code> object with its 43 * reader (a <code>javax.sql.RowSetReader</code> object) and its writer (a 44 * <code>javax.sql.RowSetWriter</code> object). 45 * <P> 46 * The Jdbc <code>RowSet</code> Implementations specification provides two 47 * reference implementations of the <code>SyncProvider</code> abstract class: 48 * <code>RIOptimisticProvider</code> and <code>RIXMLProvider</code>. 49 * The <code>RIOptimisticProvider</code> can set any <code>RowSet</code> 50 * implementation with a <code>RowSetReader</code> object and a 51 * <code>RowSetWriter</code> object. However, only the <code>RIXMLProvider</code> 52 * implementation can set an <code>XmlReader</code> object and an 53 * <code>XmlWriter</code> object. A <code>WebRowSet</code> object uses the 54 * <code>XmlReader</code> object to read data in XML format to populate itself with that 55 * data. It uses the <code>XmlWriter</code> object to write itself to a stream or 56 * <code>java.io.Writer</code> object in XML format. 57 * 58 * <h2>1.0 Naming Convention for Implementations</h2> 59 * As a guide to naming <code>SyncProvider</code> 60 * implementations, the following should be noted: 61 * <UL> 62 * <li>The name for a <code>SyncProvider</code> implementation 63 * is its fully qualified class name. 64 * <li>It is recommended that vendors supply a 65 * <code>SyncProvider</code> implementation in a package named <code>providers</code>. 66 * </UL> 67 * <p> 68 * For instance, if a vendor named Fred, Inc. offered a 69 * <code>SyncProvider</code> implementation, you could have the following: 70 * <PRE> 71 * Vendor name: Fred, Inc. 72 * Domain name of vendor: com.fred 73 * Package name: com.fred.providers 74 * SyncProvider implementation class name: HighAvailabilityProvider 75 * 76 * Fully qualified class name of SyncProvider implementation: 77 * com.fred.providers.HighAvailabilityProvider 78 * </PRE> 79 * <P> 80 * The following line of code uses the fully qualified name to register 81 * this implementation with the <code>SyncFactory</code> static instance. 82 * <PRE> 83 * SyncFactory.registerProvider( 84 * "com.fred.providers.HighAvailabilityProvider"); 85 * </PRE> 86 * <P> 87 * The default <code>SyncProvider</code> object provided with the reference 88 * implementation uses the following name: 89 * <pre> 90 * com.sun.rowset.providers.RIOptimisticProvider 91 * </pre> 92 * <p> 93 * Vendors should refer to the reference implementation synchronization 94 * providers for additional guidance on how to implement a new 95 * <code>SyncProvider</code> implementation. 96 * 97 * <h2>2.0 How a <code>RowSet</code> Object Gets Its Provider</h2> 98 * 99 * A disconnected <code>Rowset</code> object may get access to a 100 * <code>SyncProvider</code> object in one of the following two ways: 101 * <UL> 102 * <LI>Using a constructor<BR> 103 * <PRE> 104 * CachedRowSet crs = new CachedRowSet( 105 * "com.fred.providers.HighAvailabilitySyncProvider"); 106 * </PRE> 107 * <LI>Using the <code>setSyncProvider</code> method 108 * <PRE> 109 * CachedRowSet crs = new CachedRowSet(); 110 * crs.setSyncProvider("com.fred.providers.HighAvailabilitySyncProvider"); 111 * </PRE> 112 113 * </UL> 114 * <p> 115 * By default, the reference implementations of the <code>RowSet</code> synchronization 116 * providers are always available to the Java platform. 117 * If no other pluggable synchronization providers have been correctly 118 * registered, the <code>SyncFactory</code> will automatically generate 119 * an instance of the default <code>SyncProvider</code> reference implementation. 120 * Thus, in the preceding code fragment, if no implementation named 121 * <code>com.fred.providers.HighAvailabilitySyncProvider</code> has been 122 * registered with the <code>SyncFactory</code> instance, <i>crs</i> will be 123 * assigned the default provider in the reference implementation, which is 124 * <code>com.sun.rowset.providers.RIOptimisticProvider</code>. 125 * 126 * <h2>3.0 Violations and Synchronization Issues</h2> 127 * If an update between a disconnected <code>RowSet</code> object 128 * and a data source violates 129 * the original query or the underlying data source constraints, this will 130 * result in undefined behavior for all disconnected <code>RowSet</code> implementations 131 * and their designated <code>SyncProvider</code> implementations. 132 * Not defining the behavior when such violations occur offers greater flexibility 133 * for a <code>SyncProvider</code> 134 * implementation to determine its own best course of action. 135 * <p> 136 * A <code>SyncProvider</code> implementation 137 * may choose to implement a specific handler to 138 * handle a subset of query violations. 139 * However if an original query violation or a more general data source constraint 140 * violation is not handled by the <code>SyncProvider</code> implementation, 141 * all <code>SyncProvider</code> 142 * objects must throw a <code>SyncProviderException</code>. 143 * 144 * <h2>4.0 Updatable SQL VIEWs</h2> 145 * It is possible for any disconnected or connected <code>RowSet</code> object to be populated 146 * from an SQL query that is formulated originally from an SQL <code>VIEW</code>. 147 * While in many cases it is possible for an update to be performed to an 148 * underlying view, such an update requires additional metadata, which may vary. 149 * The <code>SyncProvider</code> class provides two constants to indicate whether 150 * an implementation supports updating an SQL <code>VIEW</code>. 151 * <ul> 152 * <li><code><b>NONUPDATABLE_VIEW_SYNC</b></code> - Indicates that a <code>SyncProvider</code> 153 * implementation does not support synchronization with an SQL <code>VIEW</code> as the 154 * underlying source of data for the <code>RowSet</code> object. 155 * <li><code><b>UPDATABLE_VIEW_SYNC</b></code> - Indicates that a 156 * <code>SyncProvider</code> implementation 157 * supports synchronization with an SQL <code>VIEW</code> as the underlying source 158 * of data. 159 * </ul> 160 * <P> 161 * The default is for a <code>RowSet</code> object not to be updatable if it was 162 * populated with data from an SQL <code>VIEW</code>. 163 * 164 * <h2>5.0 <code>SyncProvider</code> Constants</h2> 165 * The <code>SyncProvider</code> class provides three sets of constants that 166 * are used as return values or parameters for <code>SyncProvider</code> methods. 167 * <code>SyncProvider</code> objects may be implemented to perform synchronization 168 * between a <code>RowSet</code> object and its underlying data source with varying 169 * degrees of care. The first group of constants indicate how synchronization 170 * is handled. For example, <code>GRADE_NONE</code> indicates that a 171 * <code>SyncProvider</code> object will not take any care to see what data is 172 * valid and will simply write the <code>RowSet</code> data to the data source. 173 * <code>GRADE_MODIFIED_AT_COMMIT</code> indicates that the provider will check 174 * only modified data for validity. Other grades check all data for validity 175 * or set locks when data is modified or loaded. 176 * <OL> 177 * <LI>Constants to indicate the synchronization grade of a 178 * <code>SyncProvider</code> object 179 * <UL> 180 * <LI>SyncProvider.GRADE_NONE 181 * <LI>SyncProvider.GRADE_MODIFIED_AT_COMMIT 182 * <LI>SyncProvider.GRADE_CHECK_ALL_AT_COMMIT 183 * <LI>SyncProvider.GRADE_LOCK_WHEN_MODIFIED 184 * <LI>SyncProvider.GRADE_LOCK_WHEN_LOADED 185 * </UL> 186 * <LI>Constants to indicate what locks are set on the data source 187 * <UL> 188 * <LI>SyncProvider.DATASOURCE_NO_LOCK 189 * <LI>SyncProvider.DATASOURCE_ROW_LOCK 190 * <LI>SyncProvider.DATASOURCE_TABLE_LOCK 191 * <LI>SyncProvider.DATASOURCE_DB_LOCK 192 * </UL> 193 * <LI>Constants to indicate whether a <code>SyncProvider</code> object can 194 * perform updates to an SQL <code>VIEW</code> <BR> 195 * These constants are explained in the preceding section (4.0). 196 * <UL> 197 * <LI>SyncProvider.UPDATABLE_VIEW_SYNC 198 * <LI>SyncProvider.NONUPDATABLE_VIEW_SYNC 199 * </UL> 200 * </OL> 201 * 202 * @author Jonathan Bruce 203 * @see javax.sql.rowset.spi.SyncFactory 204 * @see javax.sql.rowset.spi.SyncFactoryException 205 * @since 1.5 206 */ 207 public abstract class SyncProvider { 208 209 /** 210 * Creates a default <code>SyncProvider</code> object. 211 */ SyncProvider()212 public SyncProvider() { 213 } 214 215 /** 216 * Returns the unique identifier for this <code>SyncProvider</code> object. 217 * 218 * @return a <code>String</code> object with the fully qualified class name of 219 * this <code>SyncProvider</code> object 220 */ getProviderID()221 public abstract String getProviderID(); 222 223 /** 224 * Returns a <code>javax.sql.RowSetReader</code> object, which can be used to 225 * populate a <code>RowSet</code> object with data. 226 * 227 * @return a <code>javax.sql.RowSetReader</code> object 228 */ getRowSetReader()229 public abstract RowSetReader getRowSetReader(); 230 231 /** 232 * Returns a <code>javax.sql.RowSetWriter</code> object, which can be 233 * used to write a <code>RowSet</code> object's data back to the 234 * underlying data source. 235 * 236 * @return a <code>javax.sql.RowSetWriter</code> object 237 */ getRowSetWriter()238 public abstract RowSetWriter getRowSetWriter(); 239 240 /** 241 * Returns a constant indicating the 242 * grade of synchronization a <code>RowSet</code> object can expect from 243 * this <code>SyncProvider</code> object. 244 * 245 * @return an int that is one of the following constants: 246 * SyncProvider.GRADE_NONE, 247 * SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT, 248 * SyncProvider.GRADE_CHECK_ALL_AT_COMMIT, 249 * SyncProvider.GRADE_LOCK_WHEN_MODIFIED, 250 * SyncProvider.GRADE_LOCK_WHEN_LOADED 251 */ getProviderGrade()252 public abstract int getProviderGrade(); 253 254 255 /** 256 * Sets a lock on the underlying data source at the level indicated by 257 * <i>datasource_lock</i>. This should cause the 258 * <code>SyncProvider</code> to adjust its behavior by increasing or 259 * decreasing the level of optimism it provides for a successful 260 * synchronization. 261 * 262 * @param datasource_lock one of the following constants indicating the severity 263 * level of data source lock required: 264 * <pre> 265 * SyncProvider.DATASOURCE_NO_LOCK, 266 * SyncProvider.DATASOURCE_ROW_LOCK, 267 * SyncProvider.DATASOURCE_TABLE_LOCK, 268 * SyncProvider.DATASOURCE_DB_LOCK, 269 * </pre> 270 * @throws SyncProviderException if an unsupported data source locking level 271 * is set. 272 * @see #getDataSourceLock 273 */ setDataSourceLock(int datasource_lock)274 public abstract void setDataSourceLock(int datasource_lock) 275 throws SyncProviderException; 276 277 /** 278 * Returns the current data source lock severity level active in this 279 * <code>SyncProvider</code> implementation. 280 * 281 * @return a constant indicating the current level of data source lock 282 * active in this <code>SyncProvider</code> object; 283 * one of the following: 284 * <pre> 285 * SyncProvider.DATASOURCE_NO_LOCK, 286 * SyncProvider.DATASOURCE_ROW_LOCK, 287 * SyncProvider.DATASOURCE_TABLE_LOCK, 288 * SyncProvider.DATASOURCE_DB_LOCK 289 * </pre> 290 * @throws SyncProviderException if an error occurs determining the data 291 * source locking level. 292 * @see #setDataSourceLock 293 294 */ getDataSourceLock()295 public abstract int getDataSourceLock() 296 throws SyncProviderException; 297 298 /** 299 * Returns whether this <code>SyncProvider</code> implementation 300 * can perform synchronization between a <code>RowSet</code> object 301 * and the SQL <code>VIEW</code> in the data source from which 302 * the <code>RowSet</code> object got its data. 303 * 304 * @return an <code>int</code> saying whether this <code>SyncProvider</code> 305 * object supports updating an SQL <code>VIEW</code>; one of the 306 * following: 307 * SyncProvider.UPDATABLE_VIEW_SYNC, 308 * SyncProvider.NONUPDATABLE_VIEW_SYNC 309 */ supportsUpdatableView()310 public abstract int supportsUpdatableView(); 311 312 /** 313 * Returns the release version of this <code>SyncProvider</code> instance. 314 * 315 * @return a <code>String</code> detailing the release version of the 316 * <code>SyncProvider</code> implementation 317 */ getVersion()318 public abstract String getVersion(); 319 320 /** 321 * Returns the vendor name of this <code>SyncProvider</code> instance 322 * 323 * @return a <code>String</code> detailing the vendor name of this 324 * <code>SyncProvider</code> implementation 325 */ getVendor()326 public abstract String getVendor(); 327 328 /* 329 * Standard description of synchronization grades that a SyncProvider 330 * could provide. 331 */ 332 333 /** 334 * Indicates that no synchronization with the originating data source is 335 * provided. A <code>SyncProvider</code> 336 * implementation returning this grade will simply attempt to write 337 * updates in the <code>RowSet</code> object to the underlying data 338 * source without checking the validity of any data. 339 * 340 */ 341 public static final int GRADE_NONE = 1; 342 343 /** 344 * Indicates a low level optimistic synchronization grade with 345 * respect to the originating data source. 346 * 347 * A <code>SyncProvider</code> implementation 348 * returning this grade will check only rows that have changed. 349 * 350 */ 351 public static final int GRADE_CHECK_MODIFIED_AT_COMMIT = 2; 352 353 /** 354 * Indicates a high level optimistic synchronization grade with 355 * respect to the originating data source. 356 * 357 * A <code>SyncProvider</code> implementation 358 * returning this grade will check all rows, including rows that have not 359 * changed. 360 */ 361 public static final int GRADE_CHECK_ALL_AT_COMMIT = 3; 362 363 /** 364 * Indicates a pessimistic synchronization grade with 365 * respect to the originating data source. 366 * 367 * A <code>SyncProvider</code> 368 * implementation returning this grade will lock the row in the originating 369 * data source. 370 */ 371 public static final int GRADE_LOCK_WHEN_MODIFIED = 4; 372 373 /** 374 * Indicates the most pessimistic synchronization grade with 375 * respect to the originating 376 * data source. A <code>SyncProvider</code> 377 * implementation returning this grade will lock the entire view and/or 378 * table affected by the original statement used to populate a 379 * <code>RowSet</code> object. 380 */ 381 public static final int GRADE_LOCK_WHEN_LOADED = 5; 382 383 /** 384 * Indicates that no locks remain on the originating data source. This is the default 385 * lock setting for all <code>SyncProvider</code> implementations unless 386 * otherwise directed by a <code>RowSet</code> object. 387 */ 388 public static final int DATASOURCE_NO_LOCK = 1; 389 390 /** 391 * Indicates that a lock is placed on the rows that are touched by the original 392 * SQL statement used to populate the <code>RowSet</code> object 393 * that is using this <code>SyncProvider</code> object. 394 */ 395 public static final int DATASOURCE_ROW_LOCK = 2; 396 397 /** 398 * Indicates that a lock is placed on all tables that are touched by the original 399 * SQL statement used to populate the <code>RowSet</code> object 400 * that is using this <code>SyncProvider</code> object. 401 */ 402 public static final int DATASOURCE_TABLE_LOCK = 3; 403 404 /** 405 * Indicates that a lock is placed on the entire data source that is the source of 406 * data for the <code>RowSet</code> object 407 * that is using this <code>SyncProvider</code> object. 408 */ 409 public static final int DATASOURCE_DB_LOCK = 4; 410 411 /** 412 * Indicates that a <code>SyncProvider</code> implementation 413 * supports synchronization between a <code>RowSet</code> object and 414 * the SQL <code>VIEW</code> used to populate it. 415 */ 416 public static final int UPDATABLE_VIEW_SYNC = 5; 417 418 /** 419 * Indicates that a <code>SyncProvider</code> implementation 420 * does <B>not</B> support synchronization between a <code>RowSet</code> 421 * object and the SQL <code>VIEW</code> used to populate it. 422 */ 423 public static final int NONUPDATABLE_VIEW_SYNC = 6; 424 } 425