| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MosaicVectorsDaoJdbc |
|
| 2.9;2.9 | ||||
| MosaicVectorsDaoJdbc$MosaicVectorInsert |
|
| 2.9;2.9 | ||||
| MosaicVectorsDaoJdbc$MosaicVectorQuery |
|
| 2.9;2.9 |
| 1 | /****************************************************************************** | |
| 2 | * MosaicVectorsDaoJdbc.java - Implement the Dao interface for the MosaicVectors | |
| 3 | * | |
| 4 | * PicMan - The BuckoSoft Picture Manager in Java | |
| 5 | * Copyright(c) 2007 - 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.LinkedList; | |
| 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.SqlUpdate; | |
| 23 | ||
| 24 | import com.buckosoft.PicMan.domain.Pic; | |
| 25 | import com.buckosoft.PicMan.domain.mosaic.MosaicVector; | |
| 26 | ||
| 27 | /** Implement the Dao Interface for the {@link com.buckosoft.PicMan.domain.mosaic.MosaicVector}s. | |
| 28 | * @author Dick Balaska | |
| 29 | * @since 2007/12/14 | |
| 30 | * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/db/MosaicVectorsDaoJdbc.java">MosaicVectorsDaoJdbc.java</a> | |
| 31 | */ | |
| 32 | 0 | public class MosaicVectorsDaoJdbc implements MosaicVectorsDao { |
| 33 | private static final boolean DEBUG = true; | |
| 34 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 35 | ||
| 36 | ||
| 37 | private DataSource ds; | |
| 38 | ||
| 39 | private String replaceString; | |
| 40 | ||
| 41 | /** Set the reference to the JDBC datasource. | |
| 42 | * @param ds The datasource as configured by Spring. | |
| 43 | * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/WebContent/WEB-INF/picManDatabase/picManDatabase.xml">picManDatabase.xml</a> | |
| 44 | */ | |
| 45 | public void setDataSource(DataSource ds) { | |
| 46 | 0 | this.ds = ds; |
| 47 | 0 | } |
| 48 | ||
| 49 | 0 | public MosaicVectorsDaoJdbc() { |
| 50 | 0 | StringBuilder sb = new StringBuilder(); |
| 51 | 0 | sb.append("REPLACE INTO mosaicVectors (pid"); |
| 52 | int d; | |
| 53 | int x; | |
| 54 | int y; | |
| 55 | 0 | for (d=1; d<=MosaicVector.MAXDEPTH; d++) { |
| 56 | 0 | for (x=0; x<d; x++) { |
| 57 | 0 | for (y=0; y<d; y++) { |
| 58 | 0 | sb.append(",c"); |
| 59 | 0 | sb.append(d); |
| 60 | 0 | sb.append("_"); |
| 61 | 0 | sb.append(x); |
| 62 | 0 | sb.append("_"); |
| 63 | 0 | sb.append(y); |
| 64 | } | |
| 65 | } | |
| 66 | } | |
| 67 | 0 | sb.append(") VALUES (?"); |
| 68 | 0 | for (d=1; d<=MosaicVector.MAXDEPTH; d++) { |
| 69 | 0 | for (y=0; y<d; y++) { |
| 70 | 0 | for (x=0; x<d; x++) { |
| 71 | 0 | sb.append(",?"); |
| 72 | } | |
| 73 | } | |
| 74 | } | |
| 75 | 0 | sb.append(")"); |
| 76 | 0 | replaceString = sb.toString(); |
| 77 | if (DEBUG) | |
| 78 | 0 | logger.info(replaceString); |
| 79 | 0 | } |
| 80 | /* (non-Javadoc) | |
| 81 | * @see com.buckosoft.PicMan.db.MosaicVectorsDao#getMosaicVector(java.lang.String) | |
| 82 | */ | |
| 83 | public MosaicVector getMosaicVector(String pic) { | |
| 84 | // TODO Auto-generated method stub | |
| 85 | 0 | return null; |
| 86 | } | |
| 87 | ||
| 88 | /* (non-Javadoc) | |
| 89 | * @see com.buckosoft.PicMan.db.MosaicVectorsDao#updateMosaicVector(com.buckosoft.PicMan.domain.MosaicVector) | |
| 90 | */ | |
| 91 | public void updateMosaicVector(MosaicVector mv) { | |
| 92 | 0 | if (sql_storeMosaicVectorINSERT == null) |
| 93 | 0 | sql_storeMosaicVectorINSERT = new MosaicVectorInsert(ds); |
| 94 | 0 | sql_storeMosaicVectorINSERT.insert(mv); |
| 95 | 0 | } |
| 96 | 0 | private MosaicVectorInsert sql_storeMosaicVectorINSERT = null; |
| 97 | ||
| 98 | ||
| 99 | /* (non-Javadoc) | |
| 100 | * @see com.buckosoft.PicMan.db.MosaicVectorsDao#getMosaicVectors(java.util.List) | |
| 101 | */ | |
| 102 | public List<MosaicVector> getMosaicVectors(List<Pic> picList) { | |
| 103 | 0 | LinkedList<MosaicVector> list = new LinkedList<MosaicVector>(); |
| 104 | ||
| 105 | 0 | return(list); |
| 106 | } | |
| 107 | ||
| 108 | /////////////////////////////////////////////////////////////////////////// | |
| 109 | class MosaicVectorQuery extends MappingSqlQuery { | |
| 110 | ||
| 111 | 0 | MosaicVectorQuery(DataSource ds) { |
| 112 | 0 | super(ds, "SELECT * from mosaicVectors"); |
| 113 | 0 | compile(); |
| 114 | 0 | } |
| 115 | ||
| 116 | 0 | MosaicVectorQuery(DataSource ds, int pid) { |
| 117 | 0 | super(ds, "SELECT * from mosaicVectors WHERE pid = ?"); |
| 118 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 119 | 0 | compile(); |
| 120 | 0 | } |
| 121 | ||
| 122 | ||
| 123 | protected Object mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 124 | 0 | MosaicVector mv = new MosaicVector(); |
| 125 | 0 | mv.pid = rs.getInt("pid"); |
| 126 | 0 | mv.rgb = rs.getInt("c1_0_0"); |
| 127 | int x,y,z; | |
| 128 | 0 | z = 2; |
| 129 | 0 | for (x=0; x<z; x++) { |
| 130 | 0 | for (y=0; y<z; y++) { |
| 131 | 0 | mv.rgb2[x][y] = rs.getInt("c2_" + x + "_" + "y"); |
| 132 | } | |
| 133 | } | |
| 134 | 0 | z = 3; |
| 135 | 0 | for (x=0; x<z; x++) { |
| 136 | 0 | for (y=0; y<z; y++) { |
| 137 | 0 | mv.rgb3[x][y] = rs.getInt("c3_" + x + "_" + "y"); |
| 138 | } | |
| 139 | } | |
| 140 | 0 | return(mv); |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | ||
| 145 | /** | |
| 146 | * <code>MosaicVector</code> Insert Object. | |
| 147 | */ | |
| 148 | protected class MosaicVectorInsert extends SqlUpdate { | |
| 149 | ||
| 150 | /** | |
| 151 | * Create a new instance of MetaSetInsert. | |
| 152 | * @param ds the DataSource to use for the insert | |
| 153 | */ | |
| 154 | 0 | protected MosaicVectorInsert(DataSource ds) { |
| 155 | 0 | super(ds, replaceString); |
| 156 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 157 | int d; | |
| 158 | int x; | |
| 159 | int y; | |
| 160 | 0 | for (d=1; d<=MosaicVector.MAXDEPTH; d++) { |
| 161 | 0 | for (y=0; y<d; y++) { |
| 162 | 0 | for (x=0; x<d; x++) { |
| 163 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 164 | } | |
| 165 | } | |
| 166 | } | |
| 167 | 0 | compile(); |
| 168 | 0 | } |
| 169 | ||
| 170 | protected void insert(MosaicVector mv) { | |
| 171 | 0 | LinkedList<Object> ll = new LinkedList<Object>(); |
| 172 | 0 | ll.add(new Integer(mv.pid)); |
| 173 | 0 | ll.add(new Integer(mv.rgb)); |
| 174 | int x; | |
| 175 | int y; | |
| 176 | 0 | for (y=0; y<2; y++) { |
| 177 | 0 | for (x=0; x<2; x++) { |
| 178 | 0 | ll.add(new Integer(mv.rgb2[x][y])); |
| 179 | } | |
| 180 | } | |
| 181 | 0 | for (y=0; y<3; y++) { |
| 182 | 0 | for (x=0; x<3; x++) { |
| 183 | 0 | ll.add(new Integer(mv.rgb3[x][y])); |
| 184 | } | |
| 185 | } | |
| 186 | ||
| 187 | ||
| 188 | 0 | Object[] objs = ll.toArray(); |
| 189 | 0 | super.update(objs); |
| 190 | // retrieveIdentity(owner); | |
| 191 | 0 | } |
| 192 | } | |
| 193 | ||
| 194 | } |