Rob Gordon is a seasoned Java developer and a big fan of open source. Oddjob is his own open source project to make job scheduling and task automation in Java much much easier. Rob is based in London. Rob is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

An Oddjob Property in Spring

06.08.2012
| 2407 views |
  • submit to reddit

Here’s my previous password passed to Spring example run from Oddjob:

Password Prompt

Run as a GUI, Oddjob provides a simple form for entering properties including a password prompt.

Here’s the Oddjob configuration:

<oddjob>
  <job>
    <sequential>
      <jobs>
        <input>
          <requests>
            <input-password prompt="Password" property="jdbc.password" />
          </requests>
        </input>
        <spring:job beanName="myQuery" xmlns:spring="oddjob:spring">
          <resources>
            <list>
              <values>
                <value value="rob/MyQuery.xml" />
              </values>
            </list>
          </resources>
        </spring:job>
      </jobs>
    </sequential>
  </job>
</oddjob>

The Spring configuration remains unchanged from my previous post, but I include it again here for your convenience:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
  <context:property-placeholder location="classpath:jdbc.properties" />
 
  <bean id="myQuery" class="rob.MyQuery">
    <property name="dataSource" ref="dataSource" />
  </bean>
 
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
  </bean>
 
</beans>

The password prompt sets the property jdbc.password within Oddjob and my new SpringJob automatically makes every property defined in Oddjob available in Spring.

SpringJob can be given the name of any Runnable defined within Spring and it will run it. Any exceptions will be reflected in the state of SpringJob, and this can be used to trigger another job such as an email, or it can be used in a retry timer.

Here it is having run successfully.

Spring Job Completed

The Oddjob configuration can be run directly from the console. The password prompt now changes to use the console:

Spring Job Console View

And that’s a very quick look at an Oddjob property in Spring.

The Oddjob Spring jobs can be found on Sourceforge here. They require Oddjob 1.2 to run, it is still in development but a reasonably stable snapshot can be found here.

 

 

Published at DZone with permission of Rob Gordon, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Fahmeed Nawaz replied on Tue, 2012/06/12 - 10:38am

after inserting into collection using collectionname.insert(new BasicDBObject("name","sivu")) in java how to check whether the data inserted or not? I mean do the insert method returns any value which shows the result that data inserted...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.