Posts

Iterate over your whole DB using hibernate

In this post I'll assume you already have your hibernate object corresponding to your DB schema. What will we try to achieve here? I will iterate all of the DB using hibernate objects, and here is a little java program which will attempt to achieve just that: import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.Query; import org.hibernate.metadata.ClassMetadata; import java.util.Map; /** * Created by IntelliJ IDEA. * User: avih * Date: May 11, 2010 * Time: 7:43:37 AM */ public class Main { private static final SessionFactory ourSessionFactory; static { try { ourSessionFactory = new AnnotationConfiguration(). configure("hibernate.cfg.xml"). buildSessionFactory(); } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); } } ...

The perfect PHP coding environment

Q: Which tools should one use in order to have the perfect PHP coding environment? A: 1. Download XAMPP which contains Apache web server + php + perl + Mysql and much more. http://www.apachefriends.org/en/xampp-windows.html 2. Download eclipse PDT (php IDE). http://www.eclipse.org/pdt/ 3. Install & configure a debugger for PHP (most recommended is Zend's debugger). http://www.eclipse.org/pdt/articles/debugger/os-php-eclipse-pdt-debug-pdf.pdf 4. Install fiddler - a great web debugging proxy. http://www.fiddler2.com/fiddler2/ 5. Install wireshark if you have an external component (like an exrternal DB) and you want to sniff the traffic. http://www.wireshark.org/ 6. Configure your fiddler to catch traffic in your localhost (If your DB is internal). http://blogs.microsoft.co.il/blogs/shair/archive/2008/12/15/how-to-use-fiddler-on-localhost.aspx That's it, You've got the tools, Now it's all about you...

Coding java gui using Swing designing it with CSS

Building a GUI in java isn't complicated having netbeans as a great Swing gui builder. But what if we want to have some of the design left out of the code in a CSS file? As when building a java applet which should blend with a website, out best shot will be to use the same CSS file in the swing code as we use for the website. How can we design the GUI components using swing? We will use TK-UI's SwingCSSEngine (which is opensourced). Their documentation can be reached using the following link: http://tk-ui.sourceforge.net/user-guide/cssengine/swingcssengine.html How is it done? Download the libraries: http://sourceforge.net/projects/tk-ui/files/org.akrogen.tkui.css.swing/ Copy the jar files (also those in their "lib" directory [excluding the commons if you wish]) into your project's (the swing project) lib directory. In the code before initializing the swing components (a method which is actually called init...

Log All Your Web-method Calls

After a good deal of trial-and-error, and delving into the CXF code, I've found a way to get CXF to log every web-method call -- parameters and all. Put the following into your Tomcat's log4j.xml: <logger name="org.apache.cxf.service.invoker"> <level value="trace"> </level> </logger> The level should be set to "trace" by default; you won't get ton's of output, just a line (maybe 2) every time a web method is called. Unfortunately, the line is a bit wordy, as in Invoking method public boolean com.company.entities.ws.EntityManagementImpl.login(java.lang.String,java.lang.String,java.lang.String) throws java.io.UnsupportedEncodingException on object com.company.entities.ws.EntityManagementImpl@71e6b with params [CLI, arg2, arg3]. but it was either use the built in log statement or write a whole interceptor and add it to the chain processing the call. If we get really annoyed we could always tweak the source and rebuil...

Java Swing Applet: HowTo

This post explains how to take an existing Java Swing application and wrap it as an applet which can then be used on any website. This post assumes the java swing class file (which is run in the original application) to be: FileUploadClientGUIView. Create the java applet wrapper as follows: package packageName ; import javax.swing.JApplet; import javax.swing.SwingUtilities; public class AppletStarter extends JApplet { //Called when this applet is loaded into the browser. public void init() { //Execute a job on the event-dispatching thread; //creating this applet's GUI. try { SwingUtilities. invokeAndWait ( new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System. err .println( "AppletStarter didn't complete successfully" ); } } private void createGUI() { //Create and set up the...

Exceptions in JUnit Tests

When an exception is thrown in a unit test, the unit test will fail, giving a red bar - unless there is a try/catch that catches the exception and swallows it quietly.  Therefore, you should make sure that catching an exception in a unit test is indeed what you really mean to do.  Should the test really handle the error and continue, perhaps succeeding, or should the test fail, giving a visual indication that something went wrong? I'd add that when the right behavior of a test case is a thrown Exception, one should add to the @TEST annotation one's expectation.  e.g. @Test(expected = NumberFormatException.class)

False condition comes true?

Image
This is a really weird bug I found in my program. I have an "if" condition, which takes a boolean variable as its condition, the variable's name is bMember. When I saw unexpected behaviour in my code and decided to debug it I saw the above surprising and un-understandable thing, the debug enters a falsed condition!? look at the picture above and see for yourselves. by the way, if someone knows why, please post a comment. Chaiavi