예제 #1
0
            /// <summary>
            /// Retrieves an embedded session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <returns>an embedded session</returns>
            internal static HsqlSession NewEmbeddedSession(
                HsqlProperties properties)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user     = properties.getProperty("user");
                string password = properties.getProperty("password");
                string scheme   = properties.getProperty("connection_type");
                string path     = properties.getProperty("database");

                try
                {
                    ISession session = org.hsqldb.DatabaseManager.newSession(
                        scheme,
                        path,
                        user,
                        password,
                        properties);

                    return(new HsqlSession(session));
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }
예제 #2
0
            /// <summary>
            /// Translates the given properties object.
            /// </summary>
            /// <param name="properties">The properties.</param>
            private static void TranslateProperties(HsqlProperties properties)
            {
                string user     = properties.getProperty("user");
                string password = properties.getProperty("password");
                int    port     = properties.getIntegerProperty("port", 0);

                if (user == null)
                {
                    user = "******";
                }
                else
                {
                    user = user.ToUpperInvariant();
                }

                if (password == null)
                {
                    password = "";
                }
                else
                {
                    password = password.ToUpperInvariant();
                }

                properties.setProperty("user", user);
                properties.setProperty("password", password);
                properties.setProperty("port", port);
            }
예제 #3
0
        /// <summary>
        /// Parses the given connection URL.
        /// </summary>
        /// <param name="url">The connection URL.</param>
        /// <returns>
        /// The collection of connection properties implied by the given URL.
        /// </returns>
        internal static org.hsqldb.persist.HsqlProperties ParseURL(string url)
        {
            org.hsqldb.persist.HsqlProperties properties
                = org.hsqldb.DatabaseURL.parseURL(url, true);

            if (properties == null || properties.isEmpty())
            {
                throw new HsqlDataSourceException("Invalid Connection URL: "
                                                  + url, org.hsqldb.Trace.GENERAL_ERROR, "S1000");
            }

            return(properties);
        }
예제 #4
0
        /// <summary>
        /// Gets an <c>HsqlSession</c> corresponding to the given connection
        /// string builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>
        /// An HsqlSession corresponding to the given connection string builder.
        /// </returns>
        internal static HsqlSession GetSession(HsqlConnectionStringBuilder builder)
        {
            string url = builder.JdbcUrl;

            org.hsqldb.persist.HsqlProperties properties = HsqlDriver.ParseURL(url);

            switch (builder.Protocol)
            {
            case ConnectionProtocol.File:
            case ConnectionProtocol.Mem:
            {
                return(HsqlSession.Factory.NewEmbeddedSession(properties));
            }

            case ConnectionProtocol.Res:
            {
                return(HsqlSession.Factory.NewEmbeddedResSession(properties));
            }

            case ConnectionProtocol.Hsql:
            {
                return(HsqlSession.Factory.NewHsqlClientSession(properties, /*tls*/ false));
            }

            case ConnectionProtocol.Hsqls:
            {
                return(HsqlSession.Factory.NewHsqlClientSession(properties, /*tls*/ true));
            }

            case ConnectionProtocol.Http:
            {
                return(HsqlSession.Factory.NewHttpClientSession(properties, /*tls*/ false));
            }

            case ConnectionProtocol.Https:
            {
                return(HsqlSession.Factory.NewHttpClientSession(properties, /*tls*/ true));
            }

            default:
            {
                throw new HsqlDataSourceException("Unknown Connection URL: "
                                                  + url, org.hsqldb.Trace.GENERAL_ERROR, "S1000");
            }
            }
        }
예제 #5
0
            /// <summary>
            /// Gets an HSQL protocol client session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <param name="tls">
            /// If set to <c>true</c>, the session uses transport layer security.
            /// </param>
            /// <returns>an HSQL protocol client session</returns>
            internal static HsqlSession NewHsqlClientSession(
                HsqlProperties properties,
                bool tls)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user     = properties.getProperty("user");
                string password = properties.getProperty("password");
                string host     = properties.getProperty("host");
                int    port     = properties.getIntegerProperty("port", 0);
                string path     = properties.getProperty("path");
                string database = properties.getProperty("database");

                try
                {
                    //Console.WriteLine(
                    //    "GetHsqlClientSession : host {0}, port {1}, database {2}, tls {3}",
                    //    host,
                    //    port,
                    //    database,
                    //    tls);

                    ISession session = new HsqlTcpClient(
                        host,
                        port,
                        path,
                        database,
                        tls,
                        user,
                        password);

                    return(new HsqlSession(session));
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }
예제 #6
0
            /// <summary>
            /// Gets an embedded session using the given properties.
            /// </summary>
            /// <remarks>
            /// It is assumed (but not checked) that the given properties
            /// object requests a session with a res: protocol database
            /// instance; work is performed toward configuring and locking
            /// the ambient class loading environment to correctly handle
            /// searching the transitive closure of <c>ikvmres:</c>
            /// protocol resources reachable by compile-time reference,
            /// starting with the assemblies referenced on the call stack,
            /// as well as the entry level, calling and executing assemblies
            /// and their related satellite assemblies.
            /// </remarks>
            /// <param name="properties">The properties.</param>
            /// <returns>an embedded session</returns>
            internal static HsqlSession NewEmbeddedResSession(
                HsqlProperties properties)
            {
                StackTrace trace = new StackTrace();

                java.util.Set set = new java.util.HashSet();

                foreach (StackFrame frame in trace.GetFrames())
                {
                    set.add(frame.GetMethod().DeclaringType.Assembly.FullName);
                }

                List <Assembly> startingList = new List <Assembly>();

                foreach (string name in set.toArray())
                {
                    try
                    {
                        startingList.Add(Assembly.Load(name));
                    }
                    catch { }
                }

                startingList.Add(Assembly.GetExecutingAssembly());
                startingList.Add(Assembly.GetCallingAssembly());

                if (Assembly.GetEntryAssembly() != null)
                {
                    startingList.Add(Assembly.GetEntryAssembly());
                }

                java.lang.ClassLoader loader
                    = IkvmResourceLoaderFactory.CreateLoader(startingList);

                lock (s_resLock)
                {
                    org.hsqldb.lib.ResourceStreamProvider.setLoader(loader);

                    return(HsqlSession.Factory.NewEmbeddedSession(properties));
                }
            }
예제 #7
0
            /// <summary>
            /// Gets an HTTP protocol client session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <param name="tls">
            /// If set to <c>true</c>, the session uses transport layer security.
            /// </param>
            /// <returns>an HTTP protocol client session</returns>
            internal static HsqlSession NewHttpClientSession(
                HsqlProperties properties,
                bool tls)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user     = properties.getProperty("user");
                string password = properties.getProperty("password");
                string host     = properties.getProperty("host");
                int    port     = properties.getIntegerProperty("port", 0);
                string path     = properties.getProperty("path");
                string database = properties.getProperty("database");

                try
                {
                    ISession session = new org.hsqldb.HTTPClientConnection(
                        host,
                        port,
                        path,
                        database,
                        tls,
                        user,
                        password);

                    return(new HsqlSession(session));
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }
            /// <summary>
            /// Gets an embedded session using the given properties.
            /// </summary>
            /// <remarks>
            /// It is assumed (but not checked) that the given properties
            /// object requests a session with a res: protocol database
            /// instance; work is performed toward configuring and locking
            /// the ambient class loading environment to correctly handle
            /// searching the transitive closure of <c>ikvmres:</c>
            /// protocol resources reachable by compile-time reference, 
            /// starting with the assemblies referenced on the call stack,
            /// as well as the entry level, calling and executing assemblies
            /// and their related satellite assemblies.
            /// </remarks>
            /// <param name="properties">The properties.</param>
            /// <returns>an embedded session</returns>
            internal static HsqlSession NewEmbeddedResSession(
                HsqlProperties properties)
            {
                StackTrace trace = new StackTrace();
                java.util.Set set = new java.util.HashSet();

                foreach (StackFrame frame in trace.GetFrames())
                {
                    set.add(frame.GetMethod().DeclaringType.Assembly.FullName);
                }

                List<Assembly> startingList = new List<Assembly>();

                foreach (string name in set.toArray())
                {
                    try
                    {
                        startingList.Add(Assembly.Load(name));
                    }
                    catch { }
                }

                startingList.Add(Assembly.GetExecutingAssembly());
                startingList.Add(Assembly.GetCallingAssembly());

                if (Assembly.GetEntryAssembly() != null)
                {
                    startingList.Add(Assembly.GetEntryAssembly());
                }

                java.lang.ClassLoader loader
                    = IkvmResourceLoaderFactory.CreateLoader(startingList);

                lock (s_resLock)
                {
                    org.hsqldb.lib.ResourceStreamProvider.setLoader(loader);

                    return HsqlSession.Factory.NewEmbeddedSession(properties);
                }
            }
            /// <summary>
            /// Translates the given properties object.
            /// </summary>
            /// <param name="properties">The properties.</param>
            private static void TranslateProperties(HsqlProperties properties)
            {
                string user = properties.getProperty("user");
                string password = properties.getProperty("password");
                int port = properties.getIntegerProperty("port", 0);

                if (user == null)
                {
                    user = "******";
                }
                else
                {
                    user = user.ToUpperInvariant();
                }

                if (password == null)
                {
                    password = "";
                }
                else
                {
                    password = password.ToUpperInvariant();
                }

                properties.setProperty("user", user);
                properties.setProperty("password", password);
                properties.setProperty("port", port);
            }
            /// <summary>
            /// Gets an HTTP protocol client session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <param name="tls">
            /// If set to <c>true</c>, the session uses transport layer security.
            /// </param>
            /// <returns>an HTTP protocol client session</returns>
            internal static HsqlSession NewHttpClientSession(
                HsqlProperties properties,
                bool tls)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user = properties.getProperty("user");
                string password = properties.getProperty("password");
                string host = properties.getProperty("host");
                int port = properties.getIntegerProperty("port", 0);
                string path = properties.getProperty("path");
                string database = properties.getProperty("database");

                try
                {
                    ISession session = new org.hsqldb.HTTPClientConnection(
                        host,
                        port,
                        path,
                        database,
                        tls,
                        user,
                        password);

                    return new HsqlSession(session);
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }
            /// <summary>
            /// Gets an HSQL protocol client session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <param name="tls">
            /// If set to <c>true</c>, the session uses transport layer security.
            /// </param>
            /// <returns>an HSQL protocol client session</returns>
            internal static HsqlSession NewHsqlClientSession(
                HsqlProperties properties,
                bool tls)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user = properties.getProperty("user");
                string password = properties.getProperty("password");
                string host = properties.getProperty("host");
                int port = properties.getIntegerProperty("port", 0);
                string path = properties.getProperty("path");
                string database = properties.getProperty("database");

                try
                {

                    //Console.WriteLine(
                    //    "GetHsqlClientSession : host {0}, port {1}, database {2}, tls {3}",
                    //    host,
                    //    port,
                    //    database,
                    //    tls);

                    ISession session = new HsqlTcpClient(
                        host,
                        port,
                        path,
                        database,
                        tls,
                        user,
                        password);

                    return new HsqlSession(session);
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }
            /// <summary>
            /// Retrieves an embedded session using the given properties.
            /// </summary>
            /// <param name="properties">The properties.</param>
            /// <returns>an embedded session</returns>
            internal static HsqlSession NewEmbeddedSession(
                HsqlProperties properties)
            {
                if (properties == null)
                {
                    throw new ArgumentNullException("properties");
                }

                TranslateProperties(properties);

                string user = properties.getProperty("user");
                string password = properties.getProperty("password");
                string scheme = properties.getProperty("connection_type");
                string path = properties.getProperty("database");

                try
                {
                    ISession session = org.hsqldb.DatabaseManager.newSession(
                        scheme,
                        path,
                        user,
                        password,
                        properties);

                    return new HsqlSession(session);
                }
                catch (org.hsqldb.HsqlException e)
                {
                    throw new HsqlDataSourceException(e);
                }
            }