ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rusty Wright <rusty.wri...@gmail.com>
Subject Re: best way to use a Map?
Date Mon, 08 Oct 2007 04:09:34 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I've replied to Brandon since this is off topic for this list.<br>
<br>
<br>
Brandon Goodin wrote:
<blockquote
 cite="mid:2fe5ef5b0710070636p3dbed365je9c4f471846c5b73@mail.gmail.com"
 type="cite">Why not just create an ImageSizes table? The ImageSizes
table would contain | id | imageId | width | height | sizeKey |<br>
  <br>
Then you have a 1 to many relationship with your Image and you can use
queryForMap and make the sizeKey (which could be size1, size2, size3,
size4...) the key of the Map.
  <br>
  <br>
Additionally it would be helpful if you posted some of your code. Your
explanation is a bit abstract... an EnumMap?<br>
  <br>
Thanks,<br>
Brandon Goodin<br>
  <br>
  <div><span class="gmail_quote">On 10/6/07, <b
 class="gmail_sendername">
Rusty Wright</b> &lt;<a moz-do-not-send="true"
 href="mailto:rusty.wright@gmail.com">rusty.wright@gmail.com</a>&gt;
wrote:</span>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">
    <div bgcolor="#ffffff" text="#000000">They aren't the available
sizes, but the actual size of each photo, so
each photo could have different dimensions, depending on whether or not
the user cropped it in Photoshop, the size the camera produces, etc.&nbsp;
It's random data that's more or less unique to each photo.&nbsp; The SIZE1,
SIZE2, etc. have within them the maximums; for example, SIZE1 might be
200 maximum width and height, SIZE4 could be 1024.&nbsp; Those are hard
coded in the enum (but I could store them elsewhere):<br>
    <br>
    <tt>public enum PhotoSizeBounds {</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; SIZE0(0), // original photo</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; SIZE1(200),</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; SIZE2(320),</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; SIZE3(640),</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; SIZE4(1024);<br>
    <br>
    </tt><tt>&nbsp;&nbsp;&nbsp; private final int max;<br>
    <br>
    </tt><tt>&nbsp;&nbsp;&nbsp; PhotoSizeBounds(final int _max) {</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; max =
_max;</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; }<br>
    <br>
    </tt><tt>&nbsp;&nbsp;&nbsp; /**</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp; * @return the maximum for this size.</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp; */</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; public int getMax() {</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
(max);</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; }</tt><br>
    <tt>}</tt><br>
    <br>
So when I display a picture at its SIZE1 size, I want its width and
height because this is for a web app and I need those 2 values for the
IMG tag.
    <div><span class="e" id="q_11576a116ab28244_1"><br>
    <br>
Ole Trenner wrote:
    <blockquote type="cite">
      <pre>(sorry if this message is a duplicate)

Rusty Wright wrote:
  </pre>
      <blockquote type="cite">
        <pre>I'm trying to figure out how to set up storing a Map of pairs of
numbers.  I have a Photo object, and it has a Map of the different sizes
in which the Photo is stored on disk.  The map keys are SIZE1, SIZE2,

and SIZE3 (an enum; the map is an EnumMap).  The values in the Map are a
simple object, ImageSize, with width and height fields. Each photo has
its own sizes; no relationships and the widths and heights are
essentially random values.


I'm thinking that in my database, each row for a Photo will have columns
size1_width, size1_height, size2_width, size2_height, etc.  Doesn't
sound too elegant but I can't see any other way.
    
        </pre>
      </blockquote>
      <pre>I'd prefer having a photo table without these sizes and storing them in
a different table with a foreign key relation to the photos table
instead. Something like that:

photos:

photo_id | photo_property_1 | photo_property_2 | ...


sizes:

size_id | photo_id - fk to photos(photo_id) | size_key | width | height

This way a change of the available number of sizes has no influence on
your database scheme.


  </pre>
      <blockquote type="cite">
        <pre>I can't see any way to get these widths and heights into and out of the
database other than to have getters and setters for each one. In order
to not clutter my Photo class with those getters and setters I was

thinking of making a PhotoDto data transfer object that does have the
getters and setters and to wrap a Photo object in that before I send it
off to iBatis.
    </pre>
      </blockquote>
      <pre>When loading the photo objects you could join the photo table and the
sizes table and use the groupBy attribute in the mapping to easily map
the collection property (that is what the sizes map is).

When storing you'd have to stick to two subsequent inserts (one for the

sizes, one for the photo itself.


Just my 2 ct...
Cheers,
Ole.


  </pre>
    </blockquote>
    </span></div>
    </div>
  </blockquote>
  </div>
  <br>
</blockquote>
</body>
</html>

Mime
View raw message