|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.ResourceBundle org.sadun.util.DatabaseResourceBundle
A resource bundle which reads resources from a database.
The default resource table is defined by the constant RESOURCETABLE_DEFAULT_NAME
.
A resource table must have the fields (KEY_NAME: VARCHAR, LOCALE: VARCHAR, VALUE: VARCHAR) which are queried when looking up for a key.
Different resource tables may be employed for different keys, by using the setResourceTable()
methods, which associate a regular expression to a table name, and make so that
a key which matches the regular expression queries the given name.
For example,
setResourceTable("STEP1DIALOG_*", "STEP1_DIALOG_RESOURCES");will associate the table STEP1_DIALOG_RESOURCES to any key matching the STEP1DIALOG_* regular expression.
The bundle typically pre-loads and caches the keys (via its autoAdjustCache
, preLoad
and cacheSize
propreties) to avoid accessing the database for each key lookup.
Field Summary | |
static int |
DEFAULT_CACHE_SIZE
Define the default key cache size to 100 |
static java.lang.String |
RESOURCETABLE_DEFAULT_NAME
Define the default name of the default resource table to "APPLICATION_RESOURCES". |
Fields inherited from class java.util.ResourceBundle |
parent |
Constructor Summary | |
DatabaseResourceBundle(javax.sql.DataSource ds)
Create a database resource bundle which will look for resource using the given RESOURCETABLE_DEFAULT_NAME
(see setResourceTable() )
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
|
|
DatabaseResourceBundle(javax.sql.DataSource ds,
int cacheSize)
Create a database resource bundle which will look for resource using the given RESOURCETABLE_DEFAULT_NAME
(see setResourceTable() )
found at the given jdbc URL, using a cache of given size.
|
|
DatabaseResourceBundle(javax.sql.DataSource ds,
java.lang.String defaultResourceTable)
Create a database resource bundle which will look for resource using the given default table name (see setResourceTable() )
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
|
|
DatabaseResourceBundle(javax.sql.DataSource ds,
java.lang.String defaultResourceTable,
int cacheSize)
Create a database resource bundle which will look for resource using the given default table name (see setResourceTable() )
found at the given jdbc URL, using a cache of the given size.
|
|
DatabaseResourceBundle(java.lang.String jdbcUrl)
Create a database resource bundle which will look for resource using the given RESOURCETABLE_DEFAULT_NAME
(see setResourceTable() )
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
|
|
DatabaseResourceBundle(java.lang.String jdbcUrl,
int cacheSize)
Create a database resource bundle which will look for resource using the given RESOURCETABLE_DEFAULT_NAME
(see setResourceTable() )
found at the given jdbc URL, using a cache of given size.
|
|
DatabaseResourceBundle(java.lang.String jdbcUrl,
java.lang.String defaultResourceTable)
Create a database resource bundle which will look for resource using the given default table name (see setResourceTable() )
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
|
|
DatabaseResourceBundle(java.lang.String jdbcUrl,
java.lang.String defaultResourceTable,
int cacheSize)
Create a database resource bundle which will look for resource using the given default table name (see setResourceTable() )
found at the given jdbc URL, using a cache of the given size.
|
Method Summary | |
void |
clearCache()
Clear the cache. |
int |
getCacheSize()
Retur the current size of the cache. |
java.lang.String |
getJdbcUrl()
Return the JDBC url of the database containing the resources. |
java.util.Enumeration |
getKeys()
Connect to all the resource tables and finds out the available keys. |
protected java.lang.Object |
handleGetObject(java.lang.String key)
Finds the table matching the key (or uses the default table) and expects it to have a (KEY: VARCHAR[50], LOCALE: VARCHAR[5], VALUE: VARCHAR[100]) structure. |
boolean |
isAutoAdjustCache()
Return the value of the auto-adjust-cache property (see setAutoAdjustCache() . |
boolean |
isPreLoad()
Return the value of the pre-load property (see setPreLoad() ). |
static void |
main(java.lang.String[] args)
|
void |
setAutoAdjustCache(boolean autoAdjustCache)
Set the auto-adjust-cache property. |
void |
setCacheSize(int cacheSize)
Set the current size of the cache. |
void |
setJdbcUrl(java.lang.String jdbcUrl)
Set the JDBC url of the database containing the resources. |
void |
setPreLoad(boolean preLoad)
Set the value of the pre-load property. |
void |
setResourceTable(java.util.regex.Pattern keyPattern,
java.lang.String tableName)
Set the resource table associated to keys matching the given regular expression. |
void |
setResourceTable(java.lang.String keyRegExpPattern,
java.lang.String tableName)
Set the resource table associated to keys matching the given regular expression. |
Methods inherited from class java.util.ResourceBundle |
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String RESOURCETABLE_DEFAULT_NAME
public static final int DEFAULT_CACHE_SIZE
Constructor Detail |
public DatabaseResourceBundle(javax.sql.DataSource ds, java.lang.String defaultResourceTable, int cacheSize)
setResourceTable()
)
found at the given jdbc URL, using a cache of the given size.
The bundle will pre-load the keys.
ds
- the data source to connect to. A ConfigurableDataSource
can be used to wrap a JDBC URL if necessarydefaultResourceTable
- the name of the table where to look, by default, for keys. The table
must have a specific layout (see class comment) and is used unless a specific table
name is set for a specific key regular expression pattern by setResourceTable()
.cacheSize
- the size of the in-core key cachepublic DatabaseResourceBundle(javax.sql.DataSource ds, java.lang.String defaultResourceTable)
setResourceTable()
)
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
The bundle will pre-load the keys.
ds
- the data source to connect to. A ConfigurableDataSource
can be used to wrap a JDBC URL if necessarydefaultResourceTable
- the name of the table where to look, by default, for keys. The table
must have a specific layout (see class comment) and is used unless a specific table
name is set for a specific key regular expression pattern by setResourceTable()
.public DatabaseResourceBundle(javax.sql.DataSource ds, int cacheSize)
RESOURCETABLE_DEFAULT_NAME
(see setResourceTable()
)
found at the given jdbc URL, using a cache of given size.
The bundle will pre-load the keys.
ds
- the data source to connect to. A ConfigurableDataSource
can be used to wrap a JDBC URL if necessarycacheSize
- the size of the in-core key cachepublic DatabaseResourceBundle(javax.sql.DataSource ds)
RESOURCETABLE_DEFAULT_NAME
(see setResourceTable()
)
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
The bundle will pre-load the keys.
ds
- the data source to connect to. A ConfigurableDataSource
can be used to wrap a JDBC URL if necessarypublic DatabaseResourceBundle(java.lang.String jdbcUrl, java.lang.String defaultResourceTable, int cacheSize)
setResourceTable()
)
found at the given jdbc URL, using a cache of the given size.
The bundle will pre-load the keys.
jdbcUrl
- the JDBC URL of the Database to connect todefaultResourceTable
- the name of the table where to look, by default, for keys. The table
must have a specific layout (see class comment) and is used unless a specific table
name is set for a specific key regular expression pattern by setResourceTable()
.cacheSize
- the size of the in-core key cachepublic DatabaseResourceBundle(java.lang.String jdbcUrl, java.lang.String defaultResourceTable)
setResourceTable()
)
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
The bundle will pre-load the keys.
jdbcUrl
- the JDBC URL of the Database to connect todefaultResourceTable
- the name of the table where to look, by default, for keys. The table
must have a specific layout (see class comment) and is used unless a specific table
name is set for a specific key regular expression pattern by setResourceTable()
.public DatabaseResourceBundle(java.lang.String jdbcUrl, int cacheSize)
RESOURCETABLE_DEFAULT_NAME
(see setResourceTable()
)
found at the given jdbc URL, using a cache of given size.
The bundle will pre-load the keys.
jdbcUrl
- the JDBC URL of the Database to connect tocacheSize
- the size of the in-core key cachepublic DatabaseResourceBundle(java.lang.String jdbcUrl)
RESOURCETABLE_DEFAULT_NAME
(see setResourceTable()
)
found at the given jdbc URL, using a cache of the DEFAULT_CACHE_SIZE
size.
The bundle will pre-load the keys.
jdbcUrl
- the JDBC URL of the Database to connect toMethod Detail |
public void clearCache()
public void setResourceTable(java.lang.String keyRegExpPattern, java.lang.String tableName)
When queried with a key, the bundle will match the key with the regular expression, and use the given table rather than the default table if there is a match.
keyRegExpPattern
- the regular expression to matchtableName
- the table where to lookup resources whose key matches the given regular
expressionpublic void setResourceTable(java.util.regex.Pattern keyPattern, java.lang.String tableName)
When queried with a key, the bundle will match the key with the regular expression, and use the given table rather than the default table if there is a match.
keyPattern
- the regular expression pattern to matchtableName
- the table where to lookup resources whose key matches the given regular
expressionprotected java.lang.Object handleGetObject(java.lang.String key)
ResourceBundle.handleGetObject(java.lang.String)
public java.util.Enumeration getKeys()
This method can be time-consuming.
ResourceBundle.getKeys()
public boolean isAutoAdjustCache()
setAutoAdjustCache()
.
public void setAutoAdjustCache(boolean autoAdjustCache)
autoAdjustCache
- if true, the cache will adjust itself to the
size necessary to hold all the keys for one resource table.public int getCacheSize()
public void setCacheSize(int cacheSize)
cacheSize
- the current size of the cache.public java.lang.String getJdbcUrl()
public void setJdbcUrl(java.lang.String jdbcUrl)
jdbcUrl
- the JDBC url of the database containing the resources.public boolean isPreLoad()
setPreLoad()
).
public void setPreLoad(boolean preLoad)
preLoad
- if true, the bundle will pre-load all the key/value pairs on
the first opportunity.public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |