jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java
author lancea
Fri, 02 Dec 2011 19:33:54 -0500
changeset 11129 f9ad1aadf3fa
parent 9035 1255eb81cc2f
child 14176 9864fbbedb87
permissions -rw-r--r--
7116445: Miscellaneous warnings in the JDBC/RowSet classes Reviewed-by: smarks, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8405
diff changeset
     2
 * Copyright (c) 2003, 2011, 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";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * The RI Optimistic Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private static String default_provider =
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   236
            "com.sun.rowset.providers.RIOptimisticProvider";
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   237
    /**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   238
     *  Permission required to invoke setJNDIContext and setLogger
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   239
     */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   240
    private static final SQLPermission SET_SYNCFACTORY_PERMISSION =
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   241
            new SQLPermission("setSyncFactory");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * The initial JNDI context where <code>SyncProvider</code> implementations can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * be stored and from which they can be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    private static Context ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * The <code>Logger</code> object to be used by the <code>SyncFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   250
    private static volatile Logger rsLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private static Level rsLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * The registry of available <code>SyncProvider</code> implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * See section 2.0 of the class comment for <code>SyncFactory</code> for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * explanation of how a provider can be added to this registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   260
    private static Hashtable<String, SyncProvider> implementations;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Internal sync object used to maintain the SPI as a singleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static Object logSync = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Internal PrintWriter field for logging facility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private static java.io.PrintWriter logWriter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Adds the the given synchronization provider to the factory register. Guidelines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * are provided in the <code>SyncProvider</code> specification for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * required naming conventions for <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Synchronization providers bound to a JNDI context can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * registered by binding a SyncProvider instance to a JNDI namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * SyncProvider p = new MySyncProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * InitialContext ic = new InitialContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * ic.bind ("jdbc/rowset/MySyncProvider", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Furthermore, an initial JNDI context should be set with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <code>SyncFactory</code> using the <code>setJNDIContext</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * The <code>SyncFactory</code> leverages this context to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * available <code>SyncProvider</code> objects bound to the JNDI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * context and its child nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param providerID A <code>String</code> object with the unique ID of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *             synchronization provider being registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @throws SyncFactoryException if an attempt is made to supply an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *         or null provider name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #setJNDIContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public static synchronized void registerProvider(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   298
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        ProviderImpl impl = new ProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        impl.setClassname(providerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        implementations.put(providerID, impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Returns the <code>SyncFactory</code> singleton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the <code>SyncFactory</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   312
    public static SyncFactory getSyncFactory() {
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   313
        /*
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   314
         * Using Initialization on Demand Holder idiom as
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   315
         * 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
   316
         * than the Double-Check Locking idiom.
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   317
         */
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   318
        return SyncFactoryHolder.factory;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   319
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Removes the designated currently registered synchronization provider from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Factory SPI register.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param providerID The unique-id of the synchronization provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @throws SyncFactoryException If an attempt is made to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * unregister a SyncProvider implementation that was not registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public static synchronized void unregisterProvider(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   330
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (implementations.containsKey(providerID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            implementations.remove(providerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private static String colon = ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    private static String strFileSep = "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private static synchronized void initMapIfNecessary() throws SyncFactoryException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // Local implementation class names and keys from Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // file, translate names into Class objects using Class.forName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // and store mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        Properties properties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (implementations == null) {
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   347
            implementations = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // check if user is supplying his Synchronisation Provider
6671
c5fbc05d7347 6984044: RowSet source needs to rebrand vendor references
lancea
parents: 6529
diff changeset
   352
                // Implementation if not using Oracle's implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                // properties.load(new FileInputStream(ROWSET_PROPERTIES));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                // The rowset.properties needs to be in jdk/jre/lib when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                // integrated with jdk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                // else it should be picked from -D option from command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // -Drowset.properties will add to standard properties. Similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                // keys will over-write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                 * Dependent on application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                String strRowsetProperties = System.getProperty("rowset.properties");
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   366
                if (strRowsetProperties != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    // Load user's implementation of SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    // here. -Drowset.properties=/abc/def/pqr.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    ROWSET_PROPERTIES = strRowsetProperties;
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   370
                    try (FileInputStream fis = new FileInputStream(ROWSET_PROPERTIES)) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   371
                        properties.load(fis);
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   372
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                 * Always available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                ROWSET_PROPERTIES = "javax" + strFileSep + "sql" +
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   380
                        strFileSep + "rowset" + strFileSep +
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   381
                        "rowset.properties";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
8405
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   385
                try (InputStream stream =
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   386
                         (cl == null) ? ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES)
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   387
                                      : cl.getResourceAsStream(ROWSET_PROPERTIES)) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   388
                    if (stream == null) {
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   389
                        throw new SyncFactoryException(
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   390
                            "Resource " + ROWSET_PROPERTIES + " not found");
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   391
                    }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   392
                    properties.load(stream);
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   393
                }
bafd7b441d80 7018385: update javax.sql classes to use try-with-resources
smarks
parents: 7184
diff changeset
   394
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   397
            // removed else, has properties should sum together
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                throw new SyncFactoryException("Cannot locate properties file: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                throw new SyncFactoryException("IOException: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
             * Now deal with -Drowset.provider.classname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
             * load additional properties from -D command line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            properties.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            String providerImpls = System.getProperty(ROWSET_SYNC_PROVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (providerImpls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                if (providerImpls.indexOf(colon) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    StringTokenizer tokenizer = new StringTokenizer(providerImpls, colon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    while (tokenizer.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        properties.put(ROWSET_SYNC_PROVIDER + "." + i, tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    properties.put(ROWSET_SYNC_PROVIDER, providerImpls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                parseProperties(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   427
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * The internal debug switch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    private static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Internal registry count for the number of providers contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    private static int providerImplIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Internal handler for all standard property parsing. Parses standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * ROWSET properties and stores lazy references into the the internal registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    private static void parseProperties(Properties p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        ProviderImpl impl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        String[] propertyNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   448
        for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   450
            String str = (String) e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            int w = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (str.startsWith(SyncFactory.ROWSET_SYNC_PROVIDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                impl = new ProviderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                impl.setIndex(providerImplIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (w == (SyncFactory.ROWSET_SYNC_PROVIDER).length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    // no property index has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    propertyNames = getPropertyNames(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    // property index has been set.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   464
                    propertyNames = getPropertyNames(true, str.substring(w - 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                key = p.getProperty(propertyNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                impl.setClassname(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                impl.setVendor(p.getProperty(propertyNames[1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                impl.setVersion(p.getProperty(propertyNames[2]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                implementations.put(key, impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Used by the parseProperties methods to disassemble each property tuple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    private static String[] getPropertyNames(boolean append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return getPropertyNames(append, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Disassembles each property and its associated value. Also handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * overloaded property names that contain indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private static String[] getPropertyNames(boolean append,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   488
            String propertyIndex) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        String dot = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        String[] propertyNames =
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   491
                new String[]{SyncFactory.ROWSET_SYNC_PROVIDER,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   492
            SyncFactory.ROWSET_SYNC_VENDOR,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   493
            SyncFactory.ROWSET_SYNC_PROVIDER_VERSION};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            for (int i = 0; i < propertyNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                propertyNames[i] = propertyNames[i] +
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   497
                        dot +
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   498
                        propertyIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return propertyNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Internal debug method that outputs the registry contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static void showImpl(ProviderImpl impl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        System.out.println("Provider implementation:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        System.out.println("Classname: " + impl.getClassname());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        System.out.println("Vendor: " + impl.getVendor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        System.out.println("Version: " + impl.getVersion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        System.out.println("Impl index: " + impl.getIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the <code>SyncProvider</code> instance identified by <i>providerID</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param providerID the unique identifier of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @return a <code>SyncProvider</code> implementation
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   522
     * @throws SyncFactoryException If the SyncProvider cannot be found,
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   523
     * the providerID is {@code null}, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * some error was encountered when trying to invoke this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public static SyncProvider getInstance(String providerID)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   527
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   528
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   529
        if(providerID == null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   530
            throw new SyncFactoryException("The providerID cannot be null");
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   531
        }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   532
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        initMapIfNecessary(); // populate HashTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        initJNDIContext();    // check JNDI context for any additional bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   536
        ProviderImpl impl = (ProviderImpl) implementations.get(providerID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (impl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // Requested SyncProvider is unavailable. Return default provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return new com.sun.rowset.providers.RIOptimisticProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        // Attempt to invoke classname from registered SyncProvider list
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   544
        Class<?> c = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
             * The SyncProvider implementation of the user will be in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
             * the classpath. We need to find the ClassLoader which loads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
             * this SyncFactory and try to laod the SyncProvider class from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
             * there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
             **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            c = Class.forName(providerID, true, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            if (c != null) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   557
                return (SyncProvider) c.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                return new com.sun.rowset.providers.RIOptimisticProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            throw new SyncFactoryException("IllegalAccessException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            throw new SyncFactoryException("InstantiationException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            throw new SyncFactoryException("ClassNotFoundException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   570
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns an Enumeration of currently registered synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * providers.  A <code>RowSet</code> implementation may use any provider in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * the enumeration as its <code>SyncProvider</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * At a minimum, the reference synchronization provider allowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * RowSet content data to be stored using a JDBC driver should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return Enumeration  A enumeration of available synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * providers that are registered with this Factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public static Enumeration<SyncProvider> getRegisteredProviders()
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   584
            throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        initMapIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        // return a collection of classnames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        // of type SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        return implementations.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Sets the logging object to be used by the <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * implementation provided by the <code>SyncFactory</code>. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>SyncProvider</code> implementations can log their events to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   597
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   598
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   599
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   600
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   601
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   602
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   603
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   604
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @param logger A Logger object instance
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   607
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   608
     *   {@code checkPermission} method denies calling {@code setLogger}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   609
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   610
     * @see SecurityManager#checkPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public static void setLogger(Logger logger) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   613
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   614
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   615
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   616
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   617
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   618
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   619
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   620
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   621
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Sets the logging object that is used by <code>SyncProvider</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * implementations provided by the <code>SyncFactory</code> SPI. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <code>SyncProvider</code> implementations can log their events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * to this object and the application can retrieve a handle to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * object using the <code>getLogger</code> method.
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   631
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   632
     * This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   633
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   634
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   635
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   636
     * {@code checkPermission} method denies calling {@code setLogger},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   637
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   638
     * {@code java.lang.SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param logger a Logger object instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @param level a Level object instance indicating the degree of logging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * required
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   643
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   644
     *   {@code checkPermission} method denies calling {@code setLogger}
6846
2cfd1dfb014b 6988310: SyncFactory.setLogger(Logger,Level) requires unspecified security permission
lancea
parents: 6671
diff changeset
   645
     * @throws java.util.logging.LoggingPermission if a security manager exists and its
2cfd1dfb014b 6988310: SyncFactory.setLogger(Logger,Level) requires unspecified security permission
lancea
parents: 6671
diff changeset
   646
     *   {@code checkPermission} method denies calling {@code setLevel}
7184
70b4f13c6f5d 6999086: Clarify that SyncFactory.setLogger can throw an NullPointerException
lancea
parents: 7182
diff changeset
   647
     * @throws NullPointerException if the logger is null
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   648
     * @see SecurityManager#checkPermission
6846
2cfd1dfb014b 6988310: SyncFactory.setLogger(Logger,Level) requires unspecified security permission
lancea
parents: 6671
diff changeset
   649
     * @see LoggingPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public static void setLogger(Logger logger, Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        // singleton
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   653
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   654
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   655
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   656
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   657
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   658
        if(logger == null){
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   659
            throw new NullPointerException("You must provide a Logger");
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   660
        }
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   661
        logger.setLevel(level);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        rsLogger = logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Returns the logging object for applications to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * synchronization events posted by SyncProvider implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @throws SyncFactoryException if no logging object has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public static Logger getLogger() throws SyncFactoryException {
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   672
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   673
        Logger result = rsLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        // only one logger per session
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   675
        if (result == null) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   676
            throw new SyncFactoryException("(SyncFactory) : No logger has been set");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   678
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   679
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   682
    /**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   683
     * Sets the initial JNDI context from which SyncProvider implementations
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   684
     * can be retrieved from a JNDI namespace
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   685
     * <p>
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   686
     *  This method checks to see that there is an {@code SQLPermission}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   687
     * object  which grants the permission {@code setSyncFactory}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   688
     * before allowing the method to succeed.  If a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   689
     * {@code SecurityManager} exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   690
     * {@code checkPermission} method denies calling {@code setJNDIContext},
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   691
     * this method throws a
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   692
     * {@code java.lang.SecurityException}.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   693
     *
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   694
     * @param ctx a valid JNDI context
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   695
     * @throws SyncFactoryException if the supplied JNDI context is null
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   696
     * @throws java.lang.SecurityException if a security manager exists and its
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   697
     *  {@code checkPermission} method denies calling {@code setJNDIContext}
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   698
     * @see SecurityManager#checkPermission
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   699
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   700
    public static synchronized void setJNDIContext(javax.naming.Context ctx)
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   701
            throws SyncFactoryException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   702
        SecurityManager sec = System.getSecurityManager();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   703
        if (sec != null) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   704
            sec.checkPermission(SET_SYNCFACTORY_PERMISSION);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   705
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (ctx == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            throw new SyncFactoryException("Invalid JNDI context supplied");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        ic = ctx;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   710
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   713
     * Controls JNDI context initialization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @throws SyncFactoryException if an error occurs parsing the JNDI context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   717
    private static synchronized void initJNDIContext() throws SyncFactoryException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   719
        if ((ic != null) && (lazyJNDICtxRefresh == false)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                parseProperties(parseJNDIContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                lazyJNDICtxRefresh = true; // touch JNDI namespace once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                throw new SyncFactoryException("SPI: NamingException: " + e.getExplanation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                e.printStackTrace();
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   728
                throw new SyncFactoryException("SPI: Exception: " + e.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Internal switch indicating whether the JNDI namespace should be re-read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private static boolean lazyJNDICtxRefresh = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Parses the set JNDI Context and passes bindings to the enumerateBindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * method when complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    private static Properties parseJNDIContext() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   743
        NamingEnumeration<?> bindings = ic.listBindings("");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        Properties properties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        // Hunt one level below context for available SyncProvider objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        return properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * Scans each binding on JNDI context and determines if any binding is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * instance of SyncProvider, if so, add this to the registry and continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * scan the current context using a re-entrant call to this method until all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * bindings have been enumerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9035
diff changeset
   758
    private static void enumerateBindings(NamingEnumeration<?> bindings,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   759
            Properties properties) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        boolean syncProviderObj = false; // move to parameters ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            Binding bd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            Object elementObj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            String element = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            while (bindings.hasMore()) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   768
                bd = (Binding) bindings.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                element = bd.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                elementObj = bd.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                if (!(ic.lookup(element) instanceof Context)) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   773
                    // skip directories/sub-contexts
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   774
                    if (ic.lookup(element) instanceof SyncProvider) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        syncProviderObj = true;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   776
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                if (syncProviderObj) {
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   780
                    SyncProvider sync = (SyncProvider) elementObj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    properties.put(SyncFactory.ROWSET_SYNC_PROVIDER,
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   782
                            sync.getProviderID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    syncProviderObj = false; // reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        } catch (javax.naming.NotContextException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            bindings.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            // Re-entrant call into method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            enumerateBindings(bindings, properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
7182
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   793
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   794
    /**
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   795
     * Lazy initialization Holder class used by {@code getSyncFactory}
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   796
     */
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   797
    private static class SyncFactoryHolder {
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   798
        static final SyncFactory factory = new SyncFactory();
f3e89472692d 6982530: javadoc update to SyncFactory & JdbcResource bundle for synchronization issues
lancea
parents: 6846
diff changeset
   799
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   802
/**
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   803
 * Internal class that defines the lazy reference construct for each registered
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   804
 * SyncProvider implementation.
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   805
 */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   806
class ProviderImpl extends SyncProvider {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   807
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   808
    private String className = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   809
    private String vendorName = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   810
    private String ver = null;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   811
    private int index;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   813
    public void setClassname(String classname) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   814
        className = classname;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   815
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   817
    public String getClassname() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   818
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   819
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   821
    public void setVendor(String vendor) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   822
        vendorName = vendor;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   823
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   825
    public String getVendor() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   826
        return vendorName;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   827
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   829
    public void setVersion(String providerVer) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   830
        ver = providerVer;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   831
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   833
    public String getVersion() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   834
        return ver;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   835
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   837
    public void setIndex(int i) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   838
        index = i;
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 getIndex() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   842
        return index;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   843
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   845
    public int getDataSourceLock() throws SyncProviderException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   847
        int dsLock = 0;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   848
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   849
            dsLock = SyncFactory.getInstance(className).getDataSourceLock();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   850
        } catch (SyncFactoryException sfEx) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   852
            throw new SyncProviderException(sfEx.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   855
        return dsLock;
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
    public int getProviderGrade() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   860
        int grade = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   862
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   863
            grade = SyncFactory.getInstance(className).getProviderGrade();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   864
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   865
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   868
        return grade;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   869
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   870
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   871
    public String getProviderID() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   872
        return className;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   873
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   875
    /*
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   876
    public javax.sql.RowSetInternal getRowSetInternal() {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   877
    try
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   878
    {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   879
    return SyncFactory.getInstance(className).getRowSetInternal();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   880
    } catch(SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   881
    //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   882
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   883
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   884
     */
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   885
    public javax.sql.RowSetReader getRowSetReader() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   887
        RowSetReader rsReader = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   889
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   890
            rsReader = SyncFactory.getInstance(className).getRowSetReader();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   891
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   892
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   895
        return rsReader;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   896
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   897
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   898
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   899
    public javax.sql.RowSetWriter getRowSetWriter() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        RowSetWriter rsWriter = null;
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   902
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   903
            rsWriter = SyncFactory.getInstance(className).getRowSetWriter();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   904
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   905
            //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   908
        return rsWriter;
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   909
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   910
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   911
    public void setDataSourceLock(int param)
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   912
            throws SyncProviderException {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   913
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   914
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   915
            SyncFactory.getInstance(className).setDataSourceLock(param);
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   916
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   917
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   918
            throw new SyncProviderException(sfEx.getMessage());
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   919
        }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   920
    }
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   921
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   922
    public int supportsUpdatableView() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        int view = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   926
        try {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   927
            view = SyncFactory.getInstance(className).supportsUpdatableView();
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   928
        } catch (SyncFactoryException sfEx) {
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   929
            //
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   930
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   932
        return view;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    }
6529
bdf98f8db729 6843995: RowSet 1.1 updates
lancea
parents: 5506
diff changeset
   934
}