<div> JavaScript is disabled on your browser.
Skip navigation links
Java™ Platform
Standard Ed. 8
compact3

Package javax.sql.rowset.spi

三分之一方供应商在其执行同步提供程序中使用的标准类和接口。

See: 描述

Package javax.sql.rowset.spi Description

三分之一方供应商在其执行同步提供程序中使用的标准类和接口。这些类和接口被称为服务提供者接口(SPI)。一个供应商可能实施包括JDBC的网页,列出可用的 SyncProvider实现发送电子邮件 jdbc@sun.com。这样做有助于使开发人员意识到实现。使一个 RowSet对象使用的一个实现,供应商必须与 SyncFactory独生子女登记。(看到一个完整的解释的注册过程和命名约定来使用。 SyncProvider类评论)

表的内容

1.0 Package Specification

The following classes and interfaces make up the javax.sql.rowset.spi package:

  • SyncFactory
  • SyncProvider
  • SyncFactoryException
  • SyncProviderException
  • SyncResolver
  • XmlReader
  • XmlWriter
  • TransactionalWriter
The following interfaces, in the javax.sql package, are also part of the SPI:
  • RowSetReader
  • RowSetWriter

A SyncProvider implementation provides a disconnected RowSet object with the mechanisms for reading data into it and for writing data that has been modified in it back to the underlying data source. A reader, a RowSetReader or XMLReader object, reads data into a RowSet object when the CachedRowSet methods execute or populate are called. A writer, a RowSetWriter or XMLWriter object, writes changes back to the underlying data source when the CachedRowSet method acceptChanges is called.

The process of writing changes in a RowSet object to its data source is known as synchronization. The SyncProvider implementation that a RowSet object is using determines the level of synchronization that the RowSet object's writer uses. The various levels of synchronization are referred to as grades.

The lower grades of synchronization are known as optimistic concurrency levels because they optimistically assume that there will be no conflicts or very few conflicts. A conflict exists when the same data modified in the RowSet object has also been modified in the data source. Using the optimistic concurrency model means that if there is a conflict, modifications to either the data source or the RowSet object will be lost.

Higher grades of synchronization are called pessimistic because they assume that others will be accessing the data source and making modifications. These grades set varying levels of locks to increase the chances that no conflicts occur.

The lowest level of synchronization is simply writing any changes made to the RowSet object to its underlying data source. The writer does nothing to check for conflicts. If there is a conflict and the data source values are overwritten, the changes other parties have made by to the data source are lost.

The RIXMLProvider implementation uses the lowest level of synchronization and just writes RowSet changes to the data source. This is true because typically XML data sources do not enable transaction techniques for maintaining the integrity of data. However, specific standards groups have considered offering XML-based synchronization. For details, see


     http://www.syncml.org

对于下一个层次,作家检查,看看是否有任何冲突,如果有,它不写任何东西给数据源。这种并发的问题是,如果另一方已经修改了相应的数据源中的数据由于RowSet对象获得的数据,对RowSet对象的更改都将丢失。的RIOptimisticProvider实现使用这一级别的同步。

在更高级别的同步,被称为悲观的并发性,笔者采取步骤,以避免冲突,通过设置锁。设置锁可以在单行上设置一个锁定,以设置一个表或整个数据源的锁。同步的水平,因此是一个折衷的用户同时访问数据源的能力和作家的能力来保持数据的RowSet对象和数据源同步。

这是一个要求所有断开的RowSet对象(CachedRowSetFilteredRowSetJoinRowSet,和WebRowSet对象)从SyncFactory机制获得SyncProvider对象。

参考实现(RI)提供了两个同步提供者。

这些 SyncProvider实现捆绑的参考实现,这使得他们总是可以 RowSet实现。 SyncProvider实现使自己可以通过和 SyncFactory单独注册。当一个 RowSet对象请求的供应商,通过指定它在构造函数或作为参数的方法的 CachedRowSet setSyncProviderSyncFactory单检查是否要求供应商已注册了。如果有,那 SyncFactory创建它的实例并将其传递给请求 RowSet对象。如果 SyncProvider实现指定尚未注册, SyncFactory独生子女的原因 SyncFactoryException对象被。如果没有指定的供应商, SyncFactory单将创建默认的提供程序实现, RIOptimisticProvider实例,并把它传递给请求 RowSet对象。

如果不指定WebRowSet对象的构造函数中的供应商,SyncFactory会给RIOptimisticProvider实例。然而,对于WebRowSet构造函数来设置供应商的RIXMLProvider,读和写在XML格式的RowSet对象。

详情见SyncProvider类规范。

供应商可能发展同步的水平可能有SyncProvider实施,从而RowSet对象选择的同步机制。供应商可以通过与甲骨文公司在jdbc@sun.com注册完全限定名称使其实现有效。这个过程将在下面进一步详细讨论。

2.0 Service Provider Interface Architecture

  • 3.0 SyncProvider Implementer's Guide

      3.1 Requirements

      A compliant SyncProvider implementation that is fully pluggable into the SyncFactory must extend and implement all abstract methods in the SyncProvider类。此外,实施必须确定等级,在类定义中定义SyncProvider锁定和可更新视图的能力。一个或一个以上的SyncProvider描述标准必须支持。预计供应商实现将提供一系列的等级,锁定,并可更新视图的能力。

      此外,该SyncProvider命名约定必须随后在SyncProvider类描述详细。

      3.2个等级

      JSR 114中定义的同步SyncProvider对象可以提供一个断开的RowSet物体质量的等级设置。这些成绩都列出从最低的服务质量到最高。

      • grade_none与原始数据源没有同步设置。一个SyncProvider实现返回这个等级会尝试写任何数据,在RowSet对象改为基础数据源,无论是在覆盖。没有尝试将原始值与当前值进行比较,以查看是否存在冲突。是的RIXMLProvider这个年级实施。

      • grade_check_modified_at_commit -一个低年级的乐观同步。一个SyncProvider实现返回这个档次的检查,最后的同步方式下电流同步更改的行的冲突。在原始数据源已被修改的任何更改将不会反映在断开RowSet对象。如果没有冲突,在RowSet对象的更改将被写入到数据源。如果有冲突,没有任何变化是书面的。的RIOptimisticProvider实现使用这种等级。

      • grade_check_all_at_commit -一个高品位的乐观同步。一个SyncProvider实现返回这个年级将检查所有的行,包括未在断开RowSet对象更改的行。这样,在基础数据源行的任何变更将反映在断开RowSet对象当同步成功完成。

      • grade_lock_when_modified -悲观级同步。SyncProvider实现返回这个等级将锁定排在原始数据源对应的排在RowSet对象改变的可能性减少其他进程的数据源中的修改相同的数据。

      • grade_lock_when_loaded更悲观的同步年级。一个SyncProvider实现返回这个级别将锁定整个表的查看和/或用来填充RowSet对象原始查询的影响。

      3.3把锁

      JSR 114定义了一组常量指定的任何锁是否已被放置在一个RowSet对象的基础数据源,如果是这样,在构建锁放置。这些锁将保持数据源而RowSet对象从数据源断开。

      这些常数应该被认为等级常数互补。对于大多数等级设置的默认设置,不需要数据源时保持一个RowSet锁对象从数据源断开。成绩GRADE_LOCK_WHEN_MODIFIEDGRADE_LOCK_WHEN_LOADED允许断开连接的RowSet对象来锁定程度的细粒度的控制。

      • datasource_no_lock没有锁保持原始数据源。这是默认的锁定所有SyncProvider实现设置,除非有RowSet对象。

      • datasource_row_lock -锁放置在被用来填充RowSet对象原始SQL查询摸排。

      • datasource_table_lock -锁放置在所有表的查询,用于填充RowSet对象感动。

      • datasource_db_lock锁上放置的RowSet对象使用整个数据源。

      3.4可更新的视图

      一个RowSet对象可能从一个SQL VIEW数据。以下常量指示SyncProvider对象可以更新表中的数据或图表,进而得到了VIEW

      • updatable_view_sync表明SyncProvider实现支持同步表或表的SQL VIEW用来填充一一RowSet对象派生。

      • nonupdatable_view_sync表明SyncProvider不实现支持同步表或表的SQL VIEW用来填充RowSet对象派生。

      3.5使用SyncProvider分级和锁定

      在下面的例子中,参考CachedRowSetImpl实现将其目前的SyncProvider对象通过调用setSyncProvider method.

      CachedRowSetImpl CRS =新cachedrowsetimpl();CRS。setsyncprovider(“com. foo。酒吧。HASyncProvider);
      应用目前可以使用断开连接的z-85d69ee0-50检索 SyncProvider对象8d-4ea6-b1fc-9bfc1a35fae0对象。它还可以检索提供程序实现的同步级别和当前使用的锁定程度。此外,一个应用程序具有的灵活性,以设置锁定的程度被使用,这可以增加成功的同步的可能性。这些操作显示在下面的代码片段中。
      syncprovider同步= getsyncprovider() CRS;开关(同步。getprovidergrade()){案例:syncprovider.grade_check_all_at_commit高等级的乐观同步打破;案例:syncprovider.grade_check_modified_at_commit低级别的乐观同步打破;案例:syncprovider.grade_lock_when_loaded一个悲观的同步级打破;案例:syncprovider.grade_lock_when_modified一个悲观的同步级打破;案例:syncprovider.grade_none与提供的原始数据源不同步打破;}开关(同步。getdatasourclock() {案例:syncprovider.datasource_db_lock/ /锁放置在整个数据源所使用的/ / RowSet对象打破;案例:syncprovider.datasource_no_lock没有锁保持在原始数据源上。打破;案例:syncprovider.datasource_row_lock将锁放在被原始的行上的行上/ / SQL语句用来填充/ /那是用syncprovider行集对象打破;案例:datasource_table_lock一把锁放在被触动的所有的桌子上/ / SQL语句用来填充/ /那是用syncprovider行集对象打破;
      也可以使用静态的实用方法在 SyncFactory类确定 SyncProvider实现目前注册的 SyncFactory列表。
      E = syncfactory getregisteredproviders()枚举;

    4.0 Resolving Synchronization Conflicts

    The interface SyncResolver provides a way for an application to decide manually what to do when a conflict occurs. When the CachedRowSet method acceptChanges finishes and has detected one or more conflicts, it throws a SyncProviderException object. An application can catch the exception and have it retrieve a SyncResolver object by calling the method SyncProviderException.getSyncResolver().

    A SyncResolver object, which is a special kind of CachedRowSet object or a JdbcRowSet object that has implemented the SyncResolver interface, examines the conflicts row by row. It is a duplicate of the RowSet object being synchronized except that it contains only the data from the data source this is causing a conflict. All of the other column values are set to null. To navigate from one conflict value to another, a SyncResolver object provides the methods nextConflict and previousConflict.

    The SyncResolver interface also provides methods for doing the following:

    • finding out whether the conflict involved an update, a delete, or an insert
    • getting the value in the data source that caused the conflict
    • setting the value that should be in the data source if it needs to be changed or setting the value that should be in the RowSet object if it needs to be changed

    When the CachedRowSet method acceptChanges is called, it delegates to the RowSet object's SyncProvider object. How the writer provided by that SyncProvider object is implemented determines what level (grade) of checking for conflicts will be done. After all checking for conflicts is completed and one or more conflicts has been found, the method acceptChanges throws a SyncProviderException object. The application can catch the exception and use it to obtain a SyncResolver object.

    The application can then use SyncResolver methods to get information about each conflict and decide what to do. If the application logic or the user decides that a value in the RowSet object should be the one to persist, the application or user can overwrite the data source value with it.

    The comment for the SyncResolver interface has more detail.

    5.0 Related Specifications

    6.0 Related Documentation

  • Skip navigation links
    Java™ Platform
    Standard Ed. 8

    Submit a bug or feature
    For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
    Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.

    本帮助文档是使用 《百度翻译》翻译,请与英文版配合使用 by--QQ:654638585