ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: best way to use a Map?
Date Sun, 07 Oct 2007 13:36:52 GMT
Why not just create an ImageSizes table? The ImageSizes table would contain
| id | imageId | width | height | sizeKey |

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.

Additionally it would be helpful if you posted some of your code. Your
explanation is a bit abstract... an EnumMap?

Brandon Goodin

On 10/6/07, Rusty Wright <rusty.wright@gmail.com> wrote:
>  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.  It's
> random data that's more or less unique to each photo.  The SIZE1, SIZE2,
> etc. have within them the maximums; for example, SIZE1 might be 200 maximum
> width and height, SIZE4 could be 1024.  Those are hard coded in the enum
> (but I could store them elsewhere):
> public enum PhotoSizeBounds {
>     SIZE0(0), // original photo
>     SIZE1(200),
>     SIZE2(320),
>     SIZE3(640),
>     SIZE4(1024);
>     private final int max;
>     PhotoSizeBounds(final int _max) {
>         max = _max;
>     }
>     /**
>      * @return the maximum for this size.
>      */
>     public int getMax() {
>         return (max);
>     }
> }
> 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.
> Ole Trenner wrote:
> (sorry if this message is a duplicate)
> Rusty Wright wrote:
>  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.
>  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.
>    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.
>  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.

View raw message