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