Example of setting parameters of DbConnector()

Hi
I understand DbConnector constructor takes 6 parameters: name, dialect, datasource, jdbctemplate, hibernatetemplate, transactiontemplate

What values do I set for the parameters? Could you give me an example?

You should use DbConnectorFactoryBean to set one up. Avoid calling the DbConnector constructor directly.

This is our spring config that sets one up:

The driverClass is the actual driver, such as “org.postgresql.Driver”.
The url/user/password are self explanatory.
The pool settings can be left as is until it causes you a problem.
The dialectName is the class name of a subclass of DbDialect, such as “com.opengamma.util.db.PostgresDbDialect”.

This can also be setup directly via an INI file using DbConnectorComponentFactory.

The hibernate parts of the connector can be null and are only needed if using the connector for hibernate.

Apparently our forum eats XML. Trying again by replacing less than and greater than with [].

[bean id=“standardDataSource” class=“com.jolbox.bonecp.BoneCPDataSource” destroy-method=“close”]
[property name=“driverClass” value="{db.standard.driver}" /] [property name="jdbcUrl" value="{db.standard.url}" /]
[property name=“username” value="{db.standard.username}" /] [property name="password" value="{db.standard.password}" /]
[property name=“poolName” value=“Standard”/]
[property name=“partitionCount” value=“4” /]
[property name=“acquireIncrement” value=“1” /]
[property name=“minConnectionsPerPartition” value=“1” /]
[property name=“maxConnectionsPerPartition” value=“12” /]
[/bean]

[bean id=“finDbConnector” class=“com.opengamma.util.db.DbConnectorFactoryBean”]
[property name=“name” value=“Financial”/]
[property name=“dataSource” ref=“standardDataSource”/]
[property name=“dialectName” value="${db.standard.dialect}"/]
[property name=“transactionIsolationLevelName” value=“ISOLATION_READ_COMMITTED” /]
[property name=“transactionPropagationBehaviorName” value=“PROPAGATION_REQUIRED” /]
[/bean]

Hi,

I did what you mention here : declare the driverClass/url/user/password/dialectName in the toolcontext.properties, and declare the new Connector in the xml file (as described in your previous post).

When i launch the server, I can see in the log the list of dbConnectors, including the connector I declared (it says something like “dbConnector : mod”).

My question is : how can I use the connector in my code? how do I declare it?

My aim is to create a batch loading some data in 2 different database (say 1 for the marketdata, and 1 for the deals/portfolios) , and store them in the OG database using the appropriate masters. Do I need to implement specific masters for those 2 connections, or can I use the declared dbConnectors, call them in the code and execute queries in the code?

Thank

Thomas

The DbConnector is generally used from other component factories defined in the configuration ini file. Thus, you create your tool class as a stand alone piece of Java code and then write an implementation of ComponentFactory to create it, which can access the DbConnector. See DbPositionMasterComponentFactory for example.