Coverage Report - com.buckosoft.PicMan.db.VirginsDaoJdbc
 
Classes in this File Line Coverage Branch Coverage Complexity
VirginsDaoJdbc
0%
0/24
0%
0/4
1.688
VirginsDaoJdbc$VirginDelete
0%
0/9
N/A
1.688
VirginsDaoJdbc$VirginInsert
0%
0/9
N/A
1.688
VirginsDaoJdbc$VirginsCount
0%
0/4
N/A
1.688
VirginsDaoJdbc$VirginsQuery
0%
0/17
N/A
1.688
 
 1  
 /******************************************************************************
 2  
  * VirginsDaoJdbc.java - Implement the Dao interface for the Virgins
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2005 - Dick Balaska
 6  
  * 
 7  
  */
 8  
 package com.buckosoft.PicMan.db;
 9  
 
 10  
 import java.util.List;
 11  
 
 12  
 import javax.sql.DataSource;
 13  
 
 14  
 import java.sql.ResultSet;
 15  
 import java.sql.SQLException;
 16  
 import java.sql.Types;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 import org.springframework.dao.DataAccessException;
 22  
 import org.springframework.jdbc.core.SqlParameter;
 23  
 import org.springframework.jdbc.object.SqlFunction;
 24  
 import org.springframework.jdbc.object.SqlUpdate;
 25  
 import org.springframework.jdbc.object.MappingSqlQuery;
 26  
 
 27  
 import com.buckosoft.PicMan.domain.Virgin;
 28  
 
 29  
 /** Implement the Dao Interface for the {@link com.buckosoft.PicMan.domain.Virgin}s.
 30  
  * @author Dick Balaska
 31  
  * @since 2005/07/31
 32  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/db/VirginsDaoJdbc.java">VirginsDaoJdbc.java</a>
 33  
  */
 34  0
 public class VirginsDaoJdbc implements VirginsDao {
 35  
 
 36  
         private final static boolean DEBUG = false;
 37  
         private final static boolean DEBUGCONNECTIONLEAK = false;
 38  
         
 39  0
         protected final Log logger = LogFactory.getLog(getClass());
 40  
         
 41  
 //        private        PicManFacade        pmf;
 42  
         private DataSource ds;
 43  
 
 44  
         /** Set the reference to the JDBC datasource.
 45  
          * @param ds The datasource as configured by Spring.
 46  
          * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/WebContent/WEB-INF/picManDatabase/picManDatabase.xml">picManDatabase.xml</a>
 47  
          */ 
 48  
         public void setDataSource(DataSource ds) {
 49  0
                 this.ds = ds;
 50  0
         }
 51  
 
 52  
         /** Get the list of Virgins, the Pics that haven't been filtered yet.
 53  
          * @return The List
 54  
          */
 55  
         @SuppressWarnings("unchecked")
 56  
         public List<Virgin> getVirgins() throws DataAccessException {
 57  
                 if (DEBUG)
 58  
                         logger.info("Getting Virgins");
 59  0
                 VirginsQuery vq = new VirginsQuery(ds);
 60  0
                 return(vq.execute());
 61  
         }
 62  
 
 63  
         
 64  
         /* (non-Javadoc)
 65  
          * @see com.buckosoft.PicMan.db.VirginsDao#getVirgins(int)
 66  
          */
 67  
         @SuppressWarnings("unchecked")
 68  
         public List<Virgin> getVirgins(int max) throws DataAccessException {
 69  
                 if (DEBUG)
 70  
                         logger.info("Getting Virgins(" + max + ")");
 71  0
                 VirginsQuery vq = new VirginsQuery(ds, max);
 72  0
                 return(vq.execute(max));
 73  
         }
 74  
 
 75  
         /* (non-Javadoc)
 76  
          * @see com.buckosoft.PicMan.db.VirginsDao#isVirgin(java.lang.String)
 77  
          */
 78  
         public boolean isVirgin(String picName) {
 79  0
                 VirginsQuery vq = new VirginsQuery(ds, picName);
 80  0
                 Virgin v = (Virgin)vq.findObject(picName);
 81  
                 if (DEBUG)
 82  
                         logger.info("IsVirgin: " + picName + ": " + v != null ? "true" : "false");
 83  0
                 return(v != null ? true : false);
 84  
         }
 85  
         
 86  
         /** Add a pic to the Virgin database
 87  
          * @param picName The name of the pic to add
 88  
          */
 89  
         public void        addVirgin(String picName) throws DataAccessException {
 90  
                 if (DEBUG)
 91  
                         logger.info("addVirgin: " + picName);
 92  0
                 VirginInsert vi = new VirginInsert(ds);
 93  0
                 Virgin v = new Virgin();
 94  0
                 v.setName(picName);
 95  0
                 vi.insert(v);
 96  0
         }
 97  
         
 98  
         /** Delete a pic from the Virgin database
 99  
          * @param picName The name of the pic to remove
 100  
          */
 101  
         public void        deleteVirgin(String picName) throws DataAccessException {
 102  
                 if (DEBUG)
 103  
                         logger.info("deleteVirgin: " + picName);
 104  0
                 VirginDelete vd = new VirginDelete(ds);
 105  0
                 Virgin v = new Virgin();
 106  0
                 v.setName(picName);
 107  0
                 vd.delete(v);
 108  0
         }
 109  
 
 110  
         /** Get the number of Virgins in the database
 111  
          * @return the count
 112  
          */
 113  
         public int        getVirginCount() {
 114  
                 if (DEBUG)
 115  
                         logger.info("getVirginCount:");
 116  
                 if (DEBUGCONNECTIONLEAK)
 117  
                         return(69);
 118  0
                 if (sql_getVirginCountQUERYr == null)
 119  0
                         sql_getVirginCountQUERYr = new VirginsCount(ds);
 120  0
                 return(sql_getVirginCountQUERYr.run());
 121  
         }
 122  
         private VirginsCount        sql_getVirginCountQUERYr;
 123  
         
 124  
         ///////////////////////////////////////////////////////////////////////////
 125  
         class VirginsQuery extends MappingSqlQuery {
 126  
                 
 127  0
                 VirginsQuery(DataSource ds) {
 128  0
                         super(ds, "SELECT * from virgins");
 129  0
                         compile();
 130  0
                 }
 131  
                 
 132  0
                 VirginsQuery(DataSource ds, int max) {
 133  0
                         super(ds, "SELECT * from virgins LIMIT ?");
 134  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 135  0
                         compile();
 136  0
                 }
 137  
                 
 138  0
                 VirginsQuery(DataSource ds, String picName) {
 139  0
                         super(ds, "SELECT * from virgins WHERE pic = ?");
 140  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 141  0
                         compile();
 142  0
                 }
 143  
                 
 144  
                 
 145  
                 protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
 146  0
                         Virgin v = new Virgin();
 147  0
                         v.setName(rs.getString("pic"));
 148  0
                         return(v);
 149  
                 }
 150  
         }
 151  
         
 152  
         /**
 153  
          * <code>Virgin</code> Count Object.
 154  
          */
 155  
         class VirginsCount extends SqlFunction {
 156  
                 
 157  0
                 VirginsCount(DataSource ds) {
 158  0
                         super(ds, "SELECT COUNT(*) from virgins");
 159  0
                         compile();
 160  0
                 }                
 161  
         }
 162  
 
 163  
         /**
 164  
          * <code>Virgin</code> Insert Object.
 165  
          */
 166  
         protected class VirginInsert extends SqlUpdate {
 167  
                 
 168  
                 /**
 169  
                  * Create a new instance of VirginInsert.
 170  
                  * @param ds the DataSource to use for the insert
 171  
                  */
 172  0
                 protected VirginInsert(DataSource ds) {
 173  0
                         super(ds, "INSERT INTO virgins VALUES(?)");
 174  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 175  0
                         compile();
 176  0
                 }
 177  
                 
 178  
                 protected void insert(Virgin v) {
 179  0
                         Object[] objs = new Object[] {
 180  0
                                         v.getName()};
 181  0
                         super.update(objs);
 182  
                         // retrieveIdentity(owner);
 183  0
                 }
 184  
         }
 185  
         
 186  
         /**
 187  
          * <code>Virgin</code> Delete Object.
 188  
          */
 189  
         protected class VirginDelete extends SqlUpdate {
 190  
                 
 191  
                 /**
 192  
                  * Create a new instance of VirginRemove.
 193  
                  * @param ds the DataSource to use for the delete
 194  
                  */
 195  0
                 protected VirginDelete(DataSource ds) {
 196  0
                         super(ds, "DELETE FROM virgins WHERE pic = (?)");
 197  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 198  0
                         compile();
 199  0
                 }
 200  
                 
 201  
                 protected void delete(Virgin v) {
 202  0
                         Object[] objs = new Object[] {
 203  0
                                         v.getName()};
 204  0
                         super.update(objs);
 205  
                         // retrieveIdentity(owner);
 206  0
                 }
 207  
         }
 208  
 }