Coverage Report - com.buckosoft.PicMan.db.MosaicTilesDaoJdbc
 
Classes in this File Line Coverage Branch Coverage Complexity
MosaicTilesDaoJdbc
0%
0/17
0%
0/4
1.417
MosaicTilesDaoJdbc$MosaicTileDelete
0%
0/7
N/A
1.417
MosaicTilesDaoJdbc$MosaicTileInsert
0%
0/19
N/A
1.417
MosaicTilesDaoJdbc$MosaicTilesCount
0%
0/5
N/A
1.417
MosaicTilesDaoJdbc$MosaicTilesQuery
0%
0/13
N/A
1.417
 
 1  
 /******************************************************************************
 2  
  * MosaicTileDaoJdbc.java - Implement the Dao interface for the MosaicTiles
 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.SqlFunction;
 22  
 import org.springframework.jdbc.object.SqlUpdate;
 23  
 
 24  
 import com.buckosoft.PicMan.domain.MosaicTile;
 25  
 
 26  
 /** Implement the Dao Interface for the {@link com.buckosoft.PicMan.domain.MosaicTile}s.
 27  
  * @author Dick Balaska
 28  
  * @since 2008/01/21
 29  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/db/MosaicTilesDaoJdbc.java">MosaicTilesDaoJdbc.java</a>
 30  
  */
 31  0
 public class MosaicTilesDaoJdbc implements MosaicTilesDao {
 32  
         private static final boolean DEBUG = false;
 33  0
         protected final Log logger = LogFactory.getLog(getClass());
 34  
 
 35  
         private DataSource ds;
 36  
         
 37  
         /** Set the reference to the JDBC datasource.
 38  
          * @param ds The datasource as configured by Spring.
 39  
          * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/WebContent/WEB-INF/picManDatabase/picManDatabase.xml">picManDatabase.xml</a>
 40  
          */ 
 41  
         public void setDataSource(DataSource ds) {
 42  0
                 this.ds = ds;
 43  0
         }
 44  
 
 45  
         /* (non-Javadoc)
 46  
          * @see com.buckosoft.PicMan.db.MosaicTilesDao#deleteMosaicTiles(int)
 47  
          */
 48  
         public void deleteMosaicTiles(int mid) {
 49  
                 if (DEBUG)
 50  
                         logger.info("deleteMosaicTile: " + mid);
 51  0
                 MosaicTileDelete mtd = new MosaicTileDelete(ds);
 52  0
                 mtd.delete(mid);
 53  
 
 54  0
         }
 55  
 
 56  
         /* (non-Javadoc)
 57  
          * @see com.buckosoft.PicMan.db.MosaicTilesDao#getMosaicTiles(int)
 58  
          */
 59  
         @SuppressWarnings("unchecked")
 60  
         public List<MosaicTile> getMosaicTiles(int mid) {
 61  0
                 if (sql_getMosaicTilesQUERY == null)
 62  0
                         sql_getMosaicTilesQUERY = new MosaicTilesQuery(ds, mid);
 63  
                 if (DEBUG)
 64  
                         logger.info("getMosaicTiles: " + mid);
 65  0
         return(sql_getMosaicTilesQUERY.execute(mid));
 66  
          }
 67  0
         private        MosaicTilesQuery        sql_getMosaicTilesQUERY = null;
 68  
 
 69  
         /* (non-Javadoc)
 70  
          * @see com.buckosoft.PicMan.db.MosaicTilesDao#getTileCount(int)
 71  
          */
 72  
         public int getTileCount(int mid) {
 73  
                 if (DEBUG)
 74  
                         logger.info("getTileCount:");
 75  0
                 if (sql_getTileCountQUERYr == null)
 76  0
                         sql_getTileCountQUERYr = new MosaicTilesCount(ds);
 77  0
                 return(sql_getTileCountQUERYr.run(mid));
 78  
         }
 79  
                 private MosaicTilesCount        sql_getTileCountQUERYr;
 80  
                 
 81  
         /* (non-Javadoc)
 82  
          * @see com.buckosoft.PicMan.db.MosaicTilesDao#storeMosaicTile(com.buckosoft.PicMan.domain.MosaicTile)
 83  
          */
 84  
         public void storeMosaicTile(MosaicTile tile) {
 85  0
                 MosaicTileInsert mti = new MosaicTileInsert(ds);
 86  0
                 mti.insert(tile);
 87  0
         }
 88  
 
 89  
         /////////////////////////////////////////////////////////////////////////////////////
 90  
         /**
 91  
          * <code>MosaicTiles</code> Count Object.
 92  
          */
 93  
         class MosaicTilesCount extends SqlFunction {
 94  
                 
 95  0
                 MosaicTilesCount(DataSource ds) {
 96  0
                         super(ds, "SELECT COUNT(*) from mosaicTiles where mid=?");
 97  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 98  0
                         compile();
 99  0
                 }                
 100  
         }
 101  
 
 102  
 
 103  
         /////////////////////////////////////////////////////////////////////////////////////
 104  
         /**
 105  
          * <code>MosaicTiles</code> Query object.
 106  
          */
 107  
         class MosaicTilesQuery extends MappingSqlQuery {
 108  
 
 109  
 /*                MosaicTilesQuery(DataSource ds) {
 110  
             super(ds, "SELECT * from MosaicTiles");
 111  
             compile();
 112  
         }
 113  
 */
 114  0
                 MosaicTilesQuery(DataSource ds, int mid) {
 115  0
             super(ds, "SELECT * from mosaicTiles where mid = ?");
 116  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 117  0
             compile();
 118  0
         }
 119  
  
 120  
         protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
 121  0
                 MosaicTile mt = new MosaicTile();
 122  0
                 mt.setMid(rs.getInt("mid"));
 123  0
                 mt.setPid(rs.getInt("pid"));
 124  0
                 mt.setX(rs.getInt("x"));
 125  0
                 mt.setY(rs.getInt("y"));
 126  0
                 mt.setWidth(rs.getInt("width"));
 127  0
                 mt.setHeight(rs.getInt("height"));
 128  0
                 return(mt);
 129  
         }
 130  
         }
 131  
 
 132  
         /////////////////////////////////////////////////////////////////////////////////////
 133  
         /**
 134  
          * <code>MosaicTile</code> Delete Object.
 135  
          */
 136  
         protected class MosaicTileDelete extends SqlUpdate {
 137  
                 
 138  
                 /**
 139  
                  * Create a new instance of MosaicTileRemove.
 140  
                  * @param ds the DataSource to use for the delete
 141  
                  */
 142  0
                 protected MosaicTileDelete(DataSource ds) {
 143  0
                         super(ds, "DELETE FROM mosaicTiles WHERE mid = (?)");
 144  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 145  0
                         compile();
 146  0
                 }
 147  
                 
 148  
                 protected void delete(int mid) {
 149  0
                         super.update(mid);
 150  0
                 }
 151  
         }
 152  
 
 153  
         /////////////////////////////////////////////////////////////////////////////////////
 154  
         /**
 155  
          * <code>MosaicTile</code> Insert Object.
 156  
          */
 157  
         protected class MosaicTileInsert extends SqlUpdate {
 158  
                 
 159  
                 /**
 160  
                  * Create a new instance of MosaicTileInsert.
 161  
                  * @param ds the DataSource to use for the insert
 162  
                  */
 163  0
                 protected MosaicTileInsert(DataSource ds) {
 164  0
                         super(ds, "REPLACE INTO mosaicTiles VALUES(?,?,?,?,?,?)");
 165  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 166  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 167  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 168  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 169  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 170  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 171  0
                         compile();
 172  0
                 }
 173  
 
 174  
                 protected void insert(MosaicTile mt) {
 175  0
                         Object[] objs = new Object[] {
 176  0
                                         new Integer(mt.getMid()),
 177  0
                                         new Integer(mt.getPid()),
 178  0
                                         new Integer(mt.getX()),
 179  0
                                         new Integer(mt.getY()),
 180  0
                                         new Integer(mt.getWidth()),
 181  0
                                         new Integer(mt.getHeight()),
 182  
                         };
 183  0
                         super.update(objs);
 184  
                         // retrieveIdentity(owner);
 185  0
                 }
 186  
         }
 187  
         
 188  
 
 189  
 }