Coverage Report - com.buckosoft.PicMan.db.MosaicBatchesDaoJdbc
 
Classes in this File Line Coverage Branch Coverage Complexity
MosaicBatchesDaoJdbc
0%
0/46
0%
0/14
1.6
MosaicBatchesDaoJdbc$MosaicBatchesCount
0%
0/4
N/A
1.6
MosaicBatchesDaoJdbc$MosaicBatchesInsert
0%
0/12
N/A
1.6
MosaicBatchesDaoJdbc$MosaicBatchesQuery
0%
0/14
N/A
1.6
MosaicBatchesDaoJdbc$MosaicBatchesUpdate
0%
0/11
N/A
1.6
 
 1  
 /******************************************************************************
 2  
  * MosaicBatchesDaoJdbc.java - Implement the Dao interface for the MosaicBatches
 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.Iterator;
 14  
 import java.util.List;
 15  
 
 16  
 import javax.sql.DataSource;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 import org.springframework.jdbc.core.SqlParameter;
 21  
 import org.springframework.jdbc.object.MappingSqlQuery;
 22  
 import org.springframework.jdbc.object.SqlFunction;
 23  
 import org.springframework.jdbc.object.SqlUpdate;
 24  
 
 25  
 import com.buckosoft.PicMan.domain.Mosaic;
 26  
 import com.buckosoft.PicMan.domain.MosaicBatch;
 27  
 
 28  
 /** Implement the Dao Interface for the {@link com.buckosoft.PicMan.domain.MosaicBatch}es.
 29  
  * @author Dick Balaska
 30  
  * @since 2008/09/19
 31  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/db/MosaicBatchesDaoJdbc.java">MosaicBatchesDaoJdbc.java</a>
 32  
  */
 33  0
 public class MosaicBatchesDaoJdbc implements MosaicBatchesDao {
 34  
         private static final boolean DEBUG = true;
 35  0
         protected final Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
         private DataSource                ds;
 38  
         private        MosaicsDao                mosaicsDao;
 39  
         
 40  
         /** Set the reference to the JDBC datasource.
 41  
          * @param ds The datasource as configured by Spring.
 42  
          * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/WebContent/WEB-INF/picManDatabase/picManDatabase.xml">picManDatabase.xml</a>
 43  
          */ 
 44  
         public void setDataSource(DataSource ds) {
 45  0
                 this.ds = ds;
 46  0
         }
 47  
 
 48  
         /** AOP setter for the MosaicsDao
 49  
          * @param mosaicsDao The MosaicsDao from the Spring Database Setup
 50  
          */
 51  
         public void setMosaicsDao(MosaicsDao mosaicsDao) {
 52  0
                 this.mosaicsDao = mosaicsDao;
 53  0
         }
 54  
         /* (non-Javadoc)
 55  
          * @see com.buckosoft.PicMan.db.MosaicBatchesDao#getMosaicBatches()
 56  
          */
 57  
         @SuppressWarnings("unchecked")
 58  
         public List<MosaicBatch> getMosaicBatches() {
 59  
                 if (DEBUG)
 60  0
                         logger.info("GetMosaicBatchesList");
 61  0
                 if (sql_getMosaicBatchesListQUERY == null)
 62  0
                         sql_getMosaicBatchesListQUERY = new MosaicBatchesQuery(ds);
 63  0
                 List<MosaicBatch> list = sql_getMosaicBatchesListQUERY.execute();
 64  0
                 Iterator<MosaicBatch> iter = list.iterator();
 65  0
                 while (iter.hasNext()) {
 66  0
                         MosaicBatch mb = iter.next();
 67  0
                         fillMosaic(mb);
 68  0
                 }
 69  0
                 return(list);
 70  
         }
 71  0
         private        MosaicBatchesQuery        sql_getMosaicBatchesListQUERY = null;
 72  
 
 73  
         /* (non-Javadoc)
 74  
          * @see com.buckosoft.PicMan.db.MosaicBatchesDao#getMosaicBatch(int)
 75  
          */
 76  
         public MosaicBatch getMosaicBatch(int mbid) {
 77  
                 if (DEBUG)
 78  0
                         logger.info("getMosaicBatch: " + mbid);
 79  0
                 if (sql_getMosaicBatchQUERY == null)
 80  0
                         sql_getMosaicBatchQUERY = new MosaicBatchesQuery(ds, mbid);
 81  0
         MosaicBatch mb = (MosaicBatch)sql_getMosaicBatchQUERY.findObject(mbid);
 82  0
         if (mb == null)
 83  0
                 return(null);
 84  0
         return(fillMosaic(mb));
 85  
         }
 86  0
         private        MosaicBatchesQuery        sql_getMosaicBatchQUERY = null;
 87  
 
 88  
         private        MosaicBatch fillMosaic(MosaicBatch mb) {
 89  0
         Mosaic m = this.mosaicsDao.getMosaic(mb.getMid());
 90  0
         mb.setBatch(true);
 91  0
         mb.setName(m.getName());
 92  0
         mb.setEngine(m.getEngine());
 93  0
         mb.setMasterPic(m.getMasterPic());
 94  0
         mb.setOutPic(m.getOutPic());
 95  0
         mb.setSid(m.getSid());
 96  0
         mb.setStartTime(m.getStartTime());
 97  0
         mb.setEngineConfig(m.getEngineConfig());
 98  0
         return(mb);
 99  
         }
 100  
         /* (non-Javadoc)
 101  
          * @see com.buckosoft.PicMan.db.MosaicBatchesDao#storeMosaicBatch(com.buckosoft.PicMan.domain.MosaicBatch)
 102  
          */
 103  
         public void storeMosaicBatch(MosaicBatch mbatch) {
 104  
                 if (DEBUG)
 105  0
                         logger.info("storeMosaic " + mbatch.getMbid());
 106  0
                 this.mosaicsDao.storeMosaic(mbatch);
 107  0
                 assert(mbatch.getMid() != 0);
 108  0
                 if (mbatch.getMbid() <= 0) {
 109  0
                         MosaicBatchesInsert mbi = new MosaicBatchesInsert(ds);
 110  0
                         mbi.insert(mbatch);
 111  0
                 } else {
 112  0
                         MosaicBatchesUpdate mbu = new MosaicBatchesUpdate(ds);
 113  0
                         mbu.update(mbatch);
 114  
                 }
 115  0
         }
 116  
         /* (non-Javadoc)
 117  
          * @see com.buckosoft.PicMan.db.MosaicBatchesDao#deleteMosaicBatch(int)
 118  
          */
 119  
         public void deleteMosaicBatch(int mbid) {
 120  
                 // TODO Auto-generated method stub
 121  
 
 122  0
         }
 123  
 
 124  
         /**
 125  
          * Object to Query for MosaicBatches
 126  
          */
 127  
         private class MosaicBatchesQuery extends MappingSqlQuery {
 128  
                 
 129  0
                 MosaicBatchesQuery(DataSource ds) {
 130  0
                         super(ds, "SELECT * from mosaicBatches");
 131  0
                         compile();
 132  0
                 }
 133  
                 
 134  0
                 MosaicBatchesQuery(DataSource ds, int mbid) {
 135  0
                         super(ds, "SELECT * from mosaicBatches where mbid = ?");
 136  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 137  0
                         compile();
 138  0
                 }
 139  
 
 140  
                 protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
 141  0
                         MosaicBatch mb = new MosaicBatch();
 142  0
                         mb.setMbid(rs.getInt("mbid"));
 143  0
                         mb.setMid(rs.getInt("mid"));
 144  0
                         mb.setSizes(rs.getString("sizes"));
 145  0
                         return(mb);
 146  
                 }
 147  
         }
 148  
         /**
 149  
          * <code>Virgin</code> Count Object.
 150  
          */
 151  
         class MosaicBatchesCount extends SqlFunction {
 152  
                 
 153  0
                 MosaicBatchesCount(DataSource ds) {
 154  0
                         super(ds, "SELECT COUNT(*) from mosaicBatches");
 155  0
                         compile();
 156  0
                 }                
 157  
         }
 158  
 
 159  
         /**
 160  
          * <code>Mosaic</code> Insert Object.
 161  
          */
 162  
         private class MosaicBatchesInsert extends SqlUpdate {
 163  
                 
 164  
                 /**
 165  
                  * Create a new instance of MosaicBatchesInsert.
 166  
                  * @param ds the DataSource to use for the insert
 167  
                  */
 168  0
                 protected MosaicBatchesInsert(DataSource ds) {
 169  0
                         super(ds, "INSERT INTO mosaicBatches VALUES(?,?,?)");
 170  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 171  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 172  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 173  0
                         compile();
 174  0
                 }
 175  
 
 176  
                 protected void insert(MosaicBatch mb) {
 177  0
                         Object[] objs = new Object[] {
 178  
                                 null,
 179  0
                                 new Integer(mb.getMid()), 
 180  0
                                 mb.getSizes()
 181  
                         };
 182  0
                         super.update(objs);
 183  0
                 }
 184  
         }
 185  
         ///////////////////////////////////////////////////////////////////////////////////////////////
 186  
         /**
 187  
          * <code>Mosaic</code> Update Object.
 188  
          */
 189  
         private class MosaicBatchesUpdate extends SqlUpdate {
 190  
                 //private        DataSource        ds;
 191  
                 
 192  
                 /**
 193  
                  * Create a new instance of MosaicBatchesUpdate.
 194  
                  * @param ds the DataSource to use for the update
 195  
                  */
 196  0
                 protected MosaicBatchesUpdate(DataSource ds) {
 197  0
                         super(ds, "UPDATE mosaicBatches SET mid=?, sizes=? WHERE mbid = ? LIMIT 1");
 198  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 199  0
                         declareParameter(new SqlParameter(Types.VARCHAR));
 200  0
                         declareParameter(new SqlParameter(Types.INTEGER));
 201  0
                         compile();
 202  0
                 }
 203  
                 /**
 204  
                  * Method to update the <code>Set</code>'s data.
 205  
                  * @param List sets The sets that should be stored
 206  
                  * @return 0
 207  
                  */
 208  
 
 209  
                 protected int update(MosaicBatch mb) {
 210  0
                         return this.update(new Object[] {
 211  0
                                         new Integer(mb.getMid()),
 212  0
                                         mb.getSizes(),                                         
 213  0
                                         new Integer(mb.getMbid())
 214  
                         });
 215  
                 }
 216  
         }
 217  
 }