public abstract class AbstractLocalizedTextService extends Object implements LocalizedTextService
The AbstractLocalizedTextService is a basic implementation of the LocalizedTextService interface,
providing all methods for lookup and creation of text items. It has a tight integration with the
LocalizedTextSetImpl which provides an interface for quick text lookup in a collection of items.
The service requires a LocalizedTextDataStore implementation for access to the data store. There
are also two optional properties: flaggingExecutorService and localizedTextSetCache.
The executorService is the ExecutorService that can be used to execute calls
in the background. Calls to flagAsUsed(LocalizedText), saveLocalizedText(LocalizedText) and
deleteLocalizedText(LocalizedText) will put additional calls on the ExecutorService (cache reloads and
background updates). If no executorService is specified, all calls are executed synchronously.
The textSetCache is the LocalizedTextSetCache implementation that is used to cache all
fetched LocalizedTextSet instances. Newly fetched instances will be stored in the cache and if an instance
is found in the cache it will be returned directly without DAO interaction.
See the EternalLocalizedTextSetCache for an implementation with eternal caching.
By default no caching is being done.
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.log4j.Logger |
LOG |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLocalizedTextService(LocalizedTextDataStore localizedTextDao) |
| Modifier and Type | Method and Description |
|---|---|
void |
deleteLocalizedText(LocalizedText text)
Deletes a LocalizedText item from the backing datastore.
|
void |
flagAsUsed(LocalizedText text)
Flags a text item as used, this will also call a method on the DAO to flag the item in the data store.
|
List<String> |
getApplications() |
List<String> |
getGroups(String application) |
Map<String,String> |
getLanguageMap(LocalizedTextSet localizedTextSet,
Language language)
Converts all LocalizedTexts in the provided language to a Map.
|
LocalizedText |
getLocalizedText(String application,
String group,
String label)
Gets a single LocalizedText item from the datastore.
|
List<LocalizedText> |
getLocalizedTextItems(String application,
String group)
Gets a list of all LocalizedText items for a given group.
|
LocalizedTextSet |
getLocalizedTextSet(String application,
String group)
Gets a
LocalizedTextSetImpl for a group of items. |
LocalizedText |
saveDefaultText(String application,
String group,
String label,
String defaultValue)
Creates a new text item with default values.
|
void |
saveLocalizedText(LocalizedText text)
Saves a LocalizedText item in the backing datastore.
|
List<LocalizedText> |
searchLocalizedTextItemsForText(String textToSearchFor)
Gets a list of all LocalizedText items containing a string.
|
void |
setExecutorService(ExecutorService executorService) |
void |
setTextSetCache(LocalizedTextSetCache textSetCache) |
protected AbstractLocalizedTextService(LocalizedTextDataStore localizedTextDao)
localizedTextDao - DAO providing callback methods to the datastore.public final void setExecutorService(ExecutorService executorService)
executorService - The ExecutorService to use for the flagAsUsed(LocalizedText) calls.public final void setTextSetCache(LocalizedTextSetCache textSetCache)
textSetCache - The LocalizedTextSetCache implementation to use for caching the textSet instances.public final LocalizedTextSet getLocalizedTextSet(String application, String group)
Gets a LocalizedTextSetImpl for a group of items. Synchronizes access to the same application/group combination.
If the textSet is not found in the cache it will be fetched from the dataStore and stored in the cache. While this is happening, other threads trying to access the same textSet will wait.
getLocalizedTextSet in interface LocalizedTextServiceapplication - Application to get the group of items from.group - Name of the group.public final List<LocalizedText> getLocalizedTextItems(String application, String group)
getLocalizedTextItems in interface LocalizedTextServiceapplication - Application to get the group of items from.group - Name of the group.public final void flagAsUsed(LocalizedText text)
flagAsUsed in interface LocalizedTextServicetext - Text item that should be flagged as used.public final LocalizedText saveDefaultText(String application, String group, String label, String defaultValue)
Creates a new text item with default values. If the item already exists in the datastore, the existing item will be returned instead. Otherwise this will also execute an insert call on the DAO. Note that no exceptions are being thrown in case saving fails. An ERROR message will be logged but the constructed text item will be returned.
Unlike a normal save or delete, this method will not trigger a cache reload for the text set the item belongs to. Because this method does a lookup first, it is assumed that other instances will fetch the recently created item and return it instead of trying to save twice. In that case fetching the single item is cheaper than reloading the entire set.
saveDefaultText in interface LocalizedTextServiceapplication - Application in which to create the text item.group - Group the text item should belong to.label - Label of the text item.defaultValue - Default value to be set for the text.public final LocalizedText getLocalizedText(String application, String group, String label)
getLocalizedText in interface LocalizedTextServiceapplication - Application in which to find the text item.group - Group the text item belongs to.label - Label of the text item.public final void saveLocalizedText(LocalizedText text)
saveLocalizedText in interface LocalizedTextServicetext - Text item to save.public final List<LocalizedText> searchLocalizedTextItemsForText(String textToSearchFor)
searchLocalizedTextItemsForText in interface LocalizedTextServicetextToSearchFor - String with the text to search for.public final List<String> getApplications()
getApplications in interface LocalizedTextServicepublic final List<String> getGroups(String application)
getGroups in interface LocalizedTextServiceapplication - Name of an application.public final void deleteLocalizedText(LocalizedText text)
deleteLocalizedText in interface LocalizedTextServicetext - Text item to delete.public final Map<String,String> getLanguageMap(LocalizedTextSet localizedTextSet, Language language)
Converts all LocalizedTexts in the provided language to a Map. The LocalizedTexts to be converted can be found in the given LocalizedTextSet.
getLanguageMap in interface LocalizedTextServicelocalizedTextSet - The LocalizedTextSet to convert.language - The language specifying which LocalizedTexts should be converted.Copyright © 2017. All rights reserved.