1 29 30 package com.caucho.amber.entity; 31 32 import com.caucho.amber.manager.AmberConnection; 33 import com.caucho.util.Alarm; 34 35 import java.sql.SQLException ; 36 import java.util.Map ; 37 38 41 public class CacheableEntityItem extends EntityItem { 42 private AmberEntityHome _home; 43 private Entity _cacheItem; 44 private long _expireTime; 45 46 public CacheableEntityItem(AmberEntityHome home, Entity cacheItem) 47 { 48 _home = home; 49 _cacheItem = cacheItem; 50 51 _expireTime = Alarm.getCurrentTime() + _home.getCacheTimeout(); 52 } 53 54 57 AmberEntityHome getEntityHome() 58 { 59 return _home; 60 } 61 62 67 public Entity getEntity() 68 { 69 long now = Alarm.getCurrentTime(); 70 71 if (_expireTime < now) { 72 _expireTime = now + _home.getCacheTimeout(); 73 74 _cacheItem.__caucho_expire(); 75 } 76 77 return _cacheItem; 78 } 79 80 85 public Entity loadEntity(int loadGroup) 86 { 87 return loadEntity(loadGroup, null); 88 } 89 90 95 public Entity loadEntity(int loadGroup, 96 Map preloadedProperties) 97 { 98 long now = Alarm.getCurrentTime(); 99 100 if (_expireTime < now) { 101 _expireTime = now + _home.getCacheTimeout(); 102 _cacheItem.__caucho_expire(); 103 } 104 105 AmberConnection aConn = _home.getManager().getCacheConnection(); 106 107 try { 108 _cacheItem.__caucho_setConnection(aConn); 109 _cacheItem.__caucho_retrieve(aConn, preloadedProperties); 110 } catch (SQLException e) { 111 throw new RuntimeException (e); 113 } finally { 114 aConn.freeConnection(); 115 } 116 117 return _cacheItem; 118 } 119 120 123 public Entity copy(AmberConnection aConn) 124 { 125 return _cacheItem.__caucho_copy(aConn, this); 126 } 127 128 131 public void save(Entity item) 132 { 133 142 } 143 144 147 public void savePart(Entity item) 148 { 149 154 } 155 156 159 public void expire() 160 { 161 _cacheItem.__caucho_expire(); 162 } 163 164 Class getInstanceClass() 165 { 166 return _cacheItem.getClass(); 167 } 168 169 public String toString() 170 { 171 return "CacheableEntityItem[" + _cacheItem + "]"; 172 } 173 } 174 | Popular Tags |