Thursday, July 29, 2010

On enterprise architect

Quote from The Role of the Enterprise Architect.

one of the fundamental requirements for being a successful EA is the ability to lead without actually owning anything: If you don't have good leadership skills, the rest of it fundamentally doesn’t matter... If you do not lead and do not take the risk to lead, the transformation won’t occur. One of the barriers for the profession today is that many architects are not prepared to take the risk of leadership.

The authority of an architect ultimately comes from their ability to articulate a compelling value proposition for architecture in general, for specific architect in a specific situation... This is probably one of the biggest problems that architects coming from a technical background have. They'll tell you about features and functions but never get around talking about benefits.

Wednesday, May 5, 2010

Missing Maven dependencies when deployed in Eclipse

I created a dynamic web project in Eclipse with Maven structure. I have Maven Eclipse Plugin so I enabled it. Everything seemed fine but the app wouldn't run in Tomcat within Eclipse. It turned out that the maven dependencies did not get copied to WEB-INF/lib when I browsed to "wtpwebapps" folder where the app was deployed.

To enable it, go to Project > properties > Java EE Module Dependencies, and check "Maven Dependencies" for this project. And it worked like a charm.

Friday, April 30, 2010

Quote from Skype architect

Technical skills are a hygiene factor for architects. You need to have them to be accepted for the job. But emotional intelligence and ability to understand organizations are the skills that define how good you really are.

Here
is the complete original post.

Saturday, April 24, 2010

Create a template project with gwt-maven-plugin archetype

I wanted to use maven for my GWT project. In the beginning, I ran archetype to create a project template with gwt-maven-plugin.

mvn archetype:generate -DarchetypeRepository=http://repository.codehaus.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=1.2 -DgroupId=myGroupId -DartifactId=myArtifactId

Friday, March 26, 2010

Download artifact from remote repository

Sometimes you may want to download an artifact from a remote repository without adding the dependency in pom.xml. You can do this with dependency:get.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT


Here is a Reference.

Friday, December 18, 2009

Where clause in Hibernate class mapping

I have a table with a column STATUS. There are two possible values: 1 and 0. 1 means active and 0 inactive. The data with inactive status are for archives only so I'd like to filter them out in the application. Of course, I can do this in the query, criteria or filter. But I wonder if there is a way to do this in mapping, once and for all. It turns out you can. You just need to specify the "where" attribute in class mapping. For example,

<class name="my.com.Report" table="IREPORT" where="STATUS=1">



This will include the active report in query. However, as always, there is a catch. This restriction does not work by default in association. According to a reference here, if the class is on the many side of one-to-many relationship, you need to add this "where" explicitly in the one-to-many mapping. But I could not figure out how to do this yet.

Tuesday, November 3, 2009

Schema Creator for HSQLDB in Unit Testing Hibernate

I am working on an application with Spring, Hibernate and MySQL database. There are several options I can unit test Hibernate DAOs. One is to use EasyMock, but it won't really test the queries. Another one is to Spring AbstractTransactionalJUnit4SpringContextTests, connecting to a test instance of MySQL. But then the tests rely on the external resource. As an alternative, I want to use a in-memory HSQLDB during unit testing to cut the dependency. The database will be created and dropped during the tests with Hibernate property "hibernate.hbm2ddl.auto=create-drop".

Sounds great. However, here is the catch. Basically, when using in-memory HSQLDB to test Hibernate with hibernate.hbm2ddl.auto=create-drop option, Hibernate does not know to create the schema BEFORE creating tables. Thus it leads to "invalid schema name" error in unit tests.

There is an ingenious solution. It created a schema creator and define it as a "depends-on" for Hibernate session factory in Spring configuration file. It thus forces the schema creation.

public final class HSQLSchemaCreator implements InitializingBean {

/**
* schema name.
*/
private String schema;

/**
* data source.
*/
private DataSource dataSource;

// setters and getters
public String getSchema() {
return schema;
}

public void setSchema(String schema) {
this.schema = schema;
}

public DataSource getDataSource() {
return dataSource;
}

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

/**
* Create schema.
* @throws Exception any exception
*/
public void afterPropertiesSet() throws Exception {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("CREATE SCHEMA " + schema + " AUTHORIZATION DBA");
}

}



    <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
depends-on="hsqlSchemaCreator">
...
</bean>

<bean id="hsqlSchemaCreator" class="com.guident.skills.util.HSQLSchemaCreator">
<property name="dataSource" ref="dataSource" />
<property name="schema" value="MY_SCHEMA" />
</bean>