Archive for the 'java' Category

Published by Fabian on 10 Jul 2008

An attempt to compare Java and PHP on a higher level

I yesterday published my first post in our corporate blog. It was an attempt to compare Java and PHP, using some historic backgrounds and comparing the evolution.

Even if it came out close in favour of Java, its really interesting to see that its pretty hard to compare those langages, because the language actually doesnt matter that much nowadays. I think we are about to reach the next level of programming language. Its the framework abstraction level. You no longer choose cobol for accounting and c++ for games, but you can choose between a financial and a gaming framework in any language.

Please be gentle with that blog post. Its not meant as criticism on either Java or PHP and sure its far from perfect. Thats basically the point of blogging. you can write about things you might have thought through, but which isnt really on a solid foundation :-)

Published by Fabian on 05 Jun 2008

A disguised XML file

In a current project we are working on XML files coming from a partner company. Readers of my blog can identify that its most likely the same project as here. Unfortunately the XSD is really loose.

Everything is type="xs:string", has minOccurs="0" and maxOccurs="unbounded". And if I say everything I mean all roughly 50 tags that are defined. Okay at least we have some structural information with sequences that might be there or not :-)

Luckily that is not that big issue as I dont need to parse it but some poor JAXB has to do that. And my poor Hibernate has to create amazing database structures to deal with that loose XML. Anyways I didn’t want to make a blog post for this alone. But today I got the confirmation on the filename of these XML files. Watch out:

PREFIX.Timestamp.txt

really, they are named txt instead of xml. With them not having an XML identifier line (<?xml version="1.0" encoding="utf-8" ?>), not having a real XSD and not having an XML filename, this isn’t really XML, is it?

Come on, who builds such a thing… as business interface…

Published by Fabian on 15 May 2008

HyperJAXB 3 – the fastest way from XML to DB

In a current project we are about to collect XML and send them out aggregated each day. Its basically a trivial Task, but keeping it maintainable and extendable for next phase of the project possibly coming is the main requirement.

In the Past I was a regular fan of JOX, which allows you to model your XML as java classes. But at that time you had to do it by hand.

Some time later now JAXB is a really good tool (actually its an API, there is a RI from Sun that also is part of Java 6). It creates Java Classes from XSD. Then only the way to the DB would be your work.

HyperJAXB to the rescue! Originally created to support Hibernate, it now is fully compatible to EJB3/JPA standards. It invokes JAXB generator on the given schema and post processes then the generated classes, making them persistable.

The project offers a complete Maven2 package that does all the tricks for you. just put your XSD inside. fire up the maven build and enjoy these complicated technologies (Maven, XML using JAXB and Java Annotations, ORM using Hibernate and Java Annotations and JPA) doing most of the work for you. All what is left for you is to write a class that does:

//get JAXB Helper to do XML->Object conversion (unmarshalling)
Unmarshaller u = JAXBContext.newInstance("demo").createUnmarshaller();
//read the object
DemoObject item = (DemoObject) u.unmarshal(new File("\\tmp\\demo.xml"));
//get JPA Helper to do Object->DB
EntityManager em = Persistence.createEntityManagerFactory("demo").createEntityManager();
//persist the object
em.persist(data);

I think this is really, really nice. I liked JAXB and JPA before I found HyperJAXB 3, but now I love them even more. You can start solving the functional issues and stop fighting the infrastructure.

Well not completely, depending on who wrote the XSD, the generated classes and Hibernate tables might look a bit messy. If that bothers you (because you might want use direct SQL from somewhere) you can tweak the XSD to make the result nicer. Either by playing with XSD mechanics (referencing elements, rather than nesting them) or customize the XSD with some HyperJAXB 3 annotations.

Update:
there is a new package: hibernate.entitymanager 3.3.2.GA that does not need the workaround below.
Make sure to update the pom.xml of your HyberJAXB project.

Note:
Unfortunately there is a small glitch in latest Hibernate packages that had cost me half a day :-)
The hibernate.entitymanager 3.3.1.ga package depends on hibernate 3.2.4ga
But 3.2.4.ga contains a bug that prevents automatically generated PKs from working. This is in the HyberJAXB cases by default true for all objects.

To resolve the issue you need to modify your pom like this:

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>3.3.1.ga</version>
			<exclusions>
				<!--  Hibernate core 3.2.4.ga is buggy -->
				<exclusion>
					<groupId>org.hibernate</groupId>
					<artifactId>hibernate</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate</artifactId>
			<version>3.2.4.sp1</version>
		</dependency>

Published by Fabian on 02 Apr 2008

Finally: Certified Java Developer

Finally the exam scores of my Java Developer Exam have arrived.

After completing the Java Programmer, Web Component Developer, and Bus sines Component Developer (which all are just a multiple choice test) I made the essay exam for the Developer two months ago.

And since its my Blog I allow me to show off with them :-)

This report shows the total number of points awarded for each section. The maximum number of points is 400, to pass you need a score of 320.

General Consideration: 100/100

Documentation: 70/70

OOD: 30/30

GUI: 35/40

Locking: 80/80

Data Store: 40/40

Network Server: 40/40

Total: 395/400


I don’t know where I missed the points for the UI but that doesn’t matter, I am not a UI specialist, nor are there really good Swing Patterns out there, so I was a bit on uncertain ground. The cool thing is that I was absolutely unsure about what kind of locking they wanted. But it seems I managed this as well.

I guess thats enough Java certifications for now. Lets see whats else out there (I guess a PHP one :-) )

Published by Fabian on 20 Mar 2008

if cascade

I am currently doing a code review, where I have found this nice pearl, I have to share.

I really hope that wordpress does not kill the lovely formatting :-)

        if (initialisePools()) {
            if (replicateServices()) {
                if (replicateLocations()) {
                    if (replicateLocationData()) {
                        if (replicateContacts()) {
                            if (replicatePackages()) {
                                if (replicateCustomers()) {
                                    if (replicateCompanies()) {
                                        if (replicateGroups()) {
                                            replicateUsers();
                                            ok=true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

A shorter way to write would be:

        ok = initialisePools() && replicateServices()
             && replicateLocations() && replicateLocationData()
             && replicateContacts() && replicatePackages()
             && replicateCustomers() && replicateCompanies()
             && replicateGroups() && replicateUsers();

any other proposals?

PS: Of course things can be always done differently, so your proposal must assume that invoking the methods separately makes sense :-)

Published by Fabian on 25 Sep 2007

Sun Certified Java Developer

Yesterday my SCJD assignment finally arrived. Its a really interesting one, but I think everybody gets the same.
There is a flat file database, which has a fixed record length after a header describing the fields. There is also one, and only one Java interface I shall implement. I don’t know if it should help or hinder me, because the API is really bad. But i will write an adaptor for it, so that can be solved :)

That database shall be running on a server, which can be either the local machine where the client is running on or a network machine. In local mode networking shall even be bypassed. How nice of Sun, to make such an iterative development possible. So i will write a local client first without thinking of networking. The local client shall be swing. That makes me a bit afraid, but I hope I can cope with it.

At last then the networking will be done. I am still not sure whether to take RMI or sockets, I tend to the latter because of less technology complexity, but it has more of: “code your own”. Perhaps I get some wise insight while doing the other stuff.

The real fun part is that I can work on this now at work partially. So doing some real coding again.

If you want to wish me much fun and a bit of luck, do it in the comments. If you have a hint on networking, do so as well :)

« Prev - Next »