src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncFactory.java
author lancea
Wed, 13 Mar 2019 14:10:18 -0400
changeset 54106 9a90236ab64c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220253: Fix Headings in java.sql.rowset Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, 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
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    62
 * <h2>1.0 Overview</h2>
2
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>
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
   111
 * <h2>2.0 Registering <code>SyncProvider</code> Implementations</h2>
2
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
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   386
                try {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   387
                    AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   388
                        InputStream in = SyncFactory.class.getModule().getResourceAsStream(ROWSET_PROPERTIES);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   389
                        if (in == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   390
                            throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   391
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   392
                        try (in) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25991
diff changeset
   393
                            properties.load(in);
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   394
                        }
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   395
                        return null;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   396
                    });
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   397
                } catch (PrivilegedActionException ex) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   398
                    Throwable e = ex.getException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   399
                    if (e instanceof SyncFactoryException) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   400
                      throw (SyncFactoryException) e;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   401
                    } else {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   402
                        SyncFactoryException sfe = new SyncFactoryException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   403
                        sfe.initCause(ex.getException());
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   404
                        throw sfe;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   405
                    }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   406
                }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   407
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   410
            // removed else, has properties should sum together
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                throw new SyncFactoryException("Cannot locate properties file: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                throw new SyncFactoryException("IOException: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             * Now deal with -Drowset.provider.classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
             * load additional properties from -D command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            properties.clear();
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   423
            String providerImpls;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   424
            try {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   425
                providerImpls = AccessController.doPrivileged(new PrivilegedAction<String>() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   426
                    public String run() {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   427
                        return System.getProperty(ROWSET_SYNC_PROVIDER);
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   428
                    }
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   429
                }, null, new PropertyPermission(ROWSET_SYNC_PROVIDER, "read"));
22301
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   430
            } catch (Exception ex) {
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   431
                providerImpls = null;
43e72ecb53b9 8022904: Enhance JDBC Parsers
lancea
parents: 18564
diff changeset
   432
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (providerImpls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                if (providerImpls.indexOf(colon) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    StringTokenizer tokenizer = new StringTokenizer(providerImpls, colon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    while (tokenizer.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        properties.put(ROWSET_SYNC_PROVIDER + "." + i, tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    properties.put(ROWSET_SYNC_PROVIDER, providerImpls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   449
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * The internal debug switch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Internal registry count for the number of providers contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private static int providerImplIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * 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
   462
     * ROWSET properties and stores lazy references into the internal registry.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    private static void parseProperties(Properties p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        ProviderImpl impl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        String[] propertyNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   470
        for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   472
            String str = (String) e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            int w = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (str.startsWith(SyncFactory.ROWSET_SYNC_PROVIDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                impl = new ProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                impl.setIndex(providerImplIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                if (w == (SyncFactory.ROWSET_SYNC_PROVIDER).length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    // no property index has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    propertyNames = getPropertyNames(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    // property index has been set.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   486
                    propertyNames = getPropertyNames(true, str.substring(w - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                key = p.getProperty(propertyNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                impl.setClassname(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                impl.setVendor(p.getProperty(propertyNames[1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                impl.setVersion(p.getProperty(propertyNames[2]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                implementations.put(key, impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Used by the parseProperties methods to disassemble each property tuple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private static String[] getPropertyNames(boolean append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return getPropertyNames(append, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Disassembles each property and its associated value. Also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * overloaded property names that contain indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static String[] getPropertyNames(boolean append,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   510
            String propertyIndex) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        String dot = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        String[] propertyNames =
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   513
                new String[]{SyncFactory.ROWSET_SYNC_PROVIDER,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   514
            SyncFactory.ROWSET_SYNC_VENDOR,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   515
            SyncFactory.ROWSET_SYNC_PROVIDER_VERSION};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            for (int i = 0; i < propertyNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                propertyNames[i] = propertyNames[i] +
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   519
                        dot +
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   520
                        propertyIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Internal debug method that outputs the registry contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private static void showImpl(ProviderImpl impl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        System.out.println("Provider implementation:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        System.out.println("Classname: " + impl.getClassname());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        System.out.println("Vendor: " + impl.getVendor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        System.out.println("Version: " + impl.getVersion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        System.out.println("Impl index: " + impl.getIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Returns the <code>SyncProvider</code> instance identified by <i>providerID</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param providerID the unique identifier of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @return a <code>SyncProvider</code> implementation
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   544
     * @throws SyncFactoryException If the SyncProvider cannot be found,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   545
     * the providerID is {@code null}, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * some error was encountered when trying to invoke this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public static SyncProvider getInstance(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   549
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   550
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   551
        if(providerID == null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   552
            throw new SyncFactoryException("The providerID cannot be null");
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   553
        }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   554
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        initMapIfNecessary(); // populate HashTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        initJNDIContext();    // check JNDI context for any additional bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   558
        ProviderImpl impl = (ProviderImpl) implementations.get(providerID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (impl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            // Requested SyncProvider is unavailable. Return default provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            return new com.sun.rowset.providers.RIOptimisticProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   565
        try {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   566
            ReflectUtil.checkPackageAccess(providerID);
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   567
        } catch (java.security.AccessControlException e) {
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   568
            SyncFactoryException sfe = new SyncFactoryException();
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   569
            sfe.initCause(e);
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   570
            throw sfe;
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   571
        }
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   572
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // Attempt to invoke classname from registered SyncProvider list
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   574
        Class<?> c = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
             * The SyncProvider implementation of the user will be in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
             * the classpath. We need to find the ClassLoader which loads
23914
754ca74db76a 8026200: Enhance RowSet Factory
lancea
parents: 22336
diff changeset
   581
             * this SyncFactory and try to load the SyncProvider class from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
             * there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
             **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            c = Class.forName(providerID, true, cl);
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 36511
diff changeset
   585
            @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 36511
diff changeset
   586
            Object result =  c.newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 36511
diff changeset
   587
            return (SyncProvider)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 36511
diff changeset
   589
        } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            throw new SyncFactoryException("IllegalAccessException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   593
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Returns an Enumeration of currently registered synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * providers.  A <code>RowSet</code> implementation may use any provider in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * the enumeration as its <code>SyncProvider</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * At a minimum, the reference synchronization provider allowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * RowSet content data to be stored using a JDBC driver should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @return Enumeration  A enumeration of available synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * providers that are registered with this Factory
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   605
     * @throws SyncFactoryException If an error occurs obtaining the registered
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   606
     * providers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public static Enumeration<SyncProvider> getRegisteredProviders()
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   609
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        // return a collection of classnames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        // of type SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return implementations.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Sets the logging object to be used by the <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * implementation provided by the <code>SyncFactory</code>. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <code>SyncProvider</code> implementations can log their events to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   622
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   623
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   624
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   625
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   626
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   627
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   628
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   629
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param logger A Logger object instance
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   632
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   633
     *   {@code checkPermission} method denies calling {@code setLogger}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   634
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   635
     * @see SecurityManager#checkPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public static void setLogger(Logger logger) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   638
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   639
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   640
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   641
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   642
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   643
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   644
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   645
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   646
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Sets the logging object that is used by <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * implementations provided by the <code>SyncFactory</code> SPI. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <code>SyncProvider</code> implementations can log their events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * to this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   656
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   657
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   658
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   659
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   660
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   661
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   662
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   663
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @param logger a Logger object instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param level a Level object instance indicating the degree of logging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * required
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   668
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   669
     *   {@code checkPermission} method denies calling {@code setLogger}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   670
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   671
     * @see SecurityManager#checkPermission
6846
2cfd1dfb014b 6988310: SyncFactory.setLogger(Logger,Level) requires unspecified security permission
lancea
parents: 6671
diff changeset
   672
     * @see LoggingPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public static void setLogger(Logger logger, Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // singleton
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   676
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   677
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   678
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   679
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   680
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   681
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   682
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   683
        }
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   684
        logger.setLevel(level);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Returns the logging object for applications to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * synchronization events posted by SyncProvider implementations.
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   691
     * @return The {@code Logger} that has been specified for use by
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   692
     * {@code SyncProvider} implementations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @throws SyncFactoryException if no logging object has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    public static Logger getLogger() throws SyncFactoryException {
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   696
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   697
        Logger result = rsLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        // only one logger per session
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   699
        if (result == null) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   700
            throw new SyncFactoryException("(SyncFactory) : No logger has been set");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   702
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   703
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   706
    /**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   707
     * Sets the initial JNDI context from which SyncProvider implementations
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   708
     * can be retrieved from a JNDI namespace
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   709
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   710
     *  This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   711
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   712
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   713
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   714
     * {@code checkPermission} method denies calling {@code setJNDIContext},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   715
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   716
     * {@code java.lang.SecurityException}.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   717
     *
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   718
     * @param ctx a valid JNDI context
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   719
     * @throws SyncFactoryException if the supplied JNDI context is null
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   720
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   721
     *  {@code checkPermission} method denies calling {@code setJNDIContext}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   722
     * @see SecurityManager#checkPermission
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   723
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   724
    public static synchronized void setJNDIContext(javax.naming.Context ctx)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   725
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   726
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   727
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   728
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   729
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        if (ctx == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            throw new SyncFactoryException("Invalid JNDI context supplied");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        ic = ctx;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   734
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   737
     * Controls JNDI context initialization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @throws SyncFactoryException if an error occurs parsing the JNDI context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   741
    private static synchronized void initJNDIContext() throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   743
        if ((ic != null) && (lazyJNDICtxRefresh == false)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                parseProperties(parseJNDIContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                lazyJNDICtxRefresh = true; // touch JNDI namespace once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                throw new SyncFactoryException("SPI: NamingException: " + e.getExplanation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                e.printStackTrace();
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   752
                throw new SyncFactoryException("SPI: Exception: " + e.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Internal switch indicating whether the JNDI namespace should be re-read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private static boolean lazyJNDICtxRefresh = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Parses the set JNDI Context and passes bindings to the enumerateBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * method when complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    private static Properties parseJNDIContext() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   767
        NamingEnumeration<?> bindings = ic.listBindings("");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        Properties properties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        // Hunt one level below context for available SyncProvider objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        return properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Scans each binding on JNDI context and determines if any binding is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * instance of SyncProvider, if so, add this to the registry and continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * scan the current context using a re-entrant call to this method until all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * bindings have been enumerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   782
    private static void enumerateBindings(NamingEnumeration<?> bindings,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   783
            Properties properties) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        boolean syncProviderObj = false; // move to parameters ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            Binding bd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            Object elementObj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            String element = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            while (bindings.hasMore()) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   792
                bd = (Binding) bindings.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                element = bd.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                elementObj = bd.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if (!(ic.lookup(element) instanceof Context)) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   797
                    // skip directories/sub-contexts
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   798
                    if (ic.lookup(element) instanceof SyncProvider) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                        syncProviderObj = true;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   800
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                if (syncProviderObj) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   804
                    SyncProvider sync = (SyncProvider) elementObj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    properties.put(SyncFactory.ROWSET_SYNC_PROVIDER,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   806
                            sync.getProviderID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    syncProviderObj = false; // reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        } catch (javax.naming.NotContextException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            bindings.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            // Re-entrant call into method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   817
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   818
    /**
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   819
     * Lazy initialization Holder class used by {@code getSyncFactory}
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   820
     */
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   821
    private static class SyncFactoryHolder {
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   822
        static final SyncFactory factory = new SyncFactory();
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   823
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   826
/**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   827
 * Internal class that defines the lazy reference construct for each registered
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   828
 * SyncProvider implementation.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   829
 */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   830
class ProviderImpl extends SyncProvider {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   831
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   832
    private String className = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   833
    private String vendorName = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   834
    private String ver = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   835
    private int index;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   837
    public void setClassname(String classname) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   838
        className = classname;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   839
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   841
    public String getClassname() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   842
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   843
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   845
    public void setVendor(String vendor) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   846
        vendorName = vendor;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   847
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   849
    public String getVendor() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   850
        return vendorName;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   851
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   853
    public void setVersion(String providerVer) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   854
        ver = providerVer;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   855
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   857
    public String getVersion() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   858
        return ver;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   859
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   861
    public void setIndex(int i) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   862
        index = i;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   863
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   865
    public int getIndex() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   866
        return index;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   867
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   869
    public int getDataSourceLock() throws SyncProviderException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   871
        int dsLock = 0;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   872
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   873
            dsLock = SyncFactory.getInstance(className).getDataSourceLock();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   874
        } catch (SyncFactoryException sfEx) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   876
            throw new SyncProviderException(sfEx.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   879
        return dsLock;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   880
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   882
    public int getProviderGrade() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   884
        int grade = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   886
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   887
            grade = SyncFactory.getInstance(className).getProviderGrade();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   888
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   889
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   892
        return grade;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   893
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   894
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   895
    public String getProviderID() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   896
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   897
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   899
    /*
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   900
    public javax.sql.RowSetInternal getRowSetInternal() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   901
    try
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   902
    {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   903
    return SyncFactory.getInstance(className).getRowSetInternal();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   904
    } catch(SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   905
    //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   906
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   907
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   908
     */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   909
    public javax.sql.RowSetReader getRowSetReader() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   911
        RowSetReader rsReader = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   913
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   914
            rsReader = SyncFactory.getInstance(className).getRowSetReader();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   915
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   916
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   919
        return rsReader;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   920
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   921
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   922
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   923
    public javax.sql.RowSetWriter getRowSetWriter() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        RowSetWriter rsWriter = null;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   926
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   927
            rsWriter = SyncFactory.getInstance(className).getRowSetWriter();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   928
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   929
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   932
        return rsWriter;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   933
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   934
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   935
    public void setDataSourceLock(int param)
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   936
            throws SyncProviderException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   937
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   938
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   939
            SyncFactory.getInstance(className).setDataSourceLock(param);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   940
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   941
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   942
            throw new SyncProviderException(sfEx.getMessage());
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
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   946
    public int supportsUpdatableView() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        int view = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   950
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   951
            view = SyncFactory.getInstance(className).supportsUpdatableView();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   952
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   953
            //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   954
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   956
        return view;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   958
}