|
From: <php...@li...> - 2009-09-23 20:07:46
|
Hi, In PHP/Java Bridge version 5.4.4.2 you can use the option JAVA_PREFER_VALUES: Download version 5.4.4.2, for example: http://downloads.sourceforge.net/project/php-java-bridge/Binary%20package/php-java-bridge_5.4.4.2/JavaBridge.jar?use_mirror=dfn Type java -jar JavaBridge.jar --version -> 5.4.4.2 Type java -jar JavaBridge.jar SERVLET_LOCAL:8081 3 "" Type php -n -dallow_url_include=On test.php Test.php: <?php define ("JAVA_PREFER_VALUES", true); require_once("http://localhost:8081/JavaBridge/java/Java.inc"); java_require("foo.jar"); try { java("Foo")->call(false); java("Foo")->call(true); java("Foo")->call(false); } catch (JavaException $e) { echo $e; } ?> Foo.java: public class Foo { public static void call(boolean b) { if (b) throw new RuntimeException("bleh!"); } } Please note that the option JAVA_PREFER_VALUES kills performance as it checks for an exception after each call (I.e. each java call generates a full network round-trip). I have tested this against PHP/Java Bridge version 5.4.4.2. In 5.5.2 this option doesn't work anymore (we'll re-enable it in a later 5.5 release). However, I think it is better to handle unchecked exceptions in your own Java class. Regards, Jost Boekemeier On Sep 23, 2009 8:30 PM, <php...@li...> wrote: Hi, I'm in the process of evaluating the PHP/Java Bridge. My company wants to use it to leverage an existing set of data model classes we have created using Hibernate. I've successfully set up a test that is working fine, but I've come across something I'm concerned and a bit confused about and was hoping the list could help me. I've read the FAQ entry which states that all exceptions crossing the boundary must be declared, as well as a thread in the mailing list archives here: http://sourceforge.net/mailarchive/message.php?msg_id=3921.39923.qm%40web505 08.mail.re2.yahoo.com My concern is that this will prevent us from using the bridge in the way we have envisioned, so I'm asking for advice on how to handle it. We want to be able to perform arbitrary operations on our data model classes within the scope of a Hibernate transaction, using a pattern like the following: $factory = getSessionFactory(); //Hibernate session factory try { $factory->getCurrentSession()->beginTransaction(); //arbitrary code here $factory->getCurrentSession()->getTransaction()->commit(); } catch (JavaException $ex) { $factory->getCurrentSession()->getTransaction()->rollback(); throw $ex; } My concern is that there are several places within the arbitrary code sections where we are calling methods that throw unchecked exceptions that subclass RuntimeException. Most of our exceptions will occur during the commit, but not all of them. Is our approach even feasible with the bridge? We do not want to have to declare "throws RuntimeException" on hundreds of methods in our data model classes. Is there some other approach we could take, perhaps passing our arbitrary code as a closure to the java side and having a top level handler for all exceptions on the java side of things? I apologize if I am misunderstanding anything. I have been programming Java for a couple of years but so far I've only used basic servlets, no JEE containers or anything more complicated so I'm basically looking for guidance. Thanks in advance! Michael Sims ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ php-java-bridge-users mailing list php...@li... https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users |