Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Wednesday, September 30, 2009
Gratitude
“Gratitude unlocks the fullness of life. It turns what we have into enough, and more. It turns denial into acceptance, chaos into order, confusion into clarity… It turns problems into gifts, failures into success, the unexpected into perfect timing, and mistakes into important events. Gratitude makes sense of our past, brings peace for today and creates a vision for tomorrow.”
- Melody Beattie through Julie911
Monday, September 28, 2009
"Never discourage anyone who continually makes progress, no matter how slow."
“Never discourage anyone who continually makes progress, no matter how slow.”
- Plato through Julie911
Sunday, September 27, 2009
Saturday, September 26, 2009
Friday, September 25, 2009
Good Java programming idioms
http://c2.com/ppr/wiki/JavaIdioms/ReturnNewObjectsFromAccessorMethods.html
Tuesday, September 22, 2009
Better Lighting for your computer
To adjust monitor lighting based on lighting:
http://www.stereopsis.com/flux/
Monday, September 21, 2009
inconvenience ...wrongly considered
“An adventure is only an inconvenience rightly considered. An inconvenience is only an adventure wrongly considered.”
- G.K. Chesterton, “On Running After One’s Hat,” All Things Considered, 1908 through Julie911
Whatever you do, make it mean something to you.
“Whatever you do, make it mean something to you.”
- Jazsmin Lewis, Barbershop through Julie911
Friday, September 18, 2009
Read the error, fix the error - Eric
To mean read the error patiently over and over again until you get a working clue of what is wrong.
Interesting article on selenium
http://roneiv.wordpress.com/2008/10/17/using-selenium-to-test-jsf-application/
Thursday, September 17, 2009
And if my God is with me Whom then shall I fear?
Your perfect love is casting out fear
And even when I'm caught in the middle of the storms of this life
I won't turn back I know You are near
And I will fear no evil
For my God is with me
And if my God is with me
Whom then shall I fear?
Whom then shall I fear?
Oh no, You never let go
Through the calm and through the storm
Oh no, You never let go
In every high and every low
Oh no, You never let go
Lord, You never let go of me
And I can see a light that is coming for the heart that holds on
A glorious light beyond all compare
And there will be an end to these troubles but until that day comes
We'll live to know You here on the earth
And I will fear no evil
For my God is with me
And if my God is with me
Whom then shall I fear?
Whom then shall I fear?
Oh no, You never let go
Through the calm and through the storm
Oh no, You never let go
In every high and every low
Oh no, You never let go
Lord, You never let go of me
Yes, I can see a light that is coming for the heart that holds on
And there will be an end to these troubles but until that day comes
Still I will praise You, still I will praise You
- Matt Redman
glorious world as we've been provided, with birds, sunshine, beautiful trees and flowers, and the radio
“I don’t know why, with such a glorious world as we’ve been provided, with birds, sunshine, beautiful trees and flowers, and the radio, why people don’t get on better than they do.”
-
Tuesday, September 15, 2009
The absolute worst situation is too much to do in too little time
The absolute worst situation is too much to do in too little time. When presented with unrealistic expectations at your workplace, STOP to breathe. Start a supply of oxygen flowing into your brain to help your clarity. Do a few stretches and then put your full attention on the task. You have likely performed a similar task before. Your brain just clouded and taking a few moments to breathe will help lighten ….. Don’t try to absorb the whole picture; instead break the big task into small, manageable parts. Finally, if you are unable to finish by the imposed deadline, calmly explain your need for extended time to your supervisor.
- Julie911
people who are so much afraid of pain ... shrink until life is a mere living death
“It takes courage to love, but pain through love is the purifying fire which those who love generously know. We all know people who are so much afraid of pain that they shut themselves up like clams in a shell and, giving out nothing, receive nothing and therefore shrink until life is a mere living death.”
- Eleanor Roosevelt through Julie911
"I like it when a flower or a little tuft of grass grows through a crack in the concrete. It's so fuckin' heroic."
“I like it when a flower or a little tuft of grass grows through a crack in the concrete. It’s so fuckin’ heroic.”
- George Carlin through Julie911
Being present is real work.
“Being present is real work.”
- Laura van Dernoot Lipsky through Julie911
Saturday, September 12, 2009
Not lost anymore - Lost
Anything lost gets found...So I stopped looking."
Friday, September 11, 2009
Wednesday, September 09, 2009
Hibernate Schema tools
The hbm2ddl.auto column indicates the values for the hbm2ddl.auto property in the hibernate configuration file
The Purpose column indicates what is the impact of using the specified hbm2ddl.auto value
The Class Name column indicates how to achieve the “purpose” programmatically.
hbm2ddl.auto option | Purpose | Class name |
create or create-drop or | create – to drop the schema and create it whenever SessionFactory is built create-drop – to drop the schema when SessionFactory is closed. | SchemaExport e.g. SchemaExport ex = new SchemaExport( new Configuration().configure() ); Ex.create(false, true); // false – don’t print sql to stdout // true – Execute ddl immediately on database |
Update | Update – Read the schema through JDBC driver (not reliable) and make schema changes to fit the schema to mappings | SchemaUpdate e.g. SchemaUpdate su = New SchemaUpdate(new Configuration().configure() ); Su.execute(false); // don’t print ddl on stdout |
Validate | Validator – compare mapping with metadata and throw exception if they do not match. | SchemaValidator e.g. new SchemaValidator(new Configuration().configure()).validate() |
Hibernate configuration file simple example with explanation in comments
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/lab</property>
<property name="hibernate.connection.username">meridian</property>
<property name="hibernate.connection.password">meridian</property>
<!--
| Which variant of SQL to use
+-->
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Use the C3P0 connection pool provider -->
<!--
| Minimum number of connections in the pool is 5. Atleast 5 connections should
| be there in the pool
+-->
<property name="hibernate.c3p0.min_size">5</property>
<!--
| Maximum number of connections in the pool is 20. There are already 20
| connections and more connections are requested, then a runtime exception is thrown.
| This is the only mandatory config. option for c3p0 (connection pool used by
| hibernate out-of-the-box.
+-->
<property name="hibernate.c3p0.max_size">20</property>
<!--
| If a connection is not used for 300 seconds, remove it from the pool
+-->
<property name="hibernate.c3p0.timeout">300</property>
<!--
| Prepared statements are cached for performance benefits. If 50 prepared statements
| are cached, the oldest prepared statement is moved out of cache
+-->
<property name="hibernate.c3p0.max_statements">50</property>
<!--
| If a connection is idle for 3000 seconds, validate it.
+-->
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Show and print nice SQL on stdout -->
<!--
| 1. Could also be hibernate.show_sql. 'hibernate' prefix is optional in xml files.
| 2. Refer to org.hibernate.cfg.Environment for a list of all property names
| 3. This could also be ...name="show_sql">${displaysql}</... Then a system property
| by name "displaysql" will have to be defined as in java -displaysql=true
+-->
<property name="show_sql">true</property>
<!--
| If the same property is specified in a properties file, this would have been
| hibernate.show_sql = true
+-->
<property name="format_sql">true</property>
<!--
| List of XML mapping files
+-->
<mapping resource="lab/Event.hbm.xml" />
<mapping resource="lab/Phone.hbm.xml" />
</session-factory>
</hibernate-configuration>
Tuesday, September 08, 2009
Simple Logging Facade 4 Java (SLF4J)
A peer of commons logging. Both are logging interfaces that applications have dependencies to. The calls to SLF4J or commons logging APIs is finally implemented by log4j or jdk logging.
Hibernate term - transactional write-behind
Hibernate, while synchronizing the persistent object changes, optimizes the list of SQL statements issued. This optimization prevents foreign key violations but still be predictable.
Hibernate term - cascading save
When a new instance of a persistence object is created, it does not have to be saved explicitly as long as it is reachable from a already persistent instance.
Hibernate term - Automatic Dirty Checking
Hibernate determines changes made to state of persistent objects during the course of a session (a unit of work with the db) and automatically synchronizes those changes with the persistence store.
Starting HSQL Database manager
Presuming hsqldb.jar is present in the ‘lib’ sub-directory of the current directory,
java -classpath ./lib/hsqldb.jar org.hsqldb.util.DatabaseManagerSwing &
Starting HSQLDB
Presuming hsqldb.jar is present in the ‘lib’ sub-directory of the current directory,
java -classpath ./lib/hsqldb.jar org.hsqldb.server.Server &
Monday, September 07, 2009
Maven default bindings
Each phase of a build lifecycle in implemented by a set of goals. These goals are part of plugins.
Which goals handle which phases is specified by binding the goals(s) to phases. Following is the list of default such bindings.
Some phases have goals binded to them by default. And for the default lifecycle, these bindings depend on the packaging value. Here are some of the goal-to-build-phase bindings.
Clean Lifecycle Bindings
clean | clean:clean |
Default Lifecycle Bindings - Packaging ejb / ejb3 / jar / par / rar / war
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war |
install | install:install |
deploy | deploy:deploy |
Default Lifecycle Bindings - Packaging ear
generate-resources | ear:generateApplicationXml |
process-resources | resources:resources |
package | ear:ear |
install | install:install |
deploy | deploy:deploy |
Default Lifecycle Bindings - Packaging maven-plugin
generate-resources | plugin:descriptor |
process-resources | resources:resources |
compile | compiler:compile |
process-test-resources | resources:testResources |
test-compile | compiler:testCompile |
test | surefire:test |
package | jar:jar and plugin:addPluginArtifactMetadata |
install | install:install and plugin:updateRegistry |
deploy | deploy:deploy |
Default Lifecycle Bindings - Packaging pom
package | site:attach-descriptor |
install | install:install |
deploy | deploy:deploy |
Site Lifecycle Bindings
site | site:site |
site-deploy | site:deploy |
Phases of the maven lifecycles
Source: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
Clean Lifecycle
pre-clean | executes processes needed prior to the actual project cleaning |
clean | remove all files generated by the previous build |
post-clean | executes processes needed to finalize the project cleaning |
Default Lifecycle
validate | validate the project is correct and all necessary information is available. |
initialize | initialize build state, e.g. set properties or create directories. |
generate-sources | generate any source code for inclusion in compilation. |
process-sources | process the source code, for example to filter any values. |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code, for example to filter any values. |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory |
process-test-classes | post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above. |
test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
prepare-package | perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above) |
package | take the compiled code and package it in its distributable format, such as a JAR. |
pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
Site Lifecycle
pre-site | executes processes needed prior to the actual project site generation |
site | generates the project's site documentation |
post-site | executes processes needed to finalize the site generation, and to prepare for site deployment |
site-deploy | deploys the generated site documentation to the specified web server |
Nice maven article
http://blogs.plexibus.com/2007/12/02/maven-guide-part-one-basics/
Friday, September 04, 2009
Creating a empty maven project structure
Maven can itself create empty project structures when you want to start a new code base. To create an empty project structure, maven needs to be told the kind of project (simple servlet web application or JSF web application with Spring and hibernate or Web application with spring, hibernate and spring MVC etc…). Maven knows the details of the directory structure for each project type through an archetype. So a simple servlet web application will have its own archetype that details how the directory structure of a simple servlet web application looks like.
So to start with execute
mvn archetype:generate
Then Maven will ask you the kind of project you want to create by listing the archetype that it knows about and asking you to select the archetype. Then it wail ask other details about your project (group id, artifact id etc… ) and after all project details are provided, will create the empty project structure for you.
Hibernate Getting Started
Hibernate Getting Started
Hibernate Mapping File - Specifies how instances of persistent classes are to be persisted and loaded. This specification is laid out by detailing the properties that are mapped to columns, classes that are mapped to tables and the relationship between classes mapped in DB semantics like foreign keys (and join tables?).
Basic Hibernate Mapping File (there are multiple listings of the same file. Each listing builds upon the previous listing):
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- This file will first be looked up in classpath, then on the web. -->
<hibernate-mapping package="org.hibernate.tutorial.domain">
[...]
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<!-- All classes that represent persistent entities, must be mapped to a table -->
<!-- This tells hibernate to persist and load instances of Event class to the EVENTS table. Each instance of Event is a row in EVENTS table -->
</class>
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<!-- The class Event bean has a property (or getter and setter) by name "id" that serves as a key or id of Event class. The id has to be stored to the column EVENT_ID. -->
<generator class="native"/>
<!-- Use hibernate's key generation strategy (How are identifier values generated?) to generate the Keys for Events. Other strategies include Data base generated keys, Globally unique keys, application generated keys -->
</id>
</class>
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<!-- Other properties of Event class. If a property is not mapped, it is not considered persistent. -->
<property name="date" type="timestamp" column="EVENT_DATE"/>
<!-- Event has a getDate() and setDate() and the value is to be stored in the column named EVENT_DATE. Type is hibernate mapping type. There are converters that convert between Java to SQL data types and visa-versa. If type not specified, hibernate will try to determine the mapping type and conversion type. This automatically (detected through reflection - can impact start up performance) type may not be what you want. For example java.util.Date can map to "date" (only date e.g. July 4th, 2009), "timestamp" (both date and time e.g. July 4th, 2009 10:00:00 HRS) or "time" (only time e.g. 10:00:00 HRS). Then you explictly specify the type -->
<property name="title"/>
<!-- Event has a getTitle() and setTitle(). Column name is not specified, so use the property name as the column name. -->
</class>
</hibernate-mapping>