| 接口 | 描述 |
|---|---|
| SyncResolver |
定义一个框架,允许应用程序使用一个手动决策树来决定在发生同步冲突时应该做什么。
|
| TransactionalWriter |
一个专门的接口,便于标准
SyncProvider抽象类的扩展使其具有更细粒度的事务控制。
|
| XmlReader |
一个专门的接口,方便了XML的
SyncProvider抽象类的扩展型同步提供者。
|
| XmlWriter |
一个专门的接口,方便了XML的
SyncProvider抽象类的扩展型同步提供者。
|
| 类 | 描述 |
|---|---|
| SyncFactory |
服务提供者接口(SPI)机制产生
SyncProvider实例被断开
RowSet对象使用。
|
| SyncProvider |
同步机制,断开
RowSet对象提供读/写能力。
|
| 异常 | 描述 |
|---|---|
| SyncFactoryException |
表示错误与
SyncFactory机制。
|
| SyncProviderException |
表明一个错误的
SyncProvider机制。
|
SyncProvider实现发送电子邮件
jdbc@sun.com。这样做有助于使开发商意识到实施。使一个
RowSet对象使用的一个实现,供应商必须与
SyncFactory独生子女登记。(看到一个完整的解释的注册过程和命名约定来使用。
SyncProvider类评论)
The following classes and interfaces make up the javax.sql.rowset.spi package:
SyncFactory SyncProvider SyncFactoryException SyncProviderException SyncResolver XmlReader XmlWriter TransactionalWriter 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对象(CachedRowSet,FilteredRowSet,JoinRowSet,和WebRowSet对象)从SyncFactory机制获得SyncProvider对象。
参考实现(RI)提供了两个同步提供者。
SyncFactory实例将电源断开RowSet对象时没有提供实现specified.RowSet对象和数据源的冲突。如果有一个冲突,这没意义,对RowSet对象的更改不会保存到数据源。WebRowSet对象,这是一个数据集,可以用XML格式或XML格式读取。实施的RIXMLProvider不检查在所有的冲突,只是写了任何更新的数据在WebRowSet对象基础数据源。WebRowSet对象使用此提供程序在处理XML数据。SyncProvider实现捆绑的参考实现,这使得他们总是可以
RowSet实现。
SyncProvider实现使自己可以通过和
SyncFactory单独注册。当一个
RowSet对象请求的供应商,通过指定它在构造函数或作为参数的方法的
CachedRowSet
setSyncProvider,
SyncFactory单检查是否要求供应商已注册了。如果有,那
SyncFactory创建它的实例并将其传递给请求
RowSet对象。如果
SyncProvider实现指定尚未注册,
SyncFactory独生子女的原因
SyncFactoryException对象被。如果没有指定的供应商,
SyncFactory单将创建默认的提供程序实现,
RIOptimisticProvider实例,并把它传递给请求
RowSet对象。
如果不指定WebRowSet对象的构造函数中的供应商,SyncFactory会给RIOptimisticProvider实例。然而,对于WebRowSet构造函数来设置供应商的RIXMLProvider,读和写在XML格式的RowSet对象。
详情见SyncProvider类规范。
供应商可能发展同步的水平可能有SyncProvider实施,从而RowSet对象选择的同步机制。供应商可以通过与甲骨文公司在jdbc@sun.com注册完全限定名称使其实现有效。这个过程将在下面进一步详细讨论。
The Service Provider Interface provides a pluggable mechanism by which SyncProvider implementations can be registered and then generated when required. The lazy reference mechanism employed by the SyncFactory limits unnecessary resource consumption by not creating an instance until it is required by a disconnected RowSet object. The SyncFactory class also provides a standard API to configure logging options and streams that may be provided by a particular SyncProvider implementation.
2.2 Registering with the SyncFactory
A third party SyncProvider implementation must be registered with the SyncFactory in order for a disconnected RowSet object to obtain it and thereby use its javax.sql.RowSetReader and javax.sql.RowSetWriter implementations. The following registration mechanisms are available to all SyncProvider implementations:
SyncProvider对象。SyncFactory为正确的工作机制。有关如何指定一个属性文件系统属性或属性以及如何配置JNDI上下文在SyncFactory类描述详细解释。
2.3 syncfactory提供者实例生成策略
的SyncFactory生成一个请求SyncProvider对象如果提供者已正确注册。以下政策时坚持一个断开的RowSet对象实例化时使用指定的SyncProvider实施或重新配置在一个SyncProvider对象运行。
SyncProvider对象是指定和SyncFactory包含供应商不参考,一SyncFactoryException抛出。SyncProvider对象是指定和SyncFactory包含引用的供应商,要求供应商提供。SyncProvider对象指定,提供参考实现供应商RIOptimisticProvider。这些政策进行了更详细的 SyncFactory类。
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物体质量的等级设置。这些成绩都列出从最低的服务质量到最高。
SyncProvider实现返回这个等级会尝试写任何数据,在RowSet对象改为基础数据源,无论是在覆盖。没有尝试将原始值与当前值进行比较,以查看是否存在冲突。是的RIXMLProvider这个年级实施。SyncProvider实现返回这个档次的检查,最后的同步方式下电流同步更改的行的冲突。在原始数据源已被修改的任何更改将不会反映在断开RowSet对象。如果没有冲突,在RowSet对象的更改将被写入到数据源。如果有冲突,没有任何变化是书面的。的RIOptimisticProvider实现使用这种等级。SyncProvider实现返回这个年级将检查所有的行,包括未在断开RowSet对象更改的行。这样,在基础数据源行的任何变更将反映在断开RowSet对象当同步成功完成。SyncProvider实现返回这个等级将锁定排在原始数据源对应的排在RowSet对象改变的可能性减少其他进程的数据源中的修改相同的数据。SyncProvider实现返回这个级别将锁定整个表的查看和/或用来填充RowSet对象原始查询的影响。3.3把锁
JSR 114定义了一组常量指定的任何锁是否已被放置在一个RowSet对象的基础数据源,如果是这样,在构建锁放置。这些锁将保持数据源而RowSet对象从数据源断开。
这些常数应该被认为等级常数互补。对于大多数等级设置的默认设置,不需要数据源时保持一个RowSet锁对象从数据源断开。成绩GRADE_LOCK_WHEN_MODIFIED和GRADE_LOCK_WHEN_LOADED允许断开连接的RowSet对象来锁定程度的细粒度的控制。
SyncProvider实现设置,除非有RowSet对象。RowSet对象原始SQL查询摸排。RowSet对象感动。RowSet对象使用整个数据源。3.4可更新的视图
一个RowSet对象可能从一个SQL VIEW数据。以下常量指示SyncProvider对象可以更新表中的数据或图表,进而得到了VIEW。
SyncProvider实现支持同步表或表的SQL VIEW用来填充一一RowSet对象派生。SyncProvider不实现不支持同步的表,用来填充RowSet对象派生的SQL VIEW。3.5使用SyncProvider分级和锁定
在下面的例子中,参考CachedRowSetImpl实现将其目前的SyncProvider对象通过调用setSyncProvider method.
CachedRowSetImpl CRS =新cachedrowsetimpl();CRS。setsyncprovider(“com. foo。酒吧。HASyncProvider);应用目前可以使用断开连接的z-025d5186-1a检索 SyncProvider对象6d-4850-8f2c-4aded90dcbc4对象。它还可以检索提供程序实现的同步级别和当前使用的锁定程度。此外,一个应用程序具有的灵活性,以设置锁定的程度被使用,这可以增加成功的同步的可能性。这些操作显示在下面的代码片段中。
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()枚举;
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:
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.
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.