April 2007 Archives
The mac port of DEFCON is finally out.
It basically takes the last scene from WarGames and makes a real-time strategy game out of it. I'm still figuring out how the game part of it works (I played the Windows version a while ago), but the unique mood and aesthetics alone justify the purchase - it simply looks and feels like nothing you've ever played before.
I gotta say, again, that I really think JPA is great. It took almost a decade, but Sun got pretty much everything right. I love just putting annotations everywhere, and anyone who thinks that is a bad idea is a dodo-head. Die XML, die!
Unfortunately, the legacy of deployment descriptors still lives on in the dusty corners of the EJB3 spec. One thing that you still can't do without a deployment descriptor is define a new Persistence Unit.
That's a fairly big omission. In the case of the app I am writing, a big part of what I need to do is allow the user to configure new databases and connect to them. I don't know what those databases are until runtime, and if I happen to want to talk to those databases via JPA, I'm pretty much out of luck - at least as far as the spec is concerned.
Here is a vendor specific-solution for Hibernate. It actually took a while for me to google this together, so maybe this will save someone some time. Maybe my googling skillz are not as mad as they used to be. Anyway.
import org.hibernate.ejb.Ejb3Configuration;
import java.sql.DataSource;
import java.util.Properties;
// ...
@SuppressWarnings("deprecation")
public static EntityManagerFactory
createEMF(DataSource ds,
Class[] entityClasses,
Properties props)
{
Ejb3Configuration ejb3conf =
new Ejb3Configuration();
ejb3conf.setDataSource(ds);
//
// set any fixed properties you want
ejb3conf.setProperty("hibernate.dialect",
org.hibernate.dialect.HSQLDialect);
ejb3conf.setProperty("hibernate.show_sql",
"false");
ejb3conf.setProperty("hibernate.hbm2ddl.auto",
"update");
if (props != null) {
Set<Entry<Object, Object>> entries = props.entrySet();
for (Entry e : entries) {
ejb3conf.setProperty(
e.getKey().toString(),
e.getValue().toString());
}
}
for (int i = 0; i < entityClasses.length; i++) {
assert entityClasses[i] != null;
ejb3conf.addAnnotatedClass(entityClasses[i]);
}
return ejb3conf.createEntityManagerFactory();
}
My friend Michael's startup launched this week:
It's half a PR service for publicists and half spam control on steroids for journalists. I'm not either one but I think it's a really great idea. Anything that gives people more control over what information gets thrown at them gets a thumbs up from me.
Michael did a great job on the app. It's all in Ruby. Even if you're not journalist, go bang on it and give him some feedback - he'd love to hear from you.
