jdk/src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncFactory.java
author chegar
Mon, 18 Aug 2014 10:59:36 +0100
changeset 25991 e48157b42439
parent 25976 jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java@4de01a56e3ee
parent 25859 jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java@3317bb8137f4
child 36511 9d0388c6b336
permissions -rw-r--r--
Merge
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 java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.FileInputStream;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
    35
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.FileNotFoundException;
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
    38
import java.security.AccessController;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
    39
import java.security.PrivilegedAction;
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
    40
import java.security.PrivilegedActionException;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
    41
import java.security.PrivilegedExceptionAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.naming.*;
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
    44
import sun.reflect.misc.ReflectUtil;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The Service Provider Interface (SPI) mechanism that generates <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * instances to be used by disconnected <code>RowSet</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The <code>SyncProvider</code> instances in turn provide the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>javax.sql.RowSetReader</code> object the <code>RowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * needs to populate itself with data and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>javax.sql.RowSetWriter</code> object it needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * propagate changes to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * data back to the underlying data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Because the methods in the <code>SyncFactory</code> class are all static,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * there is only one <code>SyncFactory</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * per Java VM at any one time. This ensures that there is a single source from which a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>RowSet</code> implementation can obtain its <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * implementation.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
    61
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <h3>1.0 Overview</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The <code>SyncFactory</code> class provides an internal registry of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * synchronization provider implementations (<code>SyncProvider</code> objects).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * This registry may be queried to determine which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * synchronization providers are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * The following line of code gets an enumeration of the providers currently registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *     java.util.Enumeration e = SyncFactory.getRegisteredProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * All standard <code>RowSet</code> implementations must provide at least two providers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  <LI>an optimistic provider for use with a <code>CachedRowSet</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     or an implementation derived from it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *  <LI>an XML provider, which is used for reading and writing XML, such as with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *       <code>WebRowSet</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Note that the JDBC RowSet Implementations include the <code>SyncProvider</code>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20880
diff changeset
    79
 * implementations <code>RIOptimisticProvider</code> and <code>RIXmlProvider</code>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * which satisfy this requirement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * The <code>SyncFactory</code> class provides accessor methods to assist
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * applications in determining which synchronization providers are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * registered with the <code>SyncFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Other methods let <code>RowSet</code> persistence providers be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * registered or de-registered with the factory mechanism. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * allows additional synchronization provider implementations to be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * available to <code>RowSet</code> objects at run time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * Applications can apply a degree of filtering to determine the level of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * synchronization that a <code>SyncProvider</code> implementation offers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * The following criteria determine whether a provider is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * made available to a <code>RowSet</code> object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <li>If a particular provider is specified by a <code>RowSet</code> object, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * the <code>SyncFactory</code> does not contain a reference to this provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * a <code>SyncFactoryException</code> is thrown stating that the synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * provider could not be found.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
   100
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <li>If a <code>RowSet</code> implementation is instantiated with a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * provider and the specified provider has been properly registered, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * requested provider is supplied. Otherwise a <code>SyncFactoryException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * is thrown.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
   105
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <li>If a <code>RowSet</code> object does not specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <code>SyncProvider</code> implementation and no additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <code>SyncProvider</code> implementations are available, the reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * implementation providers are supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <h3>2.0 Registering <code>SyncProvider</code> Implementations</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Both vendors and developers can register <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * implementations using one of the following mechanisms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <LI><B>Using the command line</B><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * The name of the provider is supplied on the command line, which will add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * the provider to the system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *    -Drowset.provider.classname=com.fred.providers.HighAvailabilityProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <li><b>Using the Standard Properties File</b><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * The reference implementation is targeted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * to ship with J2SE 1.5, which will include an additional resource file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * that may be edited by hand. Here is an example of the properties file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * included in the reference implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *   #Default JDBC RowSet sync providers listing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *   #
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *   # Optimistic synchronization provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *   rowset.provider.classname.0=com.sun.rowset.providers.RIOptimisticProvider
6671
c5fbc05d7347 6984044: RowSet source needs to rebrand vendor references
lancea
parents: 6529
diff changeset
   134
 *   rowset.provider.vendor.0=Oracle Corporation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *   rowset.provider.version.0=1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *   # XML Provider using standard XML schema
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *   rowset.provider.classname.1=com.sun.rowset.providers.RIXMLProvider
6671
c5fbc05d7347 6984044: RowSet source needs to rebrand vendor references
lancea
parents: 6529
diff changeset
   139
 *   rowset.provider.vendor.1=Oracle Corporation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *   rowset.provider.version.1=1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * The <code>SyncFactory</code> checks this file and registers the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>SyncProvider</code> implementations that it contains. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * developer or vendor can add other implementations to this file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * For example, here is a possible addition:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *     rowset.provider.classname.2=com.fred.providers.HighAvailabilityProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *     rowset.provider.vendor.2=Fred, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *     rowset.provider.version.2=1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * </PRE>
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
   151
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <li><b>Using a JNDI Context</b><BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Available providers can be registered on a JNDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * context, and the <code>SyncFactory</code> will attempt to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <code>SyncProvider</code> implementations from that JNDI context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * For example, the following code fragment registers a provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * on a JNDI context.  This is something a deployer would normally do. In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * example, <code>MyProvider</code> is being registered on a CosNaming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * namespace, which is the namespace used by J2EE resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *    import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *    Hashtable svrEnv = new  Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *    srvEnv.put(Context.INITIAL_CONTEXT_FACTORY, "CosNaming");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *    Context ctx = new InitialContext(svrEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *    com.fred.providers.MyProvider = new MyProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *    ctx.rebind("providers/MyProvider", syncProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * Next, an application will register the JNDI context with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <code>SyncFactory</code> instance.  This allows the <code>SyncFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * to browse within the JNDI context looking for <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *    Hashtable appEnv = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *    appEnv.put(Context.INITIAL_CONTEXT_FACTORY, "CosNaming");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *    appEnv.put(Context.PROVIDER_URL, "iiop://hostname/providers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *    Context ctx = new InitialContext(appEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *    SyncFactory.registerJNDIContext(ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * If a <code>RowSet</code> object attempts to obtain a <code>MyProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * object, the <code>SyncFactory</code> will try to locate it. First it searches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * for it in the system properties, then it looks in the resource files, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * finally it checks the JNDI context that has been set. The <code>SyncFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * instance verifies that the requested provider is a valid extension of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <code>SyncProvider</code> abstract class and then gives it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * <code>RowSet</code> object. In the following code fragment, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <code>CachedRowSet</code> object is created and initialized with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * <i>env</i>, which contains the binding to <code>MyProvider</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *    Hashtable env = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *    env.put(SyncFactory.ROWSET_SYNC_PROVIDER, "com.fred.providers.MyProvider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *    CachedRowSet crs = new com.sun.rowset.CachedRowSetImpl(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * Further details on these mechanisms are available in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * <code>javax.sql.rowset.spi</code> package specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * @author  Jonathan Bruce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * @see javax.sql.rowset.spi.SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * @see javax.sql.rowset.spi.SyncFactoryException
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 23914
diff changeset
   203
 * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
public class SyncFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Creates a new <code>SyncFactory</code> object, which is the singleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Having a private constructor guarantees that no more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * one <code>SyncProvider</code> object can exist at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   213
    private SyncFactory() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   214
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * The standard property-id for a synchronization provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   220
    public static final String ROWSET_SYNC_PROVIDER =
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   221
            "rowset.provider.classname";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * The standard property-id for a synchronization provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * vendor name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   226
    public static final String ROWSET_SYNC_VENDOR =
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   227
            "rowset.provider.vendor";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * The standard property-id for a synchronization provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * version tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   232
    public static final String ROWSET_SYNC_PROVIDER_VERSION =
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   233
            "rowset.provider.version";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * The standard resource file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static String ROWSET_PROPERTIES = "rowset.properties";
14176
9864fbbedb87 8000712: Remove unused fields in SyncFactory
lancea
parents: 11129
diff changeset
   238
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   239
    /**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   240
     *  Permission required to invoke setJNDIContext and setLogger
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   241
     */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   242
    private static final SQLPermission SET_SYNCFACTORY_PERMISSION =
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   243
            new SQLPermission("setSyncFactory");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * The initial JNDI context where <code>SyncProvider</code> implementations can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * be stored and from which they can be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    private static Context ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * The <code>Logger</code> object to be used by the <code>SyncFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   252
    private static volatile Logger rsLogger;
14176
9864fbbedb87 8000712: Remove unused fields in SyncFactory
lancea
parents: 11129
diff changeset
   253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * The registry of available <code>SyncProvider</code> implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * See section 2.0 of the class comment for <code>SyncFactory</code> for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * explanation of how a provider can be added to this registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   259
    private static Hashtable<String, SyncProvider> implementations;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   262
     * Adds the given synchronization provider to the factory register. Guidelines
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * are provided in the <code>SyncProvider</code> specification for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * required naming conventions for <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Synchronization providers bound to a JNDI context can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * registered by binding a SyncProvider instance to a JNDI namespace.
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   269
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <pre>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   271
     * {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * SyncProvider p = new MySyncProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * InitialContext ic = new InitialContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * ic.bind ("jdbc/rowset/MySyncProvider", p);
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   275
     * } </pre>
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   276
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Furthermore, an initial JNDI context should be set with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>SyncFactory</code> using the <code>setJNDIContext</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * The <code>SyncFactory</code> leverages this context to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * available <code>SyncProvider</code> objects bound to the JNDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * context and its child nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param providerID A <code>String</code> object with the unique ID of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *             synchronization provider being registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws SyncFactoryException if an attempt is made to supply an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *         or null provider name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #setJNDIContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public static synchronized void registerProvider(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   290
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ProviderImpl impl = new ProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        impl.setClassname(providerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        implementations.put(providerID, impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Returns the <code>SyncFactory</code> singleton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return the <code>SyncFactory</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   304
    public static SyncFactory getSyncFactory() {
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   305
        /*
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   306
         * Using Initialization on Demand Holder idiom as
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   307
         * Effective Java 2nd Edition,ITEM 71, indicates it is more performant
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   308
         * than the Double-Check Locking idiom.
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   309
         */
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   310
        return SyncFactoryHolder.factory;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   311
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Removes the designated currently registered synchronization provider from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Factory SPI register.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param providerID The unique-id of the synchronization provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @throws SyncFactoryException If an attempt is made to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * unregister a SyncProvider implementation that was not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public static synchronized void unregisterProvider(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   322
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (implementations.containsKey(providerID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            implementations.remove(providerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    private static String colon = ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static String strFileSep = "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    private static synchronized void initMapIfNecessary() throws SyncFactoryException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // Local implementation class names and keys from Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // file, translate names into Class objects using Class.forName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // and store mappings
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   336
        final Properties properties = new Properties();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (implementations == null) {
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   339
            implementations = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                // check if user is supplying his Synchronisation Provider
6671
c5fbc05d7347 6984044: RowSet source needs to rebrand vendor references
lancea
parents: 6529
diff changeset
   344
                // Implementation if not using Oracle's implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                // properties.load(new FileInputStream(ROWSET_PROPERTIES));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                // The rowset.properties needs to be in jdk/jre/lib when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                // integrated with jdk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                // else it should be picked from -D option from command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // -Drowset.properties will add to standard properties. Similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                // keys will over-write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                 * Dependent on application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                 */
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   357
                String strRowsetProperties;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   358
                try {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   359
                    strRowsetProperties = AccessController.doPrivileged(new PrivilegedAction<String>() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   360
                        public String run() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   361
                            return System.getProperty("rowset.properties");
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   362
                        }
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   363
                    }, null, new PropertyPermission("rowset.properties", "read"));
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   364
                } catch (Exception ex) {
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   365
                    System.out.println("errorget rowset.properties: " + ex);
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   366
                    strRowsetProperties = null;
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   367
                };
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   368
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   369
                if (strRowsetProperties != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    // Load user's implementation of SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    // here. -Drowset.properties=/abc/def/pqr.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    ROWSET_PROPERTIES = strRowsetProperties;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   373
                    try (FileInputStream fis = new FileInputStream(ROWSET_PROPERTIES)) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   374
                        properties.load(fis);
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   375
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                 * Always available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                ROWSET_PROPERTIES = "javax" + strFileSep + "sql" +
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   383
                        strFileSep + "rowset" + strFileSep +
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   384
                        "rowset.properties";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   388
                try {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   389
                    AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   390
                        try (InputStream stream = (cl == null) ?
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   391
                                ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES)
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   392
                                : cl.getResourceAsStream(ROWSET_PROPERTIES)) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   393
                            if (stream == null) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   394
                                throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found");
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   395
                            }
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   396
                            properties.load(stream);
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   397
                        }
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   398
                        return null;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   399
                    });
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   400
                } catch (PrivilegedActionException ex) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   401
                    Throwable e = ex.getException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   402
                    if (e instanceof SyncFactoryException) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   403
                      throw (SyncFactoryException) e;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   404
                    } else {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   405
                        SyncFactoryException sfe = new SyncFactoryException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   406
                        sfe.initCause(ex.getException());
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   407
                        throw sfe;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   408
                    }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   409
                }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   410
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   413
            // removed else, has properties should sum together
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                throw new SyncFactoryException("Cannot locate properties file: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                throw new SyncFactoryException("IOException: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
             * Now deal with -Drowset.provider.classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
             * load additional properties from -D command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            properties.clear();
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   426
            String providerImpls;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   427
            try {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   428
                providerImpls = AccessController.doPrivileged(new PrivilegedAction<String>() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   429
                    public String run() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   430
                        return System.getProperty(ROWSET_SYNC_PROVIDER);
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   431
                    }
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   432
                }, null, new PropertyPermission(ROWSET_SYNC_PROVIDER, "read"));
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   433
            } catch (Exception ex) {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   434
                providerImpls = null;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   435
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (providerImpls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (providerImpls.indexOf(colon) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    StringTokenizer tokenizer = new StringTokenizer(providerImpls, colon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    while (tokenizer.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        properties.put(ROWSET_SYNC_PROVIDER + "." + i, tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    properties.put(ROWSET_SYNC_PROVIDER, providerImpls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   452
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * The internal debug switch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    private static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Internal registry count for the number of providers contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private static int providerImplIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Internal handler for all standard property parsing. Parses standard
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   465
     * ROWSET properties and stores lazy references into the internal registry.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private static void parseProperties(Properties p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        ProviderImpl impl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String[] propertyNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   473
        for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   475
            String str = (String) e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            int w = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (str.startsWith(SyncFactory.ROWSET_SYNC_PROVIDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                impl = new ProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                impl.setIndex(providerImplIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                if (w == (SyncFactory.ROWSET_SYNC_PROVIDER).length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    // no property index has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    propertyNames = getPropertyNames(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    // property index has been set.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   489
                    propertyNames = getPropertyNames(true, str.substring(w - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                key = p.getProperty(propertyNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                impl.setClassname(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                impl.setVendor(p.getProperty(propertyNames[1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                impl.setVersion(p.getProperty(propertyNames[2]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                implementations.put(key, impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Used by the parseProperties methods to disassemble each property tuple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    private static String[] getPropertyNames(boolean append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return getPropertyNames(append, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Disassembles each property and its associated value. Also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * overloaded property names that contain indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private static String[] getPropertyNames(boolean append,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   513
            String propertyIndex) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        String dot = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        String[] propertyNames =
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   516
                new String[]{SyncFactory.ROWSET_SYNC_PROVIDER,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   517
            SyncFactory.ROWSET_SYNC_VENDOR,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   518
            SyncFactory.ROWSET_SYNC_PROVIDER_VERSION};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            for (int i = 0; i < propertyNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                propertyNames[i] = propertyNames[i] +
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   522
                        dot +
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   523
                        propertyIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Internal debug method that outputs the registry contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    private static void showImpl(ProviderImpl impl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        System.out.println("Provider implementation:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        System.out.println("Classname: " + impl.getClassname());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        System.out.println("Vendor: " + impl.getVendor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        System.out.println("Version: " + impl.getVersion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        System.out.println("Impl index: " + impl.getIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Returns the <code>SyncProvider</code> instance identified by <i>providerID</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @param providerID the unique identifier of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @return a <code>SyncProvider</code> implementation
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   547
     * @throws SyncFactoryException If the SyncProvider cannot be found,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   548
     * the providerID is {@code null}, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * some error was encountered when trying to invoke this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public static SyncProvider getInstance(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   552
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   553
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   554
        if(providerID == null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   555
            throw new SyncFactoryException("The providerID cannot be null");
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   556
        }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   557
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        initMapIfNecessary(); // populate HashTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        initJNDIContext();    // check JNDI context for any additional bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   561
        ProviderImpl impl = (ProviderImpl) implementations.get(providerID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (impl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            // Requested SyncProvider is unavailable. Return default provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return new com.sun.rowset.providers.RIOptimisticProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   568
        try {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   569
            ReflectUtil.checkPackageAccess(providerID);
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   570
        } catch (java.security.AccessControlException e) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   571
            SyncFactoryException sfe = new SyncFactoryException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   572
            sfe.initCause(e);
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   573
            throw sfe;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   574
        }
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   575
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        // Attempt to invoke classname from registered SyncProvider list
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   577
        Class<?> c = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
             * The SyncProvider implementation of the user will be in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
             * the classpath. We need to find the ClassLoader which loads
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   584
             * this SyncFactory and try to load the SyncProvider class from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
             * there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
             **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            c = Class.forName(providerID, true, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (c != null) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   590
                return (SyncProvider) c.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                return new com.sun.rowset.providers.RIOptimisticProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw new SyncFactoryException("IllegalAccessException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            throw new SyncFactoryException("InstantiationException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            throw new SyncFactoryException("ClassNotFoundException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   603
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Returns an Enumeration of currently registered synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * providers.  A <code>RowSet</code> implementation may use any provider in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * the enumeration as its <code>SyncProvider</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * At a minimum, the reference synchronization provider allowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * RowSet content data to be stored using a JDBC driver should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @return Enumeration  A enumeration of available synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * providers that are registered with this Factory
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   615
     * @throws SyncFactoryException If an error occurs obtaining the registered
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   616
     * providers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public static Enumeration<SyncProvider> getRegisteredProviders()
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   619
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // return a collection of classnames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        // of type SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return implementations.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Sets the logging object to be used by the <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * implementation provided by the <code>SyncFactory</code>. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <code>SyncProvider</code> implementations can log their events to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   632
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   633
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   634
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   635
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   636
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   637
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   638
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   639
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @param logger A Logger object instance
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   642
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   643
     *   {@code checkPermission} method denies calling {@code setLogger}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   644
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   645
     * @see SecurityManager#checkPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public static void setLogger(Logger logger) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   648
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   649
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   650
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   651
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   652
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   653
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   654
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   655
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   656
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Sets the logging object that is used by <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * implementations provided by the <code>SyncFactory</code> SPI. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * <code>SyncProvider</code> implementations can log their events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * to this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   666
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   667
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   668
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   669
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   670
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   671
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   672
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   673
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @param logger a Logger object instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param level a Level object instance indicating the degree of logging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * required
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   678
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   679
     *   {@code checkPermission} method denies calling {@code setLogger}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   680
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   681
     * @see SecurityManager#checkPermission
6846
2cfd1dfb014b 6988310: SyncFactory.setLogger(Logger,Level) requires unspecified security permission
lancea
parents: 6671
diff changeset
   682
     * @see LoggingPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public static void setLogger(Logger logger, Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        // singleton
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   686
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   687
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   688
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   689
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   690
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   691
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   692
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   693
        }
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   694
        logger.setLevel(level);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Returns the logging object for applications to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * synchronization events posted by SyncProvider implementations.
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   701
     * @return The {@code Logger} that has been specified for use by
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   702
     * {@code SyncProvider} implementations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @throws SyncFactoryException if no logging object has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public static Logger getLogger() throws SyncFactoryException {
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   706
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   707
        Logger result = rsLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        // only one logger per session
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   709
        if (result == null) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   710
            throw new SyncFactoryException("(SyncFactory) : No logger has been set");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   712
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   713
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   716
    /**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   717
     * Sets the initial JNDI context from which SyncProvider implementations
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   718
     * can be retrieved from a JNDI namespace
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   719
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   720
     *  This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   721
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   722
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   723
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   724
     * {@code checkPermission} method denies calling {@code setJNDIContext},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   725
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   726
     * {@code java.lang.SecurityException}.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   727
     *
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   728
     * @param ctx a valid JNDI context
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   729
     * @throws SyncFactoryException if the supplied JNDI context is null
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   730
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   731
     *  {@code checkPermission} method denies calling {@code setJNDIContext}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   732
     * @see SecurityManager#checkPermission
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   733
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   734
    public static synchronized void setJNDIContext(javax.naming.Context ctx)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   735
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   736
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   737
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   738
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   739
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (ctx == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            throw new SyncFactoryException("Invalid JNDI context supplied");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        ic = ctx;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   744
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   747
     * Controls JNDI context initialization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @throws SyncFactoryException if an error occurs parsing the JNDI context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   751
    private static synchronized void initJNDIContext() throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   753
        if ((ic != null) && (lazyJNDICtxRefresh == false)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                parseProperties(parseJNDIContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                lazyJNDICtxRefresh = true; // touch JNDI namespace once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                throw new SyncFactoryException("SPI: NamingException: " + e.getExplanation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                e.printStackTrace();
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   762
                throw new SyncFactoryException("SPI: Exception: " + e.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * Internal switch indicating whether the JNDI namespace should be re-read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    private static boolean lazyJNDICtxRefresh = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * Parses the set JNDI Context and passes bindings to the enumerateBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * method when complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    private static Properties parseJNDIContext() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   777
        NamingEnumeration<?> bindings = ic.listBindings("");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        Properties properties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        // Hunt one level below context for available SyncProvider objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        return properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Scans each binding on JNDI context and determines if any binding is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * instance of SyncProvider, if so, add this to the registry and continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * scan the current context using a re-entrant call to this method until all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * bindings have been enumerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   792
    private static void enumerateBindings(NamingEnumeration<?> bindings,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   793
            Properties properties) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        boolean syncProviderObj = false; // move to parameters ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            Binding bd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            Object elementObj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            String element = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            while (bindings.hasMore()) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   802
                bd = (Binding) bindings.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                element = bd.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                elementObj = bd.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                if (!(ic.lookup(element) instanceof Context)) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   807
                    // skip directories/sub-contexts
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   808
                    if (ic.lookup(element) instanceof SyncProvider) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                        syncProviderObj = true;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   810
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                if (syncProviderObj) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   814
                    SyncProvider sync = (SyncProvider) elementObj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    properties.put(SyncFactory.ROWSET_SYNC_PROVIDER,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   816
                            sync.getProviderID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    syncProviderObj = false; // reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        } catch (javax.naming.NotContextException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            bindings.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            // Re-entrant call into method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   827
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   828
    /**
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   829
     * Lazy initialization Holder class used by {@code getSyncFactory}
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   830
     */
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   831
    private static class SyncFactoryHolder {
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   832
        static final SyncFactory factory = new SyncFactory();
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   833
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   836
/**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   837
 * Internal class that defines the lazy reference construct for each registered
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   838
 * SyncProvider implementation.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   839
 */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   840
class ProviderImpl extends SyncProvider {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   841
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   842
    private String className = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   843
    private String vendorName = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   844
    private String ver = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   845
    private int index;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   847
    public void setClassname(String classname) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   848
        className = classname;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   849
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   851
    public String getClassname() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   852
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   853
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   855
    public void setVendor(String vendor) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   856
        vendorName = vendor;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   857
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   859
    public String getVendor() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   860
        return vendorName;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   861
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   863
    public void setVersion(String providerVer) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   864
        ver = providerVer;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   865
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   867
    public String getVersion() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   868
        return ver;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   869
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   871
    public void setIndex(int i) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   872
        index = i;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   873
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   875
    public int getIndex() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   876
        return index;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   877
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   879
    public int getDataSourceLock() throws SyncProviderException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   881
        int dsLock = 0;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   882
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   883
            dsLock = SyncFactory.getInstance(className).getDataSourceLock();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   884
        } catch (SyncFactoryException sfEx) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   886
            throw new SyncProviderException(sfEx.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   889
        return dsLock;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   890
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   892
    public int getProviderGrade() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   894
        int grade = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   896
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   897
            grade = SyncFactory.getInstance(className).getProviderGrade();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   898
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   899
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   902
        return grade;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   903
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   904
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   905
    public String getProviderID() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   906
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   907
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   909
    /*
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   910
    public javax.sql.RowSetInternal getRowSetInternal() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   911
    try
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   912
    {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   913
    return SyncFactory.getInstance(className).getRowSetInternal();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   914
    } catch(SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   915
    //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   916
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   917
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   918
     */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   919
    public javax.sql.RowSetReader getRowSetReader() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   921
        RowSetReader rsReader = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   923
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   924
            rsReader = SyncFactory.getInstance(className).getRowSetReader();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   925
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   926
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   929
        return rsReader;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   930
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   931
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   932
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   933
    public javax.sql.RowSetWriter getRowSetWriter() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        RowSetWriter rsWriter = null;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   936
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   937
            rsWriter = SyncFactory.getInstance(className).getRowSetWriter();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   938
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   939
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   942
        return rsWriter;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   943
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   944
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   945
    public void setDataSourceLock(int param)
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   946
            throws SyncProviderException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   947
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   948
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   949
            SyncFactory.getInstance(className).setDataSourceLock(param);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   950
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   951
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   952
            throw new SyncProviderException(sfEx.getMessage());
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   953
        }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   954
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   955
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   956
    public int supportsUpdatableView() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        int view = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   960
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   961
            view = SyncFactory.getInstance(className).supportsUpdatableView();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   962
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   963
            //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   964
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   966
        return view;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   968
}