iPad

I’ve been asked a few times in the last couple of months whether I’d buy an iPad. My stock response has been probably not, but we’ll see what happens when I try one. That happened today. I bought an iPad.

So far I’m very happy with it. Its great for web browsing, watching videos, and I’ve got a couple of interesting apps for it. I’m also really happy with the quality of the onscreen keyboard. Having used an iPhone, I’d been sceptical that the iPad keyboard would be much better. I was wrong. It’s still not as good as a real keyboard, but it’s a huge improvement.

OpenJPA, Derby, and getting started fast….

The combination of Apache OpenJPA and Derby provides a fantastic and simple way to prototype database apps in Java. The only downside is that there are a couple of gotchas I keep on finding myself hitting each time I start a new project. Here’s the simplest app I can think of and all the associated files for my later use. If it’s useful to you as well, have fun!

File: src/main/java/test/Account.java

package test;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Account {

private String name;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

public Account(String name) {
this.name = name;
}

public String getName() {
return name;
}

public long getId() {
return id;
}
}

File: src/main/java/META-INF/persistence.xml

<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	<persistence-unit name="account">
		<class>test.Account</class>
		<properties>
			<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
			<property name="openjpa.ConnectionURL" value="jdbc:derby:testdb;create=true" />
			<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />
		</properties>
	</persistence-unit>
</persistence>

File: src/test/java/test/AccountTest.java

package test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import junit.framework.TestCase;

public class AccountTest extends TestCase {

	public void testAccount() {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("account");
		EntityManager em = emf.createEntityManager();
		EntityTransaction et = em.getTransaction();
		et.begin();
		Account a = new Account("Bob");
		em.persist(a);
		et.commit();
		System.out.println("a"+a.getId());
	}
}

File: pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test</groupId>
	<artifactId>test</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>test</name>
	<dependencies>
		<dependency>
			<groupId>org.apache.openjpa</groupId>
			<artifactId>openjpa-all</artifactId>
			<version>2.0.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.derby</groupId>
			<artifactId>derby</artifactId>
			<version>10.5.3.0_1</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.1</version>
			<type>jar</type>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.0.2</version>
				<configuration>
					<source>1.5</source>
					<target>1.5</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>openjpa-maven-plugin</artifactId>
				<version>1.0</version>
				<configuration>
					<includes>**/entities/*.class</includes>
					<excludes>**/entities/XML*.class</excludes>
					<addDefaultConstructor>true</addDefaultConstructor>
					<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
				</configuration>
				<executions>
					<execution>
						<id>enhancer</id>
						<phase>process-classes</phase>
						<goals>
							<goal>enhance</goal>
						</goals>
					</execution>
				</executions>
				<dependencies>
					<dependency>
						<groupId>org.apache.openjpa</groupId>
						<artifactId>openjpa</artifactId>
						<version>2.0.0</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>
</project>

Adding a JavaScript host object with Rhino

I’ve been thinking a fair bit about server side JavaScript recently, but haven’t really dug in. One of the things I’ve been wondering is how easy it is to define a host object with Rhino. Turns out it’s trivial:

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;
public class Test {
public static class TestHost extends ScriptableObject {
  private String val = "";
  public String getClassName() {
    return "TestHost";
  }
  public String jsGet_val() {
    return val;
  }
  public void jsSet_val(String s) {
    val = s;
    System.out.println("from java: " + s);
  }
}

public static void main(String args[]) throws Exception {
  Context c = Context.enter();
  ScriptableObject so = c.initStandardObjects();
  ScriptableObject.defineClass(so, TestHost.class);
  System.out.println(c.evaluateString(so,
      "var t = new TestHost(); t.val='ee';'from script: '+t.val", "",
      1, null));
  }
}

Results in:

from java: ee
from script: ee

Ordnance Survey Free

There’s been a lot of positive rumblings coming from government recently about open and linked data. One of them is a consultation about the future of the Ordnance Survey, and in particular, a proposal to release a number of existing OS products for use at no charge under a CC-By license. This is Section 7, and the part of the consultation I want to focus on right now.

From Section 7:

Ordnance Survey Free is intended to allow communities to combine (or “mash-up”) government data about their community and environment from a number of sources and illustrate their findings in a geographic context:
•    the raster products will enable developers to produce an application that overlays their information on a map and to zoom-in from a national view with MiniScale® down to the street level with OS Street View®
•    the gazetteer, boundary and postcode information will enable widespread use of these commonly used geographies and it will act as a link between other government data sets which reference the same geography
•    the 1:50 000 Scale Gazetteer provides a definitive source of town and place names to search and locate a place of interest on the map; Code-Point® provides the location of every postcode to enable accurate search and display of specific locations and it will link to other data with a postcode reference
•    Boundary-LineTM provides the outline and a unique reference to all the administrative and electoral units of Great Britain
•    MeridianTM 2 and Strategi® are small scale vector products which provide the geometry of features to allow customisation and combination with other data. MeridianTM 2 includes a full named and attributed road network.

It is Code-Point and Boundary-Line which I feel are the most import data sets to make freely available.

In our democracy, with a First Past the Post electoral system, which is supposed to provide a strong link between citizen and representative, the fact that today, the Boundary-Line dataset is private, and not free-for-use by any citizen is astonishing. I struggle to believe that Boundary-Line is commercially significant to the OS, or alternatively that the majority of licensees are not public bodies*. Releasing Code-Point would increase the value of a Boundary-Line release significantly, allowing correlation of post-code and administrative region. With Post Codes as the primary location identifier in every day use, building services on top of Boundary-Line without Code-Point would be really tricky.

I’m sure that there are similar arguments for the other sets suggested, but I think Boundary-Line and Code-Point are a crucial and clear starting point.

Another portion of Section 7 asks how these OS Free products should be delivered (Web App, Download, Web API, DVD priced at/near cost). To which I can only respond… yes! The Boundary-Line and Code-Point information should be made accessible as Linked Data along the lines of the data.gov.uk projects, providing a Web API. It should also be made available as an easily downloaded data set, and a simple Web App would be very easy to produce. The other data sets (which include graphical tiles) are a more difficult area, but wouldn’t advocate that OS should compete with Google Maps or Bing Maps. The OS can probably learn from OpenStreetMap from the way they share their large data sets.

The consultation runs until mid March, and I’m still considering how comprehensive a response to write, given the chances of a change in Government, and hence that chances the consultation will be ignored.

* Taking data from [1] and [2], for 2008/09, over all OS products, it appears that about 42% of OS revenue came from Central and Local Government.

[1] http://www.whatdotheyknow.com/request/costs_to_central_and_local_gover#incoming-52363

[2] http://www.ordnancesurvey.co.uk/oswebsite/aboutus/reports/annualreport/08-09/docs/accounts-2008-09.pdf

Notebooks (of the paper variety)

I often ponder what to take to a meeting – nothing, laptop, notebook+pen are the popular options. Nothing has the disadvantage that it looks like you’ve come unprepared to take notes, which I think can be a taken as a bit disrespectful. Laptop has the advantage that it allows you to do anything you can do at your desk. This is also its curse. You can all too easily get sucked into responding to an e-mail or IM rather than paying full attention to the meeting you’re in. So a notebook+pen are a solid 3rd option. They say ‘I’m prepared to listen, pay full attention, and take notes’.

If you ever take a look at a notebook I take into a meeting, you’ll notice that the last notes are from a meeting at least a month previous, probably with someone ‘important’. Also likely is that they were written, never to be read again. This is the curse of the notebook in my office.

My ‘theatre’ notebooks on the other hand get used a lot more frequently, get modified and updated, and the information used to make decisions. In short, they’re useful, and I enjoy and benefit from the format.

The ‘theatre’ meetings are, of course, out of work time so laptops are less appropriate, but there’s another reason why they get used in such different ways. The main reason is the ‘clean desk’ policy in operation at work. This means that whenever I leave my desk, any written material needs to be locked away. Frankly, this is too much hassle for me to actually use a notebook at work. Having to unlock a drawer every time I want to look at some notes and check if the drawer is locked again with everything in it whenever I leave my desk isn’t worth my time. It’s far easier to use a laptop which auto-screen-locks, and is a single thing to lock/unlock (to/from the desk) when I move around.

It was taking a look at my notes for a recent show that made me realise that I’m missing out at work. There are a bunch of benefits to the notebook+pen experience which I’m missing at work. The ones that stand out are the ease of drawing, sketching, annotating, and sharing.

Sadly, I don’t see relaxation of the clean desk policy as likely. I guess I need to hope that phones and laptops evolve to make drawing, sketching, annotating, and sharing as easy as paper.

PastryKit – Why?

Recently, John Gruber publicised the PastryKit JavaScript framework which Apple uses to give a ‘Native’ iPhone experience in iPhone WebApps published by Apple (see the DF post for example videos). What I haven’t seen anywhere is an explanation of why Apple would take this route (a JavaScript framework) to provide this experience.

The alternative approach would be for Apple to build support for this functionality into the MobileSafari browser. This could be done with, for example, Vendor Specific CSS Properties. They could introduce -iphone-app, -iphone-header, -iphone-toolbar, and -iphone-momentumscroll. These could be applied to specific <div> elements, allowing the MobileSafari to suppress Safari chrome and place elements in the correct place. There would be a few advantages to this. Firstly, the performance would be far superior. The performance on the iPhone and iPhone 3G of PastryKit isn’t quite good enough. Implementing the functionality within the browser engine would have far superior performance. Even where PastryKit performs acceptably today, it’s still chewing unnecessary battery. Secondly, extending MobileSafari would allow the functionality to be easily used by developers outwith Apple, without having to include a lot of additional JavaScript in their appliation. Thirdly, it would be iPhone specific. As it stands, I assume that PastryKit webapps running on Firefox mobile (Fennec) will behave like an iPhone app, even running on other platforms. That seems like something that Apple wouldn’t want to encourage. There are more advantages to xtending MobileSafari, but those are the main ones.

So why might Apple have developed PastryKit, and what might they be planning? I can’t help but think that this is a skunkworks or R&D project that’s escaped, without any strategic thought on Apple’s part. In that case, use of it is probably a tactical move, which I think will over time by building the support into MobileSafari. How long that takes will, IMO,  depend on the AppStore, and the competition it and the iPhone receive from Android and Pre. I think it’s only when webapps become popular on those platforms that Apple will take the step to improve the iPhone web SDK.

Another possibility is that Apple want to provide the iPhone experience on non-iPhone hardware. I can’t quite get my head around this possibility. But Apple do have a knack for surprises.

iPhone 3G – 18 months down, 6 to go

I’ve had an iPhone 3G for 18 months, and so I have 6 months to go until 2 things happen. Firstly, that my existing contract with O2 expires, and secondly that Apple release another improved version of the iPhone. So now is an interesting time to look at what I’ve enjoyed about the iPhone, and what I might be looking for in a replacement.

What I’ve enjoyed:

  • Unlimited/everywhere internet access
  • Decent mobile web browser
  • Lots of Apps available at a couple of clicks
  • Decent media player

My short wishlist for a replacement:

  • Larger screen (but not a larger device overall)
  • Wireless Data Sync (I don’t want to have to plug my phone into my laptop just to get up-to-date podcasts)
  • Decent (video) camera
  • Longer battery life
  • More powerful web-technology apis (accelerometer, camera, etc)

The iTunes experience is a force likely to drive me in the direction of an Apple replacement unless an alternative appears. One thing that would attract me to an alternative would be a cloud centric rather than PC centric sync. I’m not sure if that’s likely from anyone in the next 6 months or not.

Bad Science

As someone who’s regularly frustrated by ‘scientists say…’ reports on BBC Breakfast, happening into a talk at OpenTech by Ben Goldacre was a pleasure and a revelation. Go, watch the video, and if you enjoy it, go buy the book ‘Bad Science’. That’s what I did, and I’m very happy I did. As someone pretty fluent in the scientific method and critical thinking, I found the examples really interesting, the encouragement to really analyse what’s said in the media motivating, and the realisation there are lots of other frustrated people out there utterly relieving.

Google #1 for WebSphere ESB 6.2

WESB 6.2 was released on Friday and anyone Googleing “WebSphere ESB 6.2″ this weekend appears to get a tweet from me and a rather more in depth discussion from my colleague David Currie.

wesb62

As David points out, the combination of the policy driven mediations and the service gateway scenario support is a huge leap forward, and enables a whole host of new metadata driven scenarios. To me that’s the most exciting thing about this release. Why? Because it opens up the possibility of fewer mediation flow components, and less time in the WID tooling. There’s some good WID tooling to generate service gateway mediation flow components, but I wonder how many people will actually create service gateway mediation flow components, and how many will simply reuse an existing one with different metadata… only time and customers will tell.

Charmouth and Lyme Regis

Last weekend we (Myself, Kat, Katie, Chris and Dan) had a fun weekend exploring Charmouth and Lyme Regis. Looking forward to the next one (and for Rich, Sue, George and Jim to make it!)

Next Page »


About

I’m David Illsley, I work in Web Services development at IBM Hursley, which involves work on the Apache WS Project, where I am a committer and PMC member. When not working with technology, I spend a lot of time on the backstage aspects of theatre, and a sadly decreasing amount of time reading.

Archives

c

Disclaimer

The postings on this site solely reflect the personal views of the author and do not necessarily represent the views, positions, strategies or opinions of IBM or IBM management.

Twitter Updates