jp.terasoluna.fw.web.struts.action
Class MessageResourcesDAOImpl

java.lang.Object
  extended by jp.terasoluna.fw.web.struts.action.MessageResourcesDAOImpl
All Implemented Interfaces:
MessageResourcesDAO

public class MessageResourcesDAOImpl
extends java.lang.Object
implements MessageResourcesDAO

MessageResourcesDAO implementation class. When DBMessageResourcesFactory is used as the message resource factory class, DBMessageResources use the class in which MessageResourcesDAO is implemented. For details, refer to DBMessageResources.

How to use
In DBMessageResourcesDAOImpl, Spring framework is used. However, in the Struts framework architecture, there is no technique to fetch DI container. Hence, it is necessary to exclusively define the data source.
In the dbMessageResources.xml Bean definition file, define the data source which is needed to access the DB, place it in the class path and write the description as shown below.
*This Bean definition file should be prepared separately from the Bean definition file which is used for BLogic settings.
When datasource is fetched from JNDI

 <bean id="sampleDataSource" 
       class="org.springframework.jndi.JndiObjectFactoryBean" 
       abstract="false" scope="singleton" 
       lazy-init="default" 
       autowire="default" 
       dependency-check="default">
   <property name="jndiName" 
             value="sampleJndiDataSource" /> 
 </bean>
 
Please note that the attribute of each element differs depending on the system.

When JNDI is not used

 <bean id="dataSource"
       class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="driverClassName">
     <value>oracle.jdbc.OracleDriver</value>
   </property>
   <property name="url">
     <value>jdbc:oracle:thin:@192.0.34.166:1521:ORCL</value>
   </property>
   <property name="username"><value>username</value></property>
   <property name="password"><value>password</value></property>
 </bean>
 
Please note that the following items from the above-mentioned settings differ depending on the system.
  1. driver class name(oracle.jdbc.OracleDriver part)
  2. URL(jdbc:oracle:thin:@192.0.34.166:1521:ORCL part)
  3. User name(username)
  4. Password(password)
It is recommended to use JNDI at the time of using the data source in Web application.


Field Summary
static java.lang.String BEANS_XML
          Bean definition file in which data source is defined.
private static java.lang.String DATASOURCE_BEAN_ID
          id value at the time of fetching data source bean.
private static org.apache.commons.logging.Log log
          Log class.
private static java.lang.String MESSAGE_RESOURCES_DAO_IMPL_ERROR
          Error code indicating the failure in fetching the data source.
 
Constructor Summary
MessageResourcesDAOImpl()
           
 
Method Summary
protected  java.lang.String getBeansXml()
          Fetches the Bean definition file name in which data source is defined.
 java.util.Map<java.lang.String,java.lang.String> queryMessageMap(java.lang.String sql)
          Fetches message resource. Returns the Map in which the first column of SQL is set as a key and second column is set as a value of Map. Returns the map with any one of the duplicate values when there is a duplication in the first column of result set returned by SQL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEANS_XML

public static final java.lang.String BEANS_XML
Bean definition filw in which data source is defined.

See Also:
Constant Field Values

DATASOURCE_BEAN_ID

private static final java.lang.String DATASOURCE_BEAN_ID
id value at the time of fetching the data source bean.

See Also:
Constant Field Values

MESSAGE_RESOURCES_DAO_IMPL_ERROR

private static final java.lang.String MESSAGE_RESOURCES_DAO_IMPL_ERROR
Error code indicating the failure in fetching the data source.

See Also:
Constant Field Values

log

private static org.apache.commons.logging.Log log
Log class.

Constructor Detail

MessageResourcesDAOImpl

public MessageResourcesDAOImpl()
Method Detail

queryMessageMap

public java.util.Map<java.lang.String,java.lang.String> queryMessageMap(java.lang.String sql)
Fetches message resources. Returns Map in which the first column of SQL is set as a key and second column is set as a value of Map When there is a duplication in the first column of result set returned by SQL, returns the map with any one of the duplicate values.

Specified by:
queryMessageMap in interface MessageResourcesDAO
Parameters:
sql - SQL that fetches the message resource
Returns:
Map in which the key is message key and value is message statement.

getBeansXml

protected java.lang.String getBeansXml()
Fetches Bean definition filename in which data source is defined.

Returns:
Bean definition file name in which data source is defined