Coverage Report - com.buckosoft.PicMan.db.FiltersMicroSetsDaoJdbc
 
Classes in this File Line Coverage Branch Coverage Complexity
FiltersMicroSetsDaoJdbc
0%
0/26
0%
0/8
1.5
FiltersMicroSetsDaoJdbc$FiltersMicroSetDelete
0%
0/7
N/A
1.5
FiltersMicroSetsDaoJdbc$FiltersMicroSetInsert
0%
0/10
N/A
1.5
FiltersMicroSetsDaoJdbc$FiltersMicroSetsQuery
0%
0/27
N/A
1.5
 
 1  
 /******************************************************************************
 2  
  * FiltersMicroSetsDaoJdbc.java - Implement the Dao interface for the FiltersMicroSets
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2008 - 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.List;
 14  
 
 15  
 import javax.sql.DataSource;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 import org.springframework.jdbc.core.SqlParameter;
 20  
 import org.springframework.jdbc.object.MappingSqlQuery;
 21  
 import org.springframework.jdbc.object.SqlUpdate;
 22  
 
 23  
 import com.buckosoft.PicMan.domain.FilterMicroSet;
 24  
 
 25  
 /** Implement the Dao Interface for the {@link com.buckosoft.PicMan.domain.FilterMicroSet}s.
 26  
  * @author Dick Balaska
 27  
  * @since 2008/06/09
 28  
  */
 29  0
 public class FiltersMicroSetsDaoJdbc implements FiltersMicroSetsDao {
 30  
         private final static boolean DEBUG = false;
 31  0
         private final Log logger = LogFactory.getLog(getClass());
 32  
         
 33  
         private DataSource ds;
 34  
         
 35  
         /** Set the reference to the JDBC datasource.
 36  
          * @param ds The datasource as configured by Spring.
 37  
          * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/WebContent/WEB-INF/picManDatabase/picManDatabase.xml">picManDatabase.xml</a>
 38  
          */ 
 39  
         public void setDataSource(DataSource ds) {
 40  0
                 this.ds = ds;
 41  0
         }
 42  
 
 43  
         /* (non-Javadoc)
 44  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#getFilterMicroSet(int, int)
 45  
          */
 46  
         public FilterMicroSet getFilterMicroSet(int pid, int sid) {
 47  0
                 if (sql_getFMSQUERY == null)
 48  0
                         sql_getFMSQUERY = new FiltersMicroSetsQuery(ds, pid, sid);
 49  0
                 return((FilterMicroSet)sql_getFMSQUERY.findObject(pid, sid));
 50  
         }
 51  0
         private        FiltersMicroSetsQuery        sql_getFMSQUERY = null;
 52  
 
 53  
 
 54  
 
 55  
         /* (non-Javadoc)
 56  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#getFiltersInPid(int)
 57  
          */
 58  
         @SuppressWarnings("unchecked")
 59  
         public List<FilterMicroSet> getFiltersInPid(int pid) {
 60  
                 if (DEBUG)
 61  
                         logger.info("getFiltersInPid");
 62  0
                 if (sql_getFMSListQUERY == null)
 63  0
                         sql_getFMSListQUERY = new FiltersMicroSetsQuery(ds, pid);
 64  0
                 return(sql_getFMSListQUERY.execute(pid));
 65  
         }
 66  0
         private        FiltersMicroSetsQuery        sql_getFMSListQUERY = null;
 67  
 
 68  
 
 69  
         /* (non-Javadoc)
 70  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#deleteFilters(int)
 71  
          */
 72  
         public void deleteFilters(int pid) {
 73  0
                 FiltersMicroSetDelete fmsd = new FiltersMicroSetDelete(ds);
 74  0
                 fmsd.delete(pid);
 75  0
         }
 76  
         
 77  
         /* (non-Javadoc)
 78  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#getPicsInSet(int)
 79  
          */
 80  
         @SuppressWarnings("unchecked")
 81  
         public List<FilterMicroSet> getPicsInSet(int sid) {
 82  
                 if (DEBUG)
 83  
                         logger.info("getPicsInSet: " + sid);
 84  0
                 if (sql_getPISListQUERY == null)
 85  0
                         sql_getPISListQUERY = new FiltersMicroSetsQuery(ds, "");
 86  0
                 return(sql_getPISListQUERY.execute(sid));
 87  
         }
 88  0
         private        FiltersMicroSetsQuery        sql_getPISListQUERY = null;
 89  
 
 90  
         /* (non-Javadoc)
 91  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#getPicsInSet(int, int)
 92  
          */
 93  
         @SuppressWarnings("unchecked")
 94  
         public List<FilterMicroSet> getPicsInSet(int sid, int value) {
 95  
                 if (DEBUG)
 96  
                         logger.info("getPicsInSet: " + sid);
 97  0
                 if (sql_getPISvListQUERY == null)
 98  0
                         sql_getPISvListQUERY = new FiltersMicroSetsQuery(ds, "", value);
 99  0
                 return(sql_getPISvListQUERY.execute(sid, value));
 100  
         }
 101  0
         private        FiltersMicroSetsQuery        sql_getPISvListQUERY = null;
 102  
 
 103  
         
 104  
         /* (non-Javadoc)
 105  
          * @see com.buckosoft.PicMan.db.FiltersMicroSetsDao#storeFilter(int, int, int)
 106  
          */
 107  
         public void storeFilter(int sid, int pid, int value) {
 108  
                 if (DEBUG)
 109  
                         logger.info("addPic: " + sid);
 110  0
                 FiltersMicroSetInsert pi = new FiltersMicroSetInsert(ds);
 111  0
                 pi.insert(sid, pid, value);
 112  0
         }
 113  
 
 114  
         /**
 115  
          * Object to Query for FiltersMicroSets
 116  
          */
 117  
         private class FiltersMicroSetsQuery extends MappingSqlQuery {
 118  
                 
 119  
 /*                FiltersMicroSetsQuery(DataSource ds) {
 120  
                         super(ds, "SELECT * from pics");
 121  
                         compile();
 122  
                 }
 123  
 */                
 124  0
                 FiltersMicroSetsQuery(DataSource ds, int pid) {
 125  0
                         super(ds, "SELECT * from filtersMicroSets where pid = ?");
 126  0
             declareParameter(new SqlParameter(Types.INTEGER));
 127  0
                         compile();
 128  0
                 }
 129  0
                 FiltersMicroSetsQuery(DataSource ds, int pid, int sid) {
 130  0
                         super(ds, "SELECT * from filtersMicroSets where pid = ? AND sid = ?");
 131  0
             declareParameter(new SqlParameter(Types.INTEGER));
 132  0
             declareParameter(new SqlParameter(Types.INTEGER));
 133  0
                         compile();
 134  0
                 }
 135  0
                 FiltersMicroSetsQuery(DataSource ds, String unused) {
 136  0
                         super(ds, "SELECT * from filtersMicroSets where sid = ?");
 137  0
             declareParameter(new SqlParameter(Types.INTEGER));
 138  0
                         compile();
 139  0
                 }
 140  0
                 FiltersMicroSetsQuery(DataSource ds, String unused, int value) {
 141  0
                         super(ds, "SELECT * from filtersMicroSets where sid = ? AND value >= ?");
 142  0
             declareParameter(new SqlParameter(Types.INTEGER));
 143  0
             declareParameter(new SqlParameter(Types.INTEGER));
 144  0
                         compile();
 145  0
                 }
 146  
 
 147  
                 protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
 148  0
                         FilterMicroSet fms = new FilterMicroSet();
 149  0
                         fms.setSid(rs.getInt("sid"));
 150  0
                         fms.setPid(rs.getInt("pid"));
 151  0
                         fms.setValue(rs.getInt("value"));
 152  0
                         return(fms);
 153  
                 }
 154  
         }
 155  
 
 156  
         /**
 157  
          * <code>FiltersMicroSet</code> Insert Object.
 158  
          */
 159  
         private class FiltersMicroSetInsert extends SqlUpdate {
 160  
                 
 161  
                 /**
 162  
                  * Create a new instance of PicInsert.
 163  
                  * @param ds the DataSource to use for the insert
 164  
                  */
 165  0
                 protected FiltersMicroSetInsert(DataSource ds) {
 166  0
                         super(ds, "INSERT INTO filtersMicroSets VALUES(?,?,?)");
 167  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 168  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 169  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 170  0
                         compile();
 171  0
                 }
 172  
 
 173  
                 protected void insert(int sid, int pid, int value) {
 174  0
                         Object[] objs = new Object[] {
 175  
                                 new Integer(sid), new Integer(pid), new Integer(value) };
 176  0
                         super.update(objs);
 177  0
                 }
 178  
         }
 179  
 
 180  
         /**
 181  
          * <code>FiltersMicroSet</code> Delete Object.
 182  
          */
 183  
         protected class FiltersMicroSetDelete extends SqlUpdate {
 184  
                 
 185  
                 /**
 186  
                  * Create a new instance of FiltersMicroSetDelete.
 187  
                  * @param ds the DataSource to use for the delete
 188  
                  */
 189  0
                 protected FiltersMicroSetDelete(DataSource ds) {
 190  0
                         super(ds, "DELETE FROM filtersMicroSets WHERE pid = (?)");
 191  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 192  0
                         compile();
 193  0
                 }
 194  
                 
 195  
                 protected void delete(int pid) {
 196  0
                         super.update(pid);
 197  0
                 }
 198  
         }
 199  
         
 200  
 }