String mirconf_mailLinkName = MirConfig.getProp("Producer.MailLinkName");
String mirconf_imageRoot = MirConfig.getProp("Producer.ImageRoot");
+ //this should always be transient i.e it can never be stored in the db
+ //or ObjectStore. (so the ObjectStore should only be caching what comes
+ //directly out of the DB. @todo confirm this with rk. -mh
+ HashMap _entCache = new HashMap();
+ Boolean _hasMedia = null;
+
// constructors
public EntityContent()
public TemplateModel get(java.lang.String key) throws TemplateModelException
{
if (key!=null) {
+ if (_entCache.containsKey(key)) {
+ return (TemplateModel)_entCache.get(key);
+ }
if (key.equals("to_comments")) {
try {
- return getComments();
- }
- catch (Exception ex) {
+ _entCache.put(key, getComments());
+ return (TemplateModel)_entCache.get(key);
+ } catch (Exception ex) {
theLog.printWarning("-- getComments: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
if (key.equals("to_media_images")) {
try {
- return getImagesForContent();
+ _entCache.put(key, getImagesForContent());
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString());
}
if (key.equals("to_media_audio")) {
try {
- return getAudioForContent();
+ _entCache.put(key, getAudioForContent());
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString());
}
if (key.equals("to_media_video")) {
try {
- return getVideoForContent();
+ _entCache.put(key, getVideoForContent());
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString());
}
if (key.equals("to_media_other")) {
try {
- return getOtherMediaForContent();
+ _entCache.put(key, getOtherMediaForContent());
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString());
}
else if (key.equals("to_media_icon")) {
try {
- return getUploadedMediaForNewswire();
+ _entCache.put(key, getUploadedMediaForNewswire());
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getUploadedMediaForNewswire: could not fetch data " + ex.toString());
}
else if (key.equals("to_topics")) {
try {
- DatabaseContentToTopics.getInstance().getTopics(this);
+ _entCache.put(key,
+ DatabaseContentToTopics.getInstance().getTopics(this));
+ return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
return returnHash;
}
+ private boolean hasMedia() throws StorageObjectException
+ {
+ if (_hasMedia == null) {
+ _hasMedia =
+ new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
+ }
+ return _hasMedia.booleanValue();
+ }
+
//######## @todo all of the following getBlahForContent should have
// and optimized version where LIMIT=1 sql for list view.
private EntityList getImagesForContent()
throws StorageObjectException, TemplateModelException
{
- return DatabaseContentToMedia.getInstance().getImages(this);
+ if (hasMedia())
+ return DatabaseContentToMedia.getInstance().getImages(this);
+ else
+ return null;
}
private EntityList getAudioForContent()
throws StorageObjectException, TemplateModelException
{
- return DatabaseContentToMedia.getInstance().getAudio(this) ;
+ if (hasMedia())
+ return DatabaseContentToMedia.getInstance().getAudio(this) ;
+ else
+ return null;
}
private EntityList getVideoForContent()
throws StorageObjectException, TemplateModelException
{
- return DatabaseContentToMedia.getInstance().getVideo(this) ;
+ if (hasMedia())
+ return DatabaseContentToMedia.getInstance().getVideo(this) ;
+ else
+ return null;
}
private EntityList getOtherMediaForContent()
throws StorageObjectException, TemplateModelException
{
- return DatabaseContentToMedia.getInstance().getOther(this);
+ if (hasMedia())
+ return DatabaseContentToMedia.getInstance().getOther(this);
+ else
+ return null;
}
}