Hitachi Vantara Pentaho Community Wiki
Child pages
  • Pentaho ObjectFactory and Spring Enhancements

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<bean class="org.pentaho.MyDatasource"> 
  <pen:publish as-type="INTERFACES"/> 
</bean> 

<bean class="org.pentaho.MyCustomDatasource"> 
  <pen:publish as-type="INTERFACES"/>
    <pen:attributes> 
      <pen:attr key="priority" value="30"/> 
    </pen:attributes> 
  </pen:publish> 
</bean> 

Even though two implementations of IDatasource are registered, the second will be returned by PentahoSystem.get() and <pen:bean> as it's now the highest priority. Calls to PentahoSystem.getAll() or <pen:list> will return both, ordered by priority.

...

Code Block
xml
xml
<bean class="org.pentaho.MyDatasource"> 
  <pen:publish as-type="INTERFACES"/>
    <pen:attributes> 
      <pen:attr key="type" value="jdbc"/> 
    </pen:attributes> 
  </pen:publish> 
</bean> 

<bean class="org.pentaho.MyOlapDatasource"> 
  <pen:publish as-type="INTERFACES"/>
    <pen:attributes> 
      <pen:attr key="type" value="olap"/> 
    </pen:attributes> 
  </pen:publish> 
</bean> 

You can now query for the highest priority implementation of IDatasource matching the type=olap using the following

...

Of course in this example the list will contain only one entry.

Republish a bean based on configuration.

There are times when you want the implementation found to be based on configuration and not priority, but updating every PentahoSystem.get() call or <pen:bean> reference is burdensome. To avoid this you can combine the concepts above to achieve the same effect without having to modify every area. This technique is used in several places in 5.0

Say you have two implementations of com.foo.IWidgetProvider, one with aggressive caching and the other without. You setup a property file using the ISystemConfig detailed in the next section which you want to drive which one is used in the system.

Code Block
xml
xml

<bean class="com.foo.StandardWidgetProvider">
  <pen:publish as-type="INTERFACES">
    <pen:attributes>
      <pen:attr key="caching" value="false"/>
    </pen:attributes>
  </pen:publish>
</bean>

<bean class="com.foo.CachingWidgetProvider">
  <pen:publish as-type="INTERFACES">
    <pen:attributes>
      <pen:attr key="caching" value="true"/>
    </pen:attributes>
  </pen:publish>
</bean>

<!-- re-publish the correct one at a higher priority -->

<pen:bean class="com.foo.IWidgetProvider">
  <!-- find the one by confguration -->
  <pen:attributes>
    <pen:attr key="caching" value="${widgetSettings.cache}"/>
  </pen:attributes>

  <!-- re-publish at higher priority -->
  <pen:publish as-type="INTERFACES">
    <pen:attributes>
      <pen:attr key="priority" value="50"/>
    </pen:attributes>
  </pen:publish>
</pen:bean>

Now that we've re-published the correct bean, the following calls will return the correct implementation without any knowledge of the configuration itself.

Code Block

PentahoSystem.get(com.foo.IWidgetProvider.class)

<pen:bean class="com.foo.IWidgetProvider"/>

Anchor
systemConfig
systemConfig

...