Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, 19 September 2012

Autocomplete & API Design

Autocomplete Rocks

As an avid Eclipse user, I love auto-complete.  It feels like it's a big, easily overlooked boost to how I program.  Not because it saves a few keystrokes here and there, but because it provides such a boon to explorability of the APIs that I use.  Essentially, I'm querying my programming environment to see what my options are.

Seeing a list of IntelliJ's top 20 auto-complete features, there are some really neat ones - chain completion is particularly cool.  IntelliJ will inspect in-scope variables several levels deep, so it's able to suggest methods of in-scope objects that I hadn't even considered.

Basically, this is a specific, but handy, limited method of querying my codebase/libraries.  I can envision more complicates ones, such as a completion that would help me with that perennial Java I/O plumbing problem of how I get from a FooWriter to a StringInputStream.  Could an IDE make a few suggestions?

Auto what?

I'm also a frequent user of Apache Tapestry, and one of the things that occasionally confounds me about it is that whenever I get rusty with a particular component, I need to look at the documentation to see what I can do with it.

Not docs accessed through my IDE, but actually busting out a web browser, and navigating through some documents meant for humans to read.  Actual essays!

This is because, in Tapestry, you write event handlers by giving an ordinary method a special name:

public void onSelectedFromMyWidget() { ... }

Tapestry uses reflection to make the association between the this method, and the "selected" event thrown by the component with the name 'MyWidget'.

But here the IDE knows nothing about the meaningful names.  There's no object to inspect, no interface that defines all the callback methods.  If I forget that the event type is 'selected' for LinkSubmit components but 'action' for ActionLink components, I have to go to the documentation.  If I don't realize I've misremembered, my event handler simply never gets passed any events.

I recently learned that HLS codes in Emacs, I wonder if this is related!

Wednesday, 19 May 2010

Spring: Inject My Bean

A few weeks ago I was wondering how you get Spring to inject an existing bean that I'd instantiated myself.

I'm trying to integrate our JUnit concurrent test runner with Spring's SpringJUnit4ClassRunner, and while plumbing the depths of the relevant spring code, I came across this:


public void inject(ApplicationContext context, String beanName, Object bean, int autowiringMode) {
   AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory();
   factory.autowireBeanProperties(bean, autowiringMode, false);
   factory.initializeBean(bean, "bean name");
}

inject(bean, "myBean", appContext, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);

Simple!

Tuesday, 13 April 2010

Ill-Advised Hibernate Mapping Quandary

I'm wondering if this is possible:

class Idea {
Collection primaryTags;
Collection secondaryTags;
}

class Proposal {
Collection
primaryTags;
Collection
secondaryTags;
}

Mapped to:

CREATE TABLE (
IDEA_ID VARCHAR(36), /* Foreign key */
PROPOSAL_ID VARCHAR(36), /* Alternate key */
TAG VARCHAR(100), /* Whatever was in the String */
TAG_TYPE VARCHAR(9) /* 'PRIMARY' or 'SECONDARY' */
);

I'm thinking.. no. My problem is that I can't see a way to get Hibernate to take care of the TAG_TYPE column - a value that exists in the database, and must be inserted whenever new rows are inserted, but has a value specific to the domain collection whence it came.

Hibernate supports computed properties, but those exist on the domain side, and not in the database. I want the opposite! :-)