-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Multidimensional array mapping
PostPosted: Wed Jul 20, 2005 5:27 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
Hello!!

I need to know something... and i can't find the answer anywhere!!.

Suppose you've got:

bool something[90][90];

and now... suppose that the dimension of this matrix is generated randomly. It's not always 90 x 90.

How can you possibly map this ????

Thanks!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 7:17 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
You'd probably have to create some sort of custom type. How did you want it represented in the database?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 7:26 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
Thanks for your reply!!.

I just don't know. I was thinking, maybe i should store it in a Byte array... all i need is to have the multidimensional array stored. It actually doesn't matter how.

Thanks again!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 11:44 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
mcorleone wrote:
I was thinking, maybe i should store it in a Byte array


If database portability is a concern, be careful with array data types. Some databases don't support array-valued columns. Maybe something like

One idea (not saying it's necessarily a good one, though ;) ):
Code:
ARRAY_ID    INTEGER
ARRAY_INDEX INTEGER
ARRAY_COLS  INTEGER
VALUE       BOOLEAN (or CHAR, or BYTE?)


Since a multidimensional array can be expressed as a one dimensional array, you could do this, and then store the number of columns per row. The schema above isn't quite normalized, since ARRAY_COLS would be repeated a lot, but I'm not sure you'd want to do a separate table.

The mapping here would be... fun, but perhaps not too bad... I'm thinking it would be an indexed list. You could expose your array through a getter (unmapped) that creates it from the list, although it would probably have to have a setter to get changes to the array back in... changing the exposed array directly probably couldn't be transitively persisted. Needless to say, this wouldn't really be mapping the array, but rather mapping a representation of the array to a class that can create a copy of the array for you.

The other option, as was mentioned, of course, would be some type of UserType. I've never done one (as of yet), though, so I don't know how hard/easy it would be.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 11:36 am 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
thanks for your reply!!!

I was thinking some way of serializing the bool[][] matrix... something easier since i don't need to separate the rows and the cols... al i need is to save the [][]object.

If i can't do it with hibernate, perhaps it would be easier to serialize it to a file.

Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 12:09 pm 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
One other idea might be to convert to XML for the database, using something like XStream in a UserType to convert the object to XML and persist as a blob. This does, of course, render the contents of the database column alot less than useful for queries. The advantage being, however, that for n-dimension arrays, it still works without having to change the database structure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 12:38 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Quote:
some way of serializing the bool[][] matrix


well, I suppose since it's a boolean matrix, you could use a numeric type to "contain" the array. Here again, you'd need a UserType or a class with a getArray method that converts the number into the necessary array. Just a different (arguably simpler) way to store the value in the database. Also, I think you'd still need to store the array's dimensions in the row so your type/class would know how to structure the array.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 12:45 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
I appreciate your comments!!!

thank you!!!!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.