Announcement Announcement Module
Collapse
No announcement yet.
JDBC-based bean definitions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    nice work, thanx a lot!

    please correct me if I am wrong, just tried to understand your code and I might be wrong. This is how I understand the workflow:

    1. the InitparameterFactory retrieves the Name/Value pairs from the DB with the passed SQL and Datasource.

    2. for each bean/class where I want to use DB based properties, I declare a PropertyMapper with the target class property, a reference to the InitParametersFactory and a list of properties.

    2.a. the PropertyMapper returns a bean of the class defined in target class

    2.b. the properties are as followed:
    key = the setter of the property in the target class
    value = the value of the Property colum in the DB

    2.c. the PropertyMapper calls the setters defined in the key values with the values from the DB where Property value = value in the props field

    With a quick try I had the following issues:
    with the factory-method attribute used in the InitParametersFactory one needs Spring 1.1; no problem, I merely used 1.0.2 before and ran into an error

    I got a couple of ScheduledTimerTasks with properties like

    Code:
      <bean id="myTask" class="net.sourceforge.jwebutil.util.initparameters.PropertyMapper">
        <property name="targetClass"><value>org.springframework.scheduling.timer.ScheduledTimerTask</value></property>
        <property name="initParameters"><ref bean="initParameters" /></property>
        <property name="properties">
         <props>
          <prop key="timerTask">@*myJob</prop>
          <prop key="delay">delay</prop>
    	  <prop key="period">period</prop>
    	  <prop key="fixedRate">@true</prop>
         </props>
        </property>
      </bean>
    I had some problems with the bean reference timerTask. It was not possible
    a) to combine it with a default value (*myJob;myJobBeanRef)
    b) to combine it with a as-is value (@*myJobBeanRef)
    was I doing something wrong?

    I am getting your thoughts. More comments will follow.
    I miss a bit the possibility to define the beans itself in the DB. Not via the propertyMapper, since in my case the number of timerTask is variable. but that is not so important.

    Comment


    • #17
      Re: nice work, thanx a lot!

      Originally posted by karsten
      I had some problems with the bean reference timerTask. It was not possible
      a) to combine it with a default value (*myJob;myJobBeanRef)
      b) to combine it with a as-is value (@*myJobBeanRef)
      was I doing something wrong?
      karsten, thanks for your comments. Your workflow description is accurate.

      Problem a) You are correct - a fix will require a 1 line change to PropertyMapper.createPropertyValues().

      Problem b) From a quick look at PropertyMapper.createPropertyValues(), this should work, but I need to review it more carefully.

      I'll post the fixes as soon as I can get to it.

      Comment


      • #18
        Re: nice work, thanx a lot!

        Originally posted by MHarhen
        I'll post the fixes as soon as I can get to it
        The updated code is available from : http://members.cox.net/jwebutil/InitParameters.zip

        I was able to get a Timer working as follows:
        Code:
           
        
        <bean id="initParameters"
                class="net.sourceforge.jwebutil.util.initparameters.InitParametersFactory"
                factory-method="createInstance">
            <description>Database Init Parameters</description>
            <constructor-arg index="0"><ref    bean="DATASOURCE" /></constructor-arg>
            <constructor-arg index="1">
              <value>
                <!&#91;CDATA&#91;
                  SELECT Parameter, Value FROM InitParameters;
                &#93;&#93;>
              </value>
            </constructor-arg>
          </bean>
        
        
        <bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
              <property name="scheduledTimerTasks">
                 <list>
                    <ref local="myTask"/>
                 </list>
              </property>
           </bean>
        
          <bean id="myJob" class="....MyTask" />
        
          <bean id="myTask" class="net.sourceforge.jwebutil.util.initparameters.PropertyMapper">
            <property name="targetClass"><value>org.springframework.scheduling.timer.ScheduledTimerTask</value></property>
            <property name="initParameters"><ref bean="initParameters" /></property>
            <property name="properties">
              <props>
                <prop key="timerTask">@*myJob</prop>
                <prop key="delay">#delay</prop>
                <prop key="period">#period</prop>
                <prop key="fixedRate">@false</prop>
              </props>
            </property>
          </bean>
        In the above example,
        Code:
                <prop key="timerTask">@*myJob</prop>
        refers directly to a bean. The "#" in front of "delay" and "period" indicates that these parameters are mandatory - an exception will be thrown if not found.

        You could also refer indirectly to a bean reference using a name stored in the database, with a default reference if there is no entry in the database.
        Code:
                <prop key="timerTask">*TIMERJOB;myJob</prop>
        In the above example, TIMERJOB is the name of a parameter in the database table. The bean will be created with the value of this parameter. If the value of the parameter is null, a direct reference to the bean "myJob" will be used.

        Comment


        • #19
          Michael,
          thx for the fixes and for firming up my understanding.
          I also recognized that the issue at http://opensource.atlassian.com/proj.../browse/SPR-95 got updated from Rod.
          But I haven't had the time for a closer look at it.

          Comment

          Working...
          X