X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fentity%2FEntityContent.java;fp=source%2Fmircoders%2Fentity%2FEntityContent.java;h=e6fbbe088420ac9067e2dd56209903cb2688a653;hb=8618a7efd50ae2edf6ebcf2641d1816c702da104;hp=46fa13ddbfb2b3d44cb8d771aa798a92ba30a2f0;hpb=6fb36d4e86dce331db03a398c8a995ee93e348d0;p=mir.git diff --git a/source/mircoders/entity/EntityContent.java b/source/mircoders/entity/EntityContent.java index 46fa13dd..e6fbbe08 100755 --- a/source/mircoders/entity/EntityContent.java +++ b/source/mircoders/entity/EntityContent.java @@ -32,6 +32,12 @@ public class EntityContent extends Entity 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() @@ -157,18 +163,22 @@ public class EntityContent extends Entity 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()); @@ -177,7 +187,8 @@ public class EntityContent extends Entity } 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()); @@ -186,7 +197,8 @@ public class EntityContent extends Entity } 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()); @@ -195,7 +207,8 @@ public class EntityContent extends Entity } 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()); @@ -204,7 +217,8 @@ public class EntityContent extends Entity } 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()); @@ -213,7 +227,9 @@ public class EntityContent extends Entity } 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()); @@ -340,30 +356,51 @@ public class EntityContent extends Entity 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; } }