1 19 20 package org.openharmonise.rm.tasks; 21 22 import java.sql.*; 23 import java.sql.ResultSet ; 24 import java.util.*; 25 import java.util.logging.*; 26 import java.util.logging.Level ; 27 28 import org.openharmonise.commons.cache.*; 29 import org.openharmonise.commons.dsi.*; 30 import org.openharmonise.commons.dsi.dml.*; 31 import org.openharmonise.rm.DataAccessException; 32 import org.openharmonise.rm.dsi.DataStoreInterfaceFactory; 33 34 35 36 43 public class TaskCache extends AbstractCache { 44 45 48 private static final Logger m_logger = Logger.getLogger(TaskCache.class.getName()); 49 50 53 public void clearCache() { 54 super.clearCache(); 55 56 try { 57 initialise(); 58 } catch (CacheException e) { 59 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 60 } 61 } 62 private static TaskCache m_instance = null; 63 private static final String CACHE_NAME = "Task"; 64 private AbstractDataStoreInterface m_dsi = null; 65 66 private TaskCache() throws CacheException { 67 super(CACHE_NAME); 68 initialise(); 69 } 70 71 public static synchronized TaskCache getInstance() 72 throws CacheException { 73 if (m_instance == null) { 74 m_instance = new TaskCache(); 75 } 76 77 return m_instance; 78 } 79 80 public Task getTask(int nId) throws CacheException { 81 return (Task) super.getObject(String.valueOf(nId)); 82 } 83 84 protected Object getCacheableObject(Object key) throws java.lang.Exception { 85 Task tsk = new Task(m_dsi, Integer.parseInt((String ) key)); 86 87 return tsk; 88 } 89 90 private void initialise() throws CacheException { 91 ResultSet rs = null; 92 try { 93 m_dsi = DataStoreInterfaceFactory.getDataStoreInterface(); 94 95 SelectStatement select = new SelectStatement(); 96 Task tsk = new Task(); 97 98 select.addSelectColumn(tsk.getInstanceColumnRef(Task.ATTRIB_ID, false)); 99 100 rs = m_dsi.execute(select); 101 102 while (rs.next()) { 103 this.getObject(rs.getString(1)); 104 } 105 } catch (Exception e) { 106 throw new CacheException(e); 107 } finally { 108 if(rs != null) { 109 try { 110 rs.close(); 111 } catch (SQLException e) { 112 throw new CacheException(e); 113 } 114 } 115 } 116 } 117 118 public List getPendingTasks() throws CacheException { 119 Iterator keyIter = getCacheKeys().iterator(); 120 Vector pends = new Vector(); 121 122 while (keyIter.hasNext() == true) { 123 Task tsk = (Task) getObject(keyIter.next()); 124 125 try { 126 if (tsk.isPending() == true) { 127 pends.add(tsk); 128 } 129 } catch (DataAccessException e) { 130 throw new CacheException(e); 131 } 132 } 133 134 return pends; 135 } 136 } | Popular Tags |