Ejemplo n.º 1
0
        public static void ConfigMethod(IJvmLoader loader, int when)
        {
            if (when != (int)When.XMOG_BEFORE_LOADING)
            {
                return;
            }
            var tempDir  = createTempDirIfNeeded();
            var heapSize = 128;
            var heapEnv  = Environment.GetEnvironmentVariable("JAVA_HEAP_MB");

            if (!string.IsNullOrEmpty(heapEnv))
            {
                heapSize = int.Parse(heapEnv);
            }
            loader.MaximumHeapSizeInMB = heapSize;
            loader.ClassPath           = ".";
            foreach (var file in javaLibJars())
            {
                var tempName = tempDir + "\\" + file.Name + "." + Path.GetRandomFileName();
                file.CopyTo(tempName);
                loader.AppendToClassPath(tempName);
            }
            //loader.SetTraceLevel(TraceFacility.TraceAll, TraceLevel.TraceVerbose);
            loader.SetTraceLevel(TraceFacility.TraceAll, TraceLevel.TraceError);
            loader.TraceFile         = TRACE_FILE_NAME;
            loader.JvmPath           = Env.javaHome(@"jre\bin\client\jvm.dll");
            loader.LibraryPath       = Environment.GetEnvironmentVariable("PATH") + ";" + Env.svn(@"Java\systematic");
            loader.DashXOption["ss"] = "2M";
            if (bypassJavaDebugging)
            {
                return;
            }
            loader.Debug   = true;
            loader.Run     = "jdwp:transport=dt_socket,server=y,suspend=n,address=5044";
            loader.NoAgent = true;
            loader.DashDOption["java.compiler"] = "NONE";
        }
Ejemplo n.º 2
0
        static void Main(String[] args)
        {
            try
            {
                IJvmLoader loader = JvmLoader.GetJvmLoader();
                Console.WriteLine("CodeMesh using Java: {0}", loader.JvmPath);
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Java virtual machine could not be loaded\n{0}", Utilities.FormatException(ex));
                Console.ReadKey();
                return;
            }

            foreach (String uri in Utilities.LinkUris)
            {
                try
                {
                    using (ComponentLink componentLink = new ComponentLink(Utilities.PublicationUri))
                    {
                        Link link = componentLink.GetLink(uri);

                        if (link != null && link.IsResolved)
                        {
                            Utilities.OutputLink(uri, link.Url);
                        }
                        else
                        {
                            Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex));
                }
            }

            foreach (String uri in Utilities.BrokerUris)
            {
                try
                {
                    using (ComponentPresentationFactory factory = new ComponentPresentationFactory(Utilities.PublicationUri))
                    {
                        ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri);

                        if (presentation != null)
                        {
                            Utilities.OutputDCP(uri, presentation.Content);
                        }
                        else
                        {
                            Console.Write("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex));
                }
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            string db_file_name_prefix = args.Length > 0 && !"-info".Equals(args[0].ToLower()) ? args[0] : "test_db";

            //for now just terminate if we're invoked with the -info option
            if (args.Length > 0 && "-info".Equals(args[0].ToLower()))
            {
                return;
            }

            //the database connection
            Connection conn = null;

            Console.WriteLine("Success1!");

            IJvmLoader loader = JvmLoader.GetJvmLoader(true, true, TraceFacility.TraceJvm, TraceLevel.TraceErrors);

            //loader.JvmPath = @"jvm.dll";
            try
            {
                loader.JvmPath = @"C:\Program Files\Java\jdk1.8.0_161\jre\bin\server\jvm.dll";
                //loader.AppendBootClassPath = "hsqldb.jar";
                loader.AppendToClassPath("hsqldb.jar");
                //Append your db jar:
                // loader.AppendToClassPath("MyHSQLDB.jar");
                //Append any other Java jars needed eg:
                loader.AppendToClassPath("castor-0.9.3.21.jar");
                IJvm jvm = loader.Load();
                if (jvm != null)
                {
                    Console.WriteLine("Success2!");
                    // put the hsqldb classes (driver) on the bootclasspath to work around a
                    // limitation in the DriverManager when invoked from .NET
                    //loader.AppendBootClassPath = "../lib/hsqldb.jar;../../lib/hsqldb.jar";


                    Console.WriteLine("Success2.1!");
                    Class.ForName("java.lang.String");
                    Console.WriteLine("Success2.5!");

                    Console.WriteLine("Success3!");
                    // make the JDBC driver available by preloading it
                    Class.ForName("org.hsqldb.jdbcDriver");
                    Console.WriteLine("Success4!");
                    // connect to the database.   This will load the db files and start the
                    // database if it is not alread running.
                    // db_file_name_prefix is used to open or create files that hold the state
                    // of the db.
                    // It can contain directory names relative to the
                    // current working directory



                    conn = DriverManager.GetConnection("jdbc:hsqldb:" + db_file_name_prefix,
                                                       "sa",                      // username
                                                       "");
                    Console.WriteLine("Success5!");
                    try
                    {
                        //Uncomment this first time run:
                        //Update(conn, "CREATE TABLE sample_table ( id INTEGER IDENTITY, str_col VARCHAR(256), num_col INTEGER)");

                        //// add some rows - will create duplicates if run more then once
                        //// the id column is automatically generated
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('Ford', 100)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('Toyota', 200)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('Honda', 300)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('GM', 400)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('BMW', 80)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('Mercedes-Benz', 60)");
                        Update(conn, "INSERT INTO sample_table(str_col,num_col) VALUES('VW', 800)");
                    }
                    catch (SQLException sqle)
                    {
                        Console.WriteLine(sqle.Message);
                    }
                    catch (Throwable it)
                    {
                        Console.WriteLine(it.StackTrace);
                    }
                    catch (System.Exception ie)
                    {
                        Console.WriteLine(ie.ToString());
                    }
                    Console.WriteLine("Success6!");
                    try
                    {
                        Console.WriteLine("---------------");

                        // do a query
                        Query(conn, "SELECT * FROM sample_table WHERE num_col < 250");


                        Console.WriteLine("---------------");

                        // do another query
                        //Query(conn, "SELECT str_col FROM sample_table WHERE num_col >= 100");

                        Console.WriteLine("---------------");

                        conn.Close();
                    }
                    catch (Throwable t)
                    {
                        Console.WriteLine("Caught throwable of type {0}", t.GetClass().GetName());
                        Console.WriteLine(t.ToString());
                        return;
                    }
                    catch (JuggerNETFrameworkException jnfe)
                    {
                        Console.WriteLine("Caught framework exception");
                        Console.WriteLine(jnfe.Message);
                        Console.WriteLine(jnfe.StackTrace);
                        return;
                    }
                    Console.WriteLine("Success7!");
                }
                else
                {
                    Console.WriteLine("No Jvm!");
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Done!");
        }