Saturday, June 30, 2007

Switcher: The Mac Guys Tried to Kill Me

I've been pretty excited over the past few days about the idea of getting a Mac. I've been a PC user for the past 20 years, so the idea of getting a Mac never really phased me until recently. Having seen some of the cool things, and with Parallels making application compatibility so seamless on the Intel based Macs, the concept of actually getting one has been gnawing at my mind. Well the opportunity finally came into fruition when my fiancee decided to buy a new laptop. After a few days of discussion, I sold her on a Mac. Kind of funny since I'm not a Mac user myself.

So the big day arrived. Not my wedding day, but the actual purchase date. My fiancee was kind enough to point out that I seemed more excited about buying the laptop than our wedding, but thats another story. So we get to the Apple Store, and wouldn't you know it, our timing couldn't have been worse. Turns out that it was also the same day the IPhone was released. So after seeing a line about half a mile long, and having no success convincing the door man to let us in, we decided to wander around the mall and wait for the line to disapait. I wasn't concerned with the media circus and foolish behavior of the IPhone crowd. But I believe some of my choice words must have made an impression on the door man. I mean, why the hell did an Apple Store have a door man anyway?

So after some grumbling, and after seeing how overpriced the Sony Vaios were in the midst of my stubborn reconsideration brought upon by being turned away due to the IPhone celebration, we returned about a half an hour later to a non-existent line. All that for people to play with the IPhone, yet so few bought one. Of course the whole ordeal left me with a bit of a bad taste in my mouth, so even though I was determined to buy a MacBook, I decided to be a little bit of an antagonist towards the Apple Store staff.

Now I wasn't being a prick by any means. I more or less decided to play the part of the ignorant consumer and poke a little fun at the whole Apple counter culture that I had apparently been suckered into. So while the door man was less than customer service friendly, my salesman was more willing to answer such questions as "Whats so special about the IPhone?", "Doesn't Windows Mobile and Blackberrys already do that?", and "Why should I get a Mac, doesn't my PC do all the same things?". Of course, these questions I already knew the answers to, I just wanted to amuse myself before an act that at this point I really felt was selling my soul.

The Apple Store staff did catch on to my ribbing though, so apparently I wasn't as clever as I thought I was. They joked with me a little with such retorts as "Well, a PC guy just couldn't understand", and "Well if you had told them at the door that you were a PC guy, we wouldn't have let you in". Was that salt in the wound?

Long story short, we walked out with a very cool new MacBook, a free IPod Nano since my fiancee is in college for her Masters, a customized Western Spanish keyboard layout, a free photo printer, a copy of Parallels, andthe sense that I had accomplished my goal, gotten some good rebates, and the knowledge that Dell could never match the bang-for-buck factor I had walked out of the store with. Of course, the end of the story comes when I, in my excitement, opened the box in my fiancees truck. Now, Im pinned in the passanger seat by the printer box, the fact that I can't recline due to a lack of a extended cab, and all the remaining doo dads and doo hickeys we came out of the store with. I couldn't wait to open the box and fire up the Mac. So thats exactly what I did. So here I am in her tiny truck, with the printer pinning my feet, the MacBook box wide open, and packaging material all over. I turn on the Mac, and was satisfied. That is until a friggin Brown Recluse Spider came crawling out of the packaging material right on my lap. So between the paralizing fear of one of the most media hyped venomous spiders staring me in the face, and the fact that I couldn't move with all the boxes and packaging material pinning me in my fiancees tiny ass passangers seat, I was pretty much sure my night was going to suck from that point on. Luckily, my fiancee, not having her mobility limited by her enthusiasm for technology, she squashed the dang thing with a card she had laying around. That leaves me to wonder if the Apple Store folks decided to have the last laugh. I'll tell you, in the Mac vs PC Commercials, they sure has hell didn't show the Mac guy trying to kill the PC guy with arachnids.

So with that adventure out of the way, I am very happy with my MacBook.
With all the reviews out there I don't need to repeat. A few assessments however.

1. Parallels does indeed rock. And although it is heavily advertised as working with Windows XP, it works with just about any PC based OS, just like VMWare. In fact, we went with a Windows 2000 install instead.

2. The only distinguishable difference between the VMWare Workstation and VMWare Server instances I can tell are the price tag and the integration of native client OS apps into the Host OS. Otherwise, it works pretty much the same, with you having to install the Tools inthe the client OS in order to get things like clipboard sharing, shared folders, etc.

3. Eclipse runs like crap under OS X. Either Apple or Eclipse needs to fix that. It runs faster with Parallels than it does natively under OS X.

4. The 30 day Microsoft Office for Mac Test Drives is a joke. Theres tons of comparisons between the Mac and PC versions of Microsoft Office, so I won't comment on those.

5. iLife, while being a fairly well rounded suite of applications, just doesn't warrant me ponying up extra money. I find the idea of installing shareware on a new system distasteful. If your going to put software on a new system, put the full version, don't waste my time with time limited trials and trying to sucker me into the .Mac online service.

6. Same goes with iWork. OpenOffice.org for Aqua just had their developer, so we may not be far off from the non-X11 version.

Overall though, the MacBook does rock. I will see how well my fiancee fares with it over the course of the next few months. That will help sway my decision to either buying one, or sticking with a PC and moving back to Ubuntu for my day to day tasks.

Friday, June 15, 2007

Media: Orb Networks

Recently I have been hearing a lot from various people about Orb Networks. Orb is a small utility that you run off of your PC that streams, or "MyCasts" the various media files you have on your system, such as movies, photos, music, etc. Whats really cool about this is that it lets you access your media anywhere in the world. So if you keep an MP3 collection on a home system, if its running orb, you can access it no matter where you are, assuming you have Internet connectivity. It also gives you access to file shares remotely, which in my opinion is a bit of a security hole. What really got me interested was a forwarded link talking about using a home console gaming system for streaming. So I decided to try it out.

For my experiment, I have the entire first season of Heros, which I have been meaning to catch up on, recorded onto my laptop. The original plan was to convert them to IPod video and watch them on the go, however I do enjoy evenings with the Mrs. on the couch watching shows. I have the Memorex portable monitor I use with my IPod video, and that has video out, but thats a pain to set up. So streaming directly from my laptop to one of my gaming systems became an attractive option. This was a feature of the hacked XBox's, so I wanted to give the XBox 360 built in media player a test.

First, I had to install the Orb client onto my laptop. After installing it, I configured it to not startup on Windows bootup. I also added my media folder to the list of folders for Orb to search that contains media files. After I installed it, I ran a virus scan and a malware scan using AdAware to make sure no spyware was installed with this application. I also did a quick packet capture while the service is running to see who the Orb client is phoning home to, like I do with other apps (and found some surprising results, which phone home to sites that are now blocked at my firewall). After a few minutes, I was convinced I wasn't seeing any bizarre connections, of course further investigation might be required.

Once installed, I had to sign up for an account. And that was all there was to it.

Once the Orb client was set up, from my XBox 360, I went to the Media/Video option, told it to connect to my system, and it displayed my folders.

A few things came up though. Performance was dismally bad over a 10Mbps network and using my wireless adaptor on my laptop. I had to move the 360 and my laptop over to my 100 Mbps switch. Once there, performance was acceptable. So apparently the adaptive feature doesn't quite work as advertised. Also, from the XBox 360, the fast forward and rewind buttons did not work. Not sure if this was an issue with Orb or with the Xbox. Additionally, I tried it out using the Wii. This worked fairly well also. But since I was accessing it using the Opera browser, the browser navigation bars never disappeared. That detracted from the viewing experience. Plus I had to connect to the Orb servers using the Wii, where as with the XBox 360 it connected directly to my laptop. So I think I'll be watching these from my 360 for the time being.

Some other features that I did not test were the ability to record TV using a TV Tuner card. When I set up ORB, it asked me my location and cable channel, and pulled up a TV Guide. Apparently I can watch my cable TV remotely also, just like with a Slingbox. Not sure if the hardware cost for a TV Tuner card and a dedicated machine is cheaper than a Slingbox, but I do like the added abilities of Orb.

Overall, I am impressed. Where as I was a little suspicious of this software at first, I found no evidence of spyware with it. So I am not sure how Orb stays in business or who pays for their servers. It did exactly what I needed for media streaming to my home entertainment system via my XBox 360, which opens new avenues for me. So, I can honestly say that I will be using Orb regularly.

Monday, June 11, 2007

Eclipse/Java: Using Hibernate for Data Access

I have been wanting to do a little work with Hibernate for some time now. I finally have a project that has come up where I can get the excuse to do so. The first step, however, was to get myself familiar with how Hibernate works.

For the better part of a few hours I have been messing around with getting Hibernate Synchronizer to work with Eclipse. There are quite a few annoying bugs, but so far it has been the best of the Hibernate Eclipse plugins. And I also used Hibernate version 3 as my library in my project. Since my test database is a SQL Server database, I also used jTDS JDBC Driver for Sql Server. I used this instead of the Microsoft driver since the Microsoft driver just plain didn’t work with Hibernate. For the record, I am using Eclipse 3.3 since the project I am working with uses BIRT 2.2 M6 reports, and I wanted my development under one roof, and its using JDK 1.5 R11.

The first step of my process was to create a regular Java project under Eclipse. I am sure to include the Hibernate Jar file and the jTDS Jar file in my classpath/included libraries.

Once created, I go to New, Other, and select Hibernate Configuration File. This will bring up the Hibernate Configuration File Utility as shown in Figure 1. Be sure you get your configuration right since this is the last time you will see this screen once you Finish. I have yet to figure out how to bring this back up. I enter the relevant information as shown.

Figure 1. The Hibernate Config Wizard

Next, I need to create the mapping file so Hibernate can generate my proxy classes to handle communication with the database and provide general getters, setters, and other classes. So I go to File/New/Other/Hibernate/Hibernate Mapping File. Assuming everything is OK with my connection, on the next screen I can click on the refresh button to get a list of the tables available for mapping. In my case, I ran into a bug using the Microsoft JDBC drivers here that wouldn’t let me connect. From my list of tables, I want a class to handle Opportunities, so I select the appropriate table from the list. Once done, I move over to the properties tab. Since this is SQL Server, I need to change the ID generator over from Sequences to Identity. Not sure exactly why this is necessary, but I’m not going to argue the point either. With Derby I was able to use Sequences, and I’d imagine Oracle would work just fine with this as well. If you use the wrong type, you will get an error when you run your resulting program complaining that the generator type is not supported in that database.

Figure 2. The Mapping Screen

Figure 3. The Mapping Properties

With the mapping file complete, now I can go through the motions of finishing up the configuration and generating the classes. First, I right mouse click on .hbm.xml file that gets creating with the mapping, and I select Add Mapping Reference. I encountered a bug here where when adding the mapping, it deletes the XML version and DOCTYPE tags from the hibernate.cfg.xml file, so be sure you have those handy just in case. If not, you will encounter an error when your finished program tries to access the hibernate configuration. Next, I open up the hbm.xml file, and change the value of the meta attribute=”sync-DAO” tag to true. This will generate the DAO objects for my test program. I am not sure why this defaults to false. Once done, I can save the file, then right mouse click on the hbm.xml file, and under the Hibernate Synchronizer menu, I select Synchronize Files. This will generate the needed classes.

That’s pretty much it. Now, I can use Hibernate to access my database. This saves me a lot of time. Instead of having to generate all the ORM classes myself, I can let Hibernate do the leg work for me. There is also a version of Hibernate for .Net. A few notes of bugs I came across. Like I mentioned above, the add Mapping Reference wipes out the XML header from the hibernate.cfg.xml file. I didn’t realize this until I went to run my program and Hibernate couldn’t recognize the format. The error I got was:

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource TableOpportunity.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:98)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 10 more
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 11 more


I also got errors when I didn’t include all of the necessary LIB files for Hibernate. This one confused me, since I thought the necessary files would be in the Hibernate3.jar file. However, I was mistaken. So be sure to include those. The exact error I got was:

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.getNewConfiguration(_BaseRootDAO.java:192)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:90)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)



The third main issue I ran into was the fact that Hibernate refused to find my hibernate.cfg.xml file. This was pretty annoying. The error looked like so:


Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:98)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)

What I ended up having to do was under the run configuration for my project, I had to specifically add the Project folders root, where my hibernate.cfg.xml file was located, to my classpath. I did this under the Classpath tab, clicking on User Entries, then advanced, Add Folder, and pointed to the root of my project.

Figure 4. Adding the path for the hibernate.cfg.xml

Now, for the example program I used to test the configuration. Basically I just want to to get all Opportunities from my table and display a couple of fields for them. My test program ends up looking like so:

package com.digiassn.blogspot;

import java.util.Iterator;
import java.util.List;

import com.digiassn.blogspot.HibernateClasses.TableOpportunity;
import com.digiassn.blogspot.HibernateClasses.dao.TableOpportunityDAO;
import com.digiassn.blogspot.HibernateClasses.dao._RootDAO;

public class TestHibernate {
public static void main(String[] args) {
_RootDAO.initialize();

TableOpportunityDAO td = new TableOpportunityDAO();
List opps = td.findAll();

for (Iterator i = opps.listIterator(); i.hasNext();) {
TableOpportunity t = (TableOpportunity) i.next();
System.out.println(t.getName() + " - " + t.getFrcstClsAmount()
+ " - " + t.getServiceStartDate() + " - "
+ t.getServiceBranch());
}

}
}