|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjp.terasoluna.fw.web.codelist.DBCodeListLoader
public class DBCodeListLoader
Implementation class of ReloadableCodeListLoader
initializes the code list information by using the database.
To generate the code list by using this class, it is necessary to first execute load() method
after specifying the data source in "dataSource" attribute and "load" in "init-method" attribute.
Since this class is not thread safe, the blockage design should be created
by using business blockage function or server blockage function. This will enable to
execute reload() method in a scenario where code list can not be referred.
Please note that if this class is made thread safe, exclusive access control is applied to refer the code list.
This could result into the performance degradation.
SQL that fetches the code list from the database, is set from the Bean definition file.
Configuration example of Bean definition file.
When data source is defined as TerasolunaDataSource.
<bean id="loader1"
class="jp.terasoluna.fw.web.codelist.DBCodeListLoader"
init-method="load">
<property name="dataSource">
<ref bean="TerasolunaDataSource"/>
</property>
<property name="sql">
<value>SELECT KEY, VALUE FROM CODE_LISTS</value>
</property>
</bean>
CodeBean class which stores the codelist, possesses the attribute id and name.
The codelist is stored in the CodeBean as per the sequence of columns specified in SELECT statement.
In the above-example, KEY is stored as per id sequence and VALUE is
stored as per name sequence.
If the fetched columns are less than two and if only KEY is fetched,
null is stored in the name.
When the columns which are fetched by SELECT statement are 3 or more,
columns after 3rd column are ignored.
The result which is fetched by SQL is stored in servlet context.
In JSP, the "name" attribute of <logic:iterate> tag
and "collection" attribute of <html:options> tag in Struts,
are referred as bean name.
In the following example, bean name is specified as
"loader1" in the "collection" attribute of
<html:options>.
<ts:defineCodeList id="loader1" />
...
<html:select property="selectOptions">
<html:options collection="loader1"
labelProperty="name"
property="id"/>
</html:select>
ReloadCodeListAction
For usage method of code list in JSP, refer to
DefineCodeListTag
and
WriteCodeCountTag
.
CodeBean
,
ReloadCodeListAction
,
DefineCodeListTag
,
WriteCodeCountTag
Field Summary | |
---|---|
private java.util.List<CodeBean> |
codeLists
Code list. |
private javax.sql.DataSource |
dataSource
Data source used for connecting to DB. |
private java.lang.Object |
lockObject
Lock object used in the code list. |
private org.apache.commons.logging.Log |
log
Log class. |
private java.lang.String |
sql
SQL to fetch the code list. |
Constructor Summary | |
---|---|
DBCodeListLoader()
|
Method Summary | |
---|---|
CodeBean[] |
getCodeBeans()
Fetches the code list. Code list can be fetched as an array of CodeBean .*Code list is the unique information in the application. In case of overriding this method, implementation should be done in such a way that there should be no impact even if the contents of code list are edited by using business logic. |
javax.sql.DataSource |
getDataSource()
Fetches the dataSource. |
java.lang.String |
getSql()
Fetches the SQL which retrieves the code list. |
void |
load()
Initializes the code list. |
protected void |
loadCodeList()
Loads the code list. Generates the code list based on the dataSource and the specified SQL statement. |
void |
reload()
Reloads the code list. |
void |
setDataSource(javax.sql.DataSource dataSource)
Sets the dataSource. |
void |
setSql(java.lang.String sql)
Sets the SQL to fetch the code list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private org.apache.commons.logging.Log log
private java.util.List<CodeBean> codeLists
CodeBean
private java.lang.String sql
private javax.sql.DataSource dataSource
private final java.lang.Object lockObject
Constructor Detail |
---|
public DBCodeListLoader()
Method Detail |
---|
public void load()
Uses the loadCodeList()
and generates the
code list based on the dataSource and the specified SQL statement.
No process is performed if the code list already exists.
load
in interface CodeListLoader
public void reload()
Calls loadCodeList()
method after syncronizing the codeLists.
It is recommended to use this method in the administration business which is currently under blocked state.
reload
in interface ReloadableCodeListLoader
protected void loadCodeList()
public CodeBean[] getCodeBeans()
CodeBean
.
getCodeBeans
in interface CodeListLoader
public javax.sql.DataSource getDataSource()
public void setDataSource(javax.sql.DataSource dataSource)
dataSource
- Field value indicating dataSource.public java.lang.String getSql()
public void setSql(java.lang.String sql)
sql
- SQL statement
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |