changeset 32210 | 958d823579c3 |
parent 25991 | e48157b42439 |
child 45126 | 9c8ac4361d9f |
32209:24bb680a1609 | 32210:958d823579c3 |
---|---|
35 |
35 |
36 </head> |
36 </head> |
37 <body bgcolor="#ffffff"> |
37 <body bgcolor="#ffffff"> |
38 |
38 |
39 The standard classes and interfaces that a third party vendor has to |
39 The standard classes and interfaces that a third party vendor has to |
40 use in its implementation of a synchronization provider. These classes and |
40 use in its implementation of a synchronization provider. These classes and |
41 interfaces are referred to as the Service Provider Interface (SPI). A vendor may |
41 interfaces are referred to as the Service Provider Interface (SPI). A vendor may |
42 have its implementation included on the JDBC web page that lists available |
42 have its implementation included on the JDBC web page that lists available |
43 <code>SyncProvider</code> implementations by sending email to <code>jdbc@sun.com</code>. |
43 <code>SyncProvider</code> implementations by sending email to <code>jdbc@sun.com</code>. |
44 Doing this helps make developers aware of the implementation. To make it possible |
44 Doing this helps make developers aware of the implementation. To make it possible |
45 for a <code>RowSet</code> object to use an implementation, the vendor must register |
45 for a <code>RowSet</code> object to use an implementation, the vendor must register |
46 it with the <code>SyncFactory</code> singleton. (See the class comment for |
46 it with the <code>SyncFactory</code> singleton. (See the class comment for |
47 <code>SyncProvider</code> for a full explanation of the registration process and |
47 <code>SyncProvider</code> for a full explanation of the registration process and |
48 the naming convention to be used.) |
48 the naming convention to be used.) |
49 |
49 |
50 <h2>Table of Contents</h2> |
50 <h2>Table of Contents</h2> |
51 <ul> |
51 <ul> |
52 <li><a href="#pkgspec">1.0 Package Specification</a> |
52 <li><a href="#pkgspec">1.0 Package Specification</a> |
79 <P> |
79 <P> |
80 A <code>SyncProvider</code> implementation provides a disconnected <code>RowSet</code> |
80 A <code>SyncProvider</code> implementation provides a disconnected <code>RowSet</code> |
81 object with the mechanisms for reading data into it and for writing data that has been |
81 object with the mechanisms for reading data into it and for writing data that has been |
82 modified in it |
82 modified in it |
83 back to the underlying data source. A <i>reader</i>, a <code>RowSetReader</code> or |
83 back to the underlying data source. A <i>reader</i>, a <code>RowSetReader</code> or |
84 <code>XMLReader</code> object, reads data into a <code>RowSet</code> object when the |
84 <code>XMLReader</code> object, reads data into a <code>RowSet</code> object when the |
85 <code>CachedRowSet</code> methods <code>execute</code> or <code>populate</code> |
85 <code>CachedRowSet</code> methods <code>execute</code> or <code>populate</code> |
86 are called. A <i>writer</i>, a <code>RowSetWriter</code> or <code>XMLWriter</code> |
86 are called. A <i>writer</i>, a <code>RowSetWriter</code> or <code>XMLWriter</code> |
87 object, writes changes back to the underlying data source when the |
87 object, writes changes back to the underlying data source when the |
88 <code>CachedRowSet</code> method <code>acceptChanges</code> is called. |
88 <code>CachedRowSet</code> method <code>acceptChanges</code> is called. |
89 <P> |
89 <P> |
90 The process of writing changes in a <code>RowSet</code> object to its data source |
90 The process of writing changes in a <code>RowSet</code> object to its data source |
91 is known as <i>synchronization</i>. The <code>SyncProvider</code> implementation that a |
91 is known as <i>synchronization</i>. The <code>SyncProvider</code> implementation that a |
92 <code>RowSet</code> object is using determines the level of synchronization that the |
92 <code>RowSet</code> object is using determines the level of synchronization that the |
94 referred to as <i>grades</i>. |
94 referred to as <i>grades</i>. |
95 <P> |
95 <P> |
96 The lower grades of synchronization are |
96 The lower grades of synchronization are |
97 known as <i>optimistic</i> concurrency levels because they optimistically |
97 known as <i>optimistic</i> concurrency levels because they optimistically |
98 assume that there will be no conflicts or very few conflicts. A conflict exists when |
98 assume that there will be no conflicts or very few conflicts. A conflict exists when |
99 the same data modified in the <code>RowSet</code> object has also been modified |
99 the same data modified in the <code>RowSet</code> object has also been modified |
100 in the data source. Using the optimistic concurrency model means that if there |
100 in the data source. Using the optimistic concurrency model means that if there |
101 is a conflict, modifications to either the data source or the <code>RowSet</code> |
101 is a conflict, modifications to either the data source or the <code>RowSet</code> |
102 object will be lost. |
102 object will be lost. |
103 <P> |
103 <P> |
104 Higher grades of synchronization are called <i>pessimistic</i> because they assume |
104 Higher grades of synchronization are called <i>pessimistic</i> because they assume |
105 that others will be accessing the data source and making modifications. These |
105 that others will be accessing the data source and making modifications. These |
106 grades set varying levels of locks to increase the chances that no conflicts |
106 grades set varying levels of locks to increase the chances that no conflicts |
107 occur. |
107 occur. |
108 <P> |
108 <P> |
109 The lowest level of synchronization is simply writing any changes made to the |
109 The lowest level of synchronization is simply writing any changes made to the |
110 <code>RowSet</code> object to its underlying data source. The writer does |
110 <code>RowSet</code> object to its underlying data source. The writer does |
111 nothing to check for conflicts. |
111 nothing to check for conflicts. |
112 If there is a conflict and the data |
112 If there is a conflict and the data |
113 source values are overwritten, the changes other parties have made by to the data |
113 source values are overwritten, the changes other parties have made by to the data |
114 source are lost. |
114 source are lost. |
115 <P> |
115 <P> |
116 The <code>RIXMLProvider</code> implementation uses the lowest level |
116 The <code>RIXMLProvider</code> implementation uses the lowest level |
117 of synchronization and just writes <code>RowSet</code> changes to the data source. |
117 of synchronization and just writes <code>RowSet</code> changes to the data source. |
118 This is true because typically XML data sources do not enable transaction |
118 This is true because typically XML data sources do not enable transaction |
119 techniques for maintaining the integrity of data. However, specific standards |
119 techniques for maintaining the integrity of data. However, specific standards |
120 groups have considered offering XML-based synchronization. For details, see |
120 groups have considered offering XML-based synchronization. For details, see |
121 <PRE> |
121 <PRE> |
122 <a href="http://www.syncml.org">http://www.syncml.org</a> |
122 <a href="http://www.syncml.org">http://www.syncml.org</a> |
123 </PRE> |
123 </PRE> |
124 <P> |
124 <P> |
125 For the next level up, the |
125 For the next level up, the |
126 writer checks to see if there are any conflicts, and if there are, |
126 writer checks to see if there are any conflicts, and if there are, |
127 it does not write anything to the data source. The problem with this concurrency |
127 it does not write anything to the data source. The problem with this concurrency |
128 level is that if another party has modified the corresponding data in the data source |
128 level is that if another party has modified the corresponding data in the data source |
129 since the <code>RowSet</code> object got its data, |
129 since the <code>RowSet</code> object got its data, |
130 the changes made to the <code>RowSet</code> object are lost. The |
130 the changes made to the <code>RowSet</code> object are lost. The |
131 <code>RIOptimisticProvider</code> implementation uses this level of synchronization. |
131 <code>RIOptimisticProvider</code> implementation uses this level of synchronization. |
132 <P> |
132 <P> |
133 At higher levels of synchronization, referred to as pessimistic concurrency, |
133 At higher levels of synchronization, referred to as pessimistic concurrency, |
134 the writer take steps to avoid conflicts by setting locks. Setting locks |
134 the writer take steps to avoid conflicts by setting locks. Setting locks |
135 can vary from setting a lock on a single row to setting a lock on a table |
135 can vary from setting a lock on a single row to setting a lock on a table |
136 or the entire data source. The level of synchronization is therefore a tradeoff |
136 or the entire data source. The level of synchronization is therefore a tradeoff |
137 between the ability of users to access the data source concurrently and the ability |
137 between the ability of users to access the data source concurrently and the ability |
138 of the writer to keep the data in the <code>RowSet</code> object and its data source |
138 of the writer to keep the data in the <code>RowSet</code> object and its data source |
139 synchronized. |
139 synchronized. |
140 <P> |
140 <P> |
141 It is a requirement that all disconnected <code>RowSet</code> objects |
141 It is a requirement that all disconnected <code>RowSet</code> objects |
142 (<code>CachedRowSet</code>, <code>FilteredRowSet</code>, <code>JoinRowSet</code>, |
142 (<code>CachedRowSet</code>, <code>FilteredRowSet</code>, <code>JoinRowSet</code>, |
143 and <code>WebRowSet</code> objects) obtain their <code>SyncProvider</code> objects |
143 and <code>WebRowSet</code> objects) obtain their <code>SyncProvider</code> objects |
144 from the <code>SyncFactory</code> mechanism. |
144 from the <code>SyncFactory</code> mechanism. |
145 <P> |
145 <P> |
146 The reference implementation (RI) provides two synchronization providers. |
146 The reference implementation (RI) provides two synchronization providers. |
147 <UL> |
147 <UL> |
148 <LI><b><tt>RIOptimisticProvider</tt></b> <br> |
148 <LI><b><code>RIOptimisticProvider</code></b> <br> |
149 The default provider that the <code>SyncFactory</code> instance will |
149 The default provider that the <code>SyncFactory</code> instance will |
150 supply to a disconnected <code>RowSet</code> object when no provider |
150 supply to a disconnected <code>RowSet</code> object when no provider |
151 implementation is specified.<BR> |
151 implementation is specified.<BR> |
152 This synchronization provider uses an optimistic concurrency model, |
152 This synchronization provider uses an optimistic concurrency model, |
153 assuming that there will be few conflicts among users |
153 assuming that there will be few conflicts among users |
154 who are accessing the same data in a database. It avoids |
154 who are accessing the same data in a database. It avoids |
155 using locks; rather, it checks to see if there is a conflict |
155 using locks; rather, it checks to see if there is a conflict |
156 before trying to synchronize the <code>RowSet</code> object and the |
156 before trying to synchronize the <code>RowSet</code> object and the |
157 data source. If there is a conflict, it does nothing, meaning that |
157 data source. If there is a conflict, it does nothing, meaning that |
158 changes to the <code>RowSet</code> object are not persisted to the data |
158 changes to the <code>RowSet</code> object are not persisted to the data |
159 source. |
159 source. |
160 <LI><B><tt>RIXMLProvider</tt></B> <BR> |
160 <LI><B><code>RIXMLProvider</code></B> <BR> |
161 A synchronization provider that can be used with a |
161 A synchronization provider that can be used with a |
162 <code>WebRowSet</code> object, which is a rowset that can be written |
162 <code>WebRowSet</code> object, which is a rowset that can be written |
163 in XML format or read from XML format. The |
163 in XML format or read from XML format. The |
164 <code>RIXMLProvider</code> implementation does no checking at all for |
164 <code>RIXMLProvider</code> implementation does no checking at all for |
165 conflicts and simply writes any updated data in the |
165 conflicts and simply writes any updated data in the |
166 <code>WebRowSet</code> object to the underlying data source. |
166 <code>WebRowSet</code> object to the underlying data source. |
167 <code>WebRowSet</code> objects use this provider when they are |
167 <code>WebRowSet</code> objects use this provider when they are |
168 dealing with XML data. |
168 dealing with XML data. |
169 </UL> |
169 </UL> |
170 |
170 |
171 These <code>SyncProvider</code> implementations |
171 These <code>SyncProvider</code> implementations |
172 are bundled with the reference implementation, which makes them always available to |
172 are bundled with the reference implementation, which makes them always available to |
173 <code>RowSet</code> implementations. |
173 <code>RowSet</code> implementations. |
174 <code>SyncProvider</code> implementations make themselves available by being |
174 <code>SyncProvider</code> implementations make themselves available by being |
175 registered with the <code>SyncFactory</code> singleton. When a <code>RowSet</code> |
175 registered with the <code>SyncFactory</code> singleton. When a <code>RowSet</code> |
176 object requests a provider, by specifying it in the constructor or as an argument to the |
176 object requests a provider, by specifying it in the constructor or as an argument to the |
177 <code>CachedRowSet</code> method <code>setSyncProvider</code>, |
177 <code>CachedRowSet</code> method <code>setSyncProvider</code>, |
178 the <code>SyncFactory</code> singleton |
178 the <code>SyncFactory</code> singleton |
179 checks to see if the requested provider has been registered with it. |
179 checks to see if the requested provider has been registered with it. |
180 If it has, the <code>SyncFactory</code> creates an instance of it and passes it to the |
180 If it has, the <code>SyncFactory</code> creates an instance of it and passes it to the |
181 requesting <code>RowSet</code> object. |
181 requesting <code>RowSet</code> object. |
182 If the <code>SyncProvider</code> implementation that is specified has not been registered, |
182 If the <code>SyncProvider</code> implementation that is specified has not been registered, |
183 the <code>SyncFactory</code> singleton causes a <code>SyncFactoryException</code> object |
183 the <code>SyncFactory</code> singleton causes a <code>SyncFactoryException</code> object |
184 to be thrown. If no provider is specified, |
184 to be thrown. If no provider is specified, |
185 the <code>SyncFactory</code> singleton will create an instance of the default |
185 the <code>SyncFactory</code> singleton will create an instance of the default |
186 provider implementation, <code>RIOptimisticProvider</code>, |
186 provider implementation, <code>RIOptimisticProvider</code>, |
187 and pass it to the requesting <code>RowSet</code> object. |
187 and pass it to the requesting <code>RowSet</code> object. |
188 |
188 |
189 <P> |
189 <P> |
190 If a <code>WebRowSet</code> object does not specify a provider in its constructor, the |
190 If a <code>WebRowSet</code> object does not specify a provider in its constructor, the |
191 <code>SyncFactory</code> will give it an instance of <code>RIOptimisticProvider</code>. |
191 <code>SyncFactory</code> will give it an instance of <code>RIOptimisticProvider</code>. |
192 However, the constructor for <code>WebRowSet</code> is implemented to set the provider |
192 However, the constructor for <code>WebRowSet</code> is implemented to set the provider |
193 to the <code>RIXMLProvider</code>, which reads and writes a <code>RowSet</code> object |
193 to the <code>RIXMLProvider</code>, which reads and writes a <code>RowSet</code> object |
194 in XML format. |
194 in XML format. |
195 <P> |
195 <P> |
196 See the <a href="SyncProvider.html">SyncProvider</a> class |
196 See the <a href="SyncProvider.html">SyncProvider</a> class |
197 specification for further details. |
197 specification for further details. |
198 <p> |
198 <p> |
199 Vendors may develop a <tt>SyncProvider</tt> implementation with any one of the possible |
199 Vendors may develop a <code>SyncProvider</code> implementation with any one of the possible |
200 levels of synchronization, thus giving <code>RowSet</code> objects a choice of |
200 levels of synchronization, thus giving <code>RowSet</code> objects a choice of |
201 synchronization mechanisms. A vendor can make its implementation available by |
201 synchronization mechanisms. A vendor can make its implementation available by |
202 registering the fully qualified class name with Oracle Corporation at |
202 registering the fully qualified class name with Oracle Corporation at |
203 <code>jdbc@sun.com</code>. This process is discussed in further detail below. |
203 <code>jdbc@sun.com</code>. This process is discussed in further detail below. |
204 |
204 |
205 <h3><a name="arch">2.0 Service Provider Interface Architecture</a></h3> |
205 <h3><a name="arch">2.0 Service Provider Interface Architecture</a></h3> |
206 <b>2.1 Overview</b> |
206 <b>2.1 Overview</b> |
207 <p> |
207 <p> |
208 The Service Provider Interface provides a pluggable mechanism by which |
208 The Service Provider Interface provides a pluggable mechanism by which |
209 <code>SyncProvider</code> implementations can be registered and then generated when |
209 <code>SyncProvider</code> implementations can be registered and then generated when |
210 required. The lazy reference mechanism employed by the <code>SyncFactory</code> limits |
210 required. The lazy reference mechanism employed by the <code>SyncFactory</code> limits |
211 unnecessary resource consumption by not creating an instance until it is |
211 unnecessary resource consumption by not creating an instance until it is |
212 required by a disconnected |
212 required by a disconnected |
213 <code>RowSet</code> object. The <code>SyncFactory</code> class also provides |
213 <code>RowSet</code> object. The <code>SyncFactory</code> class also provides |
214 a standard API to configure logging options and streams that <b>may</b> be provided |
214 a standard API to configure logging options and streams that <b>may</b> be provided |
215 by a particular <code>SyncProvider</code> implementation. |
215 by a particular <code>SyncProvider</code> implementation. |
216 <p> |
216 <p> |
217 <b>2.2 Registering with the <code>SyncFactory</code></b> |
217 <b>2.2 Registering with the <code>SyncFactory</code></b> |
218 <p> |
218 <p> |
219 A third party <code>SyncProvider</code> implementation must be registered with the |
219 A third party <code>SyncProvider</code> implementation must be registered with the |
220 <code>SyncFactory</code> in order for a disconnected <code>RowSet</code> object |
220 <code>SyncFactory</code> in order for a disconnected <code>RowSet</code> object |
221 to obtain it and thereby use its <code>javax.sql.RowSetReader</code> and |
221 to obtain it and thereby use its <code>javax.sql.RowSetReader</code> and |
222 <code>javax.sql.RowSetWriter</code> |
222 <code>javax.sql.RowSetWriter</code> |
223 implementations. The following registration mechanisms are available to all |
223 implementations. The following registration mechanisms are available to all |
224 <code>SyncProvider</code> implementations: |
224 <code>SyncProvider</code> implementations: |
225 <ul> |
225 <ul> |
226 <li><b>System properties</b> - Properties set at the command line. These |
226 <li><b>System properties</b> - Properties set at the command line. These |
227 properties are set at run time and apply system-wide per invocation of the Java |
227 properties are set at run time and apply system-wide per invocation of the Java |
228 application. See the section <a href="#reldocs">"Related Documentation"</a> |
228 application. See the section <a href="#reldocs">"Related Documentation"</a> |
233 property file located in the platform run-time. The |
233 property file located in the platform run-time. The |
234 reference implementation of this technology includes a standard property |
234 reference implementation of this technology includes a standard property |
235 file than can be edited to add additional <code>SyncProvider</code> objects. |
235 file than can be edited to add additional <code>SyncProvider</code> objects. |
236 |
236 |
237 <li><b>JNDI Context</b> - Available providers can be registered on a JNDI |
237 <li><b>JNDI Context</b> - Available providers can be registered on a JNDI |
238 context. The <tt>SyncFactory</tt> will attempt to load <tt>SyncProvider</tt> |
238 context. The <code>SyncFactory</code> will attempt to load <code>SyncProvider</code> |
239 objects bound to the context and register them with the factory. This |
239 objects bound to the context and register them with the factory. This |
240 context must be supplied to the <code>SyncFactory</code> for the mechanism to |
240 context must be supplied to the <code>SyncFactory</code> for the mechanism to |
241 function correctly. |
241 function correctly. |
242 </ul> |
242 </ul> |
243 <p> |
243 <p> |
244 Details on how to specify the system properties or properties in a property file |
244 Details on how to specify the system properties or properties in a property file |
245 and how to configure the JNDI Context are explained in detail in the |
245 and how to configure the JNDI Context are explained in detail in the |
248 <b>2.3 SyncFactory Provider Instance Generation Policies</b> |
248 <b>2.3 SyncFactory Provider Instance Generation Policies</b> |
249 <p> |
249 <p> |
250 The <code>SyncFactory</code> generates a requested <code>SyncProvider</code> |
250 The <code>SyncFactory</code> generates a requested <code>SyncProvider</code> |
251 object if the provider has been correctly registered. The |
251 object if the provider has been correctly registered. The |
252 following policies are adhered to when either a disconnected <code>RowSet</code> object |
252 following policies are adhered to when either a disconnected <code>RowSet</code> object |
253 is instantiated with a specified <code>SyncProvider</code> implementation or is |
253 is instantiated with a specified <code>SyncProvider</code> implementation or is |
254 reconfigured at runtime with an alternative <code>SyncProvider</code> object. |
254 reconfigured at runtime with an alternative <code>SyncProvider</code> object. |
255 <ul> |
255 <ul> |
256 <li> If a <code>SyncProvider</code> object is specified and the <code>SyncFactory</code> |
256 <li> If a <code>SyncProvider</code> object is specified and the <code>SyncFactory</code> |
257 contains <i>no</i> reference to the provider, a <code>SyncFactoryException</code> is |
257 contains <i>no</i> reference to the provider, a <code>SyncFactoryException</code> is |
258 thrown. |
258 thrown. |
259 |
259 |
260 <li> If a <code>SyncProvider</code> object is specified and the <code>SyncFactory</code> |
260 <li> If a <code>SyncProvider</code> object is specified and the <code>SyncFactory</code> |
261 contains a reference to the provider, the requested provider is supplied. |
261 contains a reference to the provider, the requested provider is supplied. |
262 |
262 |
292 object. These grades are listed from the lowest quality of service to the highest. |
292 object. These grades are listed from the lowest quality of service to the highest. |
293 <ul> |
293 <ul> |
294 <li><b>GRADE_NONE</b> - No synchronization with the originating data source is |
294 <li><b>GRADE_NONE</b> - No synchronization with the originating data source is |
295 provided. A <code>SyncProvider</code> implementation returning this grade will simply |
295 provided. A <code>SyncProvider</code> implementation returning this grade will simply |
296 attempt to write any data that has changed in the <code>RowSet</code> object to the |
296 attempt to write any data that has changed in the <code>RowSet</code> object to the |
297 underlying data source, overwriting whatever is there. No attempt is made to compare |
297 underlying data source, overwriting whatever is there. No attempt is made to compare |
298 original values with current values to see if there is a conflict. The |
298 original values with current values to see if there is a conflict. The |
299 <code>RIXMLProvider</code> is implemented with this grade. |
299 <code>RIXMLProvider</code> is implemented with this grade. |
300 |
300 |
301 <li><b>GRADE_CHECK_MODIFIED_AT_COMMIT</b> - A low grade of optimistic synchronization. |
301 <li><b>GRADE_CHECK_MODIFIED_AT_COMMIT</b> - A low grade of optimistic synchronization. |
302 A <code>SyncProvider</code> implementation returning this grade |
302 A <code>SyncProvider</code> implementation returning this grade |
303 will check for conflicts in rows that have changed between the last synchronization |
303 will check for conflicts in rows that have changed between the last synchronization |
304 and the current synchronization under way. Any changes in the originating data source |
304 and the current synchronization under way. Any changes in the originating data source |
305 that have been modified will not be reflected in the disconnected <code>RowSet</code> |
305 that have been modified will not be reflected in the disconnected <code>RowSet</code> |
306 object. If there are no conflicts, changes in the <code>RowSet</code> object will be |
306 object. If there are no conflicts, changes in the <code>RowSet</code> object will be |
307 written to the data source. If there are conflicts, no changes are written. |
307 written to the data source. If there are conflicts, no changes are written. |
308 The <code>RIOptimisticProvider</code> implementation uses this grade. |
308 The <code>RIOptimisticProvider</code> implementation uses this grade. |
331 JSR 114 defines a set of constants that specify whether any locks have been |
331 JSR 114 defines a set of constants that specify whether any locks have been |
332 placed on a <code>RowSet</code> object's underlying data source and, if so, |
332 placed on a <code>RowSet</code> object's underlying data source and, if so, |
333 on which constructs the locks are placed. These locks will remain on the data |
333 on which constructs the locks are placed. These locks will remain on the data |
334 source while the <code>RowSet</code> object is disconnected from the data source. |
334 source while the <code>RowSet</code> object is disconnected from the data source. |
335 <P> |
335 <P> |
336 These constants <b>should</b> be considered complementary to the |
336 These constants <b>should</b> be considered complementary to the |
337 grade constants. The default setting for the majority of grade settings requires |
337 grade constants. The default setting for the majority of grade settings requires |
338 that no data source locks remain when a <code>RowSet</code> object is disconnected |
338 that no data source locks remain when a <code>RowSet</code> object is disconnected |
339 from its data source. |
339 from its data source. |
340 The grades <code>GRADE_LOCK_WHEN_MODIFIED</code> and |
340 The grades <code>GRADE_LOCK_WHEN_MODIFIED</code> and |
341 <code>GRADE_LOCK_WHEN_LOADED</code> allow a disconnected <code>RowSet</code> object |
341 <code>GRADE_LOCK_WHEN_LOADED</code> allow a disconnected <code>RowSet</code> object |
342 to have a fine-grained control over the degree of locking. |
342 to have a fine-grained control over the degree of locking. |
343 <ul> |
343 <ul> |
344 <li><b>DATASOURCE_NO_LOCK</b> - No locks remain on the originating data source. |
344 <li><b>DATASOURCE_NO_LOCK</b> - No locks remain on the originating data source. |
345 This is the default lock setting for all <code>SyncProvider</code> implementations |
345 This is the default lock setting for all <code>SyncProvider</code> implementations |
346 unless otherwise directed by a <code>RowSet</code> object. |
346 unless otherwise directed by a <code>RowSet</code> object. |
347 |
347 |
348 <li><b>DATASOURCE_ROW_LOCK</b> - A lock is placed on the rows that are touched by |
348 <li><b>DATASOURCE_ROW_LOCK</b> - A lock is placed on the rows that are touched by |
349 the original SQL query used to populate the <code>RowSet</code> object. |
349 the original SQL query used to populate the <code>RowSet</code> object. |
350 |
350 |
362 The following constants indicate whether a <code>SyncProvider</code> object can |
362 The following constants indicate whether a <code>SyncProvider</code> object can |
363 update data in the table or tables from which the <code>VIEW</code> was derived. |
363 update data in the table or tables from which the <code>VIEW</code> was derived. |
364 <ul> |
364 <ul> |
365 <li><b>UPDATABLE_VIEW_SYNC</b> |
365 <li><b>UPDATABLE_VIEW_SYNC</b> |
366 Indicates that a <code>SyncProvider</code> implementation supports synchronization |
366 Indicates that a <code>SyncProvider</code> implementation supports synchronization |
367 to the table or tables from which the SQL <code>VIEW</code> used to populate a |
367 to the table or tables from which the SQL <code>VIEW</code> used to populate |
368 a <code>RowSet</code> object is derived. |
368 a <code>RowSet</code> object is derived. |
369 |
369 |
370 <li><b>NONUPDATABLE_VIEW_SYNC</b> |
370 <li><b>NONUPDATABLE_VIEW_SYNC</b> |
371 Indicates that a <code>SyncProvider</code> implementation does <b>not</b> support |
371 Indicates that a <code>SyncProvider</code> implementation does <b>not</b> support |
372 synchronization to the table or tables from which the SQL <code>VIEW</code> |
372 synchronization to the table or tables from which the SQL <code>VIEW</code> |
373 used to populate a <code>RowSet</code> object is derived. |
373 used to populate a <code>RowSet</code> object is derived. |
374 </ul> |
374 </ul> |
375 <p> |
375 <p> |
376 <b>3.5 Usage of <code>SyncProvider</code> Grading and Locking</b> |
376 <b>3.5 Usage of <code>SyncProvider</code> Grading and Locking</b> |
377 <p> |
377 <p> |
378 In the example below, the reference <tt>CachedRowSetImpl</tt> implementation |
378 In the example below, the reference <code>CachedRowSetImpl</code> implementation |
379 reconfigures its current <tt>SyncProvider</tt> object by calling the |
379 reconfigures its current <code>SyncProvider</code> object by calling the |
380 <tt>setSyncProvider</tt> method.<br> |
380 <code>setSyncProvider</code> method.<br> |
381 |
381 |
382 <PRE> |
382 <PRE> |
383 CachedRowSetImpl crs = new CachedRowSetImpl(); |
383 CachedRowSetImpl crs = new CachedRowSetImpl(); |
384 crs.setSyncProvider("com.foo.bar.HASyncProvider"); |
384 crs.setSyncProvider("com.foo.bar.HASyncProvider"); |
385 </PRE> |
385 </PRE> |
386 An application can retrieve the <tt>SyncProvider</tt> object currently in use |
386 An application can retrieve the <code>SyncProvider</code> object currently in use |
387 by a disconnected <code>RowSet</code> object. It can also retrieve the |
387 by a disconnected <code>RowSet</code> object. It can also retrieve the |
388 grade of synchronization with which the provider was implemented and the degree of |
388 grade of synchronization with which the provider was implemented and the degree of |
389 locking currently in use. In addition, an application has the flexibility to set |
389 locking currently in use. In addition, an application has the flexibility to set |
390 the degree of locking to be used, which can increase the possibilities for successful |
390 the degree of locking to be used, which can increase the possibilities for successful |
391 synchronization. These operation are shown in the following code fragment. |
391 synchronization. These operation are shown in the following code fragment. |
394 |
394 |
395 switch (sync.getProviderGrade()) { |
395 switch (sync.getProviderGrade()) { |
396 case: SyncProvider.GRADE_CHECK_ALL_AT_COMMIT |
396 case: SyncProvider.GRADE_CHECK_ALL_AT_COMMIT |
397 //A high grade of optimistic synchronization |
397 //A high grade of optimistic synchronization |
398 break; |
398 break; |
399 case: SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT |
399 case: SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT |
400 //A low grade of optimistic synchronization |
400 //A low grade of optimistic synchronization |
401 break; |
401 break; |
402 case: SyncProvider.GRADE_LOCK_WHEN_LOADED |
402 case: SyncProvider.GRADE_LOCK_WHEN_LOADED |
403 // A pessimistic synchronization grade |
403 // A pessimistic synchronization grade |
404 break; |
404 break; |
405 case: SyncProvider.GRADE_LOCK_WHEN_MODIFIED |
405 case: SyncProvider.GRADE_LOCK_WHEN_MODIFIED |
406 // A pessimistic synchronization grade |
406 // A pessimistic synchronization grade |
407 break; |
407 break; |
408 case: SyncProvider.GRADE_NONE |
408 case: SyncProvider.GRADE_NONE |
409 // No synchronization with the originating data source provided |
409 // No synchronization with the originating data source provided |
410 break; |
410 break; |
411 } |
411 } |
419 case: SyncProvider.DATASOURCE_NO_LOCK |
419 case: SyncProvider.DATASOURCE_NO_LOCK |
420 // No locks remain on the originating data source. |
420 // No locks remain on the originating data source. |
421 break; |
421 break; |
422 |
422 |
423 case: SyncProvider.DATASOURCE_ROW_LOCK |
423 case: SyncProvider.DATASOURCE_ROW_LOCK |
424 // A lock is placed on the rows that are touched by the original |
424 // A lock is placed on the rows that are touched by the original |
425 // SQL statement used to populate |
425 // SQL statement used to populate |
426 // the RowSet object that is using the SyncProvider |
426 // the RowSet object that is using the SyncProvider |
427 break; |
427 break; |
428 |
428 |
429 case: DATASOURCE_TABLE_LOCK |
429 case: DATASOURCE_TABLE_LOCK |
430 // A lock is placed on all tables that are touched by the original |
430 // A lock is placed on all tables that are touched by the original |
431 // SQL statement used to populated |
431 // SQL statement used to populated |
432 // the RowSet object that is using the SyncProvider |
432 // the RowSet object that is using the SyncProvider |
433 break; |
433 break; |
434 |
434 |
435 </PRE> |
435 </PRE> |
448 decide manually what to do when a conflict occurs. When the <code>CachedRowSet</code> |
448 decide manually what to do when a conflict occurs. When the <code>CachedRowSet</code> |
449 method <code>acceptChanges</code> finishes and has detected one or more conflicts, |
449 method <code>acceptChanges</code> finishes and has detected one or more conflicts, |
450 it throws a <code>SyncProviderException</code> object. An application can |
450 it throws a <code>SyncProviderException</code> object. An application can |
451 catch the exception and |
451 catch the exception and |
452 have it retrieve a <code>SyncResolver</code> object by calling the method |
452 have it retrieve a <code>SyncResolver</code> object by calling the method |
453 <code>SyncProviderException.getSyncResolver()</code>. |
453 <code>SyncProviderException.getSyncResolver()</code>. |
454 <P> |
454 <P> |
455 A <code>SyncResolver</code> object, which is a special kind of |
455 A <code>SyncResolver</code> object, which is a special kind of |
456 <code>CachedRowSet</code> object or |
456 <code>CachedRowSet</code> object or |
457 a <code>JdbcRowSet</code> object that has implemented the <code>SyncResolver</code> |
457 a <code>JdbcRowSet</code> object that has implemented the <code>SyncResolver</code> |
458 interface, examines the conflicts row by row. It is a duplicate of the |
458 interface, examines the conflicts row by row. It is a duplicate of the |
459 <code>RowSet</code> object being synchronized except that it contains only the data |
459 <code>RowSet</code> object being synchronized except that it contains only the data |
460 from the data source this is causing a conflict. All of the other column values are |
460 from the data source this is causing a conflict. All of the other column values are |
461 set to <code>null</code>. To navigate from one conflict value to another, a |
461 set to <code>null</code>. To navigate from one conflict value to another, a |
462 <code>SyncResolver</code> object provides the methods <code>nextConflict</code> and |
462 <code>SyncResolver</code> object provides the methods <code>nextConflict</code> and |
463 <code>previousConflict</code>. |
463 <code>previousConflict</code>. |
470 <LI>setting the value that should be in the data source if it needs to be changed |
470 <LI>setting the value that should be in the data source if it needs to be changed |
471 or setting the value that should be in the <code>RowSet</code> object if it needs |
471 or setting the value that should be in the <code>RowSet</code> object if it needs |
472 to be changed |
472 to be changed |
473 </UL> |
473 </UL> |
474 <P> |
474 <P> |
475 When the <code>CachedRowSet</code> method <code>acceptChanges</code> is called, it |
475 When the <code>CachedRowSet</code> method <code>acceptChanges</code> is called, it |
476 delegates to the <code>RowSet</code> object's <code>SyncProvider</code> object. |
476 delegates to the <code>RowSet</code> object's <code>SyncProvider</code> object. |
477 How the writer provided by that <code>SyncProvider</code> object is implemented |
477 How the writer provided by that <code>SyncProvider</code> object is implemented |
478 determines what level (grade) of checking for conflicts will be done. After all |
478 determines what level (grade) of checking for conflicts will be done. After all |
479 checking for conflicts is completed and one or more conflicts has been found, the method |
479 checking for conflicts is completed and one or more conflicts has been found, the method |
480 <code>acceptChanges</code> throws a <code>SyncProviderException</code> object. The |
480 <code>acceptChanges</code> throws a <code>SyncProviderException</code> object. The |
481 application can catch the exception and use it to obtain a <code>SyncResolver</code> object. |
481 application can catch the exception and use it to obtain a <code>SyncResolver</code> object. |
482 <P> |
482 <P> |
483 The application can then use <code>SyncResolver</code> methods to get information |
483 The application can then use <code>SyncResolver</code> methods to get information |
484 about each conflict and decide what to do. If the application logic or the user |
484 about each conflict and decide what to do. If the application logic or the user |
485 decides that a value in the <code>RowSet</code> object should be the one to |
485 decides that a value in the <code>RowSet</code> object should be the one to |
486 persist, the application or user can overwrite the data source value with it. |
486 persist, the application or user can overwrite the data source value with it. |
487 <P> |
487 <P> |
488 The comment for the <code>SyncResolver</code> interface has more detail. |
488 The comment for the <code>SyncResolver</code> interface has more detail. |
489 |
489 |
490 <h3><a name="relspec">5.0 Related Specifications</a></h3> |
490 <h3><a name="relspec">5.0 Related Specifications</a></h3> |
491 <ul> |
491 <ul> |