Merge "Issue #1638 Fixing dao cache to map by plugin name to fix plugins that resuse same dao" into development
Former-commit-id:5574de75a2
[formerlye6b8695a30
] [formerlyfea6057095
[formerly da0891694115e3b431b652d940de96cc53c94969]] Former-commit-id:fea6057095
Former-commit-id:663219cc28
This commit is contained in:
commit
5caef1db26
1 changed files with 18 additions and 19 deletions
|
@ -71,7 +71,7 @@ public class PluginFactory {
|
|||
return instance;
|
||||
}
|
||||
|
||||
private Map<Class<PluginDao>, PluginDao> pluginDaoMap = new HashMap<Class<PluginDao>, PluginDao>();
|
||||
private Map<String, PluginDao> pluginDaoMap = new HashMap<String, PluginDao>();
|
||||
|
||||
private Object daoMapLock = new Object();
|
||||
|
||||
|
@ -98,37 +98,36 @@ public class PluginFactory {
|
|||
* @throws PluginException
|
||||
* If the dao cannot be instantiated
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginDao getPluginDao(String pluginName) throws PluginException {
|
||||
PluginProperties props = PluginRegistry.getInstance()
|
||||
.getRegisteredObject(pluginName);
|
||||
if (props != null) {
|
||||
try {
|
||||
Class<PluginDao> clz = (Class<PluginDao>) props.getDao();
|
||||
PluginDao dao = pluginDaoMap.get(clz);
|
||||
if (dao == null) {
|
||||
PluginDao dao = pluginDaoMap.get(pluginName);
|
||||
if (dao == null) {
|
||||
PluginProperties props = PluginRegistry.getInstance()
|
||||
.getRegisteredObject(pluginName);
|
||||
if (props != null) {
|
||||
try {
|
||||
synchronized (daoMapLock) {
|
||||
// Create dao
|
||||
dao = (PluginDao) ConstructorUtils.invokeConstructor(
|
||||
clz, pluginName);
|
||||
props.getDao(), pluginName);
|
||||
|
||||
// Copy dao mapping
|
||||
Map<Class<PluginDao>, PluginDao> pluginDaoMapCopy = new HashMap<Class<PluginDao>, PluginDao>(
|
||||
Map<String, PluginDao> pluginDaoMapCopy = new HashMap<String, PluginDao>(
|
||||
pluginDaoMap);
|
||||
// Add dao
|
||||
pluginDaoMapCopy.put(clz, dao);
|
||||
pluginDaoMapCopy.put(pluginName, dao);
|
||||
// Reset mapping
|
||||
pluginDaoMap = pluginDaoMapCopy;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new PluginException("Error instantiating DAO for "
|
||||
+ pluginName + " plugin!", e);
|
||||
}
|
||||
return dao;
|
||||
} catch (Exception e) {
|
||||
throw new PluginException("Error instantiating DAO for "
|
||||
+ pluginName + " plugin!", e);
|
||||
} else {
|
||||
throw new PluginException("Plugin " + pluginName
|
||||
+ " is not registered with the PluginRegistry");
|
||||
}
|
||||
} else {
|
||||
throw new PluginException("Plugin " + pluginName
|
||||
+ " is not registered with the PluginRegistry");
|
||||
}
|
||||
return dao;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue