Coverage Report - com.buckosoft.PicMan.db.SetTimestampsDaoJdbc
 
Classes in this File Line Coverage Branch Coverage Complexity
SetTimestampsDaoJdbc
0%
0/25
0%
0/8
1.667
SetTimestampsDaoJdbc$FilterSetsTimestampInsert
0%
0/12
N/A
1.667
SetTimestampsDaoJdbc$FilterSetsTimestampQuery
0%
0/9
N/A
1.667
SetTimestampsDaoJdbc$SetsTimestamp
0%
0/1
N/A
1.667
 
 1  
 /******************************************************************************
 2  
  * SetTimestampsDaoJdbc.java - Implement the Dao Interface for the SetTimestamp table
 3  
  *
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2011 - Dick Balaska
 6  
  * 
 7  
  */
 8  
 package com.buckosoft.PicMan.db;
 9  
 
 10  
 import java.sql.ResultSet;
 11  
 import java.sql.SQLException;
 12  
 import java.sql.Types;
 13  
 import java.util.Date;
 14  
 import java.util.HashMap;
 15  
 import java.util.Iterator;
 16  
 import java.util.LinkedHashMap;
 17  
 import java.util.List;
 18  
 
 19  
 import javax.sql.DataSource;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.springframework.jdbc.core.SqlParameter;
 24  
 import org.springframework.jdbc.object.MappingSqlQuery;
 25  
 import org.springframework.jdbc.object.SqlUpdate;
 26  
 
 27  
 /** Implement the Dao Interface for the SetTimestamp table
 28  
  * @author Dick Balaska
 29  
  * @since 2011/12/30
 30  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/db/SetTimestampsDaoJdbc.java">SetTimestampsDaoJdbc.java</a>
 31  
  */
 32  0
 public class SetTimestampsDaoJdbc implements SetTimestampsDao {
 33  
 
 34  
         private final static boolean DEBUG = false;
 35  0
         protected final Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
         private DataSource ds;
 38  
         
 39  
         /** Set the JDBC datasource reference
 40  
      * @param ds The DataSource as generated by the Spring config/setup.
 41  
      */
 42  
         public void setDataSource(DataSource ds) {
 43  0
                 this.ds = ds;
 44  0
         }
 45  
 
 46  
         /* (non-Javadoc)
 47  
          * @see com.buckosoft.PicMan.db.FiltersDao#getFilterDates()
 48  
          */
 49  
         public HashMap<String, Date>        getSetTimestamps() {
 50  0
                 HashMap<String, Date> hm = new HashMap<String, Date>();
 51  0
                 if (sql_getFilterDatesQUERY == null)
 52  0
                         sql_getFilterDatesQUERY = new FilterSetsTimestampQuery(ds);
 53  
                 @SuppressWarnings("unchecked")
 54  0
                 List<SetsTimestamp> l = sql_getFilterDatesQUERY.execute();
 55  0
                 Iterator<SetsTimestamp> it = l.iterator();
 56  0
                 while (it.hasNext()) {
 57  0
                         SetsTimestamp st = it.next();
 58  0
                         hm.put(st.uid, st.timestamp);
 59  0
                 }
 60  0
                 return(hm);
 61  
         }
 62  0
         private FilterSetsTimestampQuery sql_getFilterDatesQUERY = null;
 63  
 
 64  
         /* (non-Javadoc)
 65  
          * @see com.buckosoft.PicMan.db.FiltersDao#updateFilterDates(java.util.LinkedHashMap)
 66  
          */
 67  
         public        void        updateFilterDates(LinkedHashMap<String, String> changed) {
 68  0
                 for (String s : changed.keySet())
 69  0
                         updateSetTimestamp(s);
 70  0
         }
 71  
 
 72  
         @Override
 73  
         public void updateSetTimestamp(String setName) {
 74  0
                 String s = "DELETE FROM setsTimestamp WHERE uid = \"" + setName + "\"";
 75  
                 if (DEBUG)
 76  
                         logger.info(s);
 77  0
                 SqlUpdate sf1 = new SqlUpdate(ds, s);
 78  0
                 sf1.update();
 79  
 
 80  0
                 if (sql_updateFilterDatesINSERT == null)
 81  0
                         sql_updateFilterDatesINSERT = new FilterSetsTimestampInsert(ds);
 82  0
                 sql_updateFilterDatesINSERT.insert(setName);
 83  
 
 84  0
         }
 85  
         FilterSetsTimestampInsert sql_updateFilterDatesINSERT;
 86  
 
 87  
         
 88  
         /** Mini-domain object representing the setsTimestamp table */
 89  0
         class SetsTimestamp {
 90  
                 String        uid;
 91  
                 Date        timestamp;
 92  
         }
 93  
         
 94  
         class FilterSetsTimestampQuery extends MappingSqlQuery {
 95  0
                 FilterSetsTimestampQuery(DataSource ds) {
 96  0
                         super(ds, "SELECT * from setsTimestamp");
 97  0
                         compile();
 98  0
                 }
 99  
                 
 100  
                 protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
 101  0
                         SetsTimestamp st = new SetsTimestamp();
 102  0
                         st.uid = rs.getString("uid");
 103  
                         try {
 104  0
                                 st.timestamp = rs.getTimestamp("timestamp");
 105  0
                         } catch (Exception e) {}
 106  
                         
 107  0
                         return(st);
 108  
                 }
 109  
                 
 110  
         }
 111  
         
 112  
         /**
 113  
          * <code>FilterSetsTimestamp</code> Insert Object.
 114  
          */
 115  
         protected class FilterSetsTimestampInsert extends SqlUpdate {
 116  
                 /**
 117  
                  * Create a new instance of FilterSetsTimestampInsert.
 118  
                  * @param ds the DataSource to use for the insert
 119  
                  */
 120  0
                 protected FilterSetsTimestampInsert(DataSource ds) {
 121  0
                         super(ds, "INSERT INTO setsTimestamp VALUES(?,?)");
 122  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 123  0
                         declareParameter(new SqlParameter(Types.TIMESTAMP));
 124  0
                         compile();
 125  0
                 }
 126  
                 
 127  
                 protected void insert(SetsTimestamp st) {
 128  0
                         Object[] objs = new Object[] {
 129  
                                         st.uid, st.timestamp };
 130  0
                         super.update(objs);
 131  0
                 }
 132  
                 protected void insert(String key) {
 133  0
                         Object[] objs = new Object[] {
 134  
                                         key, new Date() };
 135  0
                         super.update(objs);
 136  0
                 }
 137  
         }        
 138  
         
 139  
 }